/* ===== ROOT VARIABLES ===== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #10b981;
    --accent: #f59e0b;
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-card: #1e1e3f;
    --bg-hover: #252550;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #2d2d5a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --sidebar-width: 280px;
    --sidebar-collapsed: 0px;
    --header-height: 60px;
    --input-height: 80px;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ===== APP CONTAINER ===== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 100;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 28px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.logo-text {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.new-chat-btn span {
    font-size: 18px;
    font-weight: 300;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-list-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.empty-chats {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--primary);
}

.chat-item-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.chat-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: var(--transition);
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.chat-item-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.guest-prompt {
    text-align: center;
}

.guest-prompt p {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.login-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.login-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.logout-btn:hover {
    color: #ef4444;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

/* ===== CHAT HEADER ===== */
.chat-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    z-index: 50;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.model-selector {
    position: relative;
    flex: 1;
}

.model-select-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.model-select-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.model-icon {
    font-size: 16px;
}

.model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    display: none;
    overflow: hidden;
    z-index: 1000;
}

.model-dropdown.show {
    display: block;
    animation: dropdownSlide 0.2s ease;
}

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

.model-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
}

.model-option:last-child {
    border-bottom: none;
}

.model-option:hover {
    background: var(--bg-hover);
}

.model-option.selected {
    background: var(--bg-hover);
    border-left: 3px solid var(--primary);
}

.model-option-icon {
    font-size: 18px;
}

.model-option-info {
    flex: 1;
}

.model-option-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.model-option-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ===== CHAT CONTAINER ===== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

/* ===== WELCOME SCREEN ===== */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 20px;
}

.welcome-content {
    max-width: 800px;
    width: 100%;
    text-align: center;
}

.welcome-logo {
    margin-bottom: 40px;
}

.welcome-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-logo h1 {
    font-size: 42px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Stats Row - Matching LMT Academy */
.stats-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    min-width: 140px;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.stat-icon {
    font-size: 28px;
}

.stat-number {
    font-size: 28px;
    font-weight: 800;
    color: var(--primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Suggestions */
.suggestions {
    margin-top: 20px;
}

.suggestions-title {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.suggestion-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
}

.suggestion-card:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.suggestion-icon {
    font-size: 24px;
    flex-shrink: 0;
}

/* ===== MESSAGES AREA ===== */
.messages-area {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    min-height: 100%;
}

.message-wrapper {
    display: flex;
    gap: 12px;
    padding: 20px 0;
    border-bottom: 1px solid var(--border-color);
    animation: messageSlide 0.3s ease;
}

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

.message-wrapper.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
}

.message-wrapper.user .message-avatar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: var(--primary);
}

.message-wrapper.assistant .message-avatar {
    background: linear-gradient(135deg, var(--secondary), #059669);
    border-color: var(--secondary);
}

.message-content {
    flex: 1;
    max-width: calc(100% - 60px);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.message-author {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.message-model {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
}

.message-body {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
}

.message-body p {
    margin-bottom: 12px;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-body code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
}

.message-body p code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary-light);
}

.message-body ul, .message-body ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-body li {
    margin-bottom: 6px;
}

.message-body h1, .message-body h2, .message-body h3 {
    margin: 20px 0 12px;
    color: var(--text-primary);
}

.message-body blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
}

.message-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.message-body th, .message-body td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.message-body th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: var(--transition);
}

.message-wrapper:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    transition: var(--transition);
}

.message-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== INPUT AREA ===== */
.input-area {
    padding: 16px 20px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 50;
}

.input-wrapper {
    max-width: 900px;
    margin: 0 auto;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 12px 16px;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    outline: none;
    line-height: 1.5;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
    animation: modalFade 0.3s ease;
}

@keyframes modalFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 32px 32px 16px;
    text-align: center;
}

.modal-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-header p {
    font-size: 14px;
    color: var(--text-secondary);
}

.modal-body {
    padding: 16px 32px;
}

.modal-info {
    font-size: 14px;
    color: var(--text-secondary);
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-footer {
    padding: 16px 32px 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.google-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    background: linear-gradient(135deg, #4285f4, #34a853);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
}

.google-login-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.modal-close {
    padding: 12px 24px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 35, 0.8);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner p {
    color: var(--text-secondary);
    font-size: 14px;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: block;
    }

    .stats-row {
        gap: 12px;
    }

    .stat-card {
        padding: 16px 20px;
        min-width: 100px;
    }

    .stat-number {
        font-size: 22px;
    }

    .welcome-logo h1 {
        font-size: 32px;
    }

    .suggestion-cards {
        grid-template-columns: 1fr;
    }

    .messages-area {
        padding: 12px;
    }

    .message-wrapper {
        padding: 12px 0;
    }

    .input-area {
        padding: 12px 16px 16px;
    }
}

@media (max-width: 480px) {
    .stat-card {
        padding: 12px 16px;
        min-width: 80px;
    }

    .stat-number {
        font-size: 18px;
    }

    .stat-label {
        font-size: 11px;
    }

    .welcome-logo h1 {
        font-size: 28px;
    }

    .welcome-subtitle {
        font-size: 14px;
    }
}

/* ===== SELECTION ===== */
::selection {
    background: var(--primary);
    color: white;
}
