/* style.css */

/* --- Ultra-Modern Terminal Design System --- */
:root {
    /* Clinical Terminal Theme - Absolute Contrast */
    --bg-base: #0a0a0a;
    --bg-panel: #0f0f11;
    --bg-elevated: #161618;

    /* High-Vis Accents */
    --accent: #818cf8;
    --accent-dim: rgba(129, 140, 248, 0.15);
    --up-green: #10b981;
    --down-red: #ef4444;

    /* Typography - Mono focus */
    --text-primary: #e4e4e7;
    --text-muted: #71717a;
    --border: #27272a;
}

body.light-mode {
    --bg-base: #f8fafc;
    --bg-panel: #ffffff;
    --bg-elevated: #f1f5f9;
    --accent: #4f46e5;
    --accent-dim: rgba(79, 70, 229, 0.1);
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

/* --- Resets & Global --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Custom Sleek Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Helper Classes --- */
.h-100 {
    height: 100%;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.flex-1 {
    flex: 1;
}

.scroll-y {
    overflow-y: auto;
}

/* Empty States & Overlays */
.empty-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.85);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    z-index: 10;
    pointer-events: none;
}

.hide-mobile {
    display: flex;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* =========================================
   SINGLE-LINE RIBBON HEADER ARCHITECTURE
   ========================================= */
.master-header {
    display: flex;
    align-items: center;
    padding: 0 16px;
    height: 52px;
    background: var(--bg-panel);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
    white-space: nowrap;
    transition: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.master-header::-webkit-scrollbar {
    display: none;
}

/* HACK: Flatten wrappers so JS content flows horizontally */
#quote-wrapper,
#quote-dynamic-area[style],
.quote-row {
    display: contents !important;
}

/* Header Ordering */
.logo-box {
    order: 1;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 2px;
    color: #fff;
}

.control-box {
    order: 3;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 16px;
}

.telemetry-group {
    order: 9;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 16px;
}

/* Inputs & Buttons */
input.ticker-input,
select {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 6px 10px;
    border-radius: 0;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    outline: none;
    text-transform: uppercase;
    transition: none;
}

input.ticker-input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* Optgroup Styling for the New Presets Dropdown */
optgroup {
    background: var(--bg-base);
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    font-size: 11px;
    text-transform: uppercase;
}

option {
    background: var(--bg-panel);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 13px;
    text-transform: none;
}

button {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 6px 14px;
    border-radius: 0;
    font-size: 11px;
    cursor: pointer;
    transition: none;
    border: none;
}

.btn-primary {
    background: #f4f4f5;
    color: #000;
}

.btn-primary:hover {
    background: var(--text-muted);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

/* Toggles */
.api-counter-widget {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    margin-right: 10px;
}

.switch-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    position: relative;
    border: 1px solid var(--border);
    padding: 4px 8px;
}

.switch-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.slider {
    width: 28px;
    height: 14px;
    background-color: var(--bg-base);
    border-radius: 0;
    position: relative;
    transition: none;
    border: 1px solid var(--border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 8px;
    width: 8px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    border-radius: 0;
    transition: none;
}

.switch-toggle input:checked+.slider {
    background-color: var(--accent-dim);
    border-color: var(--accent);
}

.switch-toggle input:checked+.slider:before {
    transform: translateX(12px);
    background-color: var(--accent);
}

.toggle-lbl {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* Colors & Badges */
.text-green {
    color: var(--up-green) !important;
}

.text-red {
    color: var(--down-red) !important;
}

.text-accent {
    color: var(--accent) !important;
}

.market-badge {
    font-size: 10px;
    font-weight: 800;
    padding: 5px 8px;
    border-radius: 4px;
    font-family: 'Inter', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
}

.status-open {
    background: rgba(16, 185, 129, 0.1);
    color: var(--up-green);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-closed {
    background: rgba(239, 68, 68, 0.1);
    color: var(--down-red);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-unknown {
    background: var(--bg-elevated);
    color: var(--text-muted);
}

/* =========================================
   DASHBOARD & GRID RESTRAINTS
   ========================================= */
#dashboard-layout {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 1900px;
    margin: 0 auto;
}

.dashboard-top-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}

/* SPA Fade In */
.app-section {
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Layouts */
#strategy-lab-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.panel-wrapper {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.panel-wrapper>.card {
    flex: 1;
    min-height: 0;
}

/* Cards */
.card {
    background: var(--bg-panel);
    border-radius: 0;
    padding: 16px;
    border: 1px solid var(--border);
    transition: none;
}

.card:hover {
    border-color: var(--text-muted);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
}

/* -----------------------------------------
   STRATEGY LAB & TABLE STYLES
   ----------------------------------------- */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    text-align: center;
    color: var(--text-muted);
    font-size: 10px;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
}

td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
    color: #d4d4d8;
}

#options-chain-table thead {
    background: rgba(9, 9, 11, 0.95);
    backdrop-filter: blur(8px);
    position: relative;
    z-index: 20;
    will-change: transform;
}

#options-chain-table th {
    background: transparent;
}

#options-chain-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.itm-cell {
    background: rgba(255, 255, 255, 0.03);
}

/* Option Chain Specifics */
th.strike-col {
    background: var(--bg-elevated) !important;
    color: var(--text-primary);
    font-size: 11px;
}

td.strike-col {
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-weight: 800;
}

.calls-header {
    color: var(--up-green) !important;
    font-size: 12px !important;
}

.puts-header {
    color: var(--down-red) !important;
    font-size: 12px !important;
}

.calls-header-line {
    border-bottom: 2px solid var(--up-green) !important;
}

.puts-header-line {
    border-bottom: 2px solid var(--down-red) !important;
}

.atm-row td {
    background: var(--accent-dim) !important;
    border-top: 1px solid var(--accent);
    border-bottom: 1px solid var(--accent);
}

/* Metrics */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    align-content: start;
}

.metric-card {
    background: var(--bg-panel);
    padding: 14px;
    border-radius: 4px;
    border: 1px solid var(--border);
    text-align: center;
}

.metric-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.chart-box {
    height: 280px;
    position: relative;
    width: 100%;
}

.table-container {
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
    position: relative;
}

.profit-table th,
.profit-table td {
    white-space: nowrap;
}

/* Interactive Cells */
.clickable-cell {
    cursor: pointer;
    transition: color 0.2s;
}

.clickable-cell:hover {
    color: var(--accent);
}

.cell-buy-active {
    background: rgba(16, 185, 129, 0.15) !important;
    color: var(--up-green) !important;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px var(--up-green);
}

.cell-sell-active {
    background: rgba(239, 68, 68, 0.15) !important;
    color: var(--down-red) !important;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px var(--down-red);
}

#tv-wrapper {
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* Active Legs Cart */
.legs-cart-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 140px;
    overflow-y: auto;
}

.leg-cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
}

.leg-badge-action {
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 800;
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    text-transform: uppercase;
}

.leg-badge-action.buy {
    background: rgba(16, 185, 129, 0.15);
    color: var(--up-green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.leg-badge-action.sell {
    background: rgba(239, 68, 68, 0.15);
    color: var(--down-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-remove-leg {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.btn-remove-leg:hover {
    color: var(--down-red);
    background: rgba(239, 68, 68, 0.1);
}

/* Context Menu */
.context-menu {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--text-muted);
    border-radius: 0;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 1);
    padding: 4px 0;
    min-width: 180px;
    z-index: 10000;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    user-select: none;
}

.context-menu .menu-item {
    padding: 8px 14px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.2s, padding-left 0.2s;
}

.context-menu .menu-item:hover {
    background: var(--bg-elevated);
    color: var(--accent);
    padding-left: 18px;
}

.context-menu .menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.active-neon {
    border-color: var(--accent) !important;
    color: var(--accent) !important;
    background: var(--accent-dim) !important;
    box-shadow: 0 0 10px var(--accent-dim);
}

/* --- NO THEME PRESETS IN CLINICAL TERMINAL --- */

/* =========================================
   GLOBAL TOOLTIP ENGINE
   ========================================= */
#gnx-global-tooltip {
    position: absolute;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    pointer-events: none;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: none;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.6);
    max-width: 250px;
    white-space: pre-wrap;
    line-height: 1.4;
}

#gnx-global-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

body.light-mode #gnx-global-tooltip {
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-primary);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* --- Restored Chart Sentiment Buttons --- */
.sentiment-mini-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-left: 2px solid;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    margin-right: 8px;
    /* Spacing between buttons */
}

.sentiment-mini-card:hover {
    background: var(--bg-elevated);
}

.sentiment-mini-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.sentiment-mini-info span {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.sentiment-mini-info strong {
    font-size: 13px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

/* =========================================
   collapsible modules Layout Transitions
   ========================================= */

/* Collapsible Details/Summary Chevron */
details>summary {
    list-style: none;
}

details>summary::-webkit-details-marker {
    display: none;
}

details[open]>summary .collapsible-chevron {
    transform: rotate(90deg);
}

details>summary .collapsible-chevron {
    display: inline-block;
    transition: transform 0.2s ease;
}

.dashboard-top-row {
    display: flex;
    transition: all 0.3s ease;
    gap: 12px;
}

#history-container {
    flex: 1;
    transition: flex 0.3s ease;
    min-width: 0;
    /* Prevents flex items from overflowing */
}

#right-panel {
    width: 400px;
    transition: width 0.3s ease;
}

/* =========================================
   MOBILE TERMINAL OPTIMIZATIONS
   ========================================= */
@media (max-width: 1024px) {
    #dashboard-layout {
        padding: 8px;
        gap: 8px;
    }

    .dashboard-top-row {
        flex-direction: column;
    }

    #right-panel {
        width: 100%;
    }

    #strategy-lab-layout {
        grid-template-columns: 1fr;
    }
}

/* "Ghost Strike" - Sticky Strike Column for horizontal scrolls */
@media (max-width: 768px) {
    .chain-table-scroll-wrapper {
        position: relative;
    }

    .strike-col {
        position: sticky;
        left: 0;
        /* Default stick to left for small screens */
        right: 0;
        z-index: 25 !important;
        background: var(--bg-elevated) !important;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
    }

    /* If we want it centered sticky, it requires a specific JS or complex CSS.
       Sticking it to a fixed position when scrolling is the goal. */
    #options-chain-table th.strike-col,
    #options-chain-table td.strike-col {
        left: 50%;
        transform: translateX(-50%);
        width: 80px;
        min-width: 80px;
    }
}


/* Collapsed States */
.widget-collapsed #right-panel {
    width: 0;
    margin-left: -12px;
    opacity: 0;
    pointer-events: none;
}

.top-row-collapsed .dashboard-top-row {
    height: 0;
    margin: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
}

/* =========================================
   MOBILE RESPONSIVENESS & MEDIA QUERIES
   ========================================= */

@media (max-width: 1200px) {

    /* Tablet/Mid-size screens */
    .dashboard-top-row {
        flex-direction: column;
        /* Force top row components to stack vertically */
    }

    #right-panel {
        width: 100%;
    }

    #strategy-lab-layout {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    /* Mobile/Small screens */

    /* 1. Unhide the missing utility class that strategy.js relies on! */
    .hide-mobile {
        display: none !important;
    }

    /* 2. Adjust Master Header to wrap cleanly */
    .master-header {
        padding: 8px 12px;
        height: auto;
        flex-wrap: wrap;
        gap: 8px;
    }

    .logo-box {
        width: 100%;
        text-align: center;
        margin-bottom: 4px;
    }

    .control-box {
        flex-wrap: wrap;
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .telemetry-group {
        margin-left: 0;
        width: 100%;
        justify-content: center;
        margin-top: 8px;
        flex-wrap: wrap;
    }

    /* 3. Module Navigation Bar */
    .module-nav-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px;
    }

    .module-nav-bar>div {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .module-nav-bar select {
        width: 100%;
        max-width: 100% !important;
    }

    /* 4. Overall Layout Wrappers */
    #dashboard-layout {
        padding: 8px;
    }

    .dashboard-top-row {
        flex-direction: column;
    }

    #right-panel {
        width: 100%;
        margin-left: 0;
    }

    /* 5. Metrics Grids (Scanner, Strategy, etc.) */
    .metrics-grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }

    /* 6. Specific App Fixes */
    /* DCA Calculator Metrics */
    #app-dca .metric-group {
        border-left: none !important;
        padding-left: 0 !important;
        border-top: 1px solid var(--border);
        padding-top: 12px;
        width: 100%;
        text-align: center;
    }

    /* Chart specific */
    .chart-box {
        height: 300px;
    }

    /* Fix Drawing Toolbar overlap on mobile charts */
    #gnx-drawing-toolbar {
        top: auto !important;
        bottom: 16px;
        left: 50% !important;
        transform: translateX(-50%) !important;
        flex-direction: row !important;
        width: max-content;
    }

    /* Adjust badges and typography slightly for tiny screens */
    .market-badge {
        font-size: 9px;
        padding: 4px 6px;
    }

    th,
    td {
        font-size: 10px;
        padding: 6px 4px;
    }
}

/* =========================================
   INTERACTIVE TOUR ENGINE (ONBOARDING)
   ========================================= */
#gnx-tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 999990;
    pointer-events: none;
    transition: opacity 0.3s ease;
    opacity: 0;
    visibility: hidden;
}

#gnx-tour-overlay.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* The SVG Mask that dims everything except the target */
#gnx-tour-mask {
    width: 100vw;
    height: 100vh;
    fill: rgba(0, 0, 0, 0.85);
    pointer-events: none;
}

#gnx-tour-hole {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    fill: black;
}

/* The Glowing Highlight Box */
#gnx-tour-highlight {
    position: fixed;
    pointer-events: none;
    z-index: 999991;
    border: 2px solid var(--accent);
    border-radius: 6px;
    box-shadow: 0 0 20px var(--accent-dim), inset 0 0 10px rgba(129, 140, 248, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    visibility: hidden;
}

#gnx-tour-highlight.visible {
    opacity: 1;
    visibility: visible;
}

/* The Floating Popover Card */
#gnx-tour-popover {
    position: fixed;
    z-index: 999992;
    pointer-events: auto;
    background: rgba(9, 9, 11, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    width: 320px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
}

#gnx-tour-popover.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

body.light-mode #gnx-tour-popover {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.tour-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tour-title {
    font-size: 13px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.tour-progress {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.tour-body {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
}

.tour-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.btn-tour-skip {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: 700;
    transition: color 0.2s;
}

.btn-tour-skip:hover {
    color: var(--text-primary);
}