/* =============================================================================
   Cygnet Terminal — Theme, Polish & Responsive Layout
   All rules below use !important where needed to override Dash inline styles.
   ============================================================================= */

:root {
    --bg-0: #0b1220;
    --bg-1: #111c33;
    --bg-2: #1e293b;
    --bg-3: #263449;
    --border-soft: #1f2a44;
    --border: #334155;
    --border-strong: #475569;
    --text: #e6ecf5;
    --text-muted: #94a3b8;
    --text-bright: #f8fafc;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: rgba(59, 130, 246, 0.22);
    --violet: #8b5cf6;
    --teal: #14b8a6;
    --cyan: #06b6d4;
    --amber: #f59e0b;
    --amber-link: #facc15;
    --danger: #ef4444;
    --success: #22c55e;
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.18);
    --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);
}

/* -----------------------------------------------------------------------------
   Global baseline
   ----------------------------------------------------------------------------- */
html, body {
    background-color: var(--bg-0);
    color: var(--text);
}
body.app-body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overscroll-behavior-y: none;
}

::selection {
    background: var(--accent-soft);
    color: var(--text-bright);
}

/* Scrollbar — WebKit */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-0); }
::-webkit-scrollbar-thumb {
    background: var(--bg-3);
    border-radius: 8px;
    border: 2px solid var(--bg-0);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-corner { background: var(--bg-0); }

/* Firefox */
* { scrollbar-color: var(--bg-3) var(--bg-0); scrollbar-width: thin; }

/* Focus ring (keyboard only) */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

/* Placeholder color */
input::placeholder, textarea::placeholder {
    color: #64748b !important;
    opacity: 1;
}

/* -----------------------------------------------------------------------------
   Existing rules — preserved (load-bearing for Dash components)
   ----------------------------------------------------------------------------- */

/* Dropdown text color */
.Select-value-label,
.Select-placeholder,
.Select-input input,
.Select--single > .Select-control .Select-value .Select-value-label,
.VirtualizedSelectOption,
.VirtualizedSelectFocusedOption {
    color: #f1f5f9 !important;
}
.Select-menu-outer {
    background-color: #1e293b !important;
    border: 1px solid #475569 !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45) !important;
    overflow: hidden;
}
.VirtualizedSelectOption {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
}
.VirtualizedSelectFocusedOption {
    background-color: #334155 !important;
    color: #ffffff !important;
}

/* Finviz link icon styling */
.dash-table-container td.cell-markdown a,
.dash-table-container td.cell-markdown a:link,
.dash-table-container td.cell-markdown a:visited,
.dash-table-container td.cell-markdown a:active {
    color: #facc15 !important;
    text-decoration: none !important;
    font-weight: 700 !important;
    font-size: 12px !important;
}
.dash-table-container td.cell-markdown a:hover {
    color: #fef08a !important;
    text-decoration: underline !important;
}

/* DataTable filter input styling */
.dash-table-container .dash-filter input {
    color: #ffffff !important;
}

/* Economy calendar loading spinner */
@keyframes econ-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1.0); opacity: 1.0; }
}

/* News article tooltip styling */
.dash-table-container .dash-tooltip {
    background-color: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #475569 !important;
    border-radius: 8px !important;
    padding: 12px 16px !important;
    max-width: 500px !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
    white-space: normal !important;
    z-index: 9999 !important;
}

/* -----------------------------------------------------------------------------
   Buttons — global micro-interactions
   ----------------------------------------------------------------------------- */
button {
    transition: background-color 0.2s ease, filter 0.15s ease,
                transform 0.15s ease, box-shadow 0.15s ease !important;
}
button:not(:disabled):hover {
    filter: brightness(1.1);
}
button:not(:disabled):active {
    transform: translateY(1px);
    filter: brightness(0.95);
}
button:disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
}

/* Subtle lift on primary/cta buttons */
button[style*="background-color: rgb(59, 130, 246)"]:not(:disabled):hover,
button[style*="background-color: rgb(139, 92, 246)"]:not(:disabled):hover {
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.28);
    transform: translateY(-1px);
}

/* -----------------------------------------------------------------------------
   Inputs — focus ring
   ----------------------------------------------------------------------------- */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea {
    transition: border-color 0.15s ease, box-shadow 0.15s ease,
                background-color 0.15s ease !important;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
textarea:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--accent-soft) !important;
    outline: none !important;
}

/* -----------------------------------------------------------------------------
   Tabs — refined look
   ----------------------------------------------------------------------------- */
.tab-container {
    border-bottom: 1px solid var(--border-soft) !important;
}
.tab {
    transition: background-color 0.18s ease, color 0.18s ease,
                border-color 0.18s ease !important;
}
.tab:hover {
    color: var(--text-bright) !important;
    background-color: #253246 !important;
}

/* -----------------------------------------------------------------------------
   DataTable polish
   ----------------------------------------------------------------------------- */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner table {
    border-collapse: separate !important;
    border-spacing: 0 !important;
}
.dash-table-container .dash-spreadsheet-inner tr:hover td {
    background-color: #223048 !important;
}
.dash-table-container .dash-header {
    background-color: #0f172a !important;
    border-bottom: 1px solid var(--border) !important;
}

/* -----------------------------------------------------------------------------
   Plotly container — subtle card feel
   ----------------------------------------------------------------------------- */
.js-plotly-plot, .plot-container {
    border-radius: var(--r-md);
}

/* -----------------------------------------------------------------------------
   KPI cards — hover lift + gradient top edge
   ----------------------------------------------------------------------------- */
.kpi-card {
    position: relative;
    transition: transform 0.18s ease, box-shadow 0.18s ease,
                border-color 0.18s ease !important;
    overflow: hidden;
}
.kpi-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--violet), var(--cyan));
    opacity: 0.55;
}
.kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong) !important;
    box-shadow: var(--shadow-card) !important;
}

/* -----------------------------------------------------------------------------
   Login overlay polish
   ----------------------------------------------------------------------------- */
#login-overlay > div {
    box-shadow: var(--shadow-pop) !important;
    background:
        linear-gradient(var(--bg-2), var(--bg-2)) padding-box,
        linear-gradient(135deg, rgba(139, 92, 246, 0.4), rgba(59, 130, 246, 0.2)) border-box !important;
    border: 1px solid transparent !important;
}

/* -----------------------------------------------------------------------------
   Command info popup
   ----------------------------------------------------------------------------- */
#cmd-info-popup {
    box-shadow: var(--shadow-pop) !important;
}

/* =============================================================================
   RESPONSIVE — Mobile & Tablet
   ============================================================================= */

/* Tablet / small laptop */
@media (max-width: 1024px) {
    #main-app [style*="min-width: 800px"],
    #main-app [style*="minWidth: 800px"],
    #main-app [style*="min-width:800px"] { min-width: 0 !important; }
}

/* Phone landscape / small tablet */
@media (max-width: 900px) {
    /* Header: wrap its flex row, allow inputs to grow */
    #main-app > div:first-child > div {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }
    #header-cmd-input,
    #header-fv-input {
        width: 100% !important;
        flex: 1 1 160px !important;
        min-width: 140px !important;
    }
    #header-mon-display {
        order: 99;
        width: 100% !important;
        flex: 1 1 100% !important;
    }
    #cmd-info-popup {
        width: calc(100vw - 32px) !important;
        max-width: 620px;
        right: -8px !important;
    }

    /* Any minWidth: 800px flex container falls in line */
    [style*="min-width: 800px"],
    [style*="minWidth: 800px"],
    [style*="min-width:800px"] {
        min-width: 0 !important;
    }

    /* Oversized inline widths collapse */
    [style*="width: 620px"] { width: 100% !important; max-width: 100%; }
    [style*="width: 380px"] { width: 100% !important; max-width: 100%; }
}

/* Phone portrait */
@media (max-width: 640px) {
    body { font-size: 14px; }

    /* Header shrinks */
    #main-app > div:first-child {
        padding: 14px 16px !important;
    }
    #main-app h1 {
        font-size: 20px !important;
    }

    /* Tabs scroll horizontally instead of wrapping awkwardly */
    .tab-container {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        white-space: nowrap;
    }
    .tab-container .tab {
        flex: 0 0 auto !important;
    }

    /* KPI cards: 2-per-row */
    .kpi-card {
        min-width: calc(50% - 8px) !important;
        flex: 1 1 calc(50% - 8px) !important;
    }

    /* Dense padding for large panels */
    [style*="padding: 24px 40px"],
    [style*="padding: 24px"] {
        padding: 14px !important;
    }
    [style*="padding: 20px"] { padding: 14px !important; }
    [style*="padding: 16px 24px"] { padding: 12px 14px !important; }

    /* Login card fits phone width */
    #login-overlay > div {
        width: calc(100vw - 32px) !important;
        max-width: 380px;
        padding: 28px 20px !important;
    }

    /* Big inline-width boxes collapse to viewport width */
    [style*="width: 620px"],
    [style*="width: 540px"],
    [style*="width: 500px"],
    [style*="width: 460px"],
    [style*="width: 420px"],
    [style*="width: 400px"] {
        width: 100% !important;
        max-width: 100%;
    }

    /* Popup tables scroll horizontally when needed */
    .dash-table-container,
    .dash-spreadsheet-container {
        overflow-x: auto !important;
    }

    /* Any inline flex row with wide gap tightens */
    [style*="gap: 24px"] { gap: 12px !important; }
    [style*="gap: 16px"] { gap: 10px !important; }
}

/* Small phones */
@media (max-width: 420px) {
    body { font-size: 13.5px; }
    #main-app h1 { font-size: 18px !important; }
    .kpi-card {
        min-width: 100% !important;
        flex: 1 1 100% !important;
    }
    /* Buttons full-width on small screens to improve tap targets */
    [style*="padding: 10px 32px"] {
        padding: 10px 18px !important;
    }
}

/* Print — hide interactive chrome */
@media print {
    #login-overlay, #cmd-info-popup, button { display: none !important; }
}
