/* =====================================================
   Dseeker · Elegant Scholarly Design System · v5.0
   Aesthetic: Academic Excellence · Refined Scholar
   ===================================================== */

/* ─── 1. Design Tokens ─────────────────────────────── */
:root {
    /* Primary Palette - Deep Academic Blue */
    --color-primary-50:  #f0f4f8;
    --color-primary-100: #d9e2ec;
    --color-primary-200: #bcccdc;
    --color-primary-300: #9fb3c8;
    --color-primary-400: #829ab1;
    --color-primary-500: #627d98;
    --color-primary-600: #486581;
    --color-primary-700: #334e68;
    --color-primary-800: #243b53;
    --color-primary-900: #102a43;
    
    /* Warm Neutral - Paper-like */
    --color-warm-50:  #faf9f7;
    --color-warm-100: #f5f3ef;
    --color-warm-200: #ebe7e0;
    --color-warm-300: #e0dbd1;
    --color-warm-400: #c7bdb0;
    
    /* Accent - Scholarly Gold */
    --color-accent-400: #d4a574;
    --color-accent-500: #c9956b;
    --color-accent-600: #b88355;
    
    /* Semantic Colors */
    --background:        var(--color-warm-50);
    --background-pure: #ffffff;
    --foreground:        var(--color-primary-900);
    --foreground-muted:  var(--color-primary-600);
    
    --card:           var(--color-warm-50);
    --card-foreground: var(--color-primary-900);
    
    --primary:           var(--color-primary-700);
    --primary-hover:     var(--color-primary-800);
    --primary-foreground: #ffffff;
    
    --secondary:         var(--color-warm-200);
    --secondary-foreground: var(--color-primary-700);
    
    --muted:             var(--color-warm-200);
    --muted-foreground:  var(--color-primary-500);
    
    --accent:            var(--color-accent-400);
    --accent-foreground: var(--color-primary-900);
    
    --destructive:       #dc2626;
    --destructive-foreground: #ffffff;
    
    --border:            var(--color-warm-300);
    --input:             var(--color-warm-300);
    --ring:              var(--color-primary-400);
    
    --radius:            0.5rem;
    
    /* Sidebar Colors */
    --sidebar-bg:       var(--color-primary-800);
    --sidebar-fg:       var(--color-primary-100);
    --sidebar-border:   var(--color-primary-700);
    --sidebar-active:   #ffffff;
    --sidebar-hover:    var(--color-primary-700);

    /* Elevation */
    --shadow-xs:  0 1px 2px 0 rgb(16 42 67 / 0.04);
    --shadow-sm:  0 1px 3px 0 rgb(16 42 67 / 0.06), 0 1px 2px -1px rgb(16 42 67 / 0.04);
    --shadow:     0 2px 6px -1px rgb(16 42 67 / 0.08), 0 2px 4px -2px rgb(16 42 67 / 0.05);
    --shadow-md:  0 4px 10px -2px rgb(16 42 67 / 0.08), 0 2px 6px -3px rgb(16 42 67 / 0.06);
    --shadow-lg:  0 10px 24px -4px rgb(16 42 67 / 0.1), 0 4px 8px -4px rgb(16 42 67 / 0.06);
    --shadow-xl:  0 20px 40px -8px rgb(16 42 67 / 0.12);
    --shadow-2xl: 0 28px 56px -12px rgb(16 42 67 / 0.18);

    /* Motion */
    --ease-out:   cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --duration-fast:   140ms;
    --duration-base:   220ms;
    --duration-slow:   360ms;
}

/* ─── 2. Base & Reset ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    font-size: 15px;
}

body {
    background-color: var(--background);
    color: var(--foreground);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-weight: 400;
}

.view-container.hidden { display: none !important; }

/* ─── 3. Fullscreen Adaptive Background ──────────────── */
/* Clean striped background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    background-color: var(--color-warm-50);
    background-image: 
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 60px,
            rgba(16, 42, 67, 0.03) 60px,
            rgba(16, 42, 67, 0.03) 61px
        );
}

/* Subtle noise texture overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.03;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* ─── 4. Scrollbar ───────────────────────────────────── */
.custom-scroll { 
    scrollbar-width: thin; 
    scrollbar-color: hsl(215 20% 78%) transparent; 
}
.custom-scroll::-webkit-scrollbar { width: 4px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb {
    background: hsl(215 20% 80%);
    border-radius: 10px;
}
.custom-scroll::-webkit-scrollbar-thumb:hover { background: hsl(215 20% 65%); }

/* ─── 5. Sidebar ──────────────────────────────────────── */
/* Light theme sidebar - Clean & Minimal */
aside#sidebar {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-right: 1px solid #e2e8f0;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.04);
}

.sidebar-header {
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 1.5rem 1.25rem !important;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.sidebar-header .sidebar-logo-container {
    color: #1e293b;
}

.sidebar-header p {
    color: #64748b !important;
    letter-spacing: 0.12em;
    font-weight: 400;
}

.sidebar-action {
    padding: 1rem;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
}

#nav-new-search {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
    color: white !important;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25), inset 0 1px 0 rgba(255,255,255,0.15);
    transition: all var(--duration-base) var(--ease-out);
    border: none;
}

#nav-new-search:hover {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.sidebar-history-header h3 {
    color: #64748b !important;
    font-size: 0.6875rem !important;
    letter-spacing: 0.1em;
    font-weight: 600;
}

#history-list .text-muted-foreground {
    color: #94a3b8 !important;
    font-size: 0.8125rem;
}

/* History items */
#history-list > div:not(:empty) {
    animation: slideInLeft 0.25s var(--ease-out) both;
}

#history-list a,
#history-list .history-item {
    color: #475569 !important;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    padding: 0.5rem 0.75rem;
    transition: all var(--duration-fast);
}

#history-list a:hover,
#history-list .history-item:hover {
    background: #e2e8f0 !important;
    color: #1e293b !important;
}

/* History list items dynamic */
#history-list .group {
    color: #475569 !important;
}

#history-list .group:hover {
    background: #f1f5f9 !important;
}

#history-list .group .text-muted-foreground {
    color: #94a3b8 !important;
}

/* Settings button in sidebar */
#nav-settings {
    color: #64748b !important;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    transition: all var(--duration-fast);
}

#nav-settings:hover {
    background: #e2e8f0 !important;
    color: #334155 !important;
}

.sidebar-settings-container {
    border-top: 1px solid #e2e8f0 !important;
    display: flex;
    flex-shrink: 0;
    background: #f8fafc;
}

/* Sidebar toggle button */
#sidebar-toggle {
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: var(--shadow-sm);
}

#sidebar-toggle svg { color: #64748b; }

/* Collapsed sidebar adjustments */
.w-16 .sidebar-settings-container { display: flex !important; padding: 0.5rem !important; }
.w-16 .sidebar-settings-container button { justify-content: center; padding: 0.5rem; }
.w-16 .sidebar-settings-container .settings-icon { margin-right: 0 !important; }
.w-16 .sidebar-logo-container { justify-content: center !important; }
.w-16 ~ main #bottom-search-container,
aside.w-16 + main #bottom-search-container { left: 4rem !important; }

/* ─── 6. Home / Search View ─────────────────────────── */
/* Full-screen adaptive background */
#search-view {
    min-height: 100%;
    min-height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

/* Clean striped background for search view */
#search-view::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-warm-50);
    background-image:
        /* Vertical stripes */
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 80px,
            rgba(16, 42, 67, 0.04) 80px,
            rgba(16, 42, 67, 0.04) 81px
        ),
        /* Horizontal stripes */
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 80px,
            rgba(16, 42, 67, 0.02) 80px,
            rgba(16, 42, 67, 0.02) 81px
        );
    z-index: -3;
}

/* Search view content styling */
#search-view .space-y-2 {
    position: relative;
    z-index: 1;
}

#search-view h1 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--color-primary-900) 0%, var(--color-primary-700) 50%, var(--color-accent-600) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 20px rgba(16, 42, 67, 0.1);
}

#search-view .text-muted-foreground {
    font-size: 1.125rem !important;
    color: var(--color-primary-600) !important;
    letter-spacing: 0.06em;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

/* Search form */
#search-form {
    margin-top: 3rem;
    width: 100%;
}

#user-question {
    width: 100%;
    min-height: 160px;
    padding: 1.5rem 2rem;
    font-size: 1rem;
    line-height: 1.75;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    border: 1.5px solid var(--color-warm-300);
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.85);
    color: var(--color-primary-900);
    resize: none;
    outline: none;
    backdrop-filter: blur(8px);
    transition:
        border-color var(--duration-base) var(--ease-out),
        box-shadow var(--duration-base) var(--ease-out),
        background-color var(--duration-base) var(--ease-out),
        transform var(--duration-base) var(--ease-out);
    box-shadow:
        var(--shadow-sm),
        0 0 0 0 rgba(72, 101, 129, 0),
        inset 0 1px 2px rgba(255, 255, 255, 0.8);
}

#user-question:hover {
    background: rgba(255, 255, 255, 0.95);
    border-color: var(--color-primary-400);
    transform: translateY(-1px);
}

#user-question:focus {
    border-color: var(--color-primary-500);
    background: #ffffff;
    box-shadow: 
        var(--shadow-md),
        0 0 0 4px rgba(72, 101, 129, 0.1),
        inset 0 1px 2px rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

#user-question::placeholder {
    color: var(--color-primary-400);
    font-weight: 350;
    font-style: italic;
}

/* Submit button */
#search-form button[type="submit"] {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    background: linear-gradient(135deg, var(--color-primary-700) 0%, var(--color-primary-800) 100%);
    color: white;
    font-weight: 500;
    font-size: 1rem;
    letter-spacing: 0.03em;
    padding: 1rem 2.5rem;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
    box-shadow:
        0 4px 14px rgba(51, 78, 104, 0.35),
        0 1px 3px rgba(51, 78, 104, 0.2),
        inset 0 1px 0 rgba(255,255,255,0.15);
    transition: all var(--duration-base) var(--ease-out);
    position: relative;
    overflow: hidden;
}

#search-form button[type="submit"]::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}

#search-form button[type="submit"]:hover {
    background: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-700) 100%);
    transform: translateY(-2px);
    box-shadow: 
        0 6px 24px rgba(51, 78, 104, 0.4),
        0 2px 6px rgba(51, 78, 104, 0.2);
}

#search-form button[type="submit"]:hover::before {
    left: 100%;
}

#search-form button[type="submit"]:active {
    transform: translateY(0);
    box-shadow: 
        0 2px 8px rgba(51, 78, 104, 0.25),
        0 1px 2px rgba(51, 78, 104, 0.15);
}

/* ─── 6. Results View ───────────────────────────────── */
#results-view {
    background-color: var(--color-warm-50);
    background-image:
        /* Subtle vertical stripes */
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 100px,
            rgba(16, 42, 67, 0.03) 100px,
            rgba(16, 42, 67, 0.03) 101px
        );
}

#results-view h2 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--color-primary-900);
}

/* Timeline */
#timeline-container {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--color-warm-300);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

.timeline {
    display: flex;
    justify-content: space-between;
    position: relative;
    padding: 0 1.5rem;
}

.timeline::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 2.5rem;
    right: 2.5rem;
    height: 1.5px;
    background: linear-gradient(90deg, transparent, var(--color-warm-300) 10%, var(--color-warm-300) 90%, transparent);
    z-index: 0;
}

.timeline-node {
    position: relative;
    text-align: center;
    flex: 1;
    cursor: pointer;
    transition: transform var(--duration-base) var(--ease-out);
    z-index: 1;
}

.timeline-node:hover { transform: translateY(-2px); }

.timeline-node-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--color-warm-300);
    margin: 0 auto;
    transition: all var(--duration-base) var(--ease-out);
    box-shadow: var(--shadow-xs);
}

.timeline-node:hover .timeline-node-dot {
    border-color: var(--color-primary-500);
    transform: scale(1.1);
    box-shadow: 0 0 0 4px rgba(72, 101, 129, 0.1);
}

.timeline-node-label {
    margin-top: 0.625rem;
    font-size: 0.6875rem;
    color: var(--color-primary-500);
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: color var(--duration-fast);
}

.timeline-node.active .timeline-node-dot {
    border-color: var(--color-primary-500);
    background: white;
    animation: pulse-ring 2.4s ease infinite;
}
.timeline-node.active .timeline-node-label { color: var(--color-primary-700); font-weight: 600; }

.timeline-node.completed .timeline-node-dot {
    background: var(--color-primary-600);
    border-color: var(--color-primary-600);
    box-shadow: 0 0 0 4px rgba(72, 101, 129, 0.12);
}
.timeline-node.completed .timeline-node-dot::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
}
.timeline-node.completed .timeline-node-label { color: var(--color-primary-800); font-weight: 600; }

.timeline-node.error .timeline-node-dot { background: var(--destructive); border-color: var(--destructive); }
.timeline-node.error .timeline-node-label { color: var(--destructive); }

@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0 rgba(72, 101, 129, 0.5); }
    60%  { box-shadow: 0 0 0 8px rgba(72, 101, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(72, 101, 129, 0); }
}

/* Timeline tooltip */
.timeline-node::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.375rem 0.625rem;
    background: var(--color-primary-800);
    color: white;
    font-size: 0.6875rem;
    font-weight: 500;
    border-radius: 0.3125rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-fast), transform var(--duration-fast);
    box-shadow: var(--shadow-md);
}
.timeline-node:hover::after { opacity: 1; transform: translateX(-50%) translateY(-2px); }

/* Timeline details panel */
#timeline-details-panel {
    background: white !important;
    border: 1px solid var(--color-warm-300);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-md);
}
#timeline-details-panel h4 { font-weight: 600; margin-bottom: 0.75rem; color: var(--color-primary-800); }
#timeline-details-panel pre {
    background: var(--color-warm-100);
    padding: 0.75rem;
    border-radius: var(--radius);
    white-space: pre-wrap;
    word-break: break-all;
    border: 1px solid var(--color-warm-300);
    font-size: 0.8125rem;
    color: var(--color-primary-800);
}

/* Answer container */
#answer-container {
    position: relative;
    background: white;
    border-radius: 0.875rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-warm-300);
}

#answer-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2.5px;
    background: linear-gradient(90deg, var(--color-primary-600) 0%, var(--color-primary-500) 50%, var(--color-accent-500) 100%);
}

/* Sources sidebar */
#sources-list { counter-reset: source-counter; }

#sources-list li {
    position: relative;
    padding-left: 2rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    transition: color var(--duration-fast);
}

#sources-list li::before {
    counter-increment: source-counter;
    content: counter(source-counter);
    position: absolute;
    left: 0;
    top: 0.3125rem;
    width: 1.375rem;
    height: 1.375rem;
    background: var(--color-warm-200);
    color: var(--color-primary-600);
    font-size: 0.625rem;
    font-weight: 600;
    border-radius: 0.3125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-base) var(--ease-out);
}

#sources-list li:hover::before {
    background: var(--color-primary-600);
    color: white;
    transform: scale(1.08);
}

/* Source accordion */
.source-header {
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    border: 1px solid var(--color-warm-300);
    border-radius: 0.5rem;
    margin-bottom: 0.375rem;
    box-shadow: var(--shadow-xs);
    transition: all var(--duration-fast);
}

.source-header:hover {
    background: var(--color-warm-100);
    border-color: var(--color-warm-400);
    box-shadow: var(--shadow-sm);
}

.source-header a {
    font-size: 0.8125rem;
    font-weight: 400;
    text-decoration: none;
    color: var(--color-primary-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90%;
    transition: color var(--duration-fast);
}

.source-header a:hover { color: var(--color-primary-800); }

.source-header::after {
    content: '›';
    font-size: 1.125rem;
    color: var(--color-primary-400);
    transition: transform var(--duration-base) var(--ease-out);
    margin-left: 0.5rem;
    line-height: 1;
}

.source-header.expanded::after { transform: rotate(90deg); }

.source-snippet {
    display: none;
    padding: 0.625rem 0.875rem;
    font-size: 0.8125rem;
    color: var(--color-primary-600);
    background: var(--color-warm-100);
    line-height: 1.6;
    border-radius: 0 0 0.5rem 0.5rem;
    margin-top: -0.375rem;
    margin-bottom: 0.375rem;
    border: 1px solid var(--color-warm-300);
    border-top: none;
}

.source-snippet.expanded { display: block; }

/* ─── 7. Floating Search Bar ────────────────────────── */
#bottom-search-container {
    transition: left var(--duration-slow) var(--ease-out);
    padding: 1rem 1.25rem;
    background: transparent !important;
}

#new-search-form-results {
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--color-warm-300) !important;
    border-radius: 3rem;
    box-shadow: 
        var(--shadow-xl),
        0 0 0 1px rgba(72, 101, 129, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    padding: 0.3125rem !important;
}

#new-question-input {
    background: transparent;
    border: none;
    outline: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 0.9375rem;
    color: var(--color-primary-900);
    padding: 0.5rem 1rem;
}

#new-question-input::placeholder { 
    color: var(--color-primary-400); 
    font-weight: 350;
}

/* ─── 8. Settings View ──────────────────────────────── */
#settings-view h1 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-weight: 700;
    color: var(--color-primary-900);
}

/* Tabs */
.tab-btn {
    position: relative;
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-primary-500);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color var(--duration-fast);
    overflow: hidden;
}

.tab-btn::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--color-primary-600);
    transition: width var(--duration-base) var(--ease-out), left var(--duration-base) var(--ease-out);
    transform: none;
}

.tab-btn:hover { color: var(--color-primary-700); }
.tab-btn:hover::after { width: 50%; left: 25%; }
.tab-btn.active { 
    color: var(--color-primary-700); 
    background: var(--color-primary-50);
    font-weight: 600;
}
.tab-btn.active::after { width: 70%; left: 15%; }

/* Cards in settings */
#settings-view .card,
#settings-view [class*="border border-border rounded-lg bg-card"],
#settings-view .p-4.border,
#settings-view .p-5.border {
    background: white !important;
    border: 1px solid var(--color-warm-300) !important;
    border-radius: 0.75rem !important;
    box-shadow: var(--shadow-xs);
}

.card {
    background-color: white;
    color: var(--color-primary-900);
    border-radius: var(--radius);
    border: 1px solid var(--color-warm-300);
    box-shadow: var(--shadow-sm);
}

.card-header { padding: 1.5rem; padding-bottom: 0; }
.card-title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; color: var(--color-primary-800); }
.card-description { color: var(--color-primary-500); margin-top: 0.375rem; font-size: 0.875rem; }
.card-content { padding: 1.5rem; }
.card-footer { padding: 1.5rem; border-top: 1px solid var(--color-warm-300); background-color: var(--color-warm-100); }

/* Info banner in model tab */
.bg-muted\/30 { background: var(--color-warm-100) !important; }

/* ─── 9. Form Elements ──────────────────────────────── */
.label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--color-primary-700);
    letter-spacing: 0.01em;
}

.input, .textarea, select.input {
    display: flex;
    width: 100%;
    border-radius: calc(var(--radius) - 1px);
    border: 1.5px solid var(--color-warm-300);
    background-color: white;
    padding: 0.5625rem 0.875rem;
    font-size: 0.875rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    color: var(--color-primary-900);
    transition:
        border-color var(--duration-fast),
        box-shadow var(--duration-fast);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.input::placeholder, .textarea::placeholder { color: var(--color-primary-400); font-weight: 300; }

.input:focus, .textarea:focus, select.input:focus {
    outline: none;
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px rgba(72, 101, 129, 0.1);
}

select.input {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23627d98' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.125em 1.125em;
    padding-right: 2.5rem;
    cursor: pointer;
}

.textarea { min-height: 80px; resize: vertical; }
.textarea.input-sm, .input-sm { font-size: 0.8125rem; padding: 0.4375rem 0.75rem; }

/* Toggle switch */
.peer-checked + div { background: var(--color-primary-600) !important; }

/* Password toggle */
.password-toggle-btn {
    position: absolute;
    top: 50%;
    right: 0.75rem;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-primary-500);
    padding: 0.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color var(--duration-fast);
    border-radius: 0.25rem;
}

.password-toggle-btn:hover { color: var(--color-primary-700); background: var(--color-warm-200); }
.password-toggle-btn svg { width: 1rem; height: 1rem; }

/* ─── 10. Buttons ───────────────────────────────────── */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: calc(var(--radius) - 1px);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-weight: 500;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    letter-spacing: 0.01em;
    transition:
        background var(--duration-fast),
        transform var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        color var(--duration-fast);
    cursor: pointer;
    white-space: nowrap;
    border: none;
    gap: 0.4375rem;
}

.button:disabled { opacity: 0.45; cursor: not-allowed; }

.button-primary {
    background: linear-gradient(135deg, var(--color-primary-700) 0%, var(--color-primary-800) 100%);
    color: white;
    box-shadow: 0 1px 3px rgba(51, 78, 104, 0.3), 0 1px 1px rgba(51, 78, 104, 0.2);
}

.button-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-700) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(51, 78, 104, 0.3);
}

.button-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(51, 78, 104, 0.2);
}

.button-outline {
    border: 1.5px solid var(--color-warm-300);
    background: white;
    color: var(--color-primary-700);
}

.button-outline:hover:not(:disabled) {
    background: var(--color-warm-100);
    border-color: var(--color-warm-400);
}

.button-destructive {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
}

.button-destructive:hover:not(:disabled) {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
    transform: translateY(-1px);
}

.button-ghost {
    border: none;
    background: transparent;
    color: var(--color-primary-700);
}

.button-ghost:hover:not(:disabled) { background: var(--color-warm-200); }

.button-sm { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }
.button-lg { padding: 0.75rem 1.5rem; font-size: 0.9375rem; }

/* ─── 11. Prose / Report Typography ─────────────────── */
.prose {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 1rem;
    color: var(--color-primary-900);
}

.prose h1, .prose h2, .prose h3 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-weight: 700;
    color: var(--color-primary-900);
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.prose h1 {
    font-size: 1.75rem;
    margin-top: 0;
    margin-bottom: 0.75em;
    padding-bottom: 0.5em;
    border-bottom: 1.5px solid var(--color-warm-300);
}

.prose h2 {
    font-size: 1.375rem;
    margin-top: 2em;
    margin-bottom: 0.75em;
    padding-left: 0.875rem;
    position: relative;
}

.prose h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.2em;
    bottom: 0.2em;
    width: 3px;
    background: linear-gradient(to bottom, var(--color-primary-600), var(--color-accent-500));
    border-radius: 2px;
}

.prose h3 {
    font-size: 1.125rem;
    margin-top: 1.5em;
    margin-bottom: 0.625em;
    color: var(--color-primary-800);
}

.prose p {
    margin-bottom: 1.25em;
    line-height: 1.85;
    color: var(--color-primary-800);
}

.prose ul, .prose ol {
    margin-left: 1.5rem;
    margin-bottom: 1.25em;
    padding-left: 0.5rem;
}

.prose li { margin-bottom: 0.5em; line-height: 1.7; }
.prose ul li::marker { color: var(--color-primary-600); }

.prose a {
    color: var(--color-primary-700);
    text-decoration: none;
    border-bottom: 1px solid rgba(72, 101, 129, 0.25);
    transition: border-color var(--duration-fast), background var(--duration-fast);
    font-weight: 500;
    padding: 0 0.1em;
}

.prose a:hover {
    border-bottom-color: var(--color-primary-600);
    background: rgba(72, 101, 129, 0.06);
    border-radius: 2px;
}

.prose strong { font-weight: 600; color: var(--color-primary-900); }

.prose blockquote {
    border-left: 3px solid rgba(72, 101, 129, 0.4);
    padding: 0.875rem 1.25rem;
    margin: 1.5rem 0;
    color: var(--color-primary-600);
    font-style: italic;
    background: rgba(72, 101, 129, 0.03);
    border-radius: 0 0.5rem 0.5rem 0;
}

.prose blockquote p:last-child { margin-bottom: 0; }

/* Code */
.prose code {
    font-size: 0.875em;
    background: var(--color-warm-200);
    border: 1px solid var(--color-warm-300);
    border-radius: 0.25rem;
    padding: 0.125em 0.375em;
    font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
    color: var(--color-primary-700);
}

.prose pre {
    background: var(--color-primary-900);
    border-radius: 0.625rem;
    padding: 1.25rem;
    overflow-x: auto;
    margin: 1.5em 0;
    box-shadow: var(--shadow-md);
}

.prose pre code {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--color-primary-200);
    font-size: 0.875rem;
}

/* Tables */
.prose table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    font-size: 0.875rem;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-warm-300);
}

.prose th, .prose td {
    border: 1px solid var(--color-warm-300);
    padding: 0.75rem 1rem;
    text-align: left;
}

.prose th {
    background-color: var(--color-warm-100);
    font-weight: 600;
    color: var(--color-primary-800);
    font-size: 0.8125rem;
    letter-spacing: 0.02em;
}

.prose tr:nth-child(even) { background-color: var(--color-warm-50); }
.prose tr:hover { background-color: rgba(72, 101, 129, 0.03); }

/* Citation markers - Subtle and understated */
.prose .citation-marker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35em;
    height: 1.35em;
    background: rgba(100, 116, 139, 0.15);
    color: #64748b;
    font-size: 0.75em;
    font-weight: 500;
    border-radius: 4px;
    margin: 0 0.15rem;
    vertical-align: super;
    cursor: pointer;
    transition: all var(--duration-fast);
    box-shadow: none;
    border: 1px solid rgba(100, 116, 139, 0.2);
}

.prose .citation-marker:hover {
    background: rgba(100, 116, 139, 0.25);
    color: #475569;
    transform: scale(1.05);
    box-shadow: 0 1px 3px rgba(100, 116, 139, 0.15);
}

/* ─── 12. Export Modal ──────────────────────────────── */
#export-modal {
    background: rgba(16, 42, 67, 0.35) !important;
    backdrop-filter: blur(6px);
}

#export-modal > div {
    background: white;
    border-radius: 1.25rem;
    border: 1px solid var(--color-warm-300);
    box-shadow: var(--shadow-2xl);
}

#export-modal button.group {
    transition:
        transform var(--duration-base) var(--ease-out),
        box-shadow var(--duration-base) var(--ease-out),
        border-color var(--duration-base) var(--ease-out);
}

#export-modal button.group:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ─── 13. Misc. Components ──────────────────────────── */
.alert {
    background: var(--color-warm-100);
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-warm-300);
}

.separator { height: 1px; background: var(--color-warm-300); }

.skeleton {
    background: linear-gradient(90deg, var(--color-warm-200) 25%, #e8e4de 50%, var(--color-warm-200) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s ease-in-out infinite;
    border-radius: 0.25rem;
}

/* Export shimmer */
#export-report-btn { position: relative; overflow: hidden; }
#export-report-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}
#export-report-btn:hover::before { left: 100%; }

/* Mobile header */
.md\:hidden.border-b {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(12px);
    border-bottom-color: var(--color-warm-300);
}

/* ─── 14. Animations ────────────────────────────────── */
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

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

.animate-fade-in { animation: fadeInUp 0.4s var(--ease-out) forwards; }

/* ─── 15. Responsive ────────────────────────────────── */
@media (max-width: 768px) {
    html { font-size: 14px; }

    .timeline { padding: 0 0.5rem; }
    .timeline::before { left: 1.5rem; right: 1.5rem; }
    .timeline-node-label { font-size: 0.625rem; }
    .source-header { padding: 0.5rem 0.75rem; }
    .tab-btn { padding: 0.625rem 0.875rem; font-size: 0.8125rem; }
    
    #search-view {
        padding: 1rem;
    }
    
    #search-view h1 {
        font-size: clamp(2rem, 8vw, 2.75rem);
    }
    
    #user-question {
        min-height: 140px;
        padding: 1.25rem 1.5rem;
    }
}

@media (min-width: 1536px) { 
    html { font-size: 16px; }
    
    #search-view {
        padding: 3rem;
    }
}

/* ─── 16. Print ─────────────────────────────────────── */
@media print {
    .no-print { display: none !important; }
    body { background: white !important; color: black !important; }
    .prose a { color: var(--color-primary-700) !important; text-decoration: underline !important; }
    #answer-container { box-shadow: none !important; border: 1px solid #ddd !important; }
    aside#sidebar { display: none !important; }
    
    body::before,
    body::after,
    #search-view::before,
    #search-view::after {
        display: none !important;
    }
}
