:root {
    --bg-primary: #0b0f17;
    --bg-secondary: #131b26;
    --bg-tertiary: #1b2636;
    --bg-surface: #172130;
    --bg-glass: rgba(19, 27, 38, 0.85);
    --border-color: #243447;
    --border-light: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.25);
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --user-msg-bg: #1e3a8a;
    --user-msg-text: #ffffff;
    --ai-msg-bg: #172130;
    --ai-msg-text: #f0f4f8;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --sidebar-width: 280px;
    --header-height: 64px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 9999px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.9);
    --border-color: #e2e8f0;
    --border-light: rgba(0, 0, 0, 0.06);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent-primary: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.2);
    --accent-gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    --user-msg-bg: #2563eb;
    --user-msg-text: #ffffff;
    --ai-msg-bg: #ffffff;
    --ai-msg-text: #0f172a;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
}

body.font-small {
    font-size: 13.5px;
}

body.font-large {
    font-size: 17px;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    background: none;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    position: relative;
    overflow: hidden;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 10px var(--accent-glow);
    flex-shrink: 0;
    -webkit-text-fill-color: initial;
}

.brand-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

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

.sidebar-actions {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-new-chat {
    width: 100%;
    padding: 10px 14px;
    background: var(--accent-gradient);
    color: #ffffff;
    border-radius: var(--radius-md);
    font-weight: 600;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-new-chat:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

.btn-new-chat:active {
    transform: translateY(0);
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 6px 12px;
    gap: 8px;
}

.search-box svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    width: 100%;
    font-size: 13px;
}

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

.chat-history-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-history-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 10px 8px 4px 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    border: 1px solid transparent;
    position: relative;
    user-select: none;
}

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

.chat-item.active {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
}

.chat-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent-primary);
    border-radius: 0 4px 4px 0;
}

.chat-item-content {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    flex: 1;
}

.chat-item-content svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

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

.chat-item-actions {
    display: none;
    align-items: center;
    gap: 2px;
}

.chat-item:hover .chat-item-actions,
.chat-item.active .chat-item-actions {
    display: flex;
}

.chat-action-btn {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}

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

.chat-action-btn.delete:hover {
    color: var(--danger);
}

.empty-history {
    text-align: center;
    padding: 30px 10px;
    color: var(--text-muted);
    font-size: 13px;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--bg-secondary);
}

.footer-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-secondary);
    justify-content: flex-start;
}

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

.footer-btn svg {
    width: 18px;
    height: 18px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.top-navbar {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    z-index: 20;
    flex-shrink: 0;
}

.navbar-left, .navbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.model-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.model-badge:hover {
    border-color: var(--accent-primary);
}

.model-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 280px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 4px;
    z-index: 100;
}

.model-dropdown.show {
    display: flex;
}

.model-option {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    transition: background 0.15s ease;
}

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

.model-option.selected {
    background-color: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.model-option-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 13px;
}

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

.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

.welcome-screen {
    margin: auto;
    max-width: 650px;
    width: 100%;
    text-align: center;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    animation: fadeIn 0.4s ease-out;
}

.welcome-logo {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 10px 30px var(--accent-glow);
}

.welcome-logo svg {
    width: 36px;
    height: 36px;
}

.welcome-title {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.welcome-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 480px;
    line-height: 1.5;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    width: 100%;
    margin-top: 10px;
}

.suggestion-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.suggestion-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.suggestion-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.suggestion-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.message-row {
    display: flex;
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    gap: 14px;
    animation: fadeIn 0.25s ease-out;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
}

.message-row.assistant .message-avatar {
    background: var(--accent-gradient);
    color: #ffffff;
    box-shadow: 0 4px 10px var(--accent-glow);
}

.message-row.assistant .message-avatar svg {
    width: 20px;
    height: 20px;
}

.message-row.user .message-avatar {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.message-content-wrapper {
    display: flex;
    flex-direction: column;
    max-width: calc(100% - 50px);
    gap: 4px;
}

.message-row.user .message-content-wrapper {
    align-items: flex-end;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    word-break: break-word;
    font-size: 15px;
    line-height: 1.6;
    position: relative;
}

.message-row.user .message-bubble {
    background-color: var(--user-msg-bg);
    color: var(--user-msg-text);
    border-bottom-right-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.message-row.assistant .message-bubble {
    background-color: var(--ai-msg-bg);
    color: var(--ai-msg-text);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
}

.message-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    opacity: 0.8;
}

.msg-btn {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--text-muted);
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-light);
}

.msg-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-color);
}

.msg-btn svg {
    width: 13px;
    height: 13px;
}

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

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

.bottom-composer-area {
    padding: 12px 16px 20px 16px;
    background: linear-gradient(180deg, transparent 0%, var(--bg-primary) 30%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 20;
    flex-shrink: 0;
}

.composer-box {
    width: 100%;
    max-width: 860px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer-box:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.composer-textarea {
    width: 100%;
    min-height: 44px;
    max-height: 180px;
    resize: none;
    padding: 6px 4px;
    line-height: 1.5;
    color: var(--text-primary);
}

.composer-textarea::placeholder {
    color: var(--text-muted);
}

.composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-composer-tool {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
}

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

.btn-composer-tool.listening {
    color: var(--danger);
    background-color: rgba(239, 68, 68, 0.15);
    animation: pulse 1.2s infinite;
}

.btn-send {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    color: #ffffff;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-send:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    padding: 16px;
}

.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.active .modal-card {
    transform: scale(1);
}

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

.modal-title {
    font-size: 17px;
    font-weight: 700;
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.form-control {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.form-control:focus {
    border-color: var(--accent-primary);
}

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

.modal-footer {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
}

.btn-secondary {
    padding: 8px 16px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
}

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

.btn-primary {
    padding: 8px 18px;
    background: var(--accent-gradient);
    color: #ffffff;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
    opacity: 0.92;
}

.btn-danger {
    padding: 8px 18px;
    background-color: var(--danger);
    color: #ffffff;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
    pointer-events: none;
}

.toast {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    pointer-events: auto;
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 360px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--accent-primary); }

.mobile-menu-btn {
    display: none;
}

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

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

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

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

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

    .mobile-menu-btn {
        display: inline-flex;
    }

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

    .message-bubble {
        padding: 12px 14px;
        font-size: 14px;
    }

    .welcome-title {
        font-size: 22px;
    }

    .suggestions-grid {
        grid-template-columns: 1fr;
    }
}
