/* ChatGPT-inspired Dark Mode Styling */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background-color: #343541;
    color: #ECECF1;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
}

/* Initial state: centered layout */
.container.initial-state {
    justify-content: center;
    align-items: center;
}

/* Header */
.header {
    padding: 20px;
    text-align: center;
    background-color: #343541;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Hide header after first message */
.header.hidden {
    display: none;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
    color: #ECECF1;
}

/* Chat Container */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

/* Initially hidden chat container */
.container.initial-state #chat-container {
    display: none;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 20px;
    margin-bottom: 30px;
    color: #9B9BA5;
    font-size: 16px;
}

/* Message Bubbles */
.message {
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message.assistant {
    display: flex;
    justify-content: flex-start;
}

.message-content {
    max-width: 80%;
    padding: 16px;
    border-radius: 12px;
    position: relative;
}

.message.user .message-content {
    background-color: #40414F;
    color: #ECECF1;
}

.message.assistant .message-content {
    background-color: #444654;
    color: #ECECF1;
}

.message-text {
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Links in messages */
.message-text a {
    color: #19C37D;
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

/* Sources */
.sources {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #565869;
}

.sources-title {
    font-size: 12px;
    font-weight: 600;
    color: #9B9BA5;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-item {
    margin-bottom: 8px;
    font-size: 14px;
    padding: 8px;
    background-color: #40414F;
    border-radius: 6px;
    border-left: 3px solid #19C37D;
}

.source-date {
    color: #9B9BA5;
    font-size: 12px;
}

.source-author {
    color: #ECECF1;
    font-size: 13px;
    margin: 4px 0;
}

.source-link {
    display: inline-block;
    margin-top: 4px;
}

.source-link a {
    color: #19C37D;
    text-decoration: none;
    font-size: 13px;
}

.source-link a:hover {
    text-decoration: underline;
}

.source-score {
    color: #9B9BA5;
    font-size: 11px;
    margin-left: 8px;
}

/* Copy Button (in message bubbles) */
.message-content .copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: #40414F;
    border: 1px solid #565869;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    color: #9B9BA5;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
}

.message-content:hover .copy-button {
    opacity: 1;
}

.message-content .copy-button:hover {
    background-color: #565869;
    color: #ECECF1;
}

.message-content .copy-button.copied {
    color: #19C37D;
}

/* Input Container */
.input-container {
    padding: 20px;
    background-color: #343541;
    border-top: 1px solid #565869;
    transition: all 0.3s ease;
}

/* Initial state: centered input, no border */
.container.initial-state .input-container {
    border-top: none;
    width: 100%;
    max-width: 700px;
}

.input-wrapper {
    display: flex;
    align-items: flex-start;
    background-color: #40414F;
    border-radius: 12px;
    padding: 12px;
    border: 1px solid #565869;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: #19C37D;
}

#question-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #ECECF1;
    font-size: 16px;
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
    vertical-align: top;
    padding: 0;
}

#question-input::placeholder {
    color: #9B9BA5;
}

.send-button {
    background-color: #19C37D;
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 12px;
    transition: background-color 0.2s, transform 0.1s;
    flex-shrink: 0;
    color: #FFFFFF;
}

.send-button:hover {
    background-color: #16A368;
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    background-color: #565869;
    cursor: not-allowed;
    opacity: 0.5;
}

.input-footer {
    display: flex;
    justify-content: center;
    margin-top: 12px;
}

.rate-limit-info {
    font-size: 12px;
    color: #9B9BA5;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(52, 53, 65, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    border: 4px solid #565869;
    border-top: 4px solid #19C37D;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error Messages */
.error-message {
    background-color: #F44336;
    color: #FFFFFF;
    padding: 16px;
    border-radius: 12px;
    margin: 12px 0;
    text-align: center;
}

/* Scrollbar Styling */
#chat-container::-webkit-scrollbar {
    width: 8px;
}

#chat-container::-webkit-scrollbar-track {
    background: #343541;
}

#chat-container::-webkit-scrollbar-thumb {
    background: #565869;
    border-radius: 4px;
}

#chat-container::-webkit-scrollbar-thumb:hover {
    background: #6B6C7B;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
    }

    .header h1 {
        font-size: 20px;
    }

    .message-content {
        max-width: 90%;
    }

    .input-container {
        padding: 12px;
    }

    .share-button {
        top: 12px;
        right: 12px;
        font-size: 13px;
        padding: 8px 14px;
    }

    .modal-content {
        margin: 20px;
        max-width: calc(100% - 40px);
    }
}

/* Share button */
.share-button {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #40414F;
    color: #ECECF1;
    border: 1px solid #565869;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    z-index: 100;
}

.share-button:hover {
    background-color: #4e4f5f;
    border-color: #6e6f7f;
}

.share-button svg {
    flex-shrink: 0;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    background-color: #343541;
    border-radius: 12px;
    padding: 0;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 1001;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #565869;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #ECECF1;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #ECECF1;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: #40414F;
}

.modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ECECF1;
    font-size: 14px;
    cursor: pointer;
}

.form-group input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.form-group input[type="password"],
.form-group input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    background-color: #40414F;
    border: 1px solid #565869;
    border-radius: 6px;
    color: #ECECF1;
    font-size: 14px;
    font-family: inherit;
}

.form-group input[type="password"]:focus,
.form-group input[type="text"]:focus {
    outline: none;
    border-color: #10A37F;
}

.generate-button {
    width: 100%;
    padding: 12px;
    background-color: #10A37F;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.generate-button:hover {
    background-color: #0d8c6d;
}

.share-link-display {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #565869;
}

.share-link-display label {
    display: block;
    margin-bottom: 8px;
    color: #ECECF1;
    font-size: 14px;
    font-weight: 500;
}

.link-input-group {
    display: flex;
    gap: 8px;
}

.link-input-group input {
    flex: 1;
    padding: 10px 12px;
    background-color: #40414F;
    border: 1px solid #565869;
    border-radius: 6px;
    color: #ECECF1;
    font-size: 13px;
    font-family: monospace;
}

.link-input-group .copy-button {
    position: relative;  /* Override absolute positioning from .message-content .copy-button */
    padding: 10px 16px;
    background-color: #40414F;
    color: #ECECF1;
    border: 1px solid #565869;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    opacity: 1;  /* Ensure it's always visible, not hidden like message copy buttons */
}

.link-input-group .copy-button:hover {
    background-color: #4e4f5f;
    border-color: #6e6f7f;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #40414F;
    color: #ECECF1;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    animation: slideUp 0.3s ease;
}

.toast.hidden {
    display: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}
