:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --ink: #17202b;
    --muted: #667085;
    --line: #e4e7ec;
    --accent: #1f4e78;
    --accent-ink: #ffffff;
    --up: #0f7b4c;
    --down: #c0362c;
    --buy: #0f7b4c;    --buy-bg: #e3f5ec;
    --dip: #0b7285;    --dip-bg: #e0f4f7;
    --wait: #a15c00;   --wait-bg: #fdf1dc;
    --avoid: #b42318;  --avoid-bg: #fdebe9;
    --watch: #2f5bb7;  --watch-bg: #e8effc;
    --sell-bg: #c0362c;
    --mutedb: #667085; --mutedb-bg: #eef0f3;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1116;
        --card: #161b22;
        --ink: #e6e9ee;
        --muted: #8b95a5;
        --line: #262d38;
        --accent: #4f8fd1;
        --accent-ink: #0b1220;
        --up: #3fbf7f;
        --down: #f0716a;
        --buy: #49c88b;    --buy-bg: #12301f;
        --dip: #4cc3d6;    --dip-bg: #0f2a30;
        --wait: #f0b45a;   --wait-bg: #33260f;
        --avoid: #f0716a;  --avoid-bg: #3a1714;
        --watch: #7fa6f0;  --watch-bg: #16233d;
        --sell-bg: #d9443a;
        --mutedb: #9aa4b2; --mutedb-bg: #222934;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 2px 0 6px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
code { background: var(--mutedb-bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.topbar {
    display: flex; align-items: center; gap: 10px 24px; flex-wrap: wrap;
    padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; order: 2; flex-basis: 100%; }
.mainnav a { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 500; }
.mainnav a.active, .mainnav a:hover { background: var(--mutedb-bg); color: var(--ink); text-decoration: none; }
.mainnav .ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mainnav .n { display: none; }
.mainnav .short { display: none; }
.session { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-left: auto; flex-wrap: wrap; }
.session form { margin: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--up); }
.dot.off { background: var(--down); }

.wrap { max-width: 1440px; margin: 0 auto; padding: 20px 24px 8px; }
.foot { max-width: 1440px; margin: 0 auto; padding: 12px 24px 28px; color: var(--muted); font-size: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.narrow { max-width: 640px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.muted { color: var(--muted); }
.light { font-weight: 400; }
.small { font-size: 12.5px; }
.up { color: var(--up); }
.down { color: var(--down); }
.hidden { display: none !important; }
.mt { margin-top: 14px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--accent);
    background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px;
    font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.alert ul { margin: 0; padding-left: 18px; }
.alert.bad { background: var(--avoid-bg); color: var(--avoid); }
.alert.good { background: var(--buy-bg); color: var(--buy); }
.alert.warn { background: var(--wait-bg); color: var(--wait); }

.season-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.timeline { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); padding: 0; margin: 16px 0 4px; position: relative; }
.timeline::before { content: ""; position: absolute; left: 6px; right: 6px; top: 6px; height: 2px; background: var(--line); }
.timeline li { position: relative; display: flex; flex-direction: column; padding-top: 18px; font-size: 13px; }
.timeline li span:last-child { color: var(--muted); }
.tl-dot { position: absolute; top: 0; left: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 2px solid var(--line); }
.timeline li.done .tl-dot { background: var(--accent); border-color: var(--accent); }

.scanbar { display: flex; gap: 10px; align-items: center; margin-top: 12px; padding: 10px 14px; border-radius: 8px; background: var(--watch-bg); color: var(--watch); font-weight: 500; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tiles { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.tile { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; font: inherit; }
.tile b { font-size: 18px; }
.tile.on { outline: 2px solid var(--accent); }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0 14px; }
.stats > div { flex: 1 1 160px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.stats b { display: block; font-size: 18px; }
.stats span { color: var(--muted); font-size: 12px; }

.search { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 260px; background: var(--card); color: var(--ink); font: inherit; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr:hover { background: var(--mutedb-bg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid th.num { text-align: right; }
.sub { color: var(--muted); font-size: 12px; }
.sub.up { color: var(--up); }
.sub.down { color: var(--down); }
.why { max-width: 340px; white-space: normal; margin-top: 4px; }
.sym { font-weight: 700; }
.sig { min-width: 220px; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--buy-bg); color: var(--buy); margin-top: 3px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; }
.badge.xl { font-size: 16px; padding: 6px 14px; }
.badge.buy { background: var(--buy-bg); color: var(--buy); }
.badge.dip { background: var(--dip-bg); color: var(--dip); }
.badge.wait { background: var(--wait-bg); color: var(--wait); }
.badge.avoid { background: var(--avoid-bg); color: var(--avoid); }
.badge.watch { background: var(--watch-bg); color: var(--watch); }
.badge.sell { background: var(--sell-bg); color: #fff; }
.badge.hold { background: transparent; color: var(--buy); box-shadow: inset 0 0 0 1.5px var(--buy); }
.badge.muted { background: var(--mutedb-bg); color: var(--mutedb); }

.score { display: inline-block; width: 46px; height: 6px; background: var(--line); border-radius: 3px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.score span { display: block; height: 100%; background: var(--accent); }

.errors { margin-top: 12px; color: var(--muted); }

.stock-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.price { font-size: 22px; font-weight: 700; }
.price span { font-size: 15px; margin-left: 6px; }
.verdict { max-width: 560px; }
.verdict p { margin: 8px 0 12px; }
.scorebox { display: flex; gap: 10px; flex-wrap: wrap; }
.scorebox div { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; display: flex; flex-direction: column; min-width: 92px; }
.scorebox b { font-size: 18px; }
.scorebox span { font-size: 11.5px; color: var(--muted); }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; }
.cols > .card { margin-bottom: 16px; }
dl.plan { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 18px; margin: 0; }
dl.plan.four { grid-template-columns: repeat(4, 1fr); }
dl.plan div { border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
dl.plan dt { font-size: 12px; color: var(--muted); }
dl.plan dd { margin: 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
dl.plan small { font-size: 12px; font-weight: 500; color: var(--muted); }

.chart svg { width: 100%; height: 300px; display: block; }
.chart .px { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.chart .ema20 { fill: none; stroke: var(--watch); stroke-width: 1.2; }
.chart .ema50 { fill: none; stroke: var(--wait); stroke-width: 1.2; }
.chart .lvl { stroke-dasharray: 4 4; stroke-width: 1; }
.chart .lvl.entry { stroke: var(--accent); }
.chart .lvl.stop { stroke: var(--down); }
.chart .lvl.tgt { stroke: var(--up); }
.chart .lvl-t { font-size: 11px; }
.chart .lvl-t.entry { fill: var(--accent); }
.chart .lvl-t.stop { fill: var(--down); }
.chart .lvl-t.tgt { fill: var(--up); }
.chart .ax { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 2px; margin-right: 6px; vertical-align: middle; }
.legend .px::before { background: var(--ink); }
.legend .ema20::before { background: var(--watch); }
.legend .ema50::before { background: var(--wait); }
.kv { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.kv b { color: var(--ink); }

.checks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.checks ul { list-style: none; padding: 0; margin: 0; }
.checks li { display: grid; grid-template-columns: 18px 1fr; column-gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.checks li small { grid-column: 2; color: var(--muted); }
.checks .mark { font-weight: 800; }
.checks .pass .mark { color: var(--up); }
.checks .fail .mark { color: var(--down); }
.checks .info .mark { color: var(--muted); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
input, select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--ink); font: inherit; }
.w-sm { width: 110px; }

.progress-ring { border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; text-align: center; }
.progress-ring b { display: block; font-size: 22px; }
.progress-ring span { font-size: 12px; color: var(--muted); }
.chip.ok { background: var(--buy-bg); color: var(--buy); }

.prose { max-width: 900px; }
.prose li { margin-bottom: 6px; }

@media (max-width: 900px) {
    .cols, .checks { grid-template-columns: 1fr; }
    dl.plan.four { grid-template-columns: repeat(2, 1fr); }
    .wrap, .topbar { padding-left: 16px; padding-right: 16px; }
    .timeline { grid-template-columns: repeat(2, 1fr); row-gap: 12px; }
    .timeline::before { display: none; }
    .search { min-width: 0; width: 100%; }
}

.dropzone { position: relative; border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center; margin-top: 12px; transition: border-color .15s, background .15s; }
.dropzone.over, .dropzone:hover { border-color: var(--accent); background: var(--watch-bg); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone label { cursor: pointer; }
.stats.compact { margin: 0; }
.stats.compact > div { flex: 0 1 140px; }
.row-upload label.btn { cursor: pointer; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; flex-wrap: wrap; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--ink); }
tr.muted td { color: var(--muted); }

.capital { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.capital-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 0; }
.capital-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.capital-form input { width: 180px; }
.capital p { flex-basis: 100%; margin: 0; }

/* ---------- phones ---------- */
@media (max-width: 700px) {
    body { font-size: 14px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
    h1 { font-size: 20px; }
    .wrap { padding: 12px 12px 4px; }
    .foot { padding: 10px 12px 20px; }
    .card { padding: 14px; border-radius: 10px; margin-bottom: 12px; }

    /* compact header */
    .topbar { padding: 8px 12px; gap: 8px; }
    .brand-name { font-size: 15px; }
    .kite-user { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .session { gap: 6px; font-size: 12px; }

    /* bottom tab bar */
    .mainnav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
        display: grid; grid-template-columns: repeat(6, 1fr); gap: 0;
        background: var(--card); border-top: 1px solid var(--line);
        padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 10px rgba(16, 24, 40, .06);
    }
    .mainnav a { flex-direction: column; gap: 2px; padding: 6px 0; border-radius: 8px; font-size: 10.5px; font-weight: 600; text-align: center; }
    .mainnav a.active { background: none; color: var(--accent); }
    .mainnav a.active .ico { stroke-width: 2.4; }
    .mainnav .ico { width: 22px; height: 22px; }
    .mainnav .long { display: none; }
    .mainnav .short { display: block; }

    /* tables become stacked cards */
    .table-wrap { overflow: visible; }
    table.grid, .grid thead, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
    .grid thead { display: none; }
    .grid tbody tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; background: var(--card); }
    .grid tbody tr:hover { background: var(--card); }
    .grid td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; white-space: normal; }
    .grid td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; max-width: 45%; }
    .grid td:first-child { display: block; text-align: left; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 4px; }
    .grid td:first-child::before { display: none; }
    .grid td > div, .grid td .sub { text-align: right; }
    .grid td:first-child .sub { text-align: left; }
    .grid td:empty, .grid td[data-label=""]::before { display: none; }
    .grid td.sig { display: block; text-align: left; }
    .grid td.sig::before { display: block; margin-bottom: 4px; }
    .why { max-width: none; }
    .sig { min-width: 0; }
    .num { white-space: normal; }

    /* forms, tiles, stats */
    .search { min-width: 0; width: 100%; }
    .tiles { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
    .tile { flex: none; }
    .stats > div { flex: 1 1 calc(50% - 12px); padding: 8px 10px; }
    .stats b { font-size: 16px; }
    .capital-form, .capital-form label, .capital-form input { width: 100%; }
    .capital-form .btn, .capital form, .capital form .btn { width: 100%; justify-content: center; }
    .actions { width: 100%; }
    .actions .btn, .actions form, .actions form .btn { flex: 1 1 auto; justify-content: center; }
    .inline input[type=date], .w-sm { width: 100%; }
    dl.plan, dl.plan.four { grid-template-columns: 1fr 1fr; gap: 8px 12px; }
    dl.plan dd { font-size: 15px; }
    .scorebox div { min-width: 0; flex: 1 1 40%; }
    .stock-head { gap: 12px; }
    .price { font-size: 19px; }
    .chart svg { height: 220px; }
    .timeline { grid-template-columns: repeat(2, 1fr); }
    .tabs { flex-wrap: nowrap; overflow-x: auto; }
    .tab { white-space: nowrap; }
    .dropzone { padding: 16px 10px; }
}

.signin { margin: 40px auto; max-width: 380px; text-align: center; }
.logo.big { width: 48px; height: 48px; font-size: 24px; border-radius: 12px; margin: 0 auto 10px; }
form.stack { display: flex; flex-direction: column; gap: 12px; text-align: left; margin-top: 10px; }
form.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
form.stack .btn { justify-content: center; }

.chip.warn { background: var(--wait-bg); color: var(--wait); }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 4px 0 10px; cursor: pointer; }

.tag-is { display: inline-block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 0 5px; border-radius: 4px; background: var(--wait-bg); color: var(--wait); vertical-align: middle; cursor: help; white-space: nowrap; }
.badge.sm { font-size: 10.5px; padding: 1px 6px; margin-top: 3px; }

/* trading */
.live-switch { display: flex; align-items: center; gap: 10px; margin: 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; }
.live-switch .lbl { font-weight: 600; }
.live-switch.on { border-color: var(--down); background: var(--avoid-bg); }
.live-switch.on b { color: var(--down); }
.switch { position: relative; width: 46px; height: 26px; border-radius: 13px; border: 0; background: var(--line); cursor: pointer; padding: 0; transition: background .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s; }
.live-switch.on .switch { background: var(--down); }
.live-switch.on .switch .knob { left: 23px; }
.w-xs { width: 80px; }
.alert.tight { padding: 6px 10px; margin: 0 0 6px; font-size: 12.5px; }
details.log { margin-top: 6px; font-size: 12px; }
details.log ul { margin: 6px 0 0; padding-left: 16px; max-height: 220px; overflow-y: auto; }
details.log li { margin-bottom: 3px; }
.live-btn:not(:disabled) { background: var(--down); border-color: var(--down); color: #fff; }
