/* ============================================================
   Future LP Trading Desk — COINSPE brand theme
   Palette + Poppins font extracted from coinspe.com
   ============================================================ */

@font-face { font-family:'Poppins'; src:url('/static/fonts/Poppins-Regular.ttf')  format('truetype'); font-weight:400; font-style:normal; font-display:swap; }
@font-face { font-family:'Poppins'; src:url('/static/fonts/Poppins-Medium.ttf')   format('truetype'); font-weight:500; font-style:normal; font-display:swap; }
@font-face { font-family:'Poppins'; src:url('/static/fonts/Poppins-SemiBold.ttf') format('truetype'); font-weight:600; font-style:normal; font-display:swap; }
@font-face { font-family:'Poppins'; src:url('/static/fonts/Poppins-Bold.ttf')     format('truetype'); font-weight:700; font-style:normal; font-display:swap; }

:root {
    --bg:        #0d1011;   /* Coinspe page background */
    --panel:     #12171b;   /* panel background */
    --panel-2:   #171e23;   /* slightly raised */
    --border:    #212a30;
    --text:      #f0f2f5;
    --muted:     #838383;   /* Coinspe muted text */
    --dim:       #5e6673;
    --green:     #2ebd85;   /* Coinspe up green */
    --green-dim: rgba(46, 189, 133, 0.14);
    --red:       #ff515e;   /* Coinspe down red */
    --red-dim:   rgba(255, 81, 94, 0.14);
    --accent:    #fec66d;   /* Coinspe signature gold */
    --accent-dim: rgba(254, 198, 109, 0.14);
    --blue:      #4b9fff;
    --mono: "Roboto Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --sans: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    overflow: hidden;
}

.num {
    text-align: right;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

/* ---------------- App grid ---------------- */
.app {
    display: grid;
    height: 100vh;
    grid-template-rows: 52px minmax(0, 1fr);
    grid-template-columns: 250px minmax(0, 1fr) 320px;
    grid-template-areas:
        "ticker  ticker  ticker"
        "sidebar center  right";
    gap: 1px;
    background: var(--border);
}

/* ---------------- Top ticker bar ---------------- */
.ticker-bar {
    grid-area: ticker;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 14px;
    background: var(--panel);
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: thin;
}

.ticker-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.conn-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.conn-on {
    color: var(--green);
    background: var(--green-dim);
    border-color: rgba(14, 203, 129, 0.35);
}
.conn-on .conn-dot { box-shadow: 0 0 6px var(--green); animation: pulse 1.8s ease-in-out infinite; }
.conn-off {
    color: var(--red);
    background: var(--red-dim);
    border-color: rgba(246, 70, 90, 0.35);
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.ticker-symbol-block { display: flex; flex-direction: column; line-height: 1.2; }
.tk-symbol { font-size: 15px; font-weight: 700; letter-spacing: 0.02em; }
.tk-sub { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.ticker-price-block { display: flex; flex-direction: column; line-height: 1.15; }
.tk-last {
    font-family: var(--mono);
    font-size: 19px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.tk-change { font-family: var(--mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.up   { color: var(--green) !important; }
.down { color: var(--red) !important; }

.ticker-stats { display: flex; align-items: center; gap: 22px; flex-shrink: 0; padding-right: 8px; }
.tk-stat { display: flex; flex-direction: column; line-height: 1.3; }
.tk-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tk-value { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.tk-dim { color: var(--dim); }
.tk-countdown { color: var(--accent); }

/* ---------------- Left sidebar (markets) ---------------- */
.sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    min-height: 0;
}
.sidebar-head { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); }
.market-search {
    width: 100%;
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
    outline: none;
}
.market-search:focus { border-color: var(--accent); }
.market-search::placeholder { color: var(--dim); }

/* "★ only" favorites filter chip next to the search box */
.fav-filter {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--dim);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}
.fav-filter:hover { color: var(--accent); }
.fav-filter.active {
    color: var(--accent);
    background: var(--accent-dim);
    border-color: rgba(254, 198, 109, 0.30);
}

.markets-header {
    display: grid;
    grid-template-columns: 1fr 84px 58px;
    gap: 6px;
    padding: 5px 10px;
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.markets-list { flex: 1; overflow-y: auto; min-height: 0; scrollbar-width: thin; }
.market-row {
    display: grid;
    grid-template-columns: 1fr 84px 58px;
    gap: 6px;
    align-items: center;
    padding: 6px 10px;
    cursor: pointer;
    border-left: 2px solid transparent;
    font-size: 12px;
}
.market-row:hover { background: var(--panel-2); }
.market-row.active { background: var(--panel-2); border-left-color: var(--accent); }
.mr-sym { display: flex; align-items: center; gap: 4px; min-width: 0; font-weight: 600; }
.mr-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mr-sym small { display: block; font-weight: 400; font-size: 10px; color: var(--dim); }
/* favorite star: filled gold when starred, subtle outline otherwise */
.mr-star {
    flex-shrink: 0;
    padding: 0 2px;
    border: none;
    background: transparent;
    color: var(--dim);
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
}
.mr-star:hover { color: var(--accent); }
.mr-star.fav { color: var(--accent); }
.mr-last, .mr-chg {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    text-align: right;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-note { padding: 14px 10px; color: var(--dim); font-size: 12px; text-align: center; }

/* ---------------- Center chart ---------------- */
.chart-area {
    grid-area: center;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    min-width: 0;
    min-height: 0;
}

.chart-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.tb-group { display: flex; gap: 2px; }
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.tb-spacer { flex: 1; }
.tb-info { font-size: 11px; color: var(--dim); font-family: var(--mono); }

.tb-btn {
    padding: 3px 9px;
    font-size: 11px;
    border-radius: 3px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--sans);
}
.tb-btn:hover { color: var(--text); background: var(--panel-2); }
.iv-btn.iv-active { color: var(--accent); background: var(--panel-2); font-weight: 700; }
.ind-btn.ind-active { color: var(--accent); background: var(--accent-dim); border-color: rgba(254, 198, 109, 0.30); }
.ct-btn.ct-active { color: var(--accent); background: var(--panel-2); font-weight: 700; }
.alert-btn { flex-shrink: 0; }

.chart-canvas-wrap { position: relative; flex: 1; min-height: 0; min-width: 0; }
#chart-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

.chart-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
}
.ph-big { font-size: 18px; font-weight: 600; color: var(--muted); }
.ph-small { font-size: 12px; color: var(--dim); }
.chart-placeholder.hidden { display: none; }

/* ---------------- Right column: book + tape ---------------- */
.right-col {
    grid-area: right;
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    min-height: 0;
}
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.book-panel { flex: 3 1 0; }
.tape-panel { flex: 2 1 0; }

.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 8px 10px 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}
.panel-sub { font-size: 10px; color: var(--muted); font-weight: 400; font-family: var(--mono); }

.book-cols {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 6px;
    padding: 4px 10px;
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.book-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.book-asks, .book-bids {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.book-asks { justify-content: flex-end; }

.ob-row {
    position: relative;
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 6px;
    padding: 1px 10px;
    font-family: var(--mono);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
    flex-shrink: 0;
}
.ob-row > span { position: relative; z-index: 1; }
.ob-row .ob-size, .ob-row .ob-total { text-align: right; color: var(--text); }
/* cumulative depth heatmap bar, anchored right, growing right-to-left */
.ob-row::before {
    content: "";
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: var(--depth, 0%);
    z-index: 0;
}
.ob-ask .ob-price { color: var(--red); }
.ob-ask::before { background: var(--red-dim); }
.ob-bid .ob-price { color: var(--green); }
.ob-bid::before { background: var(--green-dim); }
/* subtle side tint on the size column; totals stay neutral */
.ob-ask .ob-size { color: #ff9aa1; }
.ob-bid .ob-size { color: #8ad9bb; }

/* [Book | Depth] toggle in the order-book panel head */
.ob-toggle {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}
.ob-btn {
    padding: 1px 9px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--sans);
}
.ob-btn:hover { color: var(--text); }
.ob-btn.ob-active { color: var(--accent); background: var(--accent-dim); }

/* Order-book price-grouping stepper: [−  step  +] */
.ob-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}
.obg-btn {
    width: 16px;
    padding: 0;
    font-size: 11px;
    line-height: 14px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--mono);
}
.obg-btn:hover { color: var(--accent); background: var(--panel-2); }
.obg-val {
    min-width: 34px;
    text-align: center;
    font-size: 10px;
    font-weight: 400;
    color: var(--text);
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

/* Cumulative market-depth graph (shown when the Depth view is active) */
.depth-wrap { position: relative; flex: 1; min-height: 0; }
#depth-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.depth-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* Generic visibility helper (used by the Book/Depth view switch) */
.hidden { display: none !important; }

.book-spread {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.spread-mid { font-size: 14px; font-weight: 700; }
.spread-val { font-size: 10px; color: var(--muted); }

/* ---------------- Trades tape ---------------- */
.tape-body { flex: 1; overflow-y: auto; min-height: 0; scrollbar-width: thin; }
.tape-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 6px;
    padding: 1px 10px;
    font-family: var(--mono);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
}
.tape-row .t-size { text-align: right; color: var(--text); }
.tape-row .t-time { text-align: right; color: var(--dim); }
.tape-buy  .t-price { color: var(--green); }
.tape-sell .t-price { color: var(--red); }
.tape-row.t-new { animation: tape-flash 0.5s ease-out; }
@keyframes tape-flash {
    from { background: rgba(240, 185, 11, 0.10); }
    to   { background: transparent; }
}

/* ---------------- Toasts ---------------- */
.toast-stack {
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 100;
    pointer-events: none;
}
.toast {
    padding: 8px 14px;
    border-radius: 4px;
    background: #2a1519;
    border: 1px solid rgba(255, 81, 94, 0.45);
    color: #ffd0d4;
    font-size: 12px;
    font-family: var(--mono);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
    animation: toast-in 0.18s ease-out;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------------- Scrollbars (WebKit) ---------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3441; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #39465a; }

/* ---------------- Narrow screens: stack, still usable ---------------- */
/* ---------------- Brand logo ---------------- */
.brand-logo {
    height: 20px;
    width: auto;
    flex-shrink: 0;
    display: block;
}

/* ============================================================
   Responsive — tablet + mobile web-app
   ============================================================ */
@media (max-width: 980px) {
    html, body { overflow: auto; }
    .app {
        grid-template-rows: auto minmax(380px, 58vh) auto auto;
        grid-template-columns: 1fr;
        grid-template-areas: "ticker" "center" "right" "sidebar";
        height: auto;
        min-height: 100vh;
    }
    .sidebar { max-height: 320px; }
    .right-col { flex-direction: row; }
    .book-panel, .tape-panel { flex: 1 1 0; min-height: 340px; }
    .chart-toolbar { flex-wrap: wrap; row-gap: 6px; }
}

@media (max-width: 640px) {
    html, body { font-size: 12px; }
    .app { grid-template-rows: auto minmax(300px, 52vh) auto auto; }
    .brand-logo { height: 18px; }
    .ticker-bar { gap: 12px; padding: 8px 12px; }
    .ticker-left { gap: 10px; flex-wrap: wrap; row-gap: 4px; }
    .tk-last { font-size: 20px; }
    /* stack order book + trades vertically on phones */
    .right-col { flex-direction: column; }
    .book-panel, .tape-panel { min-height: 300px; }
    .sidebar { max-height: 260px; }
    /* keep the indicator toolbar reachable — scroll horizontally */
    .chart-toolbar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: thin; }
    #indicator-group, #interval-group, #charttype-group { flex-shrink: 0; }
}
