/*
  TradeMachine. One stylesheet, no framework, no build step.

  Dark is the default because this is a screen people keep open beside charts
  for hours. Light follows the operating system or the toggle, and every color
  lives in a token so the two themes cannot drift apart.

  Numbers use tabular figures everywhere. A price column where the digits change
  width as the price moves is a column nobody can scan.
*/

:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --bg-raise: #10141a;
  --surface: #131820;
  --surface-2: #19202a;
  --border: #232b36;
  --border-strong: #2f3a47;
  --text: #e7ebf1;
  --text-dim: #9aa4b2;
  --text-faint: #6b7584;
  --accent: #ff6b2c;
  --accent-strong: #ff8a54;
  --accent-ink: #1a0a02;
  --accent-soft: rgba(255, 107, 44, 0.12);
  --gain: #22d38f;
  --gain-soft: rgba(34, 211, 143, 0.12);
  --loss: #ff5468;
  --loss-soft: rgba(255, 84, 104, 0.12);
  --warn: #f5b83d;
  --warn-soft: rgba(245, 184, 61, 0.12);
  --info: #5aa9ff;
  --info-soft: rgba(90, 169, 255, 0.12);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 9px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-raise: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #e1e6ec;
  --border-strong: #cfd6df;
  --text: #0e141b;
  --text-dim: #4e5968;
  --text-faint: #7b8594;
  --accent: #e4531a;
  --accent-strong: #c9440f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(228, 83, 26, 0.10);
  --gain: #0f9f67;
  --gain-soft: rgba(15, 159, 103, 0.10);
  --loss: #d92d45;
  --loss-soft: rgba(217, 45, 69, 0.10);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, 0.12);
  --info: #1f6fd1;
  --info-soft: rgba(31, 111, 209, 0.10);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f6f9;
    --bg-raise: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --border: #e1e6ec;
    --border-strong: #cfd6df;
    --text: #0e141b;
    --text-dim: #4e5968;
    --text-faint: #7b8594;
    --accent: #e4531a;
    --accent-strong: #c9440f;
    --accent-ink: #ffffff;
    --accent-soft: rgba(228, 83, 26, 0.10);
    --gain: #0f9f67;
    --gain-soft: rgba(15, 159, 103, 0.10);
    --loss: #d92d45;
    --loss-soft: rgba(217, 45, 69, 0.10);
    --warn: #b7791f;
    --warn-soft: rgba(183, 121, 31, 0.12);
    --info: #1f6fd1;
    --info-soft: rgba(31, 111, 209, 0.10);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over any display a class sets, or a button a
   script hid for a reason is still on screen. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.65rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 620; }
h3 { font-size: 0.95rem; font-weight: 600; }
p { margin: 0; }

code, .mono { font-family: var(--mono); font-size: 0.88em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; left: -999px; top: 8px;
  background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip:focus { left: 12px; z-index: 100; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  height: 60px; display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 680; letter-spacing: -0.02em; }
.brand:hover { color: var(--text); }
.brand img { width: 28px; height: 28px; display: block; }
.brand span { font-size: 1.02rem; }

.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--text-dim); padding: 7px 12px; border-radius: 999px;
  font-size: 0.92rem; font-weight: 520; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }

.topbar-end { display: flex; align-items: center; gap: 10px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 0.9rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 0.82rem;
}
.who-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout ---------- */

.page { max-width: 1240px; margin: 0 auto; padding: 28px 20px 64px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header p { color: var(--text-dim); margin-top: 6px; }
.eyebrow { color: var(--text-faint); font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 680px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  /* Four numbers read fine two across on a phone, and a column of four tall
     cards pushes everything that matters below the fold. */
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid-4 .stat { padding: 14px; }
  .grid-4 .stat-value { font-size: 1.2rem; }
  .grid-4 .stat-note { display: none; }
  /* The nav drops to its own full width row, so it never truncates a link to
     make room for the account controls. */
  .topbar-inner { height: auto; flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px 0; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 8px; margin: 0 -4px; }
  .who-name { display: none; }
  .page { padding: 20px 14px 56px; }
  h1 { font-size: 1.4rem; }
  .card-head { flex-wrap: wrap; }
  .card-head p { display: none; }
  .activity li { flex-wrap: wrap; gap: 2px 12px; padding: 11px 16px; }
  .activity time { min-width: 0; flex-basis: 100%; }
  .activity .mono { display: none; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  td, th { padding-left: 14px; padding-right: 14px; }
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-head p { color: var(--text-faint); font-size: 0.85rem; }

.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--text-dim); font-size: 0.82rem; font-weight: 560; }
.stat-value { font-size: 1.45rem; font-weight: 680; letter-spacing: -0.02em; }
.stat-note { color: var(--text-faint); font-size: 0.82rem; }
.stat-value-sm { font-size: 1.1rem; overflow-wrap: anywhere; }
.mt { margin-top: 16px; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; padding: 18px 20px; margin: 0; }
.facts dt { color: var(--text-dim); font-size: 0.88rem; }
.facts dd { margin: 0; font-size: 0.9rem; overflow-wrap: anywhere; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 620; letter-spacing: 0.01em;
  background: var(--surface-2); color: var(--text-dim);
  box-shadow: inset 0 0 0 1px var(--border);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.9; }
.badge.plain::before { display: none; }
.badge.ok { color: var(--gain); background: var(--gain-soft); box-shadow: none; }
.badge.bad { color: var(--loss); background: var(--loss-soft); box-shadow: none; }
.badge.warn { color: var(--warn); background: var(--warn-soft); box-shadow: none; }
.badge.info { color: var(--info); background: var(--info-soft); box-shadow: none; }
.badge.accent { color: var(--accent); background: var(--accent-soft); box-shadow: none; }

.gain { color: var(--gain); }
.loss { color: var(--loss); }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 0.85rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 60ms ease;
}
.btn:hover { background: var(--surface); border-color: var(--text-faint); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
.btn-danger { background: var(--loss-soft); border-color: transparent; color: var(--loss); }
.btn-danger:hover { background: var(--loss); color: #fff; border-color: var(--loss); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 1rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn svg { width: 18px; height: 18px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left; font-weight: 600; color: var(--text-faint);
  font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 10px 20px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.86rem; font-weight: 580; color: var(--text-dim); }
.input {
  height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg-raise); color: var(--text);
  font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-dim); }

/* ---------- Notices and empty states ---------- */

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--info-soft); color: var(--text); font-size: 0.9rem;
}
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--loss-soft); }
.notice strong { font-weight: 650; }

.empty { padding: 36px 20px; text-align: center; color: var(--text-dim); }
.empty h3 { color: var(--text); margin-bottom: 6px; }

.offline-banner {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--loss); color: #fff; padding: 9px 16px; border-radius: 999px;
  font-size: 0.86rem; font-weight: 600; box-shadow: var(--shadow); z-index: 50;
}

/* ---------- Sign in ---------- */

.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, var(--info-soft), transparent 60%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 420px; padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand img { width: 44px; height: 44px; }
.auth-brand h1 { font-size: 1.35rem; }
.auth-brand p { color: var(--text-dim); font-size: 0.9rem; margin-top: 2px; }
.auth-card .stack { gap: 14px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-foot { margin-top: 22px; color: var(--text-faint); font-size: 0.8rem; text-align: center; }

/* ---------- Footer ---------- */

.foot { max-width: 1240px; margin: 0 auto; padding: 0 20px 28px; color: var(--text-faint); font-size: 0.8rem; display: flex; gap: 12px; flex-wrap: wrap; }
.foot a { color: var(--text-dim); }

/* ---------- Activity list ---------- */

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; align-items: baseline; padding: 11px 20px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.activity li:last-child { border-bottom: none; }
.activity time { color: var(--text-faint); font-size: 0.82rem; min-width: 120px; }

/* ---------- Helpers ---------- */

.mb { margin-bottom: 16px; }
.pt0 { padding-top: 0; }
.strong { font-weight: 650; }
.upper { text-transform: uppercase; }
.self-end { align-self: end; min-height: 42px; }
.warn-text { color: var(--warn); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 0.84rem; border-radius: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.eyebrow a { color: inherit; }
.eyebrow a:hover { color: var(--text); }
.card-head h2 a { color: var(--text); }
.card-head h2 a:hover { color: var(--accent); }
h1.row, h2 { gap: 10px; }

/* ---------- Money ---------- */

.kill-banner { align-items: center; }
.kill-banner strong { color: var(--loss); margin-right: 6px; }
.kill-item {
  display: inline-block; margin: 0 8px 0 0; padding: 1px 8px; border-radius: 999px;
  background: var(--loss-soft); font-size: 0.84rem;
}

.approvals { list-style: none; margin: 0; padding: 0; }
.approval {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--warn);
}
.approval:last-child { border-bottom: none; }
.approval-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.approval-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 1rem; }
.approval-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.approval-actions form { margin: 0; }
.countdown {
  min-width: 64px; text-align: right; font-weight: 650; color: var(--warn);
  font-size: 0.95rem;
}
.countdown.urgent { color: var(--loss); }
.countdown.expired { color: var(--text-faint); font-weight: 500; }

.order-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); flex-wrap: wrap; }
.order-link:hover { color: var(--accent); }
.badge.gain { color: var(--gain); }
.badge.loss { color: var(--loss); }

.grid-ticket { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--bg-raise); border: 1px solid var(--border-strong); border-radius: 12px;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block; text-align: center; padding: 8px 0; border-radius: 9px;
  font-weight: 620; color: var(--text-dim);
}
.segmented label:first-child input:checked + span { background: var(--gain-soft); color: var(--gain); }
.segmented label:last-child input:checked + span { background: var(--loss-soft); color: var(--loss); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.tab { padding: 7px 14px; border-radius: 999px; color: var(--text-dim); font-weight: 560; font-size: 0.9rem; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--accent); background: var(--accent-soft); }

.facts-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.facts-3 > div { display: flex; flex-direction: column; gap: 2px; }

/* A form folded under a card until it is wanted. */
.fold { border-top: 1px solid var(--border); }
.fold > summary { cursor: pointer; padding: 14px 20px; font-weight: 600; color: var(--accent); list-style-position: inside; }
.fold > summary:hover { background: var(--surface-2); }
.fold[open] > summary { border-bottom: 1px solid var(--border); }

.textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.4; font-size: 0.82rem; }
select.input { padding-right: 8px; }

.live-fieldset {
  margin: 0; padding: 14px 16px 16px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 10px;
}
.live-fieldset legend { padding: 0 6px; font-size: 0.82rem; font-weight: 620; color: var(--text-dim); }

.timeline { list-style: none; margin: 0; padding: 8px 20px 16px; }
.timeline li {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  padding: 10px 0 10px 20px; border-left: 2px solid var(--border);
}
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 2px var(--border-strong);
}
.timeline li:last-child::before { background: var(--accent); box-shadow: none; }
.timeline time { color: var(--text-faint); font-size: 0.8rem; font-family: var(--mono); }

@media (max-width: 1024px) {
  .grid-ticket { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .approval { flex-direction: column; align-items: stretch; padding: 12px 14px; }
  .approval-actions { justify-content: flex-end; }
  .facts-3 { grid-template-columns: 1fr 1fr; }
  .facts.facts-3 dd { margin-bottom: 0; }
  .order-link .dim { flex-basis: 100%; }
  /* The sentence takes the whole row and the buttons sit under it, rather than
     the sentence shrinking to a word per line beside them. */
  .alerts-body > p { flex-basis: 100%; }
  /* An orders table scrolls sideways on a phone. Squeezed into the width it
     stacks every order into a tower nobody can scan. */
  .table-wrap table { min-width: 600px; }
  .order-link { flex-wrap: nowrap; white-space: nowrap; }
  .order-link .dim { flex-basis: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
