/* ==========================================================================
   DEEP LIVE — design system
   1. Tokens   2. Base   3. Shell   4. Components   5. Trading   6. Pages
   7. Responsive   8. Motion
   ========================================================================== */

/* ---------- 1. Tokens --------------------------------------------------- */
:root {
  /* type */
  --font: "Geist", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --fs-2xs: 10px; --fs-xs: 11px; --fs-sm: 12px; --fs-md: 13px; --fs-lg: 15px;
  --fs-xl: 18px; --fs-2xl: 22px; --fs-3xl: 28px;

  /* space (4px grid) + radius */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  --r-sm: 4px; --r: 6px; --r-lg: 10px; --r-pill: 999px;
  --gap: 8px;
  --pad: 12px;
  --row-h: 30px;
  --hdr-h: 52px;
  --side-w: 212px;
  --side-w-c: 60px;
  --nav-h: 60px;

  /* motion */
  --t-fast: 120ms; --t: 180ms; --ease: cubic-bezier(.2,.7,.2,1);

  /* layers */
  --z-side: 20; --z-hdr: 30; --z-banner: 35; --z-pop: 50; --z-modal: 60; --z-toast: 70;
}

/* Dark (default) */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg:      #0a0c0f;
  --bg-1:    #101317;   /* panel */
  --bg-2:    #151920;   /* elevated: popover, modal */
  --bg-3:    #1b2028;   /* input / hover */
  --bg-4:    #232934;   /* pressed / selected */
  --line:    #1f252e;
  --line-2:  #2b323d;
  --line-3:  #3a4350;
  --tx:      #e7eaef;
  --tx-2:    #a4adba;
  --tx-3:    #6c7684;
  --tx-inv:  #0a0c0f;

  --up:      #1fbf75;  --up-2: #17a564;  --up-bg: rgba(31,191,117,.12);  --up-line: rgba(31,191,117,.35);
  --dn:      #f0464f;  --dn-2: #d73640;  --dn-bg: rgba(240,70,79,.12);   --dn-line: rgba(240,70,79,.38);
  --warn:    #f2a93b;  --warn-bg: rgba(242,169,59,.12); --warn-line: rgba(242,169,59,.38);
  --info:    #5b9cff;  --info-bg: rgba(91,156,255,.12); --info-line: rgba(91,156,255,.38);
  --neutral: #7d8794;  --neutral-bg: rgba(125,135,148,.14);
  --accent:  #5b9cff;
  --focus:   #7fb2ff;

  --live:    #ff3b3b;  --live-bg: rgba(255,59,59,.14);
  --test:    #2fc4d6;  --test-bg: rgba(47,196,214,.13);

  --delta:   #f0a73b;   /* broker identity marks (small dots only) */
  --shark:   #6c8dff;

  --shadow-pop: 0 10px 30px rgba(0,0,0,.45), 0 0 0 1px var(--line-2);
  --shadow-modal: 0 24px 60px rgba(0,0,0,.6), 0 0 0 1px var(--line-2);
  --scrim: rgba(3,5,8,.66);
  --chart-grid: rgba(255,255,255,.045);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg:      #f3f5f8;
  --bg-1:    #ffffff;
  --bg-2:    #ffffff;
  --bg-3:    #f1f3f6;
  --bg-4:    #e7eaef;
  --line:    #e4e7ec;
  --line-2:  #d5dae1;
  --line-3:  #bfc6d0;
  --tx:      #0e1318;
  --tx-2:    #4a5462;
  --tx-3:    #7a8492;
  --tx-inv:  #ffffff;

  --up:      #0c9a58;  --up-2: #0a8049;  --up-bg: rgba(12,154,88,.10);  --up-line: rgba(12,154,88,.35);
  --dn:      #d42b37;  --dn-2: #b8202b;  --dn-bg: rgba(212,43,55,.09); --dn-line: rgba(212,43,55,.35);
  --warn:    #b06d00;  --warn-bg: rgba(214,140,20,.12); --warn-line: rgba(176,109,0,.4);
  --info:    #2563eb;  --info-bg: rgba(37,99,235,.09); --info-line: rgba(37,99,235,.35);
  --neutral: #6b7480;  --neutral-bg: rgba(107,116,128,.12);
  --accent:  #2563eb;
  --focus:   #2563eb;

  --live:    #e0242b;  --live-bg: rgba(224,36,43,.10);
  --test:    #0e8fa0;  --test-bg: rgba(14,143,160,.10);

  --delta:   #d08a16;
  --shark:   #4a6cf0;

  --shadow-pop: 0 10px 28px rgba(15,23,42,.12), 0 0 0 1px var(--line-2);
  --shadow-modal: 0 24px 60px rgba(15,23,42,.22), 0 0 0 1px var(--line-2);
  --scrim: rgba(15,20,28,.42);
  --chart-grid: rgba(0,0,0,.05);
}

/* ---------- 2. Base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--tx);
  font: 400 var(--fs-md)/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
table { border-collapse: collapse; width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--info-bg); }

.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums slashed-zero; letter-spacing: -.01em; }
.up   { color: var(--up); }
.dn   { color: var(--dn); }
.warn { color: var(--warn); }
.muted { color: var(--tx-2); }
.faint { color: var(--tx-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i-sm { width: 14px; height: 14px; }
.i-lg { width: 20px; height: 20px; }
.scroll { overflow: auto; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }
.row { display: flex; align-items: center; gap: var(--gap); }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.grow { flex: 1 1 auto; min-width: 0; }
.right { margin-left: auto; }
.ta-r { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- 3. Shell ---------------------------------------------------- */
.app {
  height: 100dvh; display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  grid-template-rows: auto var(--hdr-h) auto minmax(0, 1fr);
  grid-template-areas: "pre pre" "hdr hdr" "ban ban" "side main";
}
.app.side-collapsed { grid-template-columns: var(--side-w-c) minmax(0, 1fr); }

/* design preview strip — honest about what this build is */
.prebar {
  grid-area: pre; display: flex; align-items: center; gap: 10px; min-height: 26px;
  padding: 3px 12px; font-size: var(--fs-xs); color: var(--tx-2);
  background: var(--bg-1); border-bottom: 1px solid var(--line);
}
.prebar b { color: var(--tx); font-weight: 600; }
.prebar .btn { height: 20px; padding: 0 8px; font-size: var(--fs-xs); }

/* environment rail: the 2px line under the header carries the env colour everywhere */
.hdr {
  grid-area: hdr; z-index: var(--z-hdr); position: relative;
  display: flex; align-items: center; gap: 4px; padding: 0 10px 0 0;
  background: var(--bg-1); border-bottom: 1px solid var(--line);
}
.hdr::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--live); }
body.env-test .hdr::after { background: repeating-linear-gradient(-45deg, var(--test) 0 8px, transparent 8px 14px); }

.brand { display: flex; align-items: center; gap: 10px; width: var(--side-w); height: 100%; padding: 0 14px; border-right: 1px solid var(--line); flex: none; }
.side-collapsed .brand { width: var(--side-w-c); justify-content: center; padding: 0; }
.side-collapsed .brand-txt { display: none; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-txt { line-height: 1.05; }
.brand-txt b { display: block; font-size: 14px; letter-spacing: .14em; font-weight: 700; }
.brand-txt span { font-size: var(--fs-2xs); color: var(--tx-3); letter-spacing: .04em; }

.hdr-sym { display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 12px; border-right: 1px solid var(--line); }
.sym-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border-radius: var(--r); font-weight: 600; font-size: var(--fs-lg); }
.sym-btn:hover { background: var(--bg-3); }
.sym-btn .i { color: var(--tx-3); }
.hdr-px { font-size: var(--fs-xl); font-weight: 600; min-width: 108px; }

.stats { display: flex; align-items: stretch; height: 100%; overflow: hidden; }
.stat { display: flex; flex-direction: column; justify-content: center; padding: 0 12px; flex: none; white-space: nowrap; }
.px-chg { display: none; font-size: var(--fs-sm); }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .k { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: var(--fs-md); font-weight: 500; }

.hdr-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.iconbtn { position: relative; display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r); color: var(--tx-2); }
.iconbtn:hover { background: var(--bg-3); color: var(--tx); }
.iconbtn .badge { position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px; background: var(--dn); color: #fff; font-size: 9px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--bg-1); }

/* global banners: kill switch, risk halt, connection */
.banners { grid-area: ban; z-index: var(--z-banner); }
.gbanner { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: var(--fs-sm); font-weight: 500; border-bottom: 1px solid; }
.gbanner b { letter-spacing: .06em; font-weight: 700; }
.gbanner.kill { background: var(--dn); color: #fff; border-color: var(--dn-2); }
.gbanner.halt { background: var(--dn-bg); color: var(--dn); border-color: var(--dn-line); }
.gbanner.conn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.gbanner .btn { margin-left: auto; }
.gbanner.kill .btn { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.3); }

/* sidebar */
.side { grid-area: side; z-index: var(--z-side); display: flex; flex-direction: column; min-height: 0; background: var(--bg-1); border-right: 1px solid var(--line); }
.nav { flex: 1 1 auto; padding: 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-sec { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .08em; padding: 12px 10px 4px; }
.nav a {
  position: relative; display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 10px;
  border-radius: var(--r); color: var(--tx-2); font-weight: 500; text-decoration: none; white-space: nowrap;
}
.nav a:hover { background: var(--bg-3); color: var(--tx); }
.nav a[aria-current="page"] { background: var(--bg-4); color: var(--tx); }
.nav a[aria-current="page"]::before { content: ""; position: absolute; left: -8px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav a .cnt { margin-left: auto; font-size: var(--fs-2xs); color: var(--tx-3); font-family: var(--mono); }
.side-collapsed .nav a { justify-content: center; padding: 0; }
.side-collapsed .nav a span, .side-collapsed .nav a .cnt, .side-collapsed .nav-sec { display: none; }
.side-foot { padding: 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.side-collapse { align-self: flex-end; }
.side-collapsed .side-collapse { align-self: center; }

/* kill switch — the one loud control */
.kill-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 40px;
  border-radius: var(--r); background: var(--dn); color: #fff; font-weight: 700; letter-spacing: .08em; font-size: var(--fs-sm);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.2);
  transition: background var(--t-fast);
}
.kill-btn:hover { background: var(--dn-2); }
.kill-btn.armed { background: transparent; color: var(--dn); box-shadow: inset 0 0 0 1.5px var(--dn); }
.kill-btn.armed .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dn); animation: pulse 1.4s infinite; }
.side-collapsed .kill-btn span { display: none; }

.main { grid-area: main; min-width: 0; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.page { padding: var(--pad); display: flex; flex-direction: column; gap: var(--gap); min-height: 100%; }
.page-h { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 4px 2px 6px; }
.page-h h1 { font-size: var(--fs-xl); }
.page-h p { color: var(--tx-3); font-size: var(--fs-sm); }
.page-h .tools { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* mobile shell parts (hidden on desktop) */
.mnav, .mhdr { display: none; }

/* ---------- 4. Components ---------------------------------------------- */

/* panel */
.panel { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; display: flex; flex-direction: column; }
.panel-h { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.panel-h h2, .panel-h h3 { font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--tx-2); }
.panel-h .sub { font-size: var(--fs-xs); color: var(--tx-3); }
.panel-h .tools { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.panel-b { padding: 12px; min-height: 0; }
.panel-b.flush { padding: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: var(--r); border: 1px solid var(--line-2); background: var(--bg-3); color: var(--tx);
  font-weight: 500; font-size: var(--fs-md); white-space: nowrap; user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), opacity var(--t-fast);
}
.btn:hover { background: var(--bg-4); border-color: var(--line-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn-sm { height: 26px; padding: 0 8px; font-size: var(--fs-sm); }
.btn-lg { height: 42px; padding: 0 18px; font-size: var(--fs-lg); font-weight: 600; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--tx-2); }
.btn-ghost:hover { background: var(--bg-3); color: var(--tx); border-color: transparent; }
.btn-buy { background: var(--up); border-color: var(--up); color: #fff; }
.btn-buy:hover { background: var(--up-2); border-color: var(--up-2); }
.btn-sell { background: var(--dn); border-color: var(--dn); color: #fff; }
.btn-sell:hover { background: var(--dn-2); border-color: var(--dn-2); }
.btn-danger { background: var(--dn); border-color: var(--dn); color: #fff; }
.btn-danger:hover { background: var(--dn-2); border-color: var(--dn-2); }
.btn-danger-o { background: transparent; border-color: var(--dn-line); color: var(--dn); }
.btn-danger-o:hover { background: var(--dn-bg); border-color: var(--dn); }
.btn-warn-o { background: transparent; border-color: var(--warn-line); color: var(--warn); }
.btn-warn-o:hover { background: var(--warn-bg); }
.btn .kbd { margin-left: 4px; }
.btn.loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .7s linear infinite; }
.btn:not(.btn-primary):not(.btn-buy):not(.btn-sell):not(.btn-danger).loading::after { border-color: var(--line-3); border-top-color: var(--tx); }

/* hold-to-confirm: progress fills while pressed; release cancels */
.hold { position: relative; overflow: hidden; isolation: isolate; }
.hold::before { content: ""; position: absolute; inset: 0; z-index: -1; background: rgba(0,0,0,.28); transform-origin: left; transform: scaleX(var(--p, 0)); }
.hold.btn-primary::before, .hold.btn-buy::before, .hold.btn-sell::before, .hold.btn-danger::before { background: rgba(255,255,255,.26); }
.hold.done::before { transform: scaleX(1); }

/* segmented control */
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--r); }
.seg button { height: 26px; padding: 0 10px; border-radius: 4px; color: var(--tx-2); font-weight: 500; font-size: var(--fs-sm); white-space: nowrap; }
.seg button:hover { color: var(--tx); }
.seg button[aria-pressed="true"] { background: var(--bg-1); color: var(--tx); box-shadow: 0 1px 2px rgba(0,0,0,.25), 0 0 0 1px var(--line-2); }
.seg.block { display: flex; }
.seg.block button { flex: 1; }
.seg button[disabled] { opacity: .4; cursor: not-allowed; }

/* side tabs (buy/sell) */
.sidetabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0; background: var(--bg-3); border-radius: var(--r); padding: 2px; border: 1px solid var(--line); }
.sidetabs button { height: 34px; border-radius: 4px; font-weight: 600; color: var(--tx-2); }
.sidetabs button.buy[aria-pressed="true"]  { background: var(--up); color: #fff; }
.sidetabs button.sell[aria-pressed="true"] { background: var(--dn); color: #fff; }

/* tabs */
.tabs { display: flex; gap: 2px; align-items: stretch; height: 38px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { position: relative; padding: 0 10px; color: var(--tx-2); font-weight: 500; font-size: var(--fs-sm); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tabs button:hover { color: var(--tx); }
.tabs button[aria-selected="true"] { color: var(--tx); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.tabs .cnt { font-family: var(--mono); font-size: var(--fs-2xs); padding: 1px 5px; border-radius: 8px; background: var(--bg-4); color: var(--tx-2); }

/* inputs */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .lbl { font-size: var(--fs-xs); color: var(--tx-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.lbl .hint, .field > label .hint { margin-left: auto; color: var(--tx-3); font-weight: 400; }
.input {
  display: flex; align-items: center; height: 34px; padding: 0 10px; gap: 6px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--r);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:hover { border-color: var(--line-3); }
.input:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px var(--info-bg); }
.input input, .input select { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: var(--fs-md); }
.input select { font-family: var(--font); cursor: pointer; }
.input .pre, .input .suf { color: var(--tx-3); font-size: var(--fs-xs); white-space: nowrap; }
.input .suf button { color: var(--accent); font-size: var(--fs-xs); font-weight: 600; padding: 2px 4px; border-radius: 3px; }
.input .suf button:hover { background: var(--info-bg); }
.input.err { border-color: var(--dn); }
.input.err:focus-within { box-shadow: 0 0 0 3px var(--dn-bg); }
.input.ok { border-color: var(--up-line); }
.input.dis { opacity: .5; pointer-events: none; }
.input.txt input { font-family: var(--font); }
.ferr { font-size: var(--fs-xs); color: var(--dn); display: flex; gap: 4px; align-items: flex-start; }
.fhint { font-size: var(--fs-xs); color: var(--tx-3); }
textarea.input { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; font-family: var(--font); outline: 0; width: 100%; }
select.sel { height: 30px; padding: 0 28px 0 10px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--bg-3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237d8794' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center/14px; appearance: none; font-size: var(--fs-sm); outline: 0; }
select.sel:focus-visible { border-color: var(--focus); }

/* checkbox + switch */
.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-sm); color: var(--tx-2); user-select: none; }
.chk input { appearance: none; width: 16px; height: 16px; margin: 0; border-radius: 4px; border: 1.5px solid var(--line-3); background: var(--bg-3); display: grid; place-items: center; flex: none; cursor: pointer; }
.chk input:checked { background: var(--accent); border-color: var(--accent); }
.chk input:checked::after { content: ""; width: 8px; height: 4px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px,-1px); }
.chk input:disabled { opacity: .45; cursor: not-allowed; }
.chk input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.chk:has(input:checked) { color: var(--tx); }
.chk.danger input:checked { background: var(--dn); border-color: var(--dn); }

.sw { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-sm); color: var(--tx-2); user-select: none; }
.sw input { appearance: none; width: 30px; height: 18px; margin: 0; border-radius: 9px; background: var(--bg-4); border: 1px solid var(--line-2); position: relative; cursor: pointer; transition: background var(--t); flex: none; }
.sw input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--tx-2); transition: transform var(--t) var(--ease), background var(--t); }
.sw input:checked { background: var(--accent); border-color: var(--accent); }
.sw input:checked::after { transform: translateX(12px); background: #fff; }
.sw input:disabled { opacity: .45; cursor: not-allowed; }
.sw.warn input:checked { background: var(--warn); border-color: var(--warn); }

/* range */
input[type=range].rng { width: 100%; appearance: none; height: 18px; background: transparent; margin: 0; }
input[type=range].rng::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--bg-4) var(--fill, 0%)); }
input[type=range].rng::-moz-range-track { height: 4px; border-radius: 2px; background: var(--bg-4); }
input[type=range].rng::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range].rng::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--bg-1); border: 2px solid var(--accent); margin-top: -5px; }
input[type=range].rng::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--bg-1); border: 2px solid var(--accent); }
.ticks { display: flex; justify-content: space-between; font-size: var(--fs-2xs); color: var(--tx-3); font-family: var(--mono); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { height: 24px; padding: 0 8px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--bg-3); font-size: var(--fs-xs); color: var(--tx-2); font-family: var(--mono); }
.chip:hover { color: var(--tx); border-color: var(--line-3); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--info-bg); }

/* status pill (order lifecycle, generic) */
.pill { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: var(--r-sm); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; border: 1px solid transparent; }
.pill .d { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.s-up      { color: var(--up);   background: var(--up-bg);   border-color: var(--up-line); }
.pill.s-dn      { color: var(--dn);   background: var(--dn-bg);   border-color: var(--dn-line); }
.pill.s-warn    { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.s-info    { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.pill.s-neutral { color: var(--neutral); background: var(--neutral-bg); }
.pill.s-live    { color: #fff; background: var(--live); }
.pill.s-test    { color: var(--test); background: var(--test-bg); border-color: var(--test); border-style: dashed; }
.pill.pending .d { animation: pulse 1.2s infinite; }
.pill.lg { height: 24px; padding: 0 9px; font-size: var(--fs-xs); }

/* side tag */
.side-tag { display: inline-block; font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .06em; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; }
.side-tag.long, .side-tag.buy { color: var(--up); background: var(--up-bg); }
.side-tag.short, .side-tag.sell { color: var(--dn); background: var(--dn-bg); }

/* broker tag */
.bk { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: var(--fs-sm); }
.bk::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--bkc, var(--neutral)); flex: none; }
.bk.delta { --bkc: var(--delta); }
.bk.shark { --bkc: var(--shark); }

/* connection indicator */
.conn { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 9px; border-radius: var(--r); border: 1px solid var(--line); background: var(--bg-1); font-size: var(--fs-xs); white-space: nowrap; }
.conn:hover { background: var(--bg-3); }
.conn .nm { font-weight: 600; color: var(--tx); }
.conn .st { color: var(--tx-3); font-family: var(--mono); font-size: var(--fs-2xs); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--neutral); position: relative; }
.dot.CONNECTED    { background: var(--up); }
.dot.DEGRADED     { background: var(--warn); }
.dot.RECONNECTING { background: var(--warn); animation: blink 1s steps(2) infinite; }
.dot.DISCONNECTED { background: var(--dn); }
.dot.CONNECTED::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 1px solid var(--up); opacity: .0; animation: ring 2.4s var(--ease) infinite; }
.conn.c-DEGRADED, .conn.c-RECONNECTING { border-color: var(--warn-line); background: var(--warn-bg); }
.conn.c-DISCONNECTED { border-color: var(--dn-line); background: var(--dn-bg); }
.conn.c-DISCONNECTED .st { color: var(--dn); }
.conn.c-DEGRADED .st, .conn.c-RECONNECTING .st { color: var(--warn); }

/* environment pill (header) */
.env { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: var(--r); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .12em; }
.env.live { background: var(--live); color: #fff; }
.env.live .d { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulse 1.6s infinite; }
.env.test { color: var(--test); background: var(--test-bg); border: 1px dashed var(--test); }

/* key-value lists */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: var(--fs-sm); }
.kv dt { color: var(--tx-3); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kv.wide { grid-template-columns: 1fr auto; }

/* metric tiles */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: var(--gap); }
.metric { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px 12px; min-width: 0; }
.metric .k { font-size: var(--fs-xs); color: var(--tx-3); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.metric .v { font-size: var(--fs-xl); font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .s { font-size: var(--fs-xs); color: var(--tx-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric.sm .v { font-size: var(--fs-lg); }

/* meter */
.meter { height: 6px; border-radius: 3px; background: var(--bg-4); overflow: hidden; position: relative; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--up); transition: width var(--t) var(--ease); }
.meter.warn > i { background: var(--warn); }
.meter.dn > i { background: var(--dn); }
.meter .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--tx-2); }
.meter.lg { height: 10px; border-radius: 5px; }

/* tables */
.tbl-wrap { overflow: auto; scrollbar-width: none; min-height: 0; }
.tbl-wrap::-webkit-scrollbar { display: none; }
.tbl { font-size: var(--fs-sm); }
.tbl th { position: sticky; top: 0; z-index: 1; background: var(--bg-1); text-align: left; font-weight: 500; font-size: var(--fs-xs); color: var(--tx-3); padding: 0 10px; height: 30px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 0 10px; height: var(--row-h); border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--bg-3); }
.tbl tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.tbl .r { text-align: right; }
.tbl td.r { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tbl .acts { display: flex; gap: 4px; justify-content: flex-end; }
.tbl tr.new td { animation: rowin 1.6s var(--ease); }
.tbl tr.sel td { background: var(--bg-4); }
.tbl.clickable tbody tr { cursor: pointer; }
.compact .tbl td { height: 26px; }

/* empty / error / loading states */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 32px 16px; color: var(--tx-2); }
.state .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--bg-3); color: var(--tx-3); }
.state.err .ic { background: var(--dn-bg); color: var(--dn); }
.state.warn .ic { background: var(--warn-bg); color: var(--warn); }
.state h4 { font-size: var(--fs-md); color: var(--tx); }
.state p { font-size: var(--fs-sm); max-width: 340px; color: var(--tx-3); }
.state .row { margin-top: 4px; }
.sk { background: linear-gradient(90deg, var(--bg-3) 0%, var(--bg-4) 50%, var(--bg-3) 100%); background-size: 200% 100%; border-radius: 4px; animation: shimmer 1.3s linear infinite; height: 12px; }
.sk-row { display: grid; grid-template-columns: 1.2fr 1fr .8fr 1fr 1fr; gap: 16px; padding: 10px 12px; border-bottom: 1px solid var(--line); }

/* alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r); border: 1px solid; font-size: var(--fs-sm); line-height: 1.4; }
.alert .i { margin-top: 1px; }
.alert b { font-weight: 600; }
.alert .a-body { flex: 1; min-width: 0; }
.alert .a-body p { color: inherit; opacity: .85; margin-top: 2px; }
.alert.info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }
.alert.ok   { background: var(--up-bg); border-color: var(--up-line); color: var(--up); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.alert.err  { background: var(--dn-bg); border-color: var(--dn-line); color: var(--dn); }
.alert.solid-err { background: var(--dn); border-color: var(--dn); color: #fff; }

/* toasts */
.toasts { position: fixed; bottom: 16px; left: calc(var(--side-w) + 16px); flex-direction: column-reverse; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 28px)); pointer-events: none; }
.side-collapsed ~ .toasts, body:has(.side-collapsed) .toasts { left: calc(var(--side-w-c) + 16px); }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-lg); background: var(--bg-2); box-shadow: var(--shadow-pop); border-left: 3px solid var(--tc, var(--info)); font-size: var(--fs-sm); animation: toastin var(--t) var(--ease); }
.toast.out { animation: toastout var(--t) var(--ease) forwards; }
.toast .i { color: var(--tc); margin-top: 1px; }
.toast .t-body { flex: 1; min-width: 0; }
.toast .t-body b { display: block; font-weight: 600; }
.toast .t-body p { color: var(--tx-2); margin-top: 1px; }
.toast .t-meta { font-family: var(--mono); font-size: var(--fs-2xs); color: var(--tx-3); margin-top: 3px; }
.toast.ok { --tc: var(--up); } .toast.err { --tc: var(--dn); } .toast.warn { --tc: var(--warn); } .toast.info { --tc: var(--info); }

/* popovers / menus */
.pop { position: fixed; z-index: var(--z-pop); background: var(--bg-2); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); min-width: 220px; max-width: calc(100vw - 16px); padding: 6px; animation: popin var(--t-fast) var(--ease); }
.pop .mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--r); text-align: left; font-size: var(--fs-md); color: var(--tx); }
.pop .mi:hover, .pop .mi.act { background: var(--bg-3); }
.pop .mi .k { margin-left: auto; }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.pop .pop-h { padding: 6px 10px 8px; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: var(--fs-sm); }
.notif { display: flex; gap: 10px; padding: 8px 10px; border-radius: var(--r); }
.notif:hover { background: var(--bg-3); }
.notif .dotc { width: 6px; height: 6px; border-radius: 50%; margin-top: 6px; background: var(--tc, var(--info)); flex: none; }
.notif.read .dotc { background: transparent; }
.notif b { display: block; font-weight: 500; font-size: var(--fs-sm); }
.notif span { font-size: var(--fs-xs); color: var(--tx-3); }
.kbd { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 3px; border: 1px solid var(--line-2); border-bottom-width: 2px; font: 500 var(--fs-2xs) var(--mono); color: var(--tx-2); background: var(--bg-3); }

/* modals */
.scrim { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--scrim); display: grid; place-items: center; padding: 16px; animation: fadein var(--t) var(--ease); }
.modal { width: min(480px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--bg-2); border-radius: 12px; box-shadow: var(--shadow-modal); animation: modalin var(--t) var(--ease); overflow: hidden; }
.modal.wide { width: min(640px, 100%); }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-h h2 { font-size: var(--fs-lg); }
.modal-h .x { margin-left: auto; }
.modal-b { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-f { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg-1); align-items: center; }
.modal-f .grow { font-size: var(--fs-xs); color: var(--tx-3); min-width: 0; }
.modal-f .btn { flex: none; }
.modal.m-live .modal-h { box-shadow: inset 0 3px 0 var(--live); }
.modal.m-danger .modal-h { box-shadow: inset 0 3px 0 var(--dn); }
.modal.m-test .modal-h { box-shadow: inset 0 3px 0 var(--test); }

/* order summary grid inside confirm */
.osum { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.osum > div { padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.osum > div:nth-child(odd) { border-right: 1px solid var(--line); }
.osum > div:nth-last-child(-n+2) { border-bottom: 0; }
.osum .k { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .06em; color: var(--tx-3); }
.osum .v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: var(--fs-md); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.osum .v.f { font-family: var(--font); }
.ohero { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--r-lg); background: var(--bg-3); }
.ohero .big { font-size: var(--fs-2xl); font-weight: 600; }
.confirm-word { letter-spacing: .2em; font-weight: 700; text-transform: uppercase; }

/* mobile sheets */
.sheet-scrim { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--scrim); animation: fadein var(--t) var(--ease); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: calc(var(--z-modal) + 1); background: var(--bg-2); border-radius: 16px 16px 0 0; box-shadow: var(--shadow-modal); max-height: 92dvh; display: flex; flex-direction: column; animation: sheetin 220ms var(--ease); padding-bottom: env(safe-area-inset-bottom); }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line-3); margin: 8px auto 2px; flex: none; }
.sheet-h { display: flex; align-items: center; gap: 8px; padding: 6px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-h h2 { font-size: var(--fs-lg); }
.sheet-b { overflow: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }

/* tooltip (desktop only, collapsed sidebar) */
[data-tip] { position: relative; }
@media (hover: hover) and (pointer: fine) {
  .side-collapsed .nav a[data-tip]:hover::after, .tipme[data-tip]:hover::after {
    content: attr(data-tip); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    padding: 4px 8px; border-radius: 4px; background: var(--tx); color: var(--tx-inv); font-size: var(--fs-xs); white-space: nowrap; z-index: 80; pointer-events: none;
  }
}

/* ---------- 5. Trading components ------------------------------------- */

/* price flash on tick */
.fl-up { animation: flup 700ms var(--ease); }
.fl-dn { animation: fldn 700ms var(--ease); }
.stale { color: var(--tx-3) !important; text-decoration: line-through dotted var(--tx-3); }

/* workspace grid */
.page:has(> .ws) { height: 100%; }
.ws {
  display: grid; gap: var(--gap); flex: 1 1 auto; min-height: 680px;
  grid-template-columns: minmax(0, 1fr) 272px 328px;
  grid-template-rows: auto minmax(0, 1fr) 272px;
  grid-template-areas: "kpi kpi kpi" "chart book ticket" "bottom book ticket";
}
.ws > .a-kpi { grid-area: kpi; }
.ws > .a-chart { grid-area: chart; }
.ws > .a-book { grid-area: book; }
.ws > .a-ticket { grid-area: ticket; }
.ws > .a-bottom { grid-area: bottom; }
.ws.focus-trade { grid-template-rows: auto minmax(0, 1fr) 232px; }
.ws > * { min-height: 0; }
.ws > .a-book, .ws > .a-ticket, .ws > .a-bottom { overflow: hidden; }
.ws > .a-book > .panel-b { flex: 1 1 auto; overflow: auto; scrollbar-width: none; }
.ws > .a-book > .panel-b::-webkit-scrollbar { display: none; }
.ticket > .panel-b { flex: 1 1 auto; min-height: 0; }

.kpis { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-lg); }
.kpis .kp { padding: 8px 12px; min-width: 0; }
.kpis .kp + .kp { border-left: 1px solid var(--line); }
.kpis .k { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.kpis .v { font-size: var(--fs-lg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis .s { font-size: var(--fs-2xs); color: var(--tx-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* chart */
.chart-box { position: relative; flex: 1 1 auto; min-height: 0; }
.chart-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart-legend { position: absolute; left: 10px; top: 8px; display: flex; gap: 10px; font-size: var(--fs-xs); color: var(--tx-3); pointer-events: none; font-family: var(--mono); }
.chart-legend b { color: var(--tx-2); font-weight: 500; }

/* order book */
.book { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.book-h, .book-r { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 0 10px; align-items: center; }
.book-h { height: 26px; color: var(--tx-3); font-family: var(--font); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .05em; }
.book-h span:not(:first-child), .book-r span:not(:first-child) { text-align: right; }
.book-r { position: relative; height: 20px; cursor: pointer; }
.book-r:hover { background: var(--bg-3); }
.book-r .bar { position: absolute; top: 1px; bottom: 1px; right: 0; opacity: .9; transition: width 300ms var(--ease); z-index: 0; }
.book-r span { position: relative; z-index: 1; }
.book-r.ask .p { color: var(--dn); }
.book-r.bid .p { color: var(--up); }
.book-r.ask .bar { background: var(--dn-bg); }
.book-r.bid .bar { background: var(--up-bg); }
.book-r.mine::after { content: ""; position: absolute; left: 2px; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--warn); }
.book-mid { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--bg-3); }
.book-mid .last { font-size: var(--fs-lg); font-weight: 600; }
.book-mid .meta { margin-left: auto; text-align: right; font-size: var(--fs-2xs); color: var(--tx-3); line-height: 1.25; }
.imb { display: flex; height: 18px; font-size: var(--fs-2xs); font-weight: 600; font-family: var(--mono); border-radius: 3px; overflow: hidden; margin: 8px 10px; }
.imb .b { background: var(--up-bg); color: var(--up); display: flex; align-items: center; padding: 0 6px; transition: flex-basis 300ms var(--ease); }
.imb .a { background: var(--dn-bg); color: var(--dn); display: flex; align-items: center; justify-content: flex-end; padding: 0 6px; transition: flex-basis 300ms var(--ease); }
.trades .book-r { cursor: default; }
.trades .book-r.b .p { color: var(--up); }
.trades .book-r.s .p { color: var(--dn); }

/* ticket */
.ticket { display: flex; flex-direction: column; min-height: 0; }
.ticket .panel-b { display: flex; flex-direction: column; gap: 10px; overflow: auto; scrollbar-width: none; }
.ticket .panel-b::-webkit-scrollbar { display: none; }
.tk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tk-sec { border-top: 1px dashed var(--line-2); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.tk-calc { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; font-size: var(--fs-xs); }
.tk-calc dt { color: var(--tx-3); }
.tk-calc dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--tx); }
.tk-calc dd.bad { color: var(--dn); }
.tk-submit { position: sticky; bottom: 0; padding: 10px 12px 12px; background: var(--bg-1); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; border-radius: 0 0 var(--r-lg) var(--r-lg); }
.tk-block { display: flex; gap: 6px; align-items: flex-start; font-size: var(--fs-xs); color: var(--dn); }
.tk-block.w { color: var(--warn); }
.bk-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bk-pick button { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: var(--r); border: 1px solid var(--line-2); background: var(--bg-3); text-align: left; font-size: var(--fs-sm); font-weight: 500; min-width: 0; }
.bk-pick button:hover { border-color: var(--line-3); }
.bk-pick button[aria-pressed="true"] { border-color: var(--accent); background: var(--info-bg); }
.bk-pick button small { display: block; font-size: var(--fs-2xs); color: var(--tx-3); font-weight: 400; font-family: var(--mono); }
.bk-pick button .dot { margin-left: auto; }
.bk-pick button[disabled] { opacity: .5; cursor: not-allowed; }
.multi-box { padding: 8px 10px; border-radius: var(--r); border: 1px dashed var(--warn-line); background: var(--warn-bg); font-size: var(--fs-xs); color: var(--warn); display: flex; flex-direction: column; gap: 6px; }

/* position card (mobile + overview) */
.poscard { background: var(--bg-1); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; position: relative; overflow: hidden; }
.poscard::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--pc, var(--up)); }
.poscard.short { --pc: var(--dn); }
.poscard .pnl-big { font-size: 30px; font-weight: 600; line-height: 1.05; letter-spacing: -.02em; }
.poscard .grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.poscard .grid4 .k { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .05em; }
.poscard .grid4 .v { font-family: var(--mono); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prot { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prot button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 10px; border-radius: var(--r); border: 1px solid var(--line-2); background: var(--bg-3); text-align: left; }
.prot button .k { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .05em; display: flex; gap: 4px; align-items: center; width: 100%; }
.prot button .k .i { margin-left: auto; width: 12px; height: 12px; }
.prot button .v { font-family: var(--mono); font-size: var(--fs-md); }
.prot button.sl .v { color: var(--dn); }
.prot button.tp .v { color: var(--up); }
.prot button.none .v { color: var(--warn); font-family: var(--font); font-size: var(--fs-sm); }

/* broker card */
.bcard { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-lg); display: flex; flex-direction: column; min-width: 0; }
.bcard-h { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.blogo { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff; flex: none; }
.blogo.delta { background: linear-gradient(135deg, #f0a73b, #d1761a); }
.blogo.shark { background: linear-gradient(135deg, #6c8dff, #3b56d9); }
.bcard-h h3 { font-size: var(--fs-lg); }
.bcard-h p { font-size: var(--fs-xs); color: var(--tx-3); }
.bcard-h .pill { margin-left: auto; }
.bstreams { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.bstreams > div { padding: 10px 16px; min-width: 0; }
.bstreams > div + div { border-left: 1px solid var(--line); }
.bstreams .k { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .06em; }
.bstreams .v { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 500; margin-top: 2px; white-space: nowrap; }
.bstreams .m { font-size: var(--fs-2xs); color: var(--tx-3); font-family: var(--mono); }
.bbal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
.bbal > div { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.bbal > div:nth-child(odd) { border-right: 1px solid var(--line); }
.bbal .k { font-size: var(--fs-xs); color: var(--tx-3); }
.bbal .v { font-family: var(--mono); font-size: var(--fs-lg); font-weight: 500; font-variant-numeric: tabular-nums; }
.bcard-f { display: flex; gap: 8px; align-items: center; padding: 12px 16px; flex-wrap: wrap; }
.bcard-f .sync { font-size: var(--fs-xs); color: var(--tx-3); }
.secret { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r); background: var(--bg-3); border: 1px dashed var(--line-2); font-size: var(--fs-xs); color: var(--tx-3); }
.secret .i { color: var(--up); }

/* lifecycle diagram */
.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.flow .arr { color: var(--tx-3); font-size: var(--fs-xs); }
.flow-term { display: flex; gap: 6px; flex-wrap: wrap; padding-left: 12px; border-left: 2px solid var(--line-2); }
.steps { display: flex; gap: 0; align-items: center; }
.steps .st { display: flex; align-items: center; gap: 6px; font-size: var(--fs-2xs); color: var(--tx-3); font-weight: 600; letter-spacing: .04em; }
.steps .st .c { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--line-3); display: grid; place-items: center; }
.steps .st.done { color: var(--tx-2); }
.steps .st.done .c { background: var(--up); border-color: var(--up); }
.steps .st.done .c::after { content: ""; width: 5px; height: 3px; border: 1.5px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translateY(-1px); }
.steps .st.cur { color: var(--info); }
.steps .st.cur .c { border-color: var(--info); box-shadow: 0 0 0 3px var(--info-bg); }
.steps .st.bad { color: var(--dn); }
.steps .st.bad .c { background: var(--dn); border-color: var(--dn); }
.steps .ln { width: 16px; height: 1.5px; background: var(--line-2); margin: 0 4px; }
.steps .ln.done { background: var(--up); }

/* risk */
.risk-gauge { display: flex; flex-direction: column; gap: 6px; }
.risk-gauge .top { display: flex; align-items: baseline; gap: 8px; font-size: var(--fs-sm); }
.risk-gauge .top .k { color: var(--tx-2); }
.risk-gauge .top .v { margin-left: auto; font-family: var(--mono); }
.perm { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--r-lg); border: 1px solid; }
.perm.ok { background: var(--up-bg); border-color: var(--up-line); color: var(--up); }
.perm.bad { background: var(--dn); border-color: var(--dn); color: #fff; }
.perm.warnp { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.perm .ttl { font-weight: 700; letter-spacing: .08em; font-size: var(--fs-lg); }
.perm p { font-size: var(--fs-sm); opacity: .9; }
.limit-row { display: grid; grid-template-columns: minmax(0,1fr) 140px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.limit-row:last-child { border-bottom: 0; }
.limit-row b { font-weight: 500; font-size: var(--fs-md); }
.limit-row p { font-size: var(--fs-xs); color: var(--tx-3); }

/* activity */
.evt-type { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.evt-type .d { width: 6px; height: 6px; border-radius: 50%; background: var(--tc, var(--neutral)); }
.lat { font-family: var(--mono); font-size: var(--fs-xs); }
.lat.slow { color: var(--warn); }

/* analytics */
.spark { display: block; width: 100%; }
.hbar { display: grid; grid-template-columns: 76px minmax(0,1fr) 84px; gap: 10px; align-items: center; font-size: var(--fs-sm); padding: 5px 0; }
.hbar .track { height: 8px; position: relative; }
.hbar .track i { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.hbar .track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line-3); }
.ls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.ls-card { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px; }

/* design system page */
.ds-sec { display: flex; flex-direction: column; gap: 10px; }
.ds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); gap: 8px; }
.swatch { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; font-size: var(--fs-xs); }
.swatch i { display: block; height: 44px; }
.swatch div { padding: 6px 8px; }
.swatch code { font-family: var(--mono); color: var(--tx-3); font-size: var(--fs-2xs); display: block; }
.ds-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ds-label { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }
.type-row { display: flex; align-items: baseline; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.type-row code { width: 120px; flex: none; color: var(--tx-3); font: var(--fs-xs) var(--mono); }

/* preview-state drawer */
.pv { position: fixed; left: 12px; bottom: 12px; z-index: var(--z-pop); width: 300px; max-height: calc(100dvh - 120px); overflow: auto; background: var(--bg-2); box-shadow: var(--shadow-pop); border-radius: var(--r-lg); padding: 12px; display: flex; flex-direction: column; gap: 10px; animation: popin var(--t) var(--ease); }
.pv h4 { font-size: var(--fs-sm); display: flex; align-items: center; gap: 8px; }
.pv .grp { display: flex; flex-direction: column; gap: 5px; }
.pv .grp > span { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .07em; }
.pv .seg button { padding: 0 6px; font-size: var(--fs-2xs); }

/* layout helpers for pages */
.g2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--gap); }
.g3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: var(--gap); }
.g-12-8 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--gap); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ---------- 7. Responsive --------------------------------------------- */

/* laptop: icon sidebar, trim header stats */
@media (max-width: 1439px) {
  .stat.opt { display: none; }
  .kpis { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .kpis .kp:nth-child(n+5) { display: none; }
}

/* tablet: 2 columns — chart+book stack left, ticket right */
@media (max-width: 1199px) {
  .page:has(> .ws) { height: auto; }
  .ws, .ws.focus-trade {
    grid-template-columns: minmax(0, 1fr) 320px; min-height: 0;
    grid-template-rows: auto minmax(320px, 46vh) auto auto;
    grid-template-areas: "kpi kpi" "chart ticket" "book ticket" "bottom bottom";
  }
  .ws > .a-book { min-height: 300px; }
  .ws > .a-book .panel-b { display: grid; grid-template-columns: 1fr 1fr; }
  .ws > .a-bottom { min-height: 280px; max-height: 420px; }
  .stat.opt3 { display: none; }
  .px-chg { display: inline; }
  .conn .st { display: none; }
  .hdr-sym .lbl-mark { display: none; }
  .stat.opt2 { display: none; }
  .g-12-8 { grid-template-columns: minmax(0,1fr); }
  .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* mobile: a different app — no sidebar, compact header, bottom nav */
@media (max-width: 719px) {
  body { overflow: auto; }
  .app, .app.side-collapsed {
    height: auto; min-height: 100dvh; display: block;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
  .hdr, .side { display: none; }
  .prebar { font-size: var(--fs-2xs); padding: 4px 12px; }
  .prebar .opt { display: none; }
  .prebar .btn { padding: 0 6px; }
  .mhdr {
    display: flex; position: sticky; top: 0; z-index: var(--z-hdr); align-items: center; gap: 8px;
    height: 50px; padding: 0 12px; background: var(--bg-1); border-bottom: 1px solid var(--line);
  }
  .mhdr::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--live); }
  body.env-test .mhdr::after { background: repeating-linear-gradient(-45deg, var(--test) 0 8px, transparent 8px 14px); }
  .mhdr .brand-mark { width: 24px; height: 24px; }
  .mhdr .env { height: 24px; padding: 0 7px; font-size: var(--fs-2xs); }
  .mhdr .mconn { display: flex; gap: 8px; align-items: center; margin-left: auto; font-size: var(--fs-2xs); font-weight: 600; color: var(--tx-2); }
  .mhdr .mconn span { display: inline-flex; align-items: center; gap: 4px; }
  .banners { position: sticky; top: 50px; z-index: var(--z-banner); }
  .gbanner { padding: 7px 12px; font-size: var(--fs-xs); flex-wrap: wrap; }
  .main { overflow: visible; }
  .page { padding: 12px; gap: 10px; }
  .page-h h1 { font-size: var(--fs-lg); }
  .page-h .tools { margin-left: 0; width: 100%; }
  .mnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-hdr);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-1); border-top: 1px solid var(--line);
  }
  .mnav a, .mnav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: var(--fs-2xs); font-weight: 500; color: var(--tx-3); text-decoration: none; position: relative; }
  .mnav .i { width: 20px; height: 20px; }
  .mnav [aria-current="page"] { color: var(--tx); }
  .mnav [aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px; background: var(--accent); border-radius: 0 0 2px 2px; }
  .mnav .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 15px; height: 15px; border-radius: 8px; background: var(--info); color: #fff; font-size: 9px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

  .toasts, body:has(.side-collapsed) .toasts { top: 58px; bottom: auto; left: 12px; right: 12px; width: auto; flex-direction: column; }
  .scrim { place-items: end center; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 16px 16px 0 0; max-height: 94dvh; animation: sheetin 220ms var(--ease); padding-bottom: env(safe-area-inset-bottom); }
  .modal-f { flex-wrap: wrap; }
  .modal-f .grow { flex-basis: 100%; }
  .modal-f .btn { flex: 1; }
  .osum { grid-template-columns: 1fr 1fr; }

  .g2, .g3, .ls-grid { grid-template-columns: minmax(0,1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .metric .v { font-size: var(--fs-lg); }
  .bstreams { grid-template-columns: 1fr; }
  .bstreams > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .bstreams > div { display: flex; align-items: center; gap: 8px; }
  .bstreams .v { margin: 0 0 0 auto; }
  .limit-row { grid-template-columns: minmax(0,1fr) 120px; }
  .pv { left: 8px; right: 8px; width: auto; bottom: calc(var(--nav-h) + 8px); }

  /* responsive table → stacked cards */
  .rt thead { display: none; }
  .rt, .rt tbody, .rt tr, .rt td { display: block; width: 100%; }
  .rt tr { padding: 10px 12px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  .rt td { height: auto; padding: 0; border: 0; display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-sm); white-space: normal; }
  .rt td::before { content: attr(data-l); color: var(--tx-3); font-family: var(--font); font-size: var(--fs-xs); }
  .rt td.span2, .rt td.acts-cell { grid-column: 1 / -1; }
  .rt td.head { grid-column: 1 / -1; font-weight: 600; font-size: var(--fs-md); }
  .rt td.head::before, .rt td.acts-cell::before { display: none; }
  .rt td.acts-cell .acts { width: 100%; justify-content: stretch; margin-top: 6px; }
  .rt td.acts-cell .acts .btn { flex: 1; }
  .rt tbody tr:hover td { background: transparent; }
  .rt tbody tr:hover td:first-child { box-shadow: none; }
  .tbl-wrap.mask { -webkit-mask-image: none; mask-image: none; }

  /* mobile home */
  .mprice { display: flex; align-items: flex-end; gap: 10px; }
  .mprice .px { font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }
  .msplit { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .msplit .btn { height: 52px; font-size: var(--fs-lg); font-weight: 700; flex-direction: column; gap: 0; }
  .msplit .btn small { font-size: var(--fs-2xs); font-weight: 500; opacity: .85; font-family: var(--mono); }
  .acct3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-lg); }
  .acct3 > div { padding: 10px; min-width: 0; }
  .acct3 > div + div { border-left: 1px solid var(--line); }
  .acct3 .k { font-size: var(--fs-2xs); color: var(--tx-3); text-transform: uppercase; letter-spacing: .05em; }
  .acct3 .v { font-family: var(--mono); font-weight: 600; font-size: var(--fs-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mrow { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .mrow:last-child { border-bottom: 0; }
  .more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .more-grid a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border-radius: var(--r-lg); background: var(--bg-3); color: var(--tx); font-size: var(--fs-xs); font-weight: 500; text-decoration: none; text-align: center; }
  .more-grid a .i { width: 20px; height: 20px; color: var(--tx-2); }
  .tk-submit { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); border-radius: 0; margin: 0 -12px; }
}

/* touch: bigger hit targets, no sticky hovers */
@media (pointer: coarse) {
  .btn { height: 40px; }
  .btn-sm { height: 34px; }
  .input { height: 42px; }
  .input input { font-size: 16px; } /* stops iOS zoom */
  .seg button { height: 34px; }
  .chip { height: 32px; padding: 0 12px; }
  .sidetabs button { height: 42px; }
  select.sel { height: 38px; font-size: 16px; }
}
@media (hover: hover) and (pointer: fine) {
  .bcard, .metric { transition: border-color var(--t); }
  .bcard:hover, .metric:hover { border-color: var(--line-2); }
}

/* density */
body.compact { --row-h: 26px; --pad: 8px; --gap: 6px; }

/* ---------- 8. Motion ------------------------------------------------- */
@keyframes flup { 0% { background: var(--up-bg); color: var(--up); } 100% { background: transparent; } }
@keyframes fldn { 0% { background: var(--dn-bg); color: var(--dn); } 100% { background: transparent; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: .25; } }
@keyframes ring { 0% { transform: scale(.6); opacity: .7; } 80%, 100% { transform: scale(1.6); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes rowin { 0% { background: var(--info-bg); } 100% { background: transparent; } }
@keyframes toastin { from { opacity: 0; transform: translateY(6px); } }
@keyframes toastout { to { opacity: 0; transform: translateX(16px); } }
@keyframes popin { from { opacity: 0; transform: translateY(-4px); } }
@keyframes fadein { from { opacity: 0; } }
@keyframes modalin { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@keyframes sheetin { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; background: var(--bg-1); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-pop); }
.login .brand-mark { width: 34px; height: 34px; }
.mchk { width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--line-3); display: grid; place-items: center; flex: none; color: #fff; }
.mchk.on { background: var(--accent); border-color: var(--accent); }
