/* ============================================================
   AI Chat Platform — Complete Stylesheet
   ============================================================
   Structure:
   1.  CSS Custom Properties (Dark & Light themes)
   2.  CSS Reset / Base Styles
   3.  Utility Classes
   4.  Login Page
   5.  Dashboard Layout
   6.  Sidebar
   7.  Chat Header
   8.  Chat Area
   9.  Welcome Screen
   10. Message Bubbles
   11. Markdown Content
   12. Typing Indicator
   13. Message Input Area
   14. Modals
   15. API Keys List & Cards
   16. Key Form
   17. Settings Panel
   18. Theme Toggle Switch
   19. Range Slider
   20. Form Elements
   21. Buttons
   22. Icon Buttons
   23. Toast Notifications
   24. Confirmation Dialog
   25. Scrollbar Styling
   26. Selection Color
   27. Animations / Keyframes
   28. Light Theme Overrides
   29. Responsive — Tablet (<=1024px)
   30. Responsive — Mobile (<=768px)
   31. Responsive — Small Mobile (<=480px)
   32. Print Styles
   33. Accessibility (focus-visible, reduced-motion)
   ============================================================ */

/* ============================================================
   1. CSS Custom Properties
   ============================================================ */

:root {
    /* Dark theme (default) */
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-tertiary: #1a1a3e;
    --surface: #1e1e3f;
    --border: #2a2a5a;
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-rgb: 233, 69, 96;
    --user-bubble: #e94560;
    --ai-bubble: #1e1e3f;
    --success: #2ecc71;
    --error: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.9375rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-round: 50%;
    --radius-pill: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(233, 69, 96, 0.15);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout */
    --sidebar-width: 280px;
    --header-height: 60px;
    --input-area-min-height: 80px;

    /* Code block */
    --code-bg: #1a1a2e;
    --code-header-bg: #141428;
    --code-text: #abb2bf;

    /* Z-index layers */
    --z-sidebar: 100;
    --z-overlay: 90;
    --z-modal: 200;
    --z-toast: 300;
    --z-tooltip: 400;
}

/* ============================================================
   2. CSS Reset / Base Styles
   ============================================================ */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

img, svg {
    display: block;
    max-width: 100%;
}

ul, ol {
    list-style: none;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

p {
    margin-bottom: 0.5em;
}

p:last-child {
    margin-bottom: 0;
}

/* ============================================================
   3. Utility Classes
   ============================================================ */

.hidden {
    display: none !important;
}

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

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

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-block {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: var(--space-sm);
}

/* ============================================================
   4. Login Page
   ============================================================ */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(233, 69, 96, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(42, 42, 90, 0.3) 0%, transparent 50%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: var(--space-md);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-2xl) var(--space-xl);
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.5s ease;
}

.login-logo {
    margin-bottom: var(--space-md);
    display: flex;
    justify-content: center;
}

.login-logo svg {
    filter: drop-shadow(0 4px 12px rgba(233, 69, 96, 0.3));
}

.login-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.login-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.login-form .form-group {
    text-align: left;
}

.login-form .form-input {
    width: 100%;
    padding: 14px var(--space-md);
    font-size: var(--font-size-base);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.login-form .form-input::placeholder {
    color: var(--text-secondary);
}

.login-form .form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.login-error {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: var(--radius-sm);
    color: var(--error);
    font-size: var(--font-size-sm);
    animation: fadeInUp 0.3s ease;
}

.login-error[hidden] {
    display: none;
}

.error-icon {
    flex-shrink: 0;
}

.login-btn {
    width: 100%;
    padding: 14px;
    font-size: var(--font-size-md);
    font-weight: 600;
    position: relative;
}

.login-btn .btn-text,
.login-btn .btn-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.login-btn .btn-spinner[hidden] {
    display: none;
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: var(--radius-round);
    animation: spin 0.6s linear infinite;
}

.login-footer {
    margin-top: var(--space-lg);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

/* ============================================================
   5. Dashboard Layout
   ============================================================ */

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    background: var(--bg-primary);
    transition: margin-left var(--transition-smooth);
}

/* ============================================================
   6. Sidebar
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: var(--z-sidebar);
    transition: transform var(--transition-smooth);
    overflow: hidden;
}

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

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-logo svg {
    flex-shrink: 0;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    width: calc(100% - var(--space-md) * 2);
    margin: var(--space-md) var(--space-md) 0;
    padding: var(--space-sm) var(--space-md);
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-base), transform var(--transition-fast);
}

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

.new-chat-btn:active {
    transform: scale(0.98);
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-md) var(--space-md) var(--space-sm);
}

.conversation-list-header {
    padding: 0 var(--space-md) var(--space-sm);
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 var(--space-sm);
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
    min-height: 44px;
}

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

.conversation-item.active {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent);
    padding-left: calc(var(--space-md) - 3px);
}

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

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

.conversation-item-date {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.conversation-item-delete {
    display: none;
    position: absolute;
    right: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(231, 76, 60, 0.2);
    border: none;
    color: var(--error);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: background var(--transition-fast);
    align-items: center;
    justify-content: center;
}

.conversation-item:hover .conversation-item-delete {
    display: flex;
}

.conversation-item-delete:hover {
    background: rgba(231, 76, 60, 0.4);
}

.conversation-list-empty {
    padding: var(--space-lg) var(--space-md);
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

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

.sidebar-btn-icon {
    font-size: var(--font-size-md);
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.sidebar-btn-text {
    font-weight: 500;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
    opacity: 0;
    transition: opacity var(--transition-smooth);
}

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

/* ============================================================
   7. Chat Header
   ============================================================ */

.chat-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0 var(--space-md);
    height: var(--header-height);
    min-height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.hamburger {
    display: none;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.model-selector {
    min-width: 240px;
    max-width: 400px;
    padding: var(--space-sm) var(--space-md);
    padding-right: var(--space-xl);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color var(--transition-base);
}

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

.model-selector option {
    background: var(--surface);
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.provider-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.provider-badge:empty {
    display: none;
}

/* ============================================================
   8. Chat Area
   ============================================================ */

.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: relative;
}

/* ============================================================
   9. Welcome Screen
   ============================================================ */

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.welcome-icon {
    margin-bottom: var(--space-lg);
    filter: drop-shadow(0 8px 24px rgba(233, 69, 96, 0.3));
}

.welcome-title {
    font-size: clamp(var(--font-size-xl), 3vw, var(--font-size-3xl));
    font-weight: 700;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.welcome-subtitle {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin-bottom: var(--space-xl);
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
    max-width: 700px;
    width: 100%;
}

.suggestion-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: border-color var(--transition-base), background var(--transition-base), transform var(--transition-fast);
    text-align: left;
}

.suggestion-btn:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

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

.suggestion-icon {
    font-size: var(--font-size-xl);
    flex-shrink: 0;
}

.suggestion-text {
    font-weight: 500;
}

/* ============================================================
   10. Message Bubbles
   ============================================================ */

.messages-container {
    display: flex;
    flex-direction: column;
    padding: var(--space-md) var(--space-lg);
    gap: var(--space-md);
    min-height: 100%;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeInUp 0.3s ease;
}

.message-user {
    align-self: flex-end;
    align-items: flex-end;
}

.message-ai {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    padding: var(--space-md) var(--space-md);
    border-radius: var(--radius-md);
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}

.message-user .message-bubble {
    background: var(--user-bubble);
    color: #ffffff;
    border-bottom-right-radius: var(--space-xs);
}

.message-ai .message-bubble {
    background: var(--ai-bubble);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: var(--space-xs);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-xs);
    padding: 0 var(--space-xs);
}

.message-timestamp {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.message-user .message-timestamp {
    color: rgba(255, 255, 255, 0.6);
}

.message-model-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-pill);
    font-size: 10px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ============================================================
   11. Markdown Content (inside AI message bubbles)
   ============================================================ */

.message-ai .message-bubble p {
    margin-bottom: 0.6em;
}

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

.message-ai .message-bubble h1,
.message-ai .message-bubble h2,
.message-ai .message-bubble h3,
.message-ai .message-bubble h4 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
    color: var(--text-primary);
}

.message-ai .message-bubble h1 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3em;
}

.message-ai .message-bubble h2 {
    font-size: 1.3em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.2em;
}

.message-ai .message-bubble h3 {
    font-size: 1.15em;
}

.message-ai .message-bubble h4 {
    font-size: 1.05em;
}

.message-ai .message-bubble h1:first-child,
.message-ai .message-bubble h2:first-child,
.message-ai .message-bubble h3:first-child,
.message-ai .message-bubble h4:first-child {
    margin-top: 0;
}

.message-ai .message-bubble strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-ai .message-bubble em {
    font-style: italic;
}

.message-ai .message-bubble code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--code-bg);
    color: var(--accent-hover);
    padding: 2px 6px;
    border-radius: 4px;
    word-break: break-word;
}

.message-ai .message-bubble pre {
    position: relative;
    margin: 0.75em 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--code-bg);
    border: 1px solid var(--border);
}

.message-ai .message-bubble pre code {
    display: block;
    padding: var(--space-md);
    overflow-x: auto;
    background: transparent;
    color: var(--code-text);
    font-size: 0.85em;
    line-height: 1.5;
    white-space: pre;
    border-radius: 0;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) var(--space-md);
    background: var(--code-header-bg);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.code-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 3px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.code-copy-btn:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.code-copy-btn.copied {
    color: var(--success);
    border-color: var(--success);
}

.message-ai .message-bubble blockquote {
    margin: 0.75em 0;
    padding: var(--space-sm) var(--space-md);
    border-left: 3px solid var(--accent);
    background: rgba(var(--accent-rgb), 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    color: var(--text-secondary);
}

.message-ai .message-bubble blockquote p {
    margin-bottom: 0.3em;
}

.message-ai .message-bubble blockquote p:last-child {
    margin-bottom: 0;
}

.message-ai .message-bubble ul,
.message-ai .message-bubble ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-ai .message-bubble ul {
    list-style-type: disc;
}

.message-ai .message-bubble ol {
    list-style-type: decimal;
}

.message-ai .message-bubble li {
    margin-bottom: 0.3em;
    line-height: 1.5;
}

.message-ai .message-bubble li:last-child {
    margin-bottom: 0;
}

.message-ai .message-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color var(--transition-fast);
}

.message-ai .message-bubble a:hover {
    color: var(--accent-hover);
}

.message-ai .message-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1em 0;
}

.message-ai .message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75em 0;
    font-size: var(--font-size-sm);
    overflow-x: auto;
    display: block;
}

.message-ai .message-bubble thead {
    display: table-header-group;
}

.message-ai .message-bubble tbody {
    display: table-row-group;
}

.message-ai .message-bubble tr {
    display: table-row;
}

.message-ai .message-bubble table,
.message-ai .message-bubble thead,
.message-ai .message-bubble tbody,
.message-ai .message-bubble tr {
    display: revert;
}

.message-ai .message-bubble th,
.message-ai .message-bubble td {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    text-align: left;
}

.message-ai .message-bubble th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.message-ai .message-bubble tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

/* ============================================================
   12. Typing Indicator
   ============================================================ */

.typing-indicator {
    padding: var(--space-md) var(--space-lg);
    animation: fadeIn 0.3s ease;
}

.typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: var(--space-md) var(--space-lg);
    background: var(--ai-bubble);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    border-bottom-left-radius: var(--space-xs);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: var(--radius-round);
    animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

/* ============================================================
   13. Message Input Area
   ============================================================ */

.input-area {
    padding: var(--space-md) var(--space-lg) var(--space-md);
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
}

.message-input {
    flex: 1;
    min-height: 24px;
    max-height: 200px;
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: 1.5;
    resize: none;
    overflow-y: auto;
}

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

.message-input:focus {
    outline: none;
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-base), transform var(--transition-fast), opacity var(--transition-base);
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.input-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) var(--space-xs) 0;
}

.char-count {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.input-hint {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

/* ============================================================
   14. Modals
   ============================================================ */

.modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.modal[style*="display:none"],
.modal[style*="display: none"] {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: scaleIn 0.2s ease;
    z-index: 1;
    width: 100%;
}

.modal-large {
    max-width: 600px;
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-header h2,
.modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    color: var(--text-secondary);
    transition: color var(--transition-fast);
}

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

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ============================================================
   15. API Keys List & Cards
   ============================================================ */

.api-keys-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.api-key-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-base);
}

.api-key-card:hover {
    border-color: var(--text-secondary);
}

.api-key-card.active-key {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

.key-provider-icon {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xl);
    font-weight: 700;
    flex-shrink: 0;
}

.key-provider-icon.openrouter {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.key-provider-icon.groq {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.key-provider-icon.custom {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

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

.key-label {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.key-details {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: 2px;
}

.key-provider-name {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.key-masked {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.key-date {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.key-active-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 600;
}

.key-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex-shrink: 0;
}

.key-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

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

.key-action-btn.danger:hover {
    background: rgba(231, 76, 60, 0.15);
    color: var(--error);
}

.key-action-btn.activate {
    font-size: var(--font-size-xs);
    width: auto;
    padding: 0 var(--space-sm);
    font-family: var(--font-sans);
    font-weight: 500;
}

.key-action-btn.activate:hover {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
    border-color: var(--success);
}

.add-key-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-md);
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--transition-base), color var(--transition-base), background var(--transition-base);
}

.add-key-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(var(--accent-rgb), 0.05);
}

/* ============================================================
   16. Key Form
   ============================================================ */

.key-form {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border);
    animation: fadeInUp 0.3s ease;
}

.key-form-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper .form-input {
    padding-right: 44px;
}

.toggle-visibility {
    position: absolute;
    right: 4px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
}

.toggle-visibility:hover {
    color: var(--text-primary);
}

/* ============================================================
   17. Settings Panel
   ============================================================ */

.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    max-width: 100vw;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.3s ease;
    overflow: hidden;
}

.settings-panel[style*="display:none"],
.settings-panel[style*="display: none"] {
    display: none !important;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.settings-header h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
}

.settings-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-lg) 0;
}

.settings-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.settings-about {
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border);
    text-align: center;
}

.about-text {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

/* ============================================================
   18. Theme Toggle Switch
   ============================================================ */

.theme-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.theme-label-dark,
.theme-label-light {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    transition: background var(--transition-base), border-color var(--transition-base);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: var(--radius-round);
    transition: transform var(--transition-smooth), background var(--transition-base);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
    background: #ffffff;
}

.toggle-switch input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.3);
}

/* ============================================================
   19. Range Slider
   ============================================================ */

.form-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-pill);
    outline: none;
    transition: background var(--transition-base);
    cursor: pointer;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: var(--radius-round);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 10px rgba(var(--accent-rgb), 0.4);
}

.form-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: var(--radius-round);
    border: none;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.form-range::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 10px rgba(var(--accent-rgb), 0.4);
}

.form-range::-moz-range-track {
    background: var(--bg-tertiary);
    height: 6px;
    border-radius: var(--radius-pill);
}

.form-range:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.3);
}

/* ============================================================
   20. Form Elements
   ============================================================ */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-secondary);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

.form-select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: var(--space-xl);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238888aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.form-select option {
    background: var(--surface);
    color: var(--text-primary);
}

.form-textarea {
    resize: vertical;
    line-height: 1.5;
    min-height: 80px;
}

.form-hint {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.form-input.error,
.form-select.error,
.form-textarea.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.15);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================
   21. Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px var(--space-lg);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-base), transform var(--transition-fast), box-shadow var(--transition-base), opacity var(--transition-base);
    white-space: nowrap;
    user-select: none;
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover {
    transform: scale(1.02);
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(var(--accent-rgb), 0.4);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--text-secondary);
}

.btn-danger {
    background: var(--error);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
}

.btn-danger:hover:not(:disabled) {
    background: #c0392b;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4);
}

/* ============================================================
   22. Icon Buttons
   ============================================================ */

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
    flex-shrink: 0;
}

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

.icon-btn:active {
    transform: scale(0.9);
}

/* ============================================================
   23. Toast Notifications
   ============================================================ */

.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    pointer-events: auto;
    animation: slideInRight 0.3s ease;
    max-width: 380px;
    min-width: 250px;
    word-break: break-word;
}

.toast.toast-hiding {
    animation: fadeOut 0.3s ease forwards;
}

.toast-icon {
    font-size: var(--font-size-lg);
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
}

.toast-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    font-size: var(--font-size-md);
    transition: color var(--transition-fast);
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--error);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.info {
    border-left: 4px solid var(--info);
}

/* ============================================================
   24. Confirmation Dialog
   ============================================================ */

#confirmDialog .modal-content {
    text-align: left;
}

#confirmDialog .modal-body p {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    line-height: 1.6;
}

#confirmDialog .modal-footer {
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* ============================================================
   25. Scrollbar Styling
   ============================================================ */

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-pill);
}

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

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* ============================================================
   26. Selection Color
   ============================================================ */

::selection {
    background: rgba(var(--accent-rgb), 0.3);
    color: var(--text-primary);
}

::-moz-selection {
    background: rgba(var(--accent-rgb), 0.3);
    color: var(--text-primary);
}

/* ============================================================
   27. Animations / Keyframes
   ============================================================ */

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

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

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

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

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

/* ============================================================
   28. Light Theme Overrides
   ============================================================ */

.theme-light,
[data-theme="light"] {
    --bg-primary: #f5f5f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8f0;
    --surface: #ffffff;
    --border: #e0e0e8;
    --text-primary: #1a1a2e;
    --text-secondary: #666680;
    --accent: #e94560;
    --accent-hover: #d63851;
    --accent-rgb: 233, 69, 96;
    --user-bubble: #e94560;
    --ai-bubble: #f0f0f5;
    --success: #2ecc71;
    --error: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 20px rgba(233, 69, 96, 0.1);

    --code-bg: #282c34;
    --code-header-bg: #21252b;
    --code-text: #abb2bf;
}

.theme-light .login-page,
.theme-light.login-page {
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(233, 69, 96, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(200, 200, 240, 0.3) 0%, transparent 50%);
}

.theme-light .message-ai .message-bubble {
    border-color: var(--border);
}

.theme-light .message-ai .message-bubble code {
    background: rgba(233, 69, 96, 0.08);
    color: #c0392b;
}

.theme-light .model-selector {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666680' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.theme-light .form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666680' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.theme-light .sidebar {
    box-shadow: var(--shadow-sm);
}

.theme-light .toast {
    box-shadow: var(--shadow-md);
}

.theme-light .typing-dot {
    background: var(--text-secondary);
}

.theme-light ::selection {
    background: rgba(var(--accent-rgb), 0.2);
}

.theme-light ::-moz-selection {
    background: rgba(var(--accent-rgb), 0.2);
}

.theme-light ::-webkit-scrollbar-thumb {
    background: #c8c8d4;
}

.theme-light ::-webkit-scrollbar-thumb:hover {
    background: #a8a8b8;
}

.theme-light .api-key-card {
    background: var(--bg-primary);
}

.theme-light .spinner {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
}

/* ============================================================
   29. Responsive — Tablet (<=1024px)
   ============================================================ */

@media screen and (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }

    .model-selector {
        min-width: 200px;
    }

    .message {
        max-width: 85%;
    }

    .welcome-suggestions {
        grid-template-columns: 1fr;
        max-width: 400px;
    }

    .settings-panel {
        width: 340px;
    }
}

/* ============================================================
   30. Responsive — Mobile (<=768px)
   ============================================================ */

@media screen and (max-width: 768px) {
    :root {
        --sidebar-width: 300px;
        --header-height: 56px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        z-index: var(--z-sidebar);
    }

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

    .hamburger {
        display: flex;
    }

    .main-content {
        margin-left: 0;
    }

    .chat-header {
        padding: 0 var(--space-sm);
    }

    .header-center {
        justify-content: flex-start;
        flex: 1;
    }

    .model-selector {
        min-width: 0;
        max-width: 100%;
        flex: 1;
    }

    .message {
        max-width: 90%;
    }

    .messages-container {
        padding: var(--space-md) var(--space-md);
    }

    .input-area {
        padding: var(--space-sm) var(--space-md) var(--space-sm);
    }

    .input-hint {
        display: none;
    }

    .welcome-screen {
        padding: var(--space-lg) var(--space-md);
    }

    .welcome-title {
        font-size: var(--font-size-xl);
    }

    .welcome-suggestions {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .modal-content {
        margin: var(--space-md);
        max-height: calc(100vh - var(--space-xl) * 2);
    }

    .modal-large {
        max-width: 100%;
    }

    .settings-panel {
        width: 100%;
    }

    .toast-container {
        left: var(--space-md);
        right: var(--space-md);
        bottom: var(--space-md);
    }

    .toast {
        max-width: 100%;
        min-width: auto;
    }

    .provider-badge {
        display: none;
    }

    #closeSidebar {
        display: flex;
    }
}

/* Desktop: hide close sidebar button */
@media screen and (min-width: 769px) {
    #closeSidebar {
        display: none;
    }

    .sidebar {
        transform: translateX(0) !important;
    }
}

/* ============================================================
   31. Responsive — Small Mobile (<=480px)
   ============================================================ */

@media screen and (max-width: 480px) {
    .login-card {
        padding: var(--space-lg) var(--space-md);
    }

    .login-title {
        font-size: var(--font-size-xl);
    }

    .message {
        max-width: 95%;
    }

    .message-bubble {
        padding: var(--space-sm) var(--space-md);
    }

    .suggestion-btn {
        padding: var(--space-sm) var(--space-md);
    }

    .modal-body {
        padding: var(--space-md);
    }

    .api-key-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .key-actions {
        width: 100%;
        justify-content: flex-end;
        margin-top: var(--space-sm);
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .modal-footer {
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
    }

    .settings-panel {
        width: 100vw;
    }
}

/* ============================================================
   32. Print Styles
   ============================================================ */

@media print {
    .sidebar,
    .sidebar-overlay,
    .chat-header,
    .input-area,
    .toast-container,
    .modal,
    .settings-panel,
    .typing-indicator,
    #confirmDialog {
        display: none !important;
    }

    body {
        background: #ffffff;
        color: #000000;
        overflow: visible;
    }

    #app {
        height: auto;
        overflow: visible;
    }

    .main-content {
        height: auto;
        overflow: visible;
    }

    .chat-area {
        overflow: visible;
        height: auto;
    }

    .messages-container {
        display: flex !important;
        padding: 0;
    }

    .message {
        max-width: 100%;
        page-break-inside: avoid;
    }

    .message-bubble {
        box-shadow: none;
        border: 1px solid #cccccc;
    }

    .message-user .message-bubble {
        background: #f0f0f0;
        color: #000000;
    }

    .message-ai .message-bubble {
        background: #ffffff;
        color: #000000;
        border: 1px solid #cccccc;
    }

    .message-ai .message-bubble pre {
        border: 1px solid #cccccc;
    }

    .message-ai .message-bubble pre code {
        color: #333333;
        background: #f5f5f5;
    }

    .code-block-header {
        background: #e8e8e8;
        color: #333333;
    }

    .code-copy-btn {
        display: none;
    }

    a {
        color: #000000;
        text-decoration: underline;
    }
}

/* ============================================================
   33. Accessibility (focus-visible, reduced-motion)
   ============================================================ */

*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

button:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .sidebar {
        transition: none;
    }

    .toast {
        animation: none;
    }

    .modal-content {
        animation: none;
    }

    .settings-panel {
        animation: none;
    }

    .login-card {
        animation: none;
    }

    .typing-dot {
        animation: none;
        opacity: 0.5;
    }

    .typing-dot:nth-child(2) {
        opacity: 0.7;
    }

    .typing-dot:nth-child(3) {
        opacity: 0.9;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #4a4a7a;
        --text-secondary: #a0a0c0;
    }

    .message-ai .message-bubble {
        border-width: 2px;
    }

    .btn {
        border: 2px solid currentColor;
    }

    .form-input,
    .form-select,
    .form-textarea {
        border-width: 2px;
    }
}
