/* Multi-Model AI Platform - Styles */

/* =============================================================================
   CSS VARIABLES
   ============================================================================= */

:root {
    /* Dark Theme (default) */
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-hover: #3a3a3a;

    --text-primary: #ececf1;
    --text-secondary: #c5c5d2;
    --text-tertiary: #8e8ea0;

    --border-primary: #3e3e4e;
    --border-secondary: #2a2a2a;

    --accent-primary: #10a37f;
    --accent-hover: #0d8c6d;
    --accent-light: rgba(16, 163, 127, 0.1);

    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;

    --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 25px rgba(0, 0, 0, 0.5);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --sidebar-width: 280px;
    --header-height: 56px;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-hover: #e5e7eb;

    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;

    --border-primary: #e5e7eb;
    --border-secondary: #d1d5db;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* =============================================================================
   RESET & BASE
   ============================================================================= */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
}

/* =============================================================================
   LOADING SCREEN
   ============================================================================= */

.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-logo {
    width: 64px;
    height: 64px;
    background: var(--accent-primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    animation: pulse 1.5s ease-in-out infinite;
}

.loading-logo span {
    color: white;
    font-size: 24px;
    font-weight: 700;
}

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

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

/* =============================================================================
   APP CONTAINER
   ============================================================================= */

.app-container {
    display: grid;
    grid-template-areas:
        "header header"
        "sidebar main";
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* =============================================================================
   HEADER
   ============================================================================= */

.app-header {
    grid-area: header;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

/* Vertical divider line extending through header - matches sidebar border */
.app-header::after {
    content: '';
    position: absolute;
    left: calc(var(--sidebar-width) - 1px);
    top: 0;
    bottom: -1px;
    width: 1px;
    background: var(--border-primary);
    z-index: 1;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.header-left .app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-left .app-logo i {
    width: 20px;
    height: 20px;
    color: var(--accent-primary);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
}

.header-center {
    position: absolute;
    left: var(--sidebar-width);
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
}

.header-center > * {
    pointer-events: auto;
}

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

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

.model-selector-btn i {
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 1;
}

.header-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.header-icon-btn i {
    width: 20px;
    height: 20px;
}

/* =============================================================================
   MODEL SELECTOR POPUP
   ============================================================================= */

.model-selector-popup {
    position: fixed;
    top: var(--header-height);
    left: calc(var(--sidebar-width) + (100% - var(--sidebar-width)) / 2);
    transform: translateX(-50%);
    width: 400px;
    max-width: calc(100vw - var(--sidebar-width) - 48px);
    max-height: 70vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.model-selector-popup.active {
    display: flex;
}

.model-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-primary);
    font-weight: 600;
}

.model-popup-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
}

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

.model-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-primary);
}

.model-search input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
}

.model-search input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.model-search input::placeholder {
    color: var(--text-tertiary);
}

.model-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

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

.model-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    padding: 8px 12px;
}

.model-option {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.model-option.selected {
    background: var(--accent-light);
    border: 1px solid var(--accent-primary);
}

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

.model-option-description {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* =============================================================================
   SIDEBAR
   ============================================================================= */

.sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

/* App logo in sidebar (legacy - now in header) */
.sidebar .app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.sidebar .app-logo i {
    width: 24px;
    height: 24px;
    color: var(--accent-primary);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.new-chat-btn:hover {
    background: var(--accent-hover);
}

.new-chat-btn i {
    width: 18px;
    height: 18px;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: 4px;
}

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

.conversation-item.active {
    background: var(--bg-tertiary);
}

.conversation-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
}

.conversation-icon i {
    width: 16px;
    height: 16px;
}

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

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

.conversation-preview {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-delete {
    display: none;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
}

.conversation-item:hover .conversation-delete {
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-delete:hover {
    background: var(--error);
    color: white;
}

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

.clear-all-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    background: none;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.clear-all-btn:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.clear-all-btn i {
    width: 16px;
    height: 16px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* =============================================================================
   CHAT AREA
   ============================================================================= */

.chat-area {
    grid-area: main;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 100px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-tertiary);
}

.empty-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 50%;
    margin-bottom: 16px;
}

.empty-icon i {
    width: 32px;
    height: 32px;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-tertiary);
}

/* Message Styles */
.message {
    max-width: 800px;
    margin: 0 auto 24px;
    animation: fadeIn 0.2s ease;
}

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

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

.message-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
}

.message.user .message-avatar {
    background: var(--accent-primary);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

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

.message-content {
    padding-left: 44px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

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

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

/* Code Blocks */
.message-content pre {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-content code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 13px;
}

.message-content :not(pre) > code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* Scroll to Bottom */
.scroll-to-bottom {
    position: absolute;
    bottom: 140px;
    right: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all 0.15s ease;
    z-index: 10;
}

.scroll-to-bottom:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.scroll-to-bottom i {
    width: 20px;
    height: 20px;
}

/* =============================================================================
   CHAT INPUT
   ============================================================================= */

.chat-input-container {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: border-color 0.15s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-primary);
}

.chat-input-wrapper textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    outline: none;
}

.chat-input-wrapper textarea::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
}

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

.send-btn i {
    width: 16px;
    height: 16px;
}

.input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 800px;
    margin: 8px auto 0;
    padding: 0 4px;
}

.model-indicator {
    font-size: 12px;
    color: var(--text-tertiary);
}

.token-count {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* =============================================================================
   MODAL
   ============================================================================= */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
}

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

.modal-body {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.settings-intro {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.api-key-section {
    margin-bottom: 16px;
}

.api-key-section label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.api-key-section input {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: 'SF Mono', Monaco, monospace;
}

.api-key-section input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.api-key-section input::placeholder {
    color: var(--text-tertiary);
    font-family: inherit;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
}

.btn {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-primary {
    background: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* =============================================================================
   STREAMING INDICATOR
   ============================================================================= */

.streaming-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.streaming-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: streamingPulse 1.4s ease-in-out infinite;
}

.streaming-dot:nth-child(2) { animation-delay: 0.2s; }
.streaming-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes streamingPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* =============================================================================
   MOBILE RESPONSIVE
   ============================================================================= */

@media (max-width: 768px) {
    .app-container {
        grid-template-areas:
            "header"
            "main";
        grid-template-columns: 1fr;
    }

    .header-left .app-logo span {
        display: none;
    }

    .header-center {
        position: static;
        transform: none;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-container {
        padding: 12px 16px 20px;
    }

    .message-content {
        padding-left: 0;
    }

    .message-avatar {
        display: none;
    }

    .model-selector-popup {
        top: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* =============================================================================
   SCROLLBAR
   ============================================================================= */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 4px;
}

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

/* =============================================================================
   UTILITIES
   ============================================================================= */

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
