/* ============================================================
   QUANTUM STOCK TRACKER — Graph-Dominant Layout
   Qubibyte Design System
   ============================================================ */

@font-face {
    font-family: 'Khand';
    src: url('/fonts/Khand-Medium.ttf') format('truetype');
    font-weight: 500;
    font-display: swap;
}
@font-face {
    font-family: 'Khand';
    src: url('/fonts/Khand-Regular.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}

:root {
    --pri: #554A9E;
    --pri-lt: #6B5FC7;
    --sec: #0687C9;
    --acc: #AB6FAF;
    --bg0: #060614;
    --bg1: #0a0a1a;
    --bg2: #0f0f23;
    --bg3: #141428;
    --bg4: #1a1a35;
    --bg5: #1e1e3a;
    --t1: #f1f5f9;
    --t2: #94a3b8;
    --t3: #64748b;
    --brd: rgba(255,255,255,0.08);
    --brd2: rgba(255,255,255,0.14);
    --grn: #10b981;
    --grn-bg: rgba(16,185,129,0.12);
    --red: #ef4444;
    --red-bg: rgba(239,68,68,0.12);
    --blu: #38bdf8;

    --ff: 'Inter','Khand',system-ui,sans-serif;
    --fm: 'JetBrains Mono','Consolas',monospace;
    --fd: 'Khand','Inter',system-ui,sans-serif;

    --ease: cubic-bezier(0.4,0,0.2,1);
    --r: 8px;
}

*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--ff);
    background: var(--bg1);
    color: var(--t1);
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width:5px; height:5px; }
::-webkit-scrollbar-track { background:var(--bg0); }
::-webkit-scrollbar-thumb { background:var(--pri); border-radius:3px; }

/* ======================== TOP BAR ======================== */
.top-bar {
    height: 42px;
    background: var(--bg0);
    border-bottom: 1px solid var(--brd);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 14px;
    z-index: 100;
    flex-shrink: 0;
}

.top-logo img { height: 22px; object-fit: contain; opacity: 0.8; }
.top-logo img:hover { opacity:1; }

.top-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-title-text {
    font-family: var(--fd);
    font-size: 1.05em;
    font-weight: 500;
    color: var(--t2);
    letter-spacing: 0.3px;
    margin: 0;
    line-height: 1;
}

.top-live-dot {
    width: 6px; height: 6px;
    background: var(--grn);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.4); }
    50% { box-shadow: 0 0 0 4px rgba(16,185,129,0); }
}

.top-back {
    margin-left: auto;
    color: var(--t3);
    text-decoration: none;
    font-size: 0.82em;
    font-family: var(--fd);
    transition: color 0.2s;
}
.top-back:hover { color: var(--t1); }

/* ======================== MAIN APP GRID ======================== */
.app {
    display: flex;
    height: calc(100vh - 42px - 36px); /* minus top-bar and bottom-ticker */
    overflow: hidden;
}

/* ======================== STOCK SELECTOR STRIP ======================== */
.stock-strip {
    width: 160px;
    min-width: 160px;
    background: var(--bg0);
    border-right: 1px solid var(--brd);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 0;
    flex-shrink: 0;
}

.stock-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: var(--t2);
    cursor: pointer;
    transition: all 0.15s var(--ease);
    font-family: var(--ff);
    font-size: 0.82em;
    text-align: left;
}

.stock-btn:hover {
    background: rgba(255,255,255,0.03);
    color: var(--t1);
}

.stock-btn.active {
    background: rgba(85,74,158,0.12);
    border-left-color: var(--pri-lt);
    color: var(--t1);
}

.stock-btn-icon {
    font-size: 1.15em;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.stock-btn-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.stock-btn-ticker {
    font-family: var(--fm);
    font-weight: 600;
    font-size: 0.95em;
    letter-spacing: 0.3px;
}

.stock-btn-name {
    font-size: 0.78em;
    color: var(--t3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stock-btn-change {
    margin-left: auto;
    font-family: var(--fm);
    font-size: 0.75em;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}

.stock-btn-change.up { color: var(--grn); background: var(--grn-bg); }
.stock-btn-change.down { color: var(--red); background: var(--red-bg); }
.stock-btn-change.neu { color: var(--t3); background: rgba(255,255,255,0.04); }

/* ======================== CENTER PANEL ======================== */
.center-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ---- Chart bar ---- */
.chart-bar {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg2);
    border-bottom: 1px solid var(--brd);
    gap: 12px;
    flex-shrink: 0;
}

.chart-bar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chart-bar-icon { font-size: 1.1em; }

.chart-bar-name {
    font-family: var(--fd);
    font-weight: 600;
    font-size: 1em;
    color: var(--t1);
    white-space: nowrap;
}

.chart-bar-ticker {
    font-family: var(--fm);
    font-size: 0.78em;
    color: var(--t3);
    background: var(--bg3);
    padding: 2px 6px;
    border-radius: 3px;
}

.chart-bar-price {
    font-family: var(--fm);
    font-size: 0.95em;
    font-weight: 600;
    color: var(--t1);
}

.chart-bar-change {
    font-family: var(--fm);
    font-size: 0.8em;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}
.chart-bar-change.up { color: var(--grn); background: var(--grn-bg); }
.chart-bar-change.down { color: var(--red); background: var(--red-bg); }

/* Data source indicator */
.chart-bar-src {
    font-family: var(--fm);
    font-size: 0.68em;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 3px;
    letter-spacing: 0.3px;
}
.chart-bar-src.live { color: var(--grn); background: var(--grn-bg); }
.chart-bar-src.closed { color: #94a3b8; background: rgba(148,163,184,0.12); }
.chart-bar-src.sim { color: #f59e0b; background: rgba(245,158,11,0.12); }
.chart-bar-src.private { color: var(--acc); background: rgba(171,111,175,0.12); }

.chart-bar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.tf-group {
    display: flex;
    gap: 2px;
    background: var(--bg3);
    padding: 2px;
    border-radius: 5px;
    border: 1px solid var(--brd);
}

.tf-btn {
    padding: 4px 10px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--t3);
    font-family: var(--fm);
    font-size: 0.72em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.tf-btn:hover { color: var(--t1); background: rgba(255,255,255,0.05); }
.tf-btn.active {
    background: linear-gradient(135deg, var(--pri), var(--sec));
    color: #fff;
    box-shadow: 0 1px 6px rgba(85,74,158,0.3);
}

/* ======================== CHART ======================== */
.chart-wrap {
    flex: 1;
    position: relative;
    background: var(--bg1);
    cursor: crosshair;
    overflow: hidden;
    min-height: 0;
}

.chart-wrap canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Loading overlay */
.chart-loading {
    position: absolute;
    inset: 0;
    background: rgba(10,10,26,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.chart-loading.visible { opacity: 1; pointer-events: auto; }

.chart-loading-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.chart-loading-spinner {
    width: 28px; height: 28px;
    border: 2.5px solid var(--bg5);
    border-top-color: var(--pri-lt);
    border-radius: 50%;
    animation: ldspin 0.8s linear infinite;
}

@keyframes ldspin {
    to { transform: rotate(360deg); }
}

.chart-loading-text {
    font-family: var(--fm);
    font-size: 0.78em;
    color: var(--t3);
}

.chart-tooltip {
    position: absolute;
    display: none;
    padding: 10px 14px;
    background: var(--bg5);
    border: 1px solid var(--brd2);
    border-radius: var(--r);
    font-family: var(--fm);
    font-size: 0.8em;
    color: var(--t1);
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    white-space: nowrap;
}

.crosshair-v, .crosshair-h {
    position: absolute;
    display: none;
    pointer-events: none;
    z-index: 10;
}
.crosshair-v {
    width: 1px;
    top: 0; bottom: 0;
    background: rgba(255,255,255,0.12);
}
.crosshair-h {
    height: 1px;
    left: 0; right: 0;
    background: rgba(255,255,255,0.12);
}

/* Event markers on chart */
.ev-marker {
    position: absolute;
    width: 14px; height: 14px;
    border-radius: 50%;
    transform: translate(-50%,-50%);
    cursor: pointer;
    z-index: 15;
    transition: transform 0.2s;
    border: 2px solid;
}
.ev-marker:hover { transform: translate(-50%,-50%) scale(1.6); z-index: 16; }
.ev-marker.pos { background: var(--grn); border-color: var(--grn); }
.ev-marker.neg { background: var(--red); border-color: var(--red); }
.ev-marker.neu { background: var(--sec); border-color: var(--sec); }

.ev-marker::after {
    content:'';
    position:absolute;
    inset:-5px;
    border-radius:50%;
    opacity:0;
    animation: mpulse 2.5s ease-in-out infinite;
}
.ev-marker.pos::after { background:var(--grn); }
.ev-marker.neg::after { background:var(--red); }
.ev-marker.neu::after { background:var(--sec); }

@keyframes mpulse {
    0%,100% { opacity:0; transform:scale(1); }
    50% { opacity:0.25; transform:scale(1.6); }
}

/* ======================== X-AXIS ======================== */
.chart-x-axis {
    height: 22px;
    display: flex;
    justify-content: space-between;
    padding: 2px 16px 2px 0;
    font-family: var(--fm);
    font-size: 0.68em;
    color: var(--t3);
    background: var(--bg1);
    border-top: 1px solid var(--brd);
    flex-shrink: 0;
}

/* ======================== Y-AXIS ======================== */
.y-axis {
    width: 62px;
    min-width: 62px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px 6px 22px 0; /* align with chart-bar + x-axis */
    font-family: var(--fm);
    font-size: 0.7em;
    color: var(--t3);
    text-align: right;
    background: var(--bg1);
    border-left: 1px solid var(--brd);
    flex-shrink: 0;
    user-select: none;
}

/* ======================== EVENTS STRIP ======================== */
.events-strip {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: var(--bg2);
    border-top: 1px solid var(--brd);
    flex-shrink: 0;
    overflow: hidden;
}

.events-strip-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--fd);
    font-size: 0.8em;
    font-weight: 600;
    color: var(--t3);
    white-space: nowrap;
    flex-shrink: 0;
}

.events-scroll {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
    padding: 4px 0;
}
.events-scroll::-webkit-scrollbar { display:none; }

.ev-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    background: var(--bg3);
    border: 1px solid var(--brd);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}
.ev-pill:hover {
    border-color: var(--brd2);
    background: var(--bg4);
    transform: translateY(-1px);
}

.ev-pill-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ev-pill-dot.pos { background: var(--grn); }
.ev-pill-dot.neg { background: var(--red); }
.ev-pill-dot.neu { background: var(--sec); }

.ev-pill-text {
    font-size: 0.72em;
    color: var(--t2);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ev-pill-impact {
    font-family: var(--fm);
    font-size: 0.7em;
    font-weight: 600;
    flex-shrink: 0;
}
.ev-pill-impact.pos { color: var(--grn); }
.ev-pill-impact.neg { color: var(--red); }
.ev-pill-impact.neu { color: var(--sec); }

.events-empty {
    font-size: 0.75em;
    color: var(--t3);
    font-style: italic;
}

/* ======================== BOTTOM TICKER ======================== */
.bottom-ticker {
    height: 36px;
    background: var(--bg0);
    border-top: 1px solid var(--brd);
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    z-index: 50;
}

.bottom-ticker::before,
.bottom-ticker::after {
    content:'';
    position:absolute;
    top:0; bottom:0;
    width:40px;
    z-index:2;
    pointer-events:none;
}
.bottom-ticker::before { left:0; background:linear-gradient(90deg,var(--bg0),transparent); }
.bottom-ticker::after { right:0; background:linear-gradient(270deg,var(--bg0),transparent); }

.ticker-track {
    display: flex;
    animation: scroll 50s linear infinite;
    width: max-content;
    height: 100%;
    align-items: center;
}
.ticker-track:hover { animation-play-state: paused; }

@keyframes scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

.tick-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px;
    height: 100%;
    border-right: 1px solid var(--brd);
    font-size: 0.78em;
}

.tick-sym {
    font-family: var(--fm);
    font-weight: 600;
    color: var(--t1);
}

.tick-price {
    font-family: var(--fm);
    color: var(--t2);
}

.tick-chg {
    font-family: var(--fm);
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}
.tick-chg.up { color:var(--grn); background:var(--grn-bg); }
.tick-chg.down { color:var(--red); background:var(--red-bg); }
.tick-chg.neu { color:var(--t3); background:rgba(255,255,255,0.04); }

/* ======================== MODAL ======================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6,6,20,0.82);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display:flex; }

.modal-card {
    background: var(--bg3);
    border: 1px solid var(--brd2);
    border-radius: 14px;
    max-width: 500px;
    width: 100%;
    position: relative;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: mIn 0.3s cubic-bezier(0.16,1,0.3,1);
}

@keyframes mIn {
    from { transform:translateY(20px) scale(0.96); opacity:0; }
    to { transform:translateY(0) scale(1); opacity:1; }
}

.modal-x {
    position:absolute; top:12px; right:12px;
    width:30px; height:30px;
    background:rgba(255,255,255,0.08);
    border:none; border-radius:50%;
    color:var(--t2); font-size:1.15em;
    cursor:pointer; transition:all 0.15s;
    display:flex; align-items:center; justify-content:center;
    z-index:5;
}
.modal-x:hover { background:rgba(255,255,255,0.15); color:var(--t1); }

.modal-bar { height:3px; width:100%; }
.modal-bar.pos { background:linear-gradient(90deg,var(--grn),#34d399); }
.modal-bar.neg { background:linear-gradient(90deg,var(--red),#f87171); }
.modal-bar.neu { background:linear-gradient(90deg,var(--sec),var(--acc)); }

.modal-body { padding:28px; }

.modal-date {
    font-family:var(--fm);
    font-size:0.8em;
    color:var(--t3);
    margin-bottom:6px;
}

.modal-title {
    font-family:var(--fd);
    font-size:1.35em;
    font-weight:700;
    color:var(--t1);
    margin-bottom:10px;
    line-height:1.3;
}

.modal-impact {
    display:inline-block;
    font-family:var(--fm);
    font-size:0.88em;
    font-weight:700;
    padding:4px 14px;
    border-radius:20px;
    margin-bottom:16px;
}
.modal-impact.pos { color:var(--grn); background:var(--grn-bg); border:1px solid rgba(16,185,129,0.2); }
.modal-impact.neg { color:var(--red); background:var(--red-bg); border:1px solid rgba(239,68,68,0.2); }
.modal-impact.neu { color:var(--sec); background:rgba(6,135,201,0.12); border:1px solid rgba(6,135,201,0.2); }

.modal-desc {
    font-size:0.92em;
    color:var(--t2);
    line-height:1.65;
    margin-bottom:18px;
}

.modal-details { display:flex; flex-direction:column; gap:8px; }

.md-row {
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:8px 14px;
    background:var(--bg2);
    border-radius:6px;
    border:1px solid var(--brd);
}

.md-label {
    font-size:0.78em;
    color:var(--t3);
    text-transform:uppercase;
    letter-spacing:0.4px;
}

.md-val {
    font-family:var(--fm);
    font-size:0.88em;
    font-weight:600;
    color:var(--t1);
}

/* ======================== DISCLAIMER ======================== */
.disclaimer-badge {
    position: fixed;
    bottom: 44px;
    right: 12px;
    width: 24px; height: 24px;
    background: var(--bg3);
    border: 1px solid var(--brd);
    border-radius: 50%;
    color: var(--t3);
    font-size: 0.72em;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    z-index: 100;
    transition: all 0.15s;
}
.disclaimer-badge:hover {
    color: var(--t1);
    background: var(--bg4);
}

/* ======================== RESPONSIVE ======================== */
@media (max-width: 900px) {
    .stock-strip {
        width: 100%;
        min-width: unset;
        height: 48px;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--brd);
        overflow-x: auto;
        overflow-y: hidden;
        display: flex;
        padding: 0;
    }

    .stock-btn {
        flex-direction: column;
        padding: 6px 14px;
        gap: 2px;
        border-left: none;
        border-bottom: 3px solid transparent;
        min-width: 70px;
        align-items: center;
        text-align: center;
    }
    .stock-btn.active {
        border-left-color: transparent;
        border-bottom-color: var(--pri-lt);
    }

    .stock-btn-icon { font-size:1em; width:auto; }
    .stock-btn-name { display:none; }
    .stock-btn-change { margin-left:0; font-size:0.65em; }

    .app {
        flex-direction: column;
        height: calc(100vh - 42px - 36px);
    }

    .y-axis {
        display: none;
    }

    .chart-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 12px;
        gap: 6px;
    }

    .chart-bar-name { font-size:0.9em; }

    .tf-btn { padding: 3px 7px; font-size:0.65em; }

    .events-strip { height: 48px; padding: 0 8px; }

    .ev-pill { padding: 4px 10px; }
    .ev-pill-text { max-width: 140px; font-size:0.68em; }
}

@media (max-width: 480px) {
    .top-bar { padding: 0 10px; gap:8px; }
    .top-title-text { font-size:0.9em; }
    .chart-bar-left { gap:6px; }
    .chart-bar-price { font-size:0.85em; }
    .chart-bar-ticker { display:none; }
    .stock-btn { min-width: 55px; padding: 4px 8px; }
    .stock-btn-ticker { font-size:0.8em; }
    .ev-pill-text { max-width: 100px; }
}
