/* ===== BASE STYLES ===== */
* {
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    color: #e5e5e5;
    font-family: 'Roboto Serif', serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    /* Prevent layout shifts during font loading */
    font-display: swap;
}

/* ===== APP LAYOUT ===== */
.app {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
}

/* ===== HEADER ===== */
.top-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 20px 24px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    max-width: 1500px;
    margin: 0 auto;
    border-bottom: 1px solid #333;
    background: #1a1a1a;
}

.main-logo {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.025em;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
}

button.new-chat-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 12px !important;
    background: #2a2a2a !important;
    background-color: #2a2a2a !important;
    border: 1px solid #404040 !important;
    border-radius: 8px !important;
    color: #e5e5e5 !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    min-width: 44px !important;
    height: 36px !important;
    outline: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
}

button.new-chat-btn:hover {
    background: #3a3a3a !important;
    background-color: #3a3a3a !important;
    border-color: #505050 !important;
}

button.new-chat-btn:active {
    background: #333 !important;
    background-color: #333 !important;
    transform: scale(0.98) !important;
}

button.new-chat-btn svg {
    color: #e5e5e5 !important;
}

.header-model-selector {
    position: relative;
}

.main-content {
    max-width: 770px; /* Match input box width for consistency */
    margin: 0 auto;
    padding: 80px 24px 140px;
    flex: 1;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    /* Prevent width jumping */
    width: 100%;
    min-width: 0;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 60vh;
}

.welcome-message {
    text-align: center;
    margin: 0 auto;
    color: #9ca3af;
    max-width: 480px;
    padding: 60px 20px;
    box-sizing: border-box;
}

.welcome-icon {
    margin-bottom: 24px;
    display: flex;
    justify-content: center;
}

.welcome-icon svg {
    color: #3b82f6;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.welcome-message h3 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #e5e5e5;
    letter-spacing: -0.025em;
}

.welcome-message p {
    font-size: 16px;
    color: #9ca3af;
    line-height: 1.6;
    margin: 0;
}

/* ===== CHAT MESSAGES ===== */
.messages {
    flex: 1 !important;
    padding: 20px 24px !important;
    min-height: 400px !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    background: #1a1a1a !important;
    position: relative !important; /* Ensure normal positioning */
}

.message {
    width: 100% !important;
    display: flex !important;
    margin-bottom: 16px !important;
    min-height: 40px !important; /* Ensure minimum height */
    position: static !important; /* Force normal positioning */
    float: none !important; /* Clear any floats */
}

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

.message.bot {
    justify-content: flex-start !important;
}

.message-content {
    display: block;
    min-width: 120px;
    max-width: 100%; /* Increased from 70% to 85% to use more of the wider chat area */
    padding: 12px 16px;
    border-radius: 18px;
    font-family: 'Roboto Serif', serif;
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
    box-sizing: border-box;
    position: relative;
    background: #2a2a2a;
    color: #e5e5e5;
}

/* User message bubbles - right side with different color */
.message.user .message-content {
    background: #3b82f6;
    color: #ffffff;
}

/* Bot message bubbles - left side with default dark color */
.message.bot .message-content {
    background: #2a2a2a;
    color: #e5e5e5;
}

.message-time {
    font-size: 11px;
    color: #8E8E93;
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px solid rgba(142, 142, 147, 0.2);
}

/* ===== MARKDOWN STYLING IN CHAT BUBBLES ===== */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 8px 0 4px 0;
    font-weight: 600;
    color: inherit;
}

.message-content h1 { font-size: 1.4em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.2em; }

.message-content p {
    margin: 4px 0;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 8px;
    border-radius: 6px;
    margin: 8px 0;
    overflow-x: auto;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content blockquote {
    border-left: 3px solid rgba(255, 255, 255, 0.3);
    margin: 8px 0;
    padding-left: 12px;
    opacity: 0.8;
}

.message-content ul,
.message-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 2px 0;
}

.message-content strong,
.message-content b {
    font-weight: 700 !important;
    font-family: "Roboto Serif", serif !important;
}

.message-content em,
.message-content i {
    font-style: italic !important;
    font-family: "Roboto Serif", serif !important;
}

/* Math expression styling */
.message-content .math-inline {
    background-color: rgba(255, 255, 255, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
    color: #f8f8f2;
}

.message-content .math-block {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 8px 0;
    text-align: center;
    color: #f8f8f2;
    overflow-x: auto;
}

/* Boxed equations - add border around the entire math block */
.message-content .math-boxed {
    border: 2px solid #4a9eff !important;
    background-color: rgba(74, 158, 255, 0.1) !important;
}

/* Custom boxed equation styling (fallback) */
.message-content .katex-boxed {
    border: 2px solid #f8f8f2;
    padding: 8px 12px;
    border-radius: 4px;
    display: inline-block;
}

.message-content a {
    color: #60a5fa;
    text-decoration: underline;
}

.message.user .message-content a {
    color: #bfdbfe;
}

/* ===== INPUT AREA ===== */
.input-area {
    padding: 24px;
    background-color: #1a1a1a;
    border-top: 1px solid #333;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-sizing: border-box;
}

.input-container {
    max-width: 700px; /* Reasonable input width */
    margin: 0 auto;
    box-sizing: border-box;
}

/* ===== MODEL SELECTOR ===== */
.model-selector-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #2a2a2a;
    border: 1px solid #404040;
    border-radius: 8px;
    color: #e5e5e5;
    font-size: 14px;
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
    justify-content: space-between;
    position: relative;
}

.model-selector-btn:hover {
    background: #3a3a3a;
    border-color: #505050;
}

.model-name {
    color: #e5e5e5;
    flex: 1;
}

.model-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: #2a2a2a;
    border: 1px solid #404040;
    border-radius: 8px;
    padding: 8px;
    min-width: 280px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.model-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.model-option {
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-bottom: 4px;
    width: 100%;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.model-option:last-child {
    margin-bottom: 0;
}

.model-option:hover,
.model-option.active {
    background: #3a3a3a;
}

.model-option-name {
    font-weight: 500;
    color: #e5e5e5;
    margin-bottom: 2px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.model-option-desc {
    font-size: 12px;
    color: #9ca3af;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ===== INPUT WRAPPER ===== */
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background-color: #2a2a2a;
    border: 1px solid #404040;
    border-radius: 12px;
    padding: 12px 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

.input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    color: #e5e5e5;
    font-size: 18px;
    line-height: 1.5;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
    font-family: 'Roboto Serif', serif;
    width: 100%;
    box-sizing: border-box;
}

#messageInput::placeholder {
    color: #9ca3af;
}

.send-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background-color: #3b82f6;
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:disabled {
    background-color: #4b5563;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background-color: #2563eb;
    transform: none;
}

.input-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
    width: 100%;
}

.char-count {
    font-size: 12px;
    color: #9ca3af;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1024px) {
    .top-header {
        padding: 16px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: center;
        max-width: none;
        margin: 0;
    }

    .main-content {
        padding: 100px 16px 0;
        max-width: 700px; /* Match input-container width in responsive */
    }

    .messages {
        padding: 16px;
        min-height: 300px;
    }

    .input-area {
        padding: 16px;
    }

    .input-container {
        max-width: 700px; /* Match main-content width in responsive */
    }

    .main-logo {
        font-size: 20px;
    }

    .model-dropdown {
        right: 50%;
        transform: translateX(50%) translateY(-10px);
    }

    .model-dropdown.show {
        transform: translateX(50%) translateY(0);
    }
}

@media (max-width: 480px) {
    .top-header {
        padding: 12px 12px;
    }

    .main-content {
        padding: 90px 12px 0;
    }

    .main-logo {
        font-size: 18px;
    }

    .messages {
        min-height: 250px;
        padding: 12px;
    }

    .message-content {
        min-width: 100px;
        max-width: 85%;
    }
}

/* ===== SCROLLBAR STYLES ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ===== ALTERNATIVE: FLOAT-BASED LAYOUT ===== */
/*
.message {
    width: 100%;
    overflow: hidden;           // Clear floats
    margin-bottom: 16px;
}

.message.user {
    text-align: right;
}

.message.bot {
    text-align: left;
}

.message-content {
    display: inline-block;
    max-width: 70%;
    float: right;               // For user messages
}

.message.bot .message-content {
    float: left;                // Override for bot messages
}
*/

/* ===== ALTERNATIVE: POSITION-BASED LAYOUT ===== */
/*
.message {
    position: relative;
    width: 100%;
    margin-bottom: 16px;
    min-height: 40px;
}

.message.user .message-content {
    position: absolute;
    right: 0;
}

.message.bot .message-content {
    position: absolute;
    left: 0;
}
*/

/* ===== ALTERNATIVE: GRID-BASED LAYOUT ===== */
/*
.message {
    display: grid;
    width: 100%;
    margin-bottom: 16px;
}

.message.user {
    grid-template-columns: 1fr auto;  // Right-aligned
}

.message.bot {
    grid-template-columns: auto 1fr;   // Left-aligned
}

.message-content {
    grid-column: 2;  // User: column 2 (right)
}

.message.bot .message-content {
    grid-column: 1;  // Bot: column 1 (left)
}
*/

/* ===== ALTERNATIVE: TABLE-BASED LAYOUT ===== */
/*
.message {
    display: table;
    width: 100%;
    margin-bottom: 16px;
}

.message.user {
    text-align: right;
}

.message.bot {
    text-align: left;
}

.message-content {
    display: table-cell;
    max-width: 70%;
}
*/

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

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    color: #9ca3af;
}

.typing-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: #9ca3af;
    animation: typing 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-3px);
    }
}
