/* Design system: tokens + components (shared by every page). */
/* ---------- tokens ---------- */
:root, [data-theme="dark"] {
  --bg: #0b0e14;
  --bg-2: #0f131b;
  --card: #131824;
  --card-2: #182031;
  --line: #222b3b;
  --line-2: #2c3749;
  --text: #e7ebf3;
  --muted: #8b95a8;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, .14);
  --pos: #22c55e;
  --pos-soft: rgba(34, 197, 94, .13);
  --neg: #f05252;
  --neg-soft: rgba(240, 82, 82, .13);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, .12);
  --fast: #f5a524;
  --slow: #a78bfa;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-2: #eef1f6;
  --card: #ffffff;
  --card-2: #f6f8fb;
  --line: #e3e7ee;
  --line-2: #d5dbe5;
  --text: #121826;
  --muted: #5d6779;
  --accent: #2f6bff;
  --accent-soft: rgba(47, 107, 255, .10);
  --pos: #0f9d58;
  --pos-soft: rgba(15, 157, 88, .10);
  --neg: #d92d20;
  --neg-soft: rgba(217, 45, 32, .09);
  --warn: #b26b00;
  --warn-soft: rgba(245, 165, 36, .14);
  --fast: #d97706;
  --slow: #7c3aed;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 12px rgba(16,24,40,.04);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h2 { font-size: .95rem; font-weight: 600; margin: 0; }
h3 { margin: .2rem 0; }
code, pre, kbd, .mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
[hidden] { display: none !important; }

}

.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; background: var(--card-2);
  border: 1px solid var(--line); color: var(--muted); }
.badge.real { color: var(--pos); background: var(--pos-soft); border-color: transparent; }
.badge.synth { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge.whip { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge.bull { color: var(--pos); background: var(--pos-soft); border-color: transparent; }
.badge.bear { color: var(--neg); background: var(--neg-soft); border-color: transparent; }

.btn, .icon-btn {
  font: inherit; color: var(--text); background: var(--card-2); border: 1px solid var(--line-2);
  border-radius: 8px; padding: .4rem .8rem; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover, .icon-btn:hover { border-color: var(--accent); }
.btn.small, .icon-btn { padding: .3rem .6rem; font-size: .82rem; }
.btn.ghost { background: transparent; }

/* ---------- banners ---------- */
.banner { display: flex; align-items: center; gap: .8rem; padding: .55rem 1.25rem; font-size: .85rem; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--warn-soft); color: var(--text); }
.banner.warn strong { color: var(--warn); }
.banner.error { background: var(--neg-soft); color: var(--neg); }
.banner code { background: var(--card); padding: .05rem .35rem; border-radius: 4px; }

/* ---------- filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .9rem 1.1rem; padding: .8rem 1.25rem;
  background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: var(--topbar-h); z-index: 15;
}
.fgroup { display: flex; flex-direction: column; gap: .25rem; }
.fgroup > label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.fsep { width: 1px; align-self: stretch; background: var(--line); }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { font: inherit; font-size: .82rem; color: var(--muted); background: none; border: 0; padding: .3rem .65rem; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg.small button { font-size: .78rem; padding: .25rem .55rem; }
select {
  font: inherit; font-size: .85rem; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: .32rem 1.8rem .32rem .6rem; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin-top: 3px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card); border: 1px solid var(--line-2); border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: var(--muted); transition: .15s; }
.switch input:checked + span { background: var(--warn-soft); border-color: var(--warn); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--warn); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- layout ---------- */
.page { padding: 1rem 1.25rem 2rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; max-width: 1680px; margin: 0 auto; }
html, body { overflow-x: hidden; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* comparison */
.compare { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.mode-card { text-align: left; font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: .8rem .95rem; cursor: pointer; display: grid; gap: .45rem; transition: border-color .15s, transform .15s; box-shadow: var(--shadow); }
.mode-card:hover { border-color: var(--line-2); transform: translateY(-1px); }
.mode-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow); }
.mode-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.mode-name { font-weight: 600; }
.mode-net { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.mode-stats { display: flex; gap: 1rem; color: var(--muted); font-size: .78rem; flex-wrap: wrap; }
.mode-stats b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.best-tag { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--pos); }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem; box-shadow: var(--shadow); min-height: 66px; }
.kpi .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.kpi .s { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi.tight .v { font-size: 1.02rem; white-space: nowrap; }
.kpi.accent { background: linear-gradient(180deg, var(--accent-soft), transparent); border-color: var(--line-2); }

/* workspace */
.workspace { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 1rem; align-items: start; }
.tradelist { --stick: calc(var(--topbar-h) + var(--filters-h, 120px) + 12px);
  display: flex; flex-direction: column; height: calc(100dvh - var(--stick) - 16px); min-height: 480px; position: sticky; top: var(--stick); overflow: hidden; }
.kbd-hint kbd { font-size: .68rem; padding: .05rem .3rem; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; margin-left: 2px; }
.list-head, .row { display: grid; grid-template-columns: 1fr 1fr 90px; gap: .5rem; align-items: center; }
.list-head { padding: .45rem .9rem; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--line); }
.list { overflow-y: auto; flex: 1; outline: none; scroll-padding: 8px; }
.row { padding: .5rem .9rem; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.row:hover { background: var(--card-2); }
.row.sel { background: var(--accent-soft); }
.row.sel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.row .d { font-weight: 600; font-size: .84rem; }
.row .t { color: var(--muted); font-size: .76rem; font-variant-numeric: tabular-nums; }
.row .leg { font-size: .8rem; display: flex; align-items: center; gap: .35rem; }
.row .net { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.row .sub { color: var(--muted); font-size: .72rem; text-align: right; }
.arrow { font-size: .7rem; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); display: inline-block; }
.list-foot { padding: .5rem .9rem; border-top: 1px solid var(--line); }
.day-sep { padding: .3rem .9rem; font-size: .68rem; color: var(--muted); background: var(--bg-2); border-bottom: 1px solid var(--line); letter-spacing: .04em; text-transform: uppercase; position: sticky; top: 0; z-index: 1; }

.detail { display: grid; gap: 1rem; min-width: 0; }
.metabar { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .1rem; padding: .35rem; }
.meta { padding: .45rem .6rem; border-radius: 9px; }
.meta .k { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.meta .v { font-weight: 600; font-variant-numeric: tabular-nums; margin-top: .1rem; word-break: break-word; }
.meta .v .sub { color: var(--muted); font-weight: 500; font-size: .76rem; }
.meta.wide { grid-column: span 2; }
.meta.hl { background: var(--card-2); }

.chart-card { overflow: hidden; }
.legend { display: flex; gap: .9rem; font-size: .76rem; color: var(--muted); flex-wrap: wrap; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.sw-fast { background: var(--fast); } .sw-slow { background: var(--slow); }
.sw-entry { background: var(--accent); height: 8px; width: 8px; border-radius: 50%; }
.sw-exit { background: var(--warn); height: 8px; width: 8px; border-radius: 50%; }
.chart-wrap { position: relative; }
.chart { height: 440px; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--card) 60%, transparent); backdrop-filter: blur(1px); z-index: 5; }
.overlay .msg { color: var(--muted); text-align: center; max-width: 320px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.lower { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 1rem; }
.costs { width: 100%; border-collapse: collapse; font-size: .86rem; }
.costs td { padding: .42rem .9rem; border-bottom: 1px solid var(--line); }
.costs td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.costs tr.sub td { color: var(--muted); padding-left: 1.6rem; font-size: .82rem; }
.costs tr.total td { font-weight: 700; border-bottom: 0; }
.costs tr.strong td { font-weight: 600; }
.equity { height: 250px; }

.skipped { padding: 0; }
.skipped table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.skipped td, .skipped th { padding: .4rem .9rem; border-bottom: 1px solid var(--line); text-align: left; }
.skipped th { color: var(--muted); font-weight: 600; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; }

/* states */
.state { display: grid; place-items: center; text-align: center; gap: .4rem; padding: 2.5rem 1rem; color: var(--muted); }
.state-icon { font-size: 1.8rem; color: var(--accent); }
.state h3 { color: var(--text); }
.state pre { text-align: left; background: var(--bg-2); border: 1px solid var(--line); padding: .7rem .9rem; border-radius: 8px; color: var(--text); font-size: .8rem; overflow-x: auto; max-width: 100%; }
.skel { background: linear-gradient(90deg, var(--card-2) 25%, var(--line) 37%, var(--card-2) 63%); background-size: 400% 100%; animation: sh 1.3s ease infinite; border-radius: 6px; }
@keyframes sh { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skel.line { height: 12px; margin: .35rem 0; }
.skel.big { height: 20px; width: 70%; margin-top: .4rem; }

/* dialog */
.dialog { border: 1px solid var(--line-2); border-radius: 16px; background: var(--card); color: var(--text); max-width: 760px; width: calc(100% - 32px); padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.dialog::backdrop { background: rgba(5, 8, 14, .6); backdrop-filter: blur(2px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.rules { margin: 0; padding: .6rem 1.1rem 1.1rem; display: grid; grid-template-columns: 140px 1fr; gap: .55rem 1rem; font-size: .86rem; }
.rules dt { font-weight: 600; color: var(--accent); }
.rules dd { margin: 0; color: var(--text); }

/* live page */
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.status-dot.on { background: var(--pos); box-shadow: 0 0 0 4px var(--pos-soft); }
.status-dot.off { background: var(--neg); }
.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
.tbl th, .tbl td { padding: .45rem .8rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; }
.table-scroll { overflow-x: auto; }
.events { max-height: 360px; overflow-y: auto; font-size: .8rem; }
.events div { padding: .35rem .9rem; border-bottom: 1px solid var(--line); }
.events .lvl-warn { color: var(--warn); } .events .lvl-error { color: var(--neg); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .lower { grid-template-columns: minmax(0, 1fr); }
  .live-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .banner { display: block; }
  .banner code { white-space: nowrap; }
  .tradelist { position: static; height: 360px; min-height: 0; }
  .filters { position: static; }
  .compare { grid-template-columns: minmax(0, 1fr); }

  .chart { height: 340px; }
}
@media (max-width: 560px) {
  .page { padding: .75rem 1rem 2rem; }
  .filters { padding: .7rem 1rem; gap: .7rem; }
  .fsep { display: none; }
  .seg { flex-wrap: wrap; }
  .meta.wide { grid-column: auto; }
  .rules { grid-template-columns: 1fr; }

}

/* ---------- engine page ---------- */
.engine-top { display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.ctl { display: grid; gap: .8rem; padding: .9rem; }
.ctl .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.ctl select, .ctl input { width: 100%; }
input[type="number"], input[type="text"] {
  font: inherit; font-size: .9rem; color: var(--text); background: var(--card); border: 1px solid var(--line-2);
  border-radius: 8px; padding: .4rem .6rem;
}
input:focus-visible, select:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary.live, .btn.danger { background: var(--neg); border-color: var(--neg); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: .5rem; }
.seg button.live-on { background: var(--neg-soft); color: var(--neg); }
.seg button[disabled] { opacity: .45; cursor: not-allowed; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .1rem; padding: .4rem; }
.status-grid .big { font-size: 1.5rem; }
.meter-wrap { padding: 0 .9rem .9rem; }
.meter-head { display: flex; justify-content: space-between; margin-bottom: .35rem; }
.meter { height: 8px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--pos); transition: width .3s, background .3s; }
.banner.live { background: var(--neg); color: #fff; font-weight: 500; }
.banner.inset { margin: 0 .9rem .9rem; border-radius: 8px; border: 0; }
.pill { display: inline-block; padding: .1rem .5rem; border-radius: 6px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; }
.pill.paper { background: var(--accent-soft); color: var(--accent); }
.pill.live { background: var(--neg); color: #fff; }
.dialog-body { padding: 1rem 1.1rem; display: grid; gap: .7rem; font-size: .9rem; }
.dialog-body input { width: 100%; margin-top: .3rem; font-family: "JetBrains Mono", ui-monospace, monospace; }
.dialog-body dl { display: grid; grid-template-columns: 140px 1fr; gap: .3rem .8rem; margin: 0; }
.dialog-body dt { color: var(--muted); }
.dialog-body dd { margin: 0; font-weight: 600; }
.dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.1rem; border-top: 1px solid var(--line); }
@media (max-width: 900px) {
  .engine-top { grid-template-columns: minmax(0, 1fr); }
}

/* =====================================================================
   App shell: sidebar + topbar (desktop), bottom tab bar (phones)
   ===================================================================== */
:root { --sidebar-w: 248px; --topbar-h: 60px; --radius: 14px; --gold: #f5c542; }
a { color: var(--accent); }
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }
.banner.warn { display: block; line-height: 1.6; }
.banner code { white-space: nowrap; }

.sidebar {
  height: 100%; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: .5rem;
  background: var(--bg-2); border-right: 1px solid var(--line); padding: 1rem .75rem;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .25rem .5rem .9rem; text-decoration: none; color: var(--text); }
.logo { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--slow)); box-shadow: 0 6px 18px var(--accent-soft); }
.logo svg { width: 20px; height: 20px; }
.brand-title { display: block; font-weight: 700; letter-spacing: -.01em; font-size: 1.02rem; }
.brand-sub { display: block; color: var(--muted); font-size: .72rem; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: 1rem .7rem .35rem; }
.nav-link { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 500; transition: background .15s, color .15s; }
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--card); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-count { margin-left: auto; min-width: 20px; padding: 0 .4rem; border-radius: 999px; background: var(--warn); color: #111;
  font-size: .7rem; font-weight: 700; text-align: center; line-height: 20px; }

.side-foot { border-top: 1px solid var(--line); padding-top: .75rem; }
.user-card { display: flex; align-items: center; gap: .6rem; padding: .35rem .4rem; }
.user-card .who { min-width: 0; flex: 1; }
.user-card .who b { display: block; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .who span { display: block; font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: .8rem;
  color: var(--accent); background: var(--accent-soft); border: 1px solid var(--line-2); }

/* The right-hand side is the only scroll container on desktop; the sidebar never moves. */
.main { min-width: 0; min-height: 0; height: 100%; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column;
  scroll-behavior: smooth; overscroll-behavior: contain; scrollbar-gutter: stable; }
.main, .side-nav, .events, .list, .table-scroll { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.main > * { flex: none; }          /* never let the column squeeze the top bar, banners or filters */
.main > .content { flex: 1 0 auto; }
.main::-webkit-scrollbar, .side-nav::-webkit-scrollbar { width: 10px; }
.main::-webkit-scrollbar-thumb, .side-nav::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid var(--bg); }
.main::-webkit-scrollbar-thumb:hover { background: var(--muted); }
@media (prefers-reduced-motion: reduce) { .main { scroll-behavior: auto; } }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.page-title { font-size: 1.12rem; font-weight: 700; margin: 0; letter-spacing: -.01em; white-space: nowrap; }
.topbar-extra { display: flex; align-items: center; gap: .6rem; flex-wrap: nowrap; min-width: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.market-chip { display: inline-flex; align-items: center; gap: .45rem; font-size: .78rem; color: var(--muted);
  padding: .25rem .65rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); white-space: nowrap; }
.icon-btn svg { width: 16px; height: 16px; vertical-align: -3px; }
.icon-btn.round { border-radius: 999px; padding: .38rem; line-height: 0; }

.content { padding: 1.25rem; display: grid; gap: 1rem; align-content: start; max-width: 1680px; width: 100%; margin: 0 auto; grid-template-columns: minmax(0, 1fr); }
.content.narrow { max-width: 1120px; margin: 0; }

.tabbar { display: none; }

/* ---------- toasts (flash messages) ---------- */
.toasts { position: fixed; top: calc(var(--topbar-h) + 12px); right: 16px; z-index: 60; display: grid; gap: .5rem; width: min(420px, calc(100% - 32px)); }
.toast { display: flex; gap: .75rem; align-items: flex-start; padding: .75rem .9rem; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line-2); box-shadow: 0 12px 32px rgba(0,0,0,.25); font-size: .88rem; animation: toast-in .2s ease; }
.toast::before { content: ""; width: 4px; align-self: stretch; border-radius: 4px; background: var(--accent); flex: none; }
.toast.success::before { background: var(--pos); }
.toast.error::before { background: var(--neg); }
.toast.secret::before { background: var(--warn); }
.toast .msg { flex: 1; word-break: break-word; }
.toast button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- generic components ---------- */
.card-body { padding: 1rem 1.1rem; }
.card-body > :first-child { margin-top: 0; }
.card-body > :last-child { margin-bottom: 0; }
.card-head h2 { display: flex; align-items: center; gap: .5rem; }
.card-head h2 svg { width: 18px; height: 18px; color: var(--accent); flex: none; }
.chip svg { width: 12px; height: 12px; }
.section-title { font-size: .95rem; font-weight: 600; margin: 0; }
.lead { color: var(--muted); margin: .2rem 0 0; }
a.btn { display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn svg { width: 16px; height: 16px; }
.btn.block { width: 100%; padding: .65rem 1rem; }
.btn.lg { padding: .6rem 1.1rem; font-size: .95rem; }
.btn.ghost-danger { background: transparent; color: var(--neg); border-color: color-mix(in srgb, var(--neg) 45%, transparent); }
.btn.ghost-danger:hover { background: var(--neg-soft); border-color: var(--neg); }
.btn.success { background: var(--pos); border-color: var(--pos); color: #fff; font-weight: 600; }
.inline { display: inline; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.row-actions form { margin: 0; }

.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem .9rem; border-radius: 10px; font-size: .88rem;
  background: var(--neg-soft); color: var(--neg); border: 1px solid color-mix(in srgb, var(--neg) 25%, transparent); }
.alert.info { background: var(--accent-soft); color: var(--text); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.alert.warn { background: var(--warn-soft); color: var(--text); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.success { background: var(--pos-soft); color: var(--text); border-color: color-mix(in srgb, var(--pos) 30%, transparent); }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.empty { color: var(--muted); margin: 0; padding: 1.2rem 1.1rem; }

.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; margin: 0 .3rem .3rem 0; border-radius: 999px;
  font-size: .76rem; font-weight: 600; border: 1px solid var(--line); color: var(--muted); }
.chip.on { background: var(--pos-soft); color: var(--pos); border-color: transparent; }
.chip.off { text-decoration: line-through; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.neg { background: var(--neg-soft); color: var(--neg); border-color: transparent; }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.1rem; display: grid; gap: .3rem; position: relative; overflow: hidden; }
.stat .k { display: flex; align-items: center; gap: .45rem; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .k svg { width: 16px; height: 16px; color: var(--accent); }
.stat .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .s { font-size: .78rem; color: var(--muted); }
.stat.hero { background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--card); border-color: var(--line-2); }

/* key/value lists (account) */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem 1.25rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kv dd { margin: .25rem 0 0; font-weight: 600; word-break: break-word; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: .8rem .9rem; display: flex; flex-direction: column; gap: .15rem; background: var(--card-2); }
.tile.primary { background: linear-gradient(135deg, var(--accent-soft), transparent), var(--card-2); border-color: var(--line-2); }
.tile-label { color: var(--muted); font-size: .76rem; }
.tile-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem; margin-top: .75rem; }
.subcard { border: 1px solid var(--line); border-radius: 12px; padding: .85rem .95rem; }
.subcard h3 { font-size: .86rem; margin: 0 0 .5rem; }
.kv-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.kv-table td { padding: .32rem 0; border-bottom: 1px solid var(--line); }
.kv-table tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--card-2); }
.tbl tr:last-child td { border-bottom: 0; }

/* forms */
.form { display: grid; gap: .9rem; }
.field { display: grid; gap: .35rem; align-content: start; }
.field > label, .field-label { font-size: .8rem; font-weight: 600; color: var(--text); }
.field .help { font-size: .76rem; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; align-items: start; }
input[type="email"], input[type="password"], input[type="text"], input[type="number"], textarea {
  font: inherit; font-size: .92rem; color: var(--text); background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: 10px; padding: .6rem .75rem; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; gap: .6rem; align-items: flex-start; font-size: .84rem; color: var(--muted); }
.check input { margin-top: .2rem; accent-color: var(--accent); }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.input-group { display: flex; gap: .5rem; }
.input-group input { flex: 1; }
.mono-input { font-family: "JetBrains Mono", ui-monospace, monospace !important; letter-spacing: .02em; }
.dropzone { border: 1.5px dashed var(--line-2); border-radius: 12px; padding: 1rem; text-align: center; color: var(--muted);
  font-size: .85rem; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone svg { width: 26px; height: 26px; color: var(--accent); display: block; margin: 0 auto .35rem; }

/* settings layout */
.settings { display: grid; grid-template-columns: 230px minmax(0, 820px); gap: 1.5rem; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--topbar-h) + 16px); display: grid; gap: 2px; padding: .4rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.settings-nav a { display: flex; align-items: center; gap: .6rem; color: var(--muted); text-decoration: none; padding: .55rem .7rem;
  border-radius: 10px; font-weight: 500; font-size: .9rem; transition: background .15s, color .15s; white-space: nowrap; }
.settings-nav a svg { width: 17px; height: 17px; flex: none; }
.settings-nav a:hover { background: var(--card-2); color: var(--text); }
.settings-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.settings-main { display: grid; gap: 1rem; }
.settings-main .card { scroll-margin-top: calc(var(--topbar-h) + 16px); }
.status-line { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .75rem .9rem; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); }
.status-line .grow { flex: 1; min-width: 180px; }

/* setup checklist on the dashboard */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.steps li { display: flex; gap: .75rem; align-items: center; padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card-2); }
.steps .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; font-weight: 700;
  background: var(--card); border: 1px solid var(--line-2); color: var(--muted); flex: none; }
.steps li.done .n { background: var(--pos); border-color: var(--pos); color: #fff; }
.steps li .t { flex: 1; }
.steps li .t b { display: block; font-size: .9rem; }
.steps li .t span { font-size: .8rem; color: var(--muted); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.quick a { display: flex; gap: .8rem; align-items: center; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); color: var(--text); text-decoration: none; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.quick a:hover { border-color: var(--accent); transform: translateY(-1px); }
.quick .qi { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.quick .qi svg { width: 20px; height: 20px; }
.quick b { display: block; }
.quick span { font-size: .8rem; color: var(--muted); }
.home-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.welcome h2 { font-size: 1.35rem; letter-spacing: -.01em; margin: 0; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, 520px); }
.auth-hero { position: relative; overflow: hidden; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at -10% -10%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 60%),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--slow) 30%, transparent), transparent 60%), var(--bg-2);
  border-right: 1px solid var(--line); }
.auth-hero h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 1rem; max-width: 18ch; }
.auth-hero p { color: var(--muted); max-width: 46ch; font-size: 1rem; }
.auth-points { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .7rem; }
.auth-points li { display: flex; gap: .65rem; align-items: center; }
.auth-points svg { width: 18px; height: 18px; color: var(--pos); flex: none; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; padding: 2.5rem clamp(1.25rem, 4vw, 3rem); background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; margin: 0 auto; display: grid; gap: 1.2rem; }
.auth-card h2 { font-size: 1.45rem; letter-spacing: -.01em; margin: 0; }
.auth-foot { font-size: .86rem; color: var(--muted); text-align: center; }
.auth-top { display: flex; justify-content: space-between; align-items: center; }
.disclosure { font-size: .76rem; color: var(--muted); background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .75rem; max-height: 120px; overflow-y: auto; }
.pw-meter { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.pw-meter > i { display: block; height: 100%; width: 0; background: var(--neg); transition: width .2s, background .2s; }

/* profile photo */
img.avatar { object-fit: cover; padding: 0; background: var(--card-2); }
.avatar.sm { width: 32px; height: 32px; font-size: .72rem; }
.avatar.xl { width: 104px; height: 104px; font-size: 1.8rem; box-shadow: 0 0 0 4px var(--card), 0 0 0 5px var(--line-2); }
.topbar-avatar { display: inline-flex; border-radius: 50%; transition: transform .15s; text-decoration: none; }
.topbar-avatar:hover { transform: scale(1.06); }
.topbar-avatar:focus-visible, .user-card a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.user-card a { display: inline-flex; border-radius: 50%; text-decoration: none; }
.profile-head { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; padding-bottom: 1.25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.profile-meta { display: grid; gap: .3rem; min-width: 0; }
.profile-meta b { font-size: 1.1rem; }
.profile-meta .form-actions { margin-top: .35rem; }
.avatar-edit { position: relative; border-radius: 50%; flex: none; transition: outline-color .15s; }
.avatar-edit.over { outline: 2px dashed var(--accent); outline-offset: 8px; }
.avatar-edit-btn { position: absolute; right: -2px; bottom: -2px; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; cursor: pointer; border: 3px solid var(--card); transition: transform .15s; }
.avatar-edit-btn:hover { transform: scale(1.08); }
.avatar-edit-btn svg { width: 15px; height: 15px; }
label.btn { cursor: pointer; }
.crop-dialog { max-width: 460px; }
.crop-dialog .dialog-body { gap: .9rem; }
.crop-stage { position: relative; width: 100%; aspect-ratio: 1; border-radius: 14px; overflow: hidden; cursor: grab; touch-action: none; user-select: none;
  background: repeating-conic-gradient(var(--card-2) 0 25%, var(--bg-2) 0 50%) 0 0 / 22px 22px; }
.crop-stage:active { cursor: grabbing; }
.crop-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.crop-stage canvas { display: block; }
.crop-ring { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(6, 9, 15, .62); outline: 2px solid rgba(255, 255, 255, .9); }
.crop-controls { display: flex; align-items: center; gap: .6rem; }
.crop-controls input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
.crop-preview { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line-2); flex: none; background: var(--card-2); }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; animation: spin .7s linear infinite; }
.btn.busy:not(.primary):not(.success):not(.danger)::after { border-color: var(--line-2); border-top-color: var(--accent); }

/* error / pending pages */
.center-state { min-height: calc(100vh - var(--topbar-h) - 40px); display: grid; place-items: center; text-align: center; padding: 2rem 1rem; }
.center-state .big-icon { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; margin: 0 auto 1rem;
  background: var(--accent-soft); color: var(--accent); }
.center-state .big-icon svg { width: 30px; height: 30px; }
.center-state h2 { font-size: 1.4rem; margin: 0 0 .4rem; }

/* admin */
.user-cell { display: flex; align-items: center; gap: .6rem; }
.user-cell .who b { display: flex; align-items: center; gap: .4rem; }
.user-cell .who .sub { display: block; font-size: .76rem; color: var(--muted); }
.user-cell .chip { margin: 0; }
.filters-inline { display: flex; gap: .5rem; flex-wrap: wrap; }

/* =====================================================================
   Responsive shell
   ===================================================================== */
@media (max-width: 1100px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); height: auto; overflow: visible; }
  .main { height: auto; overflow: visible; scrollbar-gutter: auto; }
  .sidebar { display: none; }
  .topbar { padding: 0 1rem; }
  .topbar-extra { display: none; }
  .content { padding: 1rem; padding-bottom: 88px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; justify-content: space-around;
    background: color-mix(in srgb, var(--bg-2) 94%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom)); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .66rem; color: var(--muted);
    text-decoration: none; padding: .25rem .5rem; border-radius: 10px; min-width: 56px; }
  .tabbar a svg { width: 20px; height: 20px; }
  .tabbar a.active { color: var(--accent); }
  .settings { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; display: flex; overflow-x: auto; }
  .profile-head { justify-content: center; text-align: center; }
  .profile-meta .form-actions { justify-content: center; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-hero { display: none; }
  .toasts { top: auto; bottom: 84px; }
  .filters { top: var(--topbar-h); }
}
@media (max-width: 560px) {
  .market-chip .lbl { display: none; }
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .page-title { font-size: 1rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .stat { padding: .8rem .85rem; }
  .stat .v { font-size: 1.15rem; }
  .stat .s { font-size: .72rem; }
}
