/* Astara alerts — ember on near-black. Kalki's bones, its own colour.
   Semantics stay fixed across the app: green paid, red stopped, blue running.
   The brand gradient is never used for a state, so nothing reads as a result
   when it isn't one. */

:root {
  --bg:      #07080c;
  --bg2:     #0c0e15;
  --bg3:     #11141e;
  --bg4:     #171b28;
  --border:  #1c2130;
  --border2: #2a3145;
  --text:    #e3e7f0;
  --text2:   #98a1b8;
  --dim:     #5a6483;

  --ember:   #f97316;
  --ember2:  #fb923c;
  --rose:    #f43f5e;

  --green:   #10b981;
  --green2:  #34d399;
  --red:     #ef4444;
  --red2:    #f87171;
  --blue:    #3b82f6;
  --blue2:   #60a5fa;
  --gold:    #f59e0b;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --r: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 480px at 8% -12%, rgba(249,115,22,0.11), transparent 62%),
    radial-gradient(760px 460px at 96% -4%, rgba(244,63,94,0.08), transparent 60%);
}
.wrap { position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 0 22px 90px; }

.label { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .13em; color: var(--dim); font-weight: 500; }
.num   { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.muted { color: var(--text2); }
.dimmed{ color: var(--dim); }
h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
h3 { font-size: 14px; font-weight: 650; margin: 0; }
a { color: var(--ember2); }

/* ---------------------------------------------------------------- chrome */
header.top { position: sticky; top: 0; z-index: 40; background: rgba(7,8,12,.84); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 13px 22px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: linear-gradient(145deg, var(--ember2), var(--rose));
  display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff;
  box-shadow: 0 6px 20px rgba(249,115,22,.3);
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.brand h1 span { background: linear-gradient(135deg, var(--ember2), var(--rose)); -webkit-background-clip: text; background-clip: text; color: transparent; }

nav.tabs { display: flex; gap: 6px; }
nav.tabs button {
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text2); padding: 8px 15px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg2);
}
nav.tabs button:hover { color: var(--text); border-color: var(--border2); }
nav.tabs button[aria-selected="true"] { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--ember), #ea580c); box-shadow: 0 4px 14px rgba(249,115,22,.28); }

.conn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg2); font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.16); }
.dot.err { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.16); }
.dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

/* ---------------------------------------------------------------- controls */
button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); padding: 8px 14px; transition: background .15s, border-color .15s, filter .15s; }
button:hover:not(:disabled) { background: var(--bg3); border-color: var(--border2); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(135deg, var(--ember), #ea580c); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 4px 14px rgba(249,115,22,.3); }
button.primary:hover:not(:disabled) { filter: brightness(1.09); }
button.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
button.ghost { background: transparent; }
button.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red2); }

input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--ember); box-shadow: 0 0 0 3px rgba(249,115,22,.14); }
input.num-in { font-family: var(--mono); font-variant-numeric: tabular-nums; }
select { cursor: pointer; }

.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); }
.pad { padding: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin: 26px 0 12px; }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-family: var(--mono); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; font-weight: 600; border: 1px solid transparent; }
.badge.win     { color: var(--green2); background: rgba(16,185,129,.12);  border-color: rgba(16,185,129,.3); }
.badge.loss    { color: var(--red2);   background: rgba(239,68,68,.12);   border-color: rgba(239,68,68,.3); }
.badge.open    { color: var(--blue2);  background: rgba(59,130,246,.12);  border-color: rgba(59,130,246,.3); }
.badge.closed  { color: var(--text2);  background: rgba(148,163,184,.1);  border-color: var(--border2); }
.badge.long    { color: var(--green2); background: rgba(16,185,129,.1); }
.badge.short   { color: var(--red2);   background: rgba(239,68,68,.1); }
.badge.warn    { color: var(--gold);   background: rgba(245,158,11,.12);  border-color: rgba(245,158,11,.3); }
.badge.ghost   { color: var(--dim);    border-color: var(--border); }

.pos { color: var(--green2); }
.neg { color: var(--red2); }

/* ---------------------------------------------------------------- paste + preview */
.compose { display: grid; grid-template-columns: minmax(min(340px, 100%), 1fr) minmax(min(360px, 100%), 1.1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .compose { grid-template-columns: 1fr; } }

textarea.paste {
  min-height: 260px; resize: vertical; font-family: var(--mono); font-size: 13.5px; line-height: 1.65;
  background: var(--bg); border-radius: var(--r);
}
textarea.paste::placeholder { color: #3d465f; }

.preview-empty { display: grid; place-items: center; min-height: 260px; text-align: center; color: var(--dim); gap: 8px; padding: 26px; }
.preview-empty .big { font-size: 30px; opacity: .5; }

.sig { border: 1px solid var(--border); border-radius: var(--r); background: var(--bg2); overflow: hidden; }
.sig + .sig { margin-top: 12px; }
.sig.bad { border-color: rgba(239,68,68,.45); }
.sig-head { display: flex; align-items: center; gap: 10px; padding: 12px 15px; border-bottom: 1px solid var(--border); background: var(--bg3); flex-wrap: wrap; }
.sig-head .tkr { font-size: 17px; font-weight: 750; letter-spacing: -.01em; }
.sig-body { padding: 14px 15px; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(96px, 100%), 1fr)); gap: 10px; }
.field { display: grid; gap: 4px; }
.field > .label { font-size: 9.5px; }
.field input { padding: 7px 9px; font-size: 13px; }

.msgs { display: grid; gap: 6px; margin-top: 12px; }
.msg { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; padding: 8px 11px; border-radius: 9px; border: 1px solid transparent; }
.msg.err  { color: #fca5a5; background: rgba(239,68,68,.09);  border-color: rgba(239,68,68,.25); }
.msg.warn { color: #fcd34d; background: rgba(245,158,11,.08); border-color: rgba(245,158,11,.22); }
.msg .ic { flex: none; }

/* ---------------------------------------------------------------- the rail */
/* Stop → entry → targets on one proportional line, with the live price on it.
   Distance is to scale, so a stop that is miles away looks it. Labels hang
   below the line and drop to a second row when two levels sit too close. */
.rail { --rail-inset: 28px; position: relative; height: 84px; margin: 16px 0 4px; }
.rail.rows-1 { height: 62px; }
.rail.rows-2 { height: 84px; }
.rail.rows-3 { height: 106px; }
.rail-line { position: absolute; left: var(--rail-inset); right: var(--rail-inset); top: 24px; height: 3px; border-radius: 2px; background: var(--bg4); }
.rail-fill { position: absolute; top: 24px; height: 3px; border-radius: 2px; }
.rail-fill.up { background: linear-gradient(90deg, rgba(16,185,129,.25), var(--green)); }
.rail-fill.down { background: linear-gradient(90deg, var(--red), rgba(239,68,68,.25)); }

.tick { position: absolute; top: 24px; width: 56px; transform: translateX(-50%); text-align: center; display: flex; flex-direction: column; align-items: center; }
.tick .pin { width: 2px; background: var(--border2); border-radius: 1px; }
.tick.r0 .pin { height: 9px; }
.tick.r1 .pin { height: 31px; }
.tick.r2 .pin { height: 53px; }
.tick .val { font-family: var(--mono); font-size: 10.5px; color: var(--text2); font-variant-numeric: tabular-nums; margin-top: 3px; }
.tick .cap { font-family: var(--mono); font-size: 9px; letter-spacing: .06em; color: var(--dim); text-transform: uppercase; }
.tick.stop .pin { background: var(--red); } .tick.stop .cap { color: var(--red2); }
.tick.entry .pin { background: var(--text2); } .tick.entry .cap { color: var(--text2); } .tick.entry .val { color: var(--text); }
.tick.tp .pin { background: var(--green); } .tick.tp .cap { color: var(--green2); }
.tick.tp.hit .pin { box-shadow: 0 0 0 3px rgba(16,185,129,.2); }
.tick.tp.hit .cap::after { content: " ✓"; }

.marker { position: absolute; top: 0; transform: translateX(-50%); z-index: 2; display: flex; flex-direction: column; align-items: center; }
.marker .now { font-family: var(--mono); font-size: 10.5px; color: var(--blue2); white-space: nowrap; font-variant-numeric: tabular-nums; margin-bottom: 3px; }
.marker .bead { width: 13px; height: 13px; border-radius: 50%; background: var(--blue2); border: 3px solid var(--bg2); box-shadow: 0 0 0 2px var(--blue2), 0 0 14px rgba(96,165,250,.5); }
/* Price is outside the level band and pinned to the edge — the arrow in the
   label says which way it actually sits. */
.marker.offscale .bead { background: var(--bg2); border-color: var(--blue2); box-shadow: 0 0 0 1px var(--blue2); }
.marker.offscale .now { color: var(--text2); }

/* ---------------------------------------------------------------- templates */
.tpl-switch { display: inline-flex; padding: 3px; gap: 3px; background: var(--bg2); border: 1px solid var(--border); border-radius: 999px; }
.tpl-switch button { border: none; background: transparent; border-radius: 999px; padding: 6px 13px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--text2); }
.tpl-switch button[aria-pressed="true"] { background: var(--bg4); color: #fff; }

/* template: cards */
/* auto-FIT, not auto-fill: empty tracks collapse, so one or two setups
   stretch to the full width instead of leaving a rail squeezed into a third
   of the row. */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 14px; }
.tcard { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; transition: border-color .15s, transform .15s; }
.tcard:hover { border-color: var(--border2); }
.tcard.win  { border-left: 3px solid var(--green); }
.tcard.loss { border-left: 3px solid var(--red); }
.tcard.open { border-left: 3px solid var(--blue); }
.tcard.unfilled { border-left: 3px solid var(--gold); }
.tcard-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.tcard-head .tkr { font-size: 18px; font-weight: 750; letter-spacing: -.02em; }
.tcard-foot { display: flex; align-items: center; gap: 8px; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.stat-inline { display: flex; gap: 16px; flex-wrap: wrap; }
.stat-inline > div { display: grid; gap: 1px; }
.stat-inline .v { font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; }

/* template: tape */
table.tape { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tape th { text-align: left; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); font-weight: 500; padding: 9px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
table.tape th:hover { color: var(--text2); }
table.tape th.sorted { color: var(--ember2); }
table.tape td { padding: 10px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tape tbody tr:hover { background: var(--bg3); }
table.tape td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.minirail { width: 108px; height: 5px; border-radius: 3px; background: var(--bg4); position: relative; overflow: hidden; }
.minirail i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }

/* template: lanes */
.lanes { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(186px, 100%), 1fr)); gap: 11px; align-items: start; }
.lane { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.lane-head { padding: 11px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; background: var(--bg3); }
.lane-body { padding: 10px; display: grid; gap: 9px; min-height: 70px; }
.lane-card { background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; cursor: pointer; }
.lane-card:hover { border-color: var(--border2); }
.lane-empty { display: grid; place-items: center; color: var(--dim); font-size: 12px; padding: 18px 0; }

/* ---------------------------------------------------------------- record */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr)); gap: 12px; }
.kpi { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); padding: 15px 16px; }
.kpi .v { font-family: var(--mono); font-size: 25px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 5px; }
.kpi .sub { font-size: 11.5px; color: var(--dim); margin-top: 3px; }

.bar-row { display: grid; grid-template-columns: 78px 1fr 92px; align-items: center; gap: 11px; padding: 7px 0; }
.bar-track { height: 9px; border-radius: 5px; background: var(--bg4); overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--green), var(--green2)); }

.lead { width: 100%; border-collapse: collapse; font-size: 13px; }
.lead td, .lead th { padding: 7px 9px; border-bottom: 1px solid var(--border); }
.lead th { text-align: left; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); font-weight: 500; }

/* ---------------------------------------------------------------- formats */
pre.sample { font-family: var(--mono); font-size: 12.5px; line-height: 1.7; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 13px 15px; margin: 0; overflow-x: auto; color: var(--text2); }
.sample-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(290px, 100%), 1fr)); gap: 14px; }
.kv { display: grid; grid-template-columns: 148px 1fr; gap: 8px 14px; font-size: 13px; }
.kv code { font-family: var(--mono); font-size: 12px; color: var(--ember2); }

/* ---------------------------------------------------------------- drawer + toast */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.62); backdrop-filter: blur(3px); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--bg2); border-left: 1px solid var(--border); z-index: 61; overflow-y: auto; box-shadow: -20px 0 60px rgba(0,0,0,.5); }
.drawer-head { position: sticky; top: 0; background: var(--bg2); border-bottom: 1px solid var(--border); padding: 16px 20px; display: flex; align-items: center; gap: 10px; z-index: 1; }

#toasts { position: fixed; bottom: 22px; right: 22px; z-index: 90; display: grid; gap: 9px; }
.toast { background: var(--bg3); border: 1px solid var(--border2); border-radius: 10px; padding: 11px 15px; font-size: 13px; box-shadow: 0 12px 34px rgba(0,0,0,.45); max-width: 360px; animation: rise .2s ease; }
.toast.ok  { border-color: rgba(16,185,129,.4); }
.toast.err { border-color: rgba(239,68,68,.45); }
@keyframes rise { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

.empty { display: grid; place-items: center; gap: 10px; padding: 60px 20px; text-align: center; color: var(--dim); }
.empty .big { font-size: 38px; opacity: .45; }
[hidden] { display: none !important; }

/* ================================================================ phones */
/* Everything here is about viewing on a handset: the board has to be readable
   and the controls tappable at 375px without the page scrolling sideways. */
@media (max-width: 620px) {
  .wrap { padding: 0 13px 64px; }

  /* The header was eating a third of the screen. The tagline goes, the logo
     shrinks, and the tabs become a single scrollable row. */
  .top-inner { padding: 10px 13px; gap: 9px; }
  .logo { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
  .brand { gap: 9px; }
  .brand h1 { font-size: 15px; }
  .brand .label { display: none; }

  nav.tabs {
    order: 3;
    flex: 1 1 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1px;
  }
  nav.tabs::-webkit-scrollbar { display: none; }
  nav.tabs button { flex: none; padding: 7px 13px; }

  .conn { padding: 6px 10px; font-size: 10px; }

  /* Two selects squeezed into a flex row collapsed to bare chevrons — give the
     board's controls their own full-width row and let them share it evenly. */
  .section-head { flex-wrap: wrap; gap: 8px; margin: 18px 0 11px; }
  .section-head > .row { width: 100%; flex-wrap: wrap; gap: 8px; }
  .section-head select { flex: 1 1 100px; max-width: none !important; }
  #btn-refresh { flex: 0 0 auto; }
  .tpl-switch { flex: 1 1 100%; justify-content: space-between; }
  .tpl-switch button { flex: 1; }

  /* Cards */
  .tcard { padding: 14px; }
  .tcard-head .tkr { font-size: 17px; }
  .stat-inline { gap: 14px; }

  /* A narrower rail needs tighter labels and a smaller inset to match. */
  .rail { --rail-inset: 21px; }
  .tick { width: 42px; }
  .tick .val { font-size: 9.5px; }
  .tick .cap { font-size: 8px; letter-spacing: .04em; }
  .marker .now { font-size: 9.5px; }

  /* 16px keeps iOS Safari from zooming the page when a field is focused. */
  input, textarea, select { font-size: 16px; }
  textarea.paste { font-size: 13.5px; min-height: 200px; }

  .kpi { padding: 13px 14px; }
  .kpi .v { font-size: 21px; }

  /* Formats: label-above-value reads far better than a 148px side column. */
  .kv { grid-template-columns: 1fr; gap: 3px 0; }
  .kv > .label { margin-top: 9px; }

  .drawer { width: 100%; border-left: none; }
  .drawer-head { padding: 13px 15px; }
  .drawer-head h2 { font-size: 16px; }

  .bar-row { grid-template-columns: 52px 1fr 78px; gap: 8px; }
  #toasts { left: 13px; right: 13px; bottom: 13px; }
  .toast { max-width: none; }
}

/* Very narrow handsets: stop the stat row wrapping mid-number. */
@media (max-width: 380px) {
  .stat-inline { gap: 11px; }
  .stat-inline .v { font-size: 13px; }
  .tick { width: 38px; }
  .rail { --rail-inset: 19px; }
}
