/* =========================================
   1. FOUNDATION: VARIABLES & RESET
   ========================================= */

:root {
    /* --- COLOR PALETTE: NEUTRALS --- */
    --bg-root: #050505;
    --bg-panel: #0f0f0f;
    --bg-card: #0e0e0e;
    --border: #222222;
    --border-dim: #1a1a1a;

    /* --- COLOR PALETTE: ACCENTS --- */
    --accent: #00ff9d;
    --accent-dim: rgba(0, 255, 157, 0.08);
    --accent-glow: rgba(0, 255, 157, 0.3);
    
    --error: #ff4444;
    --error-dim: rgba(255, 68, 68, 0.1);
    
    --gold: #ffd700;
    --gold-dim: rgba(255, 215, 0, 0.1);
    
    --cyan: #00ccff;
    --cyan-dim: rgba(0, 204, 255, 0.1);

    /* --- TYPOGRAPHY --- */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    --text-main: #e5e5e5;
    --text-dim: #888888;
    --text-muted: #555555;

    /* --- LAYERS (Z-INDEX SYSTEM) --- */
    --z-background: -1;
    --z-base: 1;
    --z-nav: 100;
    --z-overlay: 1000;
    --z-modal: 5000;
    --z-toast: 10000;
    --z-max: 99999;
}

/* --- RESET & BASE --- */
* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

*:focus-visible {
    outline: 1px solid var(--accent);
    outline-offset: 2px;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg-root);
    color: var(--text-main);
    overflow: hidden; /* App-like behavior */
    font-family: var(--font-main);
}

/* --- GLOBAL SCROLLBARS (Integrated from legacy code) --- */
/* Firefox */
html, body {
    scrollbar-width: thin;
    scrollbar-color: var(--accent) var(--bg-root);
}

/* Webkit (Chrome, Edge, Safari) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px; /* For horizontal scroll */
    background: var(--bg-root);
}

::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
    border: 1px solid var(--bg-root);
}

::-webkit-scrollbar-thumb:hover {
    background: #00ffaa;
    box-shadow: 0 0 5px var(--accent);
}

::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

/* =========================================
   2. ROOT LAYOUT & BACKGROUND FX
   ========================================= */

#trading-os-root {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Mobile browser fix */
    background: var(--bg-root);
    display: flex;
    flex-direction: column;
    isolation: isolate;
    overflow: hidden;
    z-index: var(--z-base);
}

/* --- BACKGROUND GRID --- */
.background-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.08; /* Subtler than original 0.1 */
    z-index: var(--z-background);
    pointer-events: none;
}

/* --- CRT SCANLINES --- */
.scanlines {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%,
        rgba(0, 0, 0, 0.1) 50%
    );
    background-size: 100% 4px;
    opacity: 0.3;
    pointer-events: none;
    z-index: var(--z-max);
    mix-blend-mode: overlay; /* Better blending with content */
}

/* --- CRT STARTUP FLASH (Animation) --- */
.crt-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: var(--z-max);
    animation: turnOn 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    pointer-events: none;
}

@keyframes turnOn {
    0% { transform: scale(1, 0.005) translate3d(0, 0, 0); }
    30% { transform: scale(1, 0.005) translate3d(0, 0, 0); opacity: 1; }
    35% { transform: scale(1, 0.005) translate3d(0, 0, 0); opacity: 0; }
    36% { transform: scale(1, 1) translate3d(0, 0, 0); opacity: 1; background: #fff; }
    40% { transform: scale(1, 1) translate3d(0, 0, 0); opacity: 1; background: #000; }
    100% { transform: scale(1, 1) translate3d(0, 0, 0); opacity: 0; }
}


/* =========================================
   2. UI COMPONENTS & INTERACTION
   ========================================= */

/* --- A. BUTTON SYSTEM --- */
/* Common Base */
button, 
.btn-tech, 
.btn-main, 
.btn-ghost, 
.btn-modal, 
.btn-sm,
.btn-link {
    font-family: var(--font-mono);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    user-select: none;
    text-decoration: none;
}

/* Primary Neon Button (.btn-tech, .btn-main, .btn-glow) */
.btn-tech, 
.btn-main,
.btn-glow {
    background: rgba(0, 255, 157, 0.05);
    border-color: rgba(0, 255, 157, 0.3);
    color: var(--accent);
    padding: 10px 20px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(0, 255, 157, 0.05);
}

.btn-tech:hover, 
.btn-main:hover,
.btn-glow:hover {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 255, 157, 0.4);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.btn-tech:active, 
.btn-main:active {
    transform: translateY(0);
    box-shadow: 0 0 5px rgba(0, 255, 157, 0.4);
}

/* Secondary / Ghost Button */
.btn-ghost, 
.btn-outline,
.btn-modal {
    background: transparent;
    border-color: var(--border-dim);
    color: var(--text-dim);
    padding: 8px 16px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 4px;
}

.btn-ghost:hover, 
.btn-outline:hover,
.btn-modal:hover {
    border-color: var(--text-muted);
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

/* Modal Primary Override */
.btn-modal.primary {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(0, 255, 157, 0.05);
}
.btn-modal.primary:hover {
    background: var(--accent);
    color: #000;
}

/* Destructive Actions */
.btn-modal.danger,
.port-del:hover,
.strat-del-btn:hover {
    color: var(--error);
    border-color: var(--error);
    background: rgba(255, 68, 68, 0.05);
}
.btn-modal.danger:hover {
    background: var(--error);
    color: #fff;
    box-shadow: 0 0 15px var(--error-dim);
}

/* Small Utility Buttons (Filters) */
.btn-sm {
    padding: 6px 12px;
    font-size: 9px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 3px;
}
.btn-sm:hover {
    border-color: var(--text-muted);
    color: var(--text-main);
}
.btn-sm.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-dim);
}

/* Text Links */
.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-dim);
    font-size: 10px;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.btn-link:hover {
    color: var(--accent);
    text-decoration-color: var(--accent);
}

/* --- B. INPUTS & FORMS --- */
input, 
select, 
textarea,
.inp-std,
.sys-inp-tech,
.calc-input {
    width: 100%;
    background: var(--bg-root);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 10px 12px;
    border-radius: 4px;
    outline: none;
    transition: all 0.2s ease;
}

/* Focus State (Neon) */
input:focus, 
select:focus, 
textarea:focus,
.inp-std:focus,
.sys-inp-tech:focus,
.calc-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-dim), inset 0 0 10px rgba(0,0,0,0.5);
    background: #080808;
}

/* Disabled State */
input:disabled, 
select:disabled, 
textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #111;
    border-style: dashed;
}

/* Textarea Specifics */
textarea, .inp-area {
    min-height: 80px;
    resize: vertical;
    line-height: 1.5;
}

/* Custom Select Arrow */
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23555' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}
select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2300ff9d' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
}

/* Range Sliders */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
    height: 4px;
    margin: 10px 0;
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -5px;
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent);
    transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* --- C. AUTOCOMPLETE DROPDOWN --- */
.search-wrap {
    position: relative;
    width: 100%;
}

.search-results {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: var(--z-modal); /* Ensure above other inputs */
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: none; /* Controlled by JS */
}

.search-item {
    padding: 10px 12px;
    font-size: 11px;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    cursor: pointer;
    transition: background 0.1s;
    display: flex;
    justify-content: space-between;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background: var(--accent-dim);
    color: #fff;
    padding-left: 16px; /* Subtle slide interaction */
}

/* --- D. COMMON CARD STYLES --- */
/* Base for Strat, KPI, System, and Debrief Cards */
.strat-card,
.kpi-card,
.sys-card,
.ana-card,
.debrief-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    overflow: hidden;
}

.strat-card:hover,
.kpi-card:hover,
.sys-card:hover,
.debrief-card:hover {
    border-color: var(--text-muted);
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    background: #111;
}

/* Specific KPI Layout override */
.kpi-card {
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* --- E. TOOLTIPS --- */
/* Common tooltip styling used by multiple ID-based tooltips */
#chart-tooltip,
#ticker-tooltip,
.chart-hud {
    position: fixed; /* Fixed prevents scroll issues */
    pointer-events: none;
    background: rgba(10, 10, 10, 0.95);
    border: 1px solid var(--accent);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 10px;
    font-family: var(--font-mono);
    z-index: var(--z-max);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    min-width: 140px;
    display: none; /* JS toggles this */
}

/* --- F. PROGRESS BARS --- */
.progress-track, 
.xp-bar-bg {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill, 
.xp-bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px var(--accent);
}

/* =========================================
   3. LAYOUT STRUCTURE & NAVIGATION
   ========================================= */

:root {
    --sidebar-width: 250px;
    --header-height: 60px;
}

/* --- APP SHELL --- */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Mobile browser address bar fix */
    background: var(--bg-root);
    overflow: hidden; /* Prevent body scroll, handle inside content-area */
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 500; /* Below Auth (9999) but above content */
    transition: transform 0.3s ease;
}

.brand-area {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand-logo {
    font-family: var(--font-mono);
    font-weight: 800;
    font-size: 18px;
    color: #fff;
    letter-spacing: -1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- NAVIGATION MENU --- */
.nav-menu {
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
}

.nav-btn {
    width: 100%;
    justify-content: flex-start; /* Align text left */
    padding: 12px 15px;
    background: transparent;
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.02);
}

.nav-btn.active {
    background: rgba(0, 255, 157, 0.05);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 700;
    box-shadow: inset 10px 0 20px -10px rgba(0, 255, 157, 0.1);
}

/* Inbox Badge on Nav */
.inbox-badge {
    margin-left: auto;
    background: var(--error);
    color: #fff;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 700;
    box-shadow: 0 0 5px var(--error-dim);
}

/* Sidebar Footer */
.nav-bottom {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
    flex-shrink: 0;
}

.user-badge {
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 12px;
    font-family: var(--font-mono);
    text-align: center;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.btn-logout {
    width: 100%;
    background: #111;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px;
    border-radius: 4px;
    font-size: 10px;
    text-transform: uppercase;
    cursor: pointer;
    transition: 0.2s;
}
.btn-logout:hover {
    border-color: var(--error);
    color: var(--error);
    background: var(--error-dim);
}

/* --- MAIN CONTENT AREA --- */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    /* Subtle background tint for depth */
    background: radial-gradient(circle at top right, rgba(0,255,157,0.02), transparent 40%);
}

/* --- TOP BAR --- */
.top-bar {
    height: var(--header-height);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    background: rgba(10, 10, 10, 0.85); /* Semi-transparent */
    backdrop-filter: blur(10px);
    z-index: 400;
}

.status-led {
    font-size: 10px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.led-light {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent);
    animation: pulse 2s infinite;
}

.date-display {
    font-size: 12px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-weight: 600;
}

/* --- VIEW SECTIONS (TABS) --- */
.view-section {
    display: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 25px;
    scroll-behavior: smooth;
}

.view-section.active {
    display: block;
    animation: viewSlideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* --- PANELS & CONTAINERS --- */
.term-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.full-height {
    height: 100%;
    min-height: 500px;
}

.dashboard-split {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

/* --- ANIMATIONS --- */
@keyframes viewSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { opacity: 0.5; box-shadow: 0 0 0 var(--accent); }
    50% { opacity: 1; box-shadow: 0 0 10px var(--accent); }
    100% { opacity: 0.5; box-shadow: 0 0 0 var(--accent); }
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    /* Collapse to column layout */
    .app-layout {
        flex-direction: column;
    }

    /* Convert sidebar to top scrolling nav */
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex-direction: row;
        align-items: center;
        padding: 0;
        z-index: 500;
    }

    .brand-area, .nav-bottom {
        display: none; /* Hide Logo & Footer on Mobile */
    }

    .nav-menu {
        flex-direction: row;
        overflow-x: auto; /* Horizontal Scroll */
        padding: 10px;
        gap: 10px;
        -webkit-overflow-scrolling: touch;
    }

    .nav-btn {
        width: auto;
        white-space: nowrap;
        padding: 8px 12px;
        font-size: 10px;
        border-left: none;
        border-bottom: 2px solid transparent;
    }

    .nav-btn.active {
        border-left: none;
        border-bottom-color: var(--accent);
        background: transparent;
        box-shadow: none;
    }

    /* Content adjustments */
    .content-area {
        height: calc(100dvh - 55px); /* Subtract nav height */
    }

    .top-bar {
        padding: 0 15px;
        height: 50px;
    }

    .view-section {
        padding: 15px;
    }
    
    /* Panel Adjustments */
    .term-panel {
        padding: 15px;
    }
    
    .dashboard-split {
        grid-template-columns: 1fr;
    }
}

