/* ============================================================================
   Portfolio dashboard
   Colour tokens follow a validated categorical palette: asset-class hues are
   assigned by fixed slot, never cycled, and the dark steps are chosen for the
   dark surface rather than flipped from the light ones.
   ========================================================================== */

:root {
  color-scheme: light;

  --page:          #f9f9f7;
  --surface:       #fcfcfb;
  --surface-2:     #f2f1ed;
  --text:          #0b0b0b;
  --text-2:        #52514e;
  --muted:         #898781;
  --grid:          #e1e0d9;
  --baseline:      #c3c2b7;
  --border:        rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --shadow:        0 1px 2px rgba(11,11,11,.05), 0 8px 24px -12px rgba(11,11,11,.14);
  --shadow-lg:     0 24px 60px -20px rgba(11,11,11,.30);

  --accent:        #2a78d6;
  --accent-ink:    #ffffff;
  --accent-soft:   #eaf2fd;

  --pos:           #006300;
  --neg:           #c0302f;
  --warn:          #fab219;

  /* Asset-class slots */
  --c-asx:      #2a78d6;
  --c-us:       #eb6834;
  --c-crypto:   #1baf7a;
  --c-property: #eda100;
  --c-super:    #e87ba4;
  --c-liability:#898781;

  --r-sm: 7px;
  --r:    11px;
  --r-lg: 16px;
  --gap:  18px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:          #0d0d0d;
    --surface:       #1a1a19;
    --surface-2:     #232322;
    --text:          #ffffff;
    --text-2:        #c3c2b7;
    --muted:         #898781;
    --grid:          #2c2c2a;
    --baseline:      #383835;
    --border:        rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);
    --shadow:        0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    --shadow-lg:     0 24px 60px -20px rgba(0,0,0,.75);

    --accent:        #3987e5;
    --accent-ink:    #08121f;
    --accent-soft:   #16273c;

    --pos:           #0ca30c;
    --neg:           #e66767;

    --c-asx:      #3987e5;
    --c-us:       #d95926;
    --c-crypto:   #199e70;
    --c-property: #c98500;
    --c-super:    #d55181;
    --c-liability:#898781;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:          #0d0d0d;
  --surface:       #1a1a19;
  --surface-2:     #232322;
  --text:          #ffffff;
  --text-2:        #c3c2b7;
  --muted:         #898781;
  --grid:          #2c2c2a;
  --baseline:      #383835;
  --border:        rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --shadow:        0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg:     0 24px 60px -20px rgba(0,0,0,.75);

  --accent:        #3987e5;
  --accent-ink:    #08121f;
  --accent-soft:   #16273c;

  --pos:           #0ca30c;
  --neg:           #e66767;

  --c-asx:      #3987e5;
  --c-us:       #d95926;
  --c-crypto:   #199e70;
  --c-property: #c98500;
  --c-super:    #d55181;
  --c-liability:#898781;
}

/* ------------------------------------------------------------------ base -- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num  { text-align: right; font-variant-numeric: tabular-nums; }
.pos  { color: var(--pos); }
.neg  { color: var(--neg); }
.meta { color: var(--muted); font-size: 12.5px; }

/* --------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background .13s ease, border-color .13s ease, transform .08s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.btn-icon { width: 36px; padding: 0; color: var(--text-2); }
.btn-block { width: 100%; height: 42px; }
.btn-danger-ghost { border-color: transparent; color: var(--neg); }
.btn-danger-ghost:hover { background: var(--surface-2); }

.ico { flex: none; }

.linkish {
  background: none; border: 0; padding: 0;
  color: var(--text-2); font-size: 12.5px; cursor: pointer;
  text-decoration: none; border-bottom: 1px solid var(--border-strong);
}
.linkish:hover { color: var(--text); }

.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.seg {
  height: 28px; padding: 0 11px;
  border: 0; border-radius: 5px; background: transparent;
  color: var(--text-2); font-size: 12.5px; font-weight: 550; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.seg:hover { color: var(--text); }
.seg.is-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

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

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 58px; padding: 0 22px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: 8px; background: var(--accent); color: var(--accent-ink);
}
.brand-name { font-weight: 640; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 9px; }

.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .ico-sun { display: none; }
  :root:where(:not([data-theme="light"])) .ico-moon { display: block; }
}

.banner {
  padding: 10px 22px;
  background: color-mix(in srgb, var(--warn) 16%, var(--page));
  border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 13px;
}

/* ---------------------------------------------------------------- layout -- */

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 22px 48px;
  display: flex; flex-direction: column; gap: var(--gap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 620; letter-spacing: -0.01em; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-controls { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.grid-2 {
  display: grid; gap: var(--gap);
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

/* --------------------------------------------------------------- summary -- */

.summary {
  display: grid; gap: var(--gap);
  grid-template-columns: minmax(260px, 0.9fr) minmax(0, 2.1fr);
  align-items: stretch;
}

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  display: flex; flex-direction: column; justify-content: center;
}
.hero-label { color: var(--muted); font-size: 12.5px; font-weight: 550; letter-spacing: .02em; text-transform: uppercase; }
.hero-value {
  font-size: clamp(34px, 4.4vw, 50px);
  font-weight: 660; letter-spacing: -0.035em; line-height: 1.08;
  margin-top: 6px;
}
.hero-delta { margin-top: 7px; font-size: 13.5px; color: var(--text-2); }
.hero-note { margin-top: 4px; font-size: 12px; color: var(--muted); }

/* The day-movement tile, given a touch more weight than its neighbours. */
.tile-accent { border-color: var(--border-strong); background: var(--surface); }
.tile-accent .tile-value { font-size: 23px; }

.tiles {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 16px 17px;
  display: flex; flex-direction: column; gap: 3px;
  min-width: 0;
}
.tile-label { color: var(--muted); font-size: 12px; font-weight: 550; }
.tile-value { font-size: 21px; font-weight: 620; letter-spacing: -0.02em; }
.tile-sub { font-size: 12px; color: var(--text-2); }

/* ---------------------------------------------------------------- charts -- */

.chart-card { padding-bottom: 14px; }
.chart-host { position: relative; width: 100%; }
.chart-host svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  margin: -4px 0 12px;
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.legend-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.chart-empty {
  display: grid; place-items: center;
  min-height: 220px; text-align: center;
  color: var(--muted); font-size: 13px;
  border: 1px dashed var(--border-strong); border-radius: var(--r);
  padding: 24px;
}

.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 9px 11px;
  font-size: 12.5px; min-width: 132px;
  transition: opacity .1s ease;
}
.tip[hidden] { display: none; }
.tip-date { color: var(--muted); font-size: 11.5px; margin-bottom: 5px; }
.tip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; margin-top: 3px; }
.tip-name { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tip-val { font-variant-numeric: tabular-nums; font-weight: 580; }
.tip-total { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }

/* ------------------------------------------------------------ allocation -- */

.alloc { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 20px; align-items: center; }
.alloc-chart { position: relative; }
.alloc-centre {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none;
}
.alloc-centre-val { font-size: 17px; font-weight: 640; letter-spacing: -0.02em; }
.alloc-centre-lab { font-size: 11px; color: var(--muted); }
.alloc-rows { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.alloc-row { display: grid; grid-template-columns: 10px minmax(0,1fr) auto auto; gap: 10px; align-items: center; font-size: 13px; }
.alloc-key { width: 10px; height: 10px; border-radius: 3px; }
.alloc-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-pct { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 46px; text-align: right; }
.alloc-val { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 84px; text-align: right; font-size: 12.5px; }

/* ---------------------------------------------------------------- manual -- */

.manual-list { display: flex; flex-direction: column; gap: 10px; }
.manual-row {
  display: grid; grid-template-columns: 10px minmax(0,1fr) 128px auto; gap: 11px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface-2);
}
.manual-key { width: 10px; height: 10px; border-radius: 3px; }
.manual-name { font-size: 13.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manual-meta { font-size: 11.5px; color: var(--muted); }
.manual-input { height: 34px; }
.manual-empty { color: var(--muted); font-size: 13px; padding: 2px 2px 0; line-height: 1.55; }
.manual-empty-state {
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px; border: 1px dashed var(--border-strong); border-radius: var(--r);
}
.manual-starters { display: flex; flex-wrap: wrap; gap: 8px; }

/* ----------------------------------------------------------------- table -- */

/* The bleed lets the table scroll edge to edge inside the card. `contain: paint`
   keeps its scrollable overflow from leaking into the page's scroll region,
   which otherwise lets the whole document pan sideways on a phone. */
.table-host {
  overflow-x: auto;
  margin: 0 -20px;
  padding: 0 20px;
  contain: paint;
  overscroll-behavior-x: contain;
}
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 550; font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase;
  color: var(--muted); padding: 0 12px 9px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th.num { text-align: right; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .arrow { opacity: .55; margin-left: 3px; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.act { width: 40px; text-align: right; }

.grp td {
  padding: 16px 12px 6px;
  border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
}
.grp:first-child td { padding-top: 4px; }
.grp-key { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }

.h-name { display: flex; flex-direction: column; gap: 1px; min-width: 150px; }
.h-title { font-weight: 550; }
.h-sub { font-size: 11.5px; color: var(--muted); }
.h-sub .warn-dot { color: var(--warn); }

.weight-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.weight-bar { width: 44px; height: 5px; border-radius: 3px; background: var(--grid); overflow: hidden; flex: none; }
.weight-fill { display: block; height: 100%; border-radius: 3px; }
.weight-num { font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

.row-btn {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer;
}
.row-btn:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); }

.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 0 10px; }

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

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; font-weight: 550; color: var(--text-2); margin-bottom: 5px; }
.field-hint { display: block; font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.45; }
.opt { color: var(--muted); font-weight: 400; }
.field-row { display: grid; grid-template-columns: 1fr 1fr 96px; gap: 11px; }
.field-narrow { min-width: 0; }

.input {
  width: 100%; height: 38px; padding: 0 11px;
  background: var(--page);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
select.input { appearance: none; padding-right: 30px; cursor: pointer; }

.form-error {
  background: color-mix(in srgb, var(--neg) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--neg) 34%, transparent);
  color: var(--neg); border-radius: var(--r-sm);
  padding: 9px 11px; font-size: 12.5px;
}

/* ---------------------------------------------------------------- modals -- */

.modal {
  border: 0; padding: 0; background: transparent;
  max-width: min(520px, calc(100vw - 32px)); width: 100%;
  color: var(--text);
}
.modal::backdrop { background: rgba(8, 8, 8, .48); backdrop-filter: blur(2px); }
.modal-inner {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 620; }
.modal-body { padding: 18px; max-height: min(64vh, 560px); overflow-y: auto; }
.modal-body .field:last-of-type { margin-bottom: 0; }
.modal-foot {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.spacer { flex: 1; }

.diag-row {
  display: grid; grid-template-columns: 18px minmax(0,1fr); gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.diag-row:last-child { border-bottom: 0; }
.diag-name { font-size: 13px; font-weight: 550; }
.diag-detail { font-size: 12px; color: var(--muted); word-break: break-word; }
.diag-ok { color: var(--pos); }
.diag-bad { color: var(--neg); }

.cron-box {
  margin-top: 14px; padding: 13px; border: 1px solid var(--border);
  border-radius: var(--r); background: var(--surface-2);
}
.cron-cmd {
  display: block; margin: 10px 0; padding: 9px 10px;
  background: var(--page); border: 1px solid var(--border); border-radius: var(--r-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px; word-break: break-all; line-height: 1.5;
  user-select: all;
}

/* ----------------------------------------------------------------- toast -- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--page);
  padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 550;
  box-shadow: var(--shadow-lg);
}
.toast[hidden] { display: none; }

/* ------------------------------------------------------------------ foot -- */

.foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; padding: 4px 2px;
}
.foot-links { display: flex; gap: 16px; align-items: center; }

/* ------------------------------------------------------------- gate pages -- */

.gate-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.gate { width: 100%; max-width: 400px; }
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 30px 28px;
}
.gate-mark {
  width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 13px; background: var(--accent); color: var(--accent-ink); margin-bottom: 16px;
}
.gate-title { font-size: 21px; font-weight: 640; letter-spacing: -0.02em; }
.gate-sub { color: var(--text-2); font-size: 13.5px; margin-top: 7px; line-height: 1.55; }
.gate-form { margin-top: 20px; }
.gate-error {
  background: color-mix(in srgb, var(--neg) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--neg) 34%, transparent);
  color: var(--neg); border-radius: var(--r-sm); padding: 9px 11px;
  font-size: 12.5px; margin-top: 16px;
}
.gate-note { color: var(--muted); font-size: 11.5px; margin-top: 18px; line-height: 1.55; }
.gate-note code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.input-pin { height: 46px; font-size: 18px; letter-spacing: .12em; text-align: center; }

/* ------------------------------------------------------------ responsive -- */

@media (max-width: 1080px) {
  .summary { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alloc { grid-template-columns: 1fr; justify-items: center; }
  .alloc-rows { width: 100%; }
}
/* Narrow screens: drop the columns you can infer from the others, so the four
   that matter fit without a sideways hunt. */
@media (max-width: 760px) {
  .table th:nth-child(2), .table td:nth-child(2),
  .table th:nth-child(3), .table td:nth-child(3),
  .table th:nth-child(7), .table td:nth-child(7) { display: none; }
  .h-name { min-width: 120px; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 14px; }
  .wrap { padding: 16px 14px 40px; }
  .card { padding: 16px; }
  .table-host { margin: 0 -16px; padding: 0 16px; }
  .meta { display: none; }
  .card-head { flex-direction: column; align-items: stretch; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .field-row .field-narrow { grid-column: span 2; }
  .manual-row { grid-template-columns: 10px minmax(0,1fr); row-gap: 8px; }
  .manual-row .manual-input, .manual-row .btn { grid-column: 2; }
  .hero-value { font-size: 36px; }
}

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

@media print {
  .topbar, .card-controls, .foot-links, .row-btn, .toast { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
