/* ==========================================================================
   Flight Deck — Design System Stylesheet
   Replaces all inline <style> from index.html
   ========================================================================== */

/* ==========================================================================
   1. CSS Custom Properties (Design Tokens)
   ========================================================================== */

:root {
    /* Backgrounds */
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-tertiary: #e2e8f0;
    --bg-input: #ffffff;

    /* Glass system */
    --glass-bg: #ffffff;
    --glass-border: #e2e8f0;
    --glass-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --glass-card-bg: #ffffff;
    --glass-card-hover-bg: #f8fafc;
    --glass-card-border: #e2e8f0;
    --glass-card-hover-border: #3b82f6;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    /* Accent colors */
    --accent-cyan: #0369a1;
    --accent-amber: #92400e;
    --accent-emerald: #065f46;
    --accent-rose: #9f1239;
    --accent-indigo: #3730a3;
    --accent-purple: #581c87;

    /* Borders */
    --border-primary: #cbd5e1;
    --border-secondary: #e2e8f0;

    /* Inputs */
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --input-text: #0f172a;
    --input-placeholder: #94a3b8;

    /* Scrollbar */
    --scrollbar-track: rgba(241, 245, 249, 0.8);
    --scrollbar-thumb: rgba(203, 213, 225, 0.9);

    /* Background radials */
    --bg-radial-1: transparent;
    --bg-radial-2: transparent;
    --bg-radial-3: transparent;
}

html.dark {
    /* Backgrounds */
    --bg-primary: #0b0f17;
    --bg-secondary: #111726;
    --bg-tertiary: #1e293b;
    --bg-input: #0f172a;

    /* Glass system */
    --glass-bg: #111726;
    --glass-border: #1e293b;
    --glass-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.25), 0 2px 6px -2px rgba(0, 0, 0, 0.2);
    --glass-card-bg: #151e2e;
    --glass-card-hover-bg: #1a2538;
    --glass-card-border: #1e2d42;
    --glass-card-hover-border: #3b82f6;

    /* Text */
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-faint: #64748b;

    /* Accent colors */
    --accent-cyan: #22d3ee;
    --accent-amber: #fbbf24;
    --accent-emerald: #34d399;
    --accent-rose: #fb7185;
    --accent-indigo: #818cf8;
    --accent-purple: #c084fc;

    /* Borders */
    --border-primary: #334155;
    --border-secondary: #1e293b;

    /* Inputs */
    --input-bg: #0f172a;
    --input-border: #334155;
    --input-text: #f8fafc;
    --input-placeholder: #64748b;

    /* Scrollbar */
    --scrollbar-track: rgba(15, 23, 42, 0.6);
    --scrollbar-thumb: rgba(51, 65, 85, 0.8);

    /* Background radials */
    --bg-radial-1: rgba(30, 41, 59, 0.12);
    --bg-radial-2: rgba(15, 23, 42, 0.08);
    --bg-radial-3: transparent;
}

/* ==========================================================================
   13. Theme switching anti-flicker
   ========================================================================== */

html.theme-switching,
html.theme-switching *:not(.theme-toggle-pill) {
    transition: none !important;
}

/* ==========================================================================
   2. Body & Background styles
   ========================================================================== */

body {
    background-color: var(--bg-primary);
    background-image:
        radial-gradient(at 0% 0%, var(--bg-radial-1) 0px, transparent 50%),
        radial-gradient(at 100% 0%, var(--bg-radial-2) 0px, transparent 50%),
        radial-gradient(at 50% 100%, var(--bg-radial-3) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-primary);
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* ==========================================================================
   3. Dashboard grid containment
   ========================================================================== */

#dashboard-grid {
    contain: content;
}

/* ==========================================================================
   4. Responsive grid columns (@media queries)
   ========================================================================== */

@media (min-width: 1900px) {
    #groups-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 2400px) {
    #groups-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* ==========================================================================
   5. Glass panel & glass card component styles
   ========================================================================== */

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    will-change: transform;
    transform: translateZ(0);
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.glass-card {
    background: var(--glass-card-bg);
    border: 1px solid var(--glass-card-border);
    will-change: transform;
    transform: translateZ(0);
    transition: background-color 0.15s ease, border-color 0.15s ease,
                transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-card:hover {
    background: var(--glass-card-hover-bg);
    border-color: var(--glass-card-hover-border);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
    .glass-panel,
    .glass-card {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        transition: none !important;
    }
}

/* ==========================================================================
   6. Light mode overrides — using CSS custom properties where possible
   ========================================================================== */

/* --- Text color remapping for dark-mode utility classes in light mode --- */

html.light .text-white,
html.light .text-slate-100,
html.light .text-slate-200 {
    color: #0f172a;
}

html.light .text-slate-300 {
    color: #334155;
}

html.light .text-slate-400,
html.light .text-slate-500 {
    color: #475569;
}

/* --- Solid buttons, badges, and pills retain crisp white text in light mode --- */
html.light button.bg-blue-600, html.light button.bg-blue-500, html.light button.bg-blue-700,
html.light .bg-blue-600, html.light .bg-blue-600 .text-white, html.light .bg-blue-500, html.light .bg-blue-500 .text-white,
html.light .tab-btn.bg-blue-600, html.light .tab-btn.bg-blue-600 span, html.light .tab-btn.bg-blue-600 i,
html.light button.bg-cyan-600, html.light button.bg-cyan-500, html.light button.bg-cyan-700,
html.light button.bg-indigo-600, html.light button.bg-emerald-600, html.light button.bg-rose-600,
html.light .bg-cyan-600, html.light .bg-cyan-600 .text-white,
html.light .bg-cyan-700, html.light .bg-cyan-700 .text-white,
html.light .bg-cyan-500, html.light .bg-cyan-500 .text-white,
html.light .bg-indigo-600, html.light .bg-indigo-600 .text-white,
html.light .bg-indigo-500, html.light .bg-indigo-500 .text-white,
html.light .bg-emerald-600, html.light .bg-emerald-600 .text-white,
html.light .bg-emerald-500, html.light .bg-emerald-500 .text-white,
html.light .bg-rose-600, html.light .bg-rose-600 .text-white,
html.light .bg-rose-500, html.light .bg-rose-500 .text-white,
html.light .bg-amber-600, html.light .bg-amber-600 .text-white,
html.light .bg-amber-500, html.light .bg-amber-500 .text-white,
html.light .bg-purple-500, html.light .bg-purple-500 .text-white,
html.light .bg-red-600, html.light .bg-red-600 .text-white,
html.light .bg-slate-800 button, html.light .bg-slate-900 button.bg-cyan-600, html.light .bg-slate-900 button.bg-blue-600 {
    color: #ffffff !important;
}

/* --- Tab button overrides --- */
html.light .tab-btn:not(.bg-blue-600) {
    background-color: #ffffff !important;
    color: #475569 !important;
    border-color: #e2e8f0 !important;
}

html.light .tab-btn:not(.bg-blue-600):hover {
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
}

/* --- High-contrast mappings for pastel dark-mode text colors --- */
html.light .text-cyan-100,
html.light .text-cyan-200,
html.light .text-cyan-300,
html.light .text-cyan-400 {
    color: #0369a1 !important;
}

html.light .text-amber-100,
html.light .text-amber-100\/90,
html.light .text-amber-200,
html.light .text-amber-200\/80,
html.light .text-amber-300,
html.light .text-amber-400,
html.light .text-amber-300\/80,
html.light .text-amber-300\/90 {
    color: #92400e !important;
}

html.light .text-emerald-100,
html.light .text-emerald-200,
html.light .text-emerald-300,
html.light .text-emerald-400 {
    color: #065f46 !important;
}

html.light .text-rose-100,
html.light .text-rose-200,
html.light .text-rose-300,
html.light .text-rose-400,
html.light .text-rose-300\/90,
html.light .text-red-100,
html.light .text-red-200,
html.light .text-red-300,
html.light .text-red-400 {
    color: #9f1239 !important;
}

html.light .text-indigo-100,
html.light .text-indigo-200,
html.light .text-indigo-300,
html.light .text-indigo-400 {
    color: #3730a3 !important;
}

html.light .text-purple-100,
html.light .text-purple-200,
html.light .text-purple-300,
html.light .text-purple-400 {
    color: #581c87 !important;
}

/* --- Background overrides for slate levels across all opacities --- */
html.light .bg-slate-950,
html.light .bg-slate-950\/95,
html.light .bg-slate-950\/90,
html.light .bg-slate-950\/80,
html.light .bg-slate-950\/70,
html.light .bg-slate-950\/60,
html.light .bg-slate-950\/50,
html.light .bg-slate-950\/40,
html.light .bg-slate-950\/30,
html.light .bg-slate-950\/20 {
    background-color: #ffffff !important;
}

html.light .bg-slate-900,
html.light .bg-slate-900\/95,
html.light .bg-slate-900\/90,
html.light .bg-slate-900\/80,
html.light .bg-slate-900\/70,
html.light .bg-slate-900\/60,
html.light .bg-slate-900\/50,
html.light .bg-slate-900\/40,
html.light .bg-slate-900\/30,
html.light .bg-slate-900\/20 {
    background-color: #f1f5f9 !important;
}

html.light .bg-slate-800,
html.light .bg-slate-800\/95,
html.light .bg-slate-800\/90,
html.light .bg-slate-800\/80,
html.light .bg-slate-800\/70,
html.light .bg-slate-800\/60,
html.light .bg-slate-800\/50,
html.light .bg-slate-800\/40,
html.light .bg-slate-800\/30 {
    background-color: #e2e8f0 !important;
}

/* --- Color-accented container backgrounds in light mode --- */
html.light .bg-cyan-950,
html.light .bg-cyan-950\/90,
html.light .bg-cyan-950\/80,
html.light .bg-cyan-950\/70,
html.light .bg-cyan-950\/60,
html.light .bg-cyan-950\/50,
html.light .bg-cyan-950\/40,
html.light .bg-cyan-950\/30,
html.light .bg-cyan-950\/20,
html.light .bg-cyan-950\/5,
html.light .bg-cyan-900,
html.light .bg-cyan-900\/80,
html.light .bg-cyan-900\/60,
html.light .bg-cyan-800 {
    background-color: #e0f2fe !important;
}

html.light .bg-amber-950,
html.light .bg-amber-950\/90,
html.light .bg-amber-950\/80,
html.light .bg-amber-950\/70,
html.light .bg-amber-950\/60,
html.light .bg-amber-950\/50,
html.light .bg-amber-950\/40,
html.light .bg-amber-950\/30,
html.light .bg-amber-950\/20,
html.light .bg-amber-900,
html.light .bg-amber-900\/80,
html.light .bg-amber-900\/60,
html.light .bg-amber-800 {
    background-color: #fef3c7 !important;
}

html.light .bg-emerald-950,
html.light .bg-emerald-950\/90,
html.light .bg-emerald-950\/80,
html.light .bg-emerald-950\/70,
html.light .bg-emerald-950\/60,
html.light .bg-emerald-950\/50,
html.light .bg-emerald-950\/40,
html.light .bg-emerald-950\/30,
html.light .bg-emerald-950\/20,
html.light .bg-emerald-900 {
    background-color: #d1fae5 !important;
}

html.light .bg-rose-950,
html.light .bg-rose-950\/90,
html.light .bg-rose-950\/80,
html.light .bg-rose-950\/70,
html.light .bg-rose-950\/60,
html.light .bg-rose-950\/50,
html.light .bg-rose-950\/40,
html.light .bg-rose-950\/30,
html.light .bg-rose-950\/20,
html.light .bg-red-950,
html.light .bg-red-950\/90,
html.light .bg-red-950\/80,
html.light .bg-red-950\/70,
html.light .bg-red-950\/60,
html.light .bg-red-950\/50,
html.light .bg-red-950\/40,
html.light .bg-red-950\/30 {
    background-color: #ffe4e6 !important;
}

html.light .bg-indigo-950,
html.light .bg-indigo-950\/90,
html.light .bg-indigo-950\/80,
html.light .bg-indigo-950\/60,
html.light .bg-indigo-950\/40 {
    background-color: #e0e7ff !important;
}

html.light .bg-purple-950,
html.light .bg-purple-950\/90,
html.light .bg-purple-950\/80,
html.light .bg-purple-950\/60 {
    background-color: #f3e8ff !important;
}

html.light .bg-black,
html.light .bg-black\/80,
html.light .bg-black\/60,
html.light .bg-black\/50,
html.light .bg-black\/40 {
    background-color: rgba(203, 213, 225, 0.6) !important;
}

/* --- Border overrides for light mode --- */
html.light .border-slate-800,
html.light .border-slate-800\/90,
html.light .border-slate-800\/80,
html.light .border-slate-800\/70,
html.light .border-slate-800\/60 {
    border-color: #cbd5e1 !important;
}

html.light .border-slate-700,
html.light .border-slate-700\/80,
html.light .border-slate-700\/60 {
    border-color: #cbd5e1 !important;
}

html.light .border-slate-600 {
    border-color: #94a3b8 !important;
}

html.light .border-cyan-500\/50,
html.light .border-cyan-500\/40,
html.light .border-cyan-500\/30,
html.light .border-cyan-500\/20,
html.light .border-cyan-400 {
    border-color: #0284c7 !important;
}

html.light .border-amber-500\/50,
html.light .border-amber-500\/40,
html.light .border-amber-500\/30,
html.light .border-amber-400 {
    border-color: #d97706 !important;
}

html.light .border-emerald-500\/50,
html.light .border-emerald-500\/40,
html.light .border-emerald-500\/30 {
    border-color: #059669 !important;
}

html.light .border-rose-500\/50,
html.light .border-rose-500\/40,
html.light .border-rose-500\/30,
html.light .border-red-800\/60 {
    border-color: #e11d48 !important;
}

/* --- Light mode form elements --- */
html.light select,
html.light input,
html.light textarea {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

html.light select option {
    background-color: #ffffff !important;
    color: #0f172a !important;
}

html.light select optgroup {
    background-color: #f1f5f9 !important;
    color: #0284c7 !important;
}

html.light input::placeholder,
html.light textarea::placeholder {
    color: #94a3b8 !important;
}

/* ==========================================================================
   7. Scrollbar styles
   ========================================================================== */

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

html.dark ::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
}

html.light ::-webkit-scrollbar-track {
    background: rgba(241, 245, 249, 0.8);
}

html.dark ::-webkit-scrollbar-thumb {
    background: rgba(51, 65, 85, 0.8);
    border-radius: 3px;
}

html.light ::-webkit-scrollbar-thumb {
    background: rgba(203, 213, 225, 0.9);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(6, 182, 212, 0.8);
}

/* ==========================================================================
   8. HTMX indicator styles
   ========================================================================== */

.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in-out;
}

.htmx-request .htmx-indicator {
    opacity: 1;
}

.htmx-request.htmx-indicator {
    opacity: 1;
}

/* ==========================================================================
   9. Dashboard grid HTMX transitions (no blur — perf optimized)
   ========================================================================== */

#dashboard-grid {
    transition: opacity 220ms cubic-bezier(0.4, 0, 0.2, 1),
                transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
    will-change: opacity, transform;
}

/* Swapping state: smooth fade out & slight slide down */
#dashboard-grid.htmx-swapping {
    opacity: 0;
    transform: translateY(8px);
}

/* Settling state: smooth fade in & slide into place */
#dashboard-grid.htmx-settling {
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================================================
   10. Top loader progress bar
   ========================================================================== */

#top-loader {
    height: 3px;
    background: linear-gradient(90deg, #2563eb, #3b82f6, #60a5fa, #2563eb);
    background-size: 200% 100%;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.htmx-request #top-loader,
#top-loader.htmx-request,
.htmx-request#top-loader {
    opacity: 1;
    animation: topLoaderGlow 1.2s infinite linear;
}

@keyframes topLoaderGlow {
    0% { background-position: 0% 0%; }
    100% { background-position: 200% 0%; }
}

/* ==========================================================================
   11. View Transitions API rules — REMOVED (conflicts with HTMX swap transitions)
   ========================================================================== */

/* ==========================================================================
   12. Print media stylesheet (improved)
   ========================================================================== */

@media print {
    /* Hide interactive chrome, not all forms/inputs */
    header, footer, nav, #tabs-nav, .no-print, .htmx-indicator,
    #toolbox-drawer, #promptai-drawer, #news-sidebar-drawer-overlay,
    #capitol-command-sidebar, #acronym-modal-container {
        display: none !important;
    }

    /* Hide interactive buttons and navigation controls */
    .tool-subtab-btn, .fav-star-btn, .drag-handle-group, .drag-handle-item,
    button[onclick*="toggle"], button[onclick*="copy"] {
        display: none !important;
    }

    /* Keep result containers visible for printing */
    #pt-result-container, #pay-result-container, #bah-result-container,
    .tool-panel:not(.hidden) {
        display: block !important;
    }

    html, body {
        background: #ffffff !important;
        color: #000000 !important;
    }

    #dashboard-grid, .glass-panel, .glass-card {
        background: #ffffff !important;
        border: 1px solid #cbd5e1 !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 12px !important;
        width: 100% !important;
    }

    h1, h2, h3, h4, h5, p, span, td, th, div {
        color: #000000 !important;
    }

    table, tr, .glass-card {
        page-break-inside: avoid;
    }
}

/* ==========================================================================
   14. Scrollbar hide utility
   ========================================================================== */

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* ==========================================================================
   15. Improved contrast for small text
   ========================================================================== */

html.dark .font-mono.text-\[11px\],
html.dark .font-mono.text-\[10px\] {
    color: #a1a1aa;
}
