/* Trading Haven — one stylesheet, no build step.
   Theme tokens are defined for all three viewer states: bare :root is the
   complete light palette, the prefers-color-scheme block covers the default
   "system" setting, and the [data-theme] blocks let an explicit choice win. */

/* The hidden attribute must beat any author display rule. Without this, a
   selector like `.signin { display: grid }` silently overrides `hidden`, and
   the element keeps rendering after JS sets the attribute — which is exactly
   what left the sign-in form sitting above the app, a full screen tall, after
   a successful login. Any element with a display rule needs this defence, so
   it is declared once, here, for all of them. */
[hidden] { display: none !important; }

:root {
  --bg:        #eef1f4;
  --surface:   #ffffff;
  --surface-2: #f4f6f8;
  --raised:    #e6eaee;
  --ink:       #10161d;
  --ink-2:     #3f4a56;
  --muted:     #6b7683;
  --line:      #d3dae1;
  --line-soft: #e4e9ee;

  --accent:      #0f7d86;
  --accent-ink:  #ffffff;
  --accent-wash: #dcf0f1;

  --gain:      #146c46;
  --gain-wash: #dcefe4;
  --loss:      #a3342a;
  --loss-wash: #f6e0dd;
  --warn:      #8a5a08;
  --warn-wash: #f8ecd6;

  --shadow: 0 1px 2px rgba(16, 22, 29, .06), 0 4px 12px rgba(16, 22, 29, .05);
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0d1117;
    --surface:   #151b23;
    --surface-2: #1b222b;
    --raised:    #222b35;
    --ink:       #e3e8ee;
    --ink-2:     #b9c2cd;
    --muted:     #808d9b;
    --line:      #2a333e;
    --line-soft: #212932;

    --accent:      #3fb5bf;
    --accent-ink:  #06232a;
    --accent-wash: #102f34;

    --gain:      #45b07d;
    --gain-wash: #10281e;
    --loss:      #e0705f;
    --loss-wash: #2c1917;
    --warn:      #d3a247;
    --warn-wash: #2a2213;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg:        #0d1117;
  --surface:   #151b23;
  --surface-2: #1b222b;
  --raised:    #222b35;
  --ink:       #e3e8ee;
  --ink-2:     #b9c2cd;
  --muted:     #808d9b;
  --line:      #2a333e;
  --line-soft: #212932;
  --accent:      #3fb5bf;
  --accent-ink:  #06232a;
  --accent-wash: #102f34;
  --gain:      #45b07d;
  --gain-wash: #10281e;
  --loss:      #e0705f;
  --loss-wash: #2c1917;
  --warn:      #d3a247;
  --warn-wash: #2a2213;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono, .num {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}

.primary {
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: var(--radius);
  padding: 9px 16px; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }

.ghost {
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px;
}
.ghost:hover { background: var(--raised); color: var(--ink); }

/* ------------------------------------------------------------- sign in */

.signin {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
}
.signin-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 32px;
  width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 12px;
}
.signin-card h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.signin-sub { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.signin-card label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.signin-field { display: flex; gap: 8px; }
.signin-field input { flex: 1; }

.error { color: var(--loss); font-size: 13px; margin: 4px 0 0; }
.ok { color: var(--gain); font-size: 13px; }

/* -------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  font-weight: 800; letter-spacing: -.03em; font-size: 17px; color: var(--accent);
}
.brand-name { font-size: 13px; color: var(--muted); }

.tabs { display: flex; gap: 2px; margin-left: auto; }
.tabs button {
  background: none; border: none; color: var(--muted);
  padding: 7px 13px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
}
.tabs button:hover { background: var(--raised); color: var(--ink); }
.tabs button.active { background: var(--accent-wash); color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1560px; margin: 0 auto; }

/* ------------------------------------------------------------- banners */

.banner {
  margin: 0; padding: 10px 20px;
  background: var(--warn-wash); color: var(--warn);
  border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 500;
}

.rollstrip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  padding: 12px 16px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-size: 13.5px;
}
.rollstrip b { font-size: 16px; }
.rollstrip .sep { color: var(--line); }

/* --------------------------------------------------------------- stats */

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px;
}
.stat { background: var(--surface); padding: 12px 14px; }
.stat .v {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 21px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2;
}
.stat .k {
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted); margin-top: 4px;
}
.stat .v.pos { color: var(--gain); }
.stat .v.neg { color: var(--loss); }

/* ------------------------------------------------------------ controls */

.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 22px;
  margin-bottom: 12px;
}
.ctl-label {
  font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.kgroup { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.segmented {
  display: inline-flex; border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; background: var(--surface);
}
.segmented button {
  background: none; border: none; color: var(--ink-2);
  padding: 6px 13px; font-size: 13px; font-weight: 500;
  border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }

.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); }
.check input { width: 15px; height: 15px; accent-color: var(--accent); padding: 0; }

#uni-search { min-width: 260px; }

/* -------------------------------------------------------------- tables */

.tablewrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }

thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: right; white-space: nowrap;
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  padding: 9px 10px; border-bottom: 1px solid var(--line);
}
thead th:first-child, tbody td:first-child { text-align: left; }

tbody td {
  text-align: right; white-space: nowrap;
  padding: 8px 10px; border-bottom: 1px solid var(--line-soft);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }
td.tkr { font-weight: 700; color: var(--ink); letter-spacing: -.01em; }
td.sub { color: var(--muted); font-size: 12px; }
.pos { color: var(--gain); font-weight: 600; }
.neg { color: var(--loss); font-weight: 600; }

.pill {
  display: inline-block; padding: 2px 7px; border-radius: 10px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase;
}
.pill.warn { background: var(--warn-wash); color: var(--warn); }
.pill.gain { background: var(--gain-wash); color: var(--gain); }
.pill.loss { background: var(--loss-wash); color: var(--loss); }
.pill.mute { background: var(--raised); color: var(--muted); }

.rowact { display: inline-flex; gap: 4px; }
.rowact button { padding: 3px 8px; font-size: 12px; }

.empty { color: var(--muted); text-align: center; padding: 32px 12px; font-size: 14px; }

/* ------------------------------------------------------------- drawers */

.drawer {
  margin-top: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.drawer > summary {
  cursor: pointer; padding: 10px 14px;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  list-style: none;
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before { content: "▸ "; color: var(--muted); }
.drawer[open] > summary::before { content: "▾ "; }
.drawer[open] > summary { border-bottom: 1px solid var(--line); }
.drawer .tablewrap { border: none; border-radius: 0; }

/* ---------------------------------------------------------------- forms */

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; padding: 16px; align-items: end;
}
.form-grid label { display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--ink-2); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid .error { grid-column: 1 / -1; }

.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; padding: 18px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 16px;
}
.settings-grid label { display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--ink-2); }
.settings-grid .actions { grid-column: 1 / -1; }

.notepanel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
}
.notepanel h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted); }
.notepanel dt { font-weight: 700; font-size: 13px; margin-top: 10px; }
.notepanel dd { margin: 3px 0 0; color: var(--ink-2); font-size: 13.5px; }
.notepanel code { background: var(--raised); padding: 1px 5px; border-radius: 3px;
  font-size: 12.5px; font-family: ui-monospace, Menlo, Consolas, monospace; }

.runlog {
  max-height: 300px; overflow-y: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
  line-height: 1.6;
}
.runlog div { display: flex; gap: 10px; padding: 1px 0; }
.runlog .t { color: var(--muted); flex: none; }
.runlog .error { color: var(--loss); margin: 0; }
.runlog .warn { color: var(--warn); }

.caveat {
  margin: 16px 0 0; padding: 11px 14px;
  background: var(--warn-wash); color: var(--warn);
  border-radius: var(--radius); font-size: 12.5px; font-weight: 500;
}

/* --------------------------------------------------------------- phone */

@media (max-width: 720px) {
  main { padding: 12px; }
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 12px; }
  .tabs { margin-left: 0; order: 3; width: 100%; overflow-x: auto; }
  #signout { order: 2; }

  /* Tables become stacked cards: the header row is hidden and each cell
     carries its own label from data-label. A new column therefore needs a
     label or its value appears with nothing naming it. */
  .tablewrap { border: none; background: none; overflow: visible; }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); margin-bottom: 10px; padding: 6px 12px;
  }
  tbody td {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 14px; text-align: right; white-space: normal;
    border-bottom: 1px solid var(--line-soft); padding: 6px 0;
  }
  tbody td::before {
    content: attr(data-label);
    font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--muted); text-align: left;
  }
  tbody td:empty { display: none; }
  tbody td[data-label=""] { justify-content: flex-end; }
  tbody tr:hover td { background: none; }
}

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

/* ------------------------------------------------------------- vol cap */

/* The tab reuses .banner, .stats/.stat, .controls, .segmented and .notepanel.
   Only what has no equivalent elsewhere is defined here. The default .banner
   is already warning-toned, so .ok recolours it for the common case — most
   months this tab has nothing to report and should not look alarming. */

#tab-volcap .banner { border: 1px solid var(--line); border-radius: 4px; margin-bottom: 14px; }
#tab-volcap .banner.ok { background: var(--gain-wash); color: var(--gain); }
#tab-volcap .banner.warn { background: var(--warn-wash); color: var(--warn); }
#tab-volcap .stat .v.warn { color: var(--warn); }

.ctl-select { min-width: 148px; }

.vc-form {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  padding: 14px 16px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.vc-form label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--muted); font-weight: 500;
}
.vc-form input { min-width: 168px; }

.vc-orders {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); margin: 12px 0;
}
.vc-order { background: var(--surface); padding: 14px 16px; }
.vc-order-head {
  font-size: 12px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.vc-order-amt {
  font-size: 26px; font-weight: 600; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin: 4px 0 2px;
}
.vc-order-amt.pos { color: var(--gain); }
.vc-order-amt.neg { color: var(--loss); }
.vc-order-sub { font-size: 12.5px; color: var(--muted); }

.vc-note { font-size: 13px; color: var(--ink-2); margin: 10px 0 12px; max-width: 70ch; }

@media (max-width: 720px) {
  .vc-form label, .vc-form input { width: 100%; }
}

/* --------------------------------------------- dashboard, calc, trades */

/* The trades table is editable in place, so its cells hold inputs rather than
   text. .mini keeps those inputs from dominating the row. */
.mini {
  width: 100%; min-width: 86px; max-width: 132px;
  padding: 4px 6px; font-size: 12.5px;
}
#vc-trades td, #vc-trades th { padding: 6px 8px; }
#vc-trades .ghost { padding: 4px 9px; font-size: 12px; }
.ghost.danger { color: var(--loss); }
.ghost.danger:hover { border-color: var(--loss); }

.sec-note { font-size: 13px; color: var(--muted); margin: -4px 0 10px; max-width: 70ch; }

.vc-calc {
  font-size: 14px; line-height: 1.65; color: var(--ink-2);
  max-width: 74ch; margin: 0 0 14px;
}

#tab-dashboard .banner { border: 1px solid var(--line); border-radius: 4px; margin-bottom: 14px; }
#tab-dashboard .banner.ok { background: var(--gain-wash); color: var(--gain); }
#tab-dashboard .banner.warn { background: var(--warn-wash); color: var(--warn); }

#vc-dash { margin-bottom: 14px; }

@media (max-width: 720px) {
  .mini { max-width: none; }
}
