/* HoldingView — a ledger-like, calm workspace: warm paper neutrals, one deep green accent,
   Plex for text and figures, Newsreader for the large numbers. */
:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #18201c;
  --muted: #5f6b64;
  --line: #e1e5df;
  --grid: #eceee9;
  --accent: #1f6b4f;
  --accent-ink: #ffffff;
  --up: #1d7a4c;
  --down: #c2412f;
  --warn: #a86b00;
  --chart-muted: #c9d0ca;
  --tip-bg: #ffffff;
  --shadow: 0 6px 24px rgba(24, 32, 28, 0.10);
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --display: "Newsreader", Georgia, "Times New Roman", serif;
  --r: 8px;
  --gap: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --panel: #181e1b;
    --ink: #e6ebe7;
    --muted: #97a39c;
    --line: #2a332e;
    --grid: #222a26;
    --accent: #4fb488;
    --accent-ink: #0d1411;
    --up: #4fc283;
    --down: #ef7563;
    --warn: #e0a33a;
    --chart-muted: #3d4842;
    --tip-bg: #1f2622;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { text-wrap: balance; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons and fields */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 45%, var(--line)); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }
input, select {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 9px 11px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; border-color: var(--accent); }
.error { color: var(--down); margin: 0; font-size: 13px; }
.error.ok { color: var(--up); }
.fineprint { font-size: 12px; color: var(--muted); margin: 0; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .01em; }
.mark { width: 20px; height: 20px; border-radius: 5px; background:
  linear-gradient(var(--accent), var(--accent)) 0 100% / 5px 60% no-repeat,
  linear-gradient(var(--accent), var(--accent)) 50% 100% / 5px 100% no-repeat,
  linear-gradient(var(--accent), var(--accent)) 100% 100% / 5px 35% no-repeat; }

/* Sign in */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.auth-card h1 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 8px 0 0; }
.auth-card .muted { margin: -8px 0 4px; }
.switch { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.topbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 20px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: var(--r); font-weight: 500; }
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { color: var(--ink); background: var(--panel); border: 1px solid var(--line); padding: 5px 9px; }
.status { margin-left: auto; font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--chart-muted); }
.status .dot.live { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 22%, transparent); }
.status .dot.warn { background: var(--warn); }

/* Pages */
.page { max-width: 1280px; margin: 0 auto; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 20px; }
.page.narrow { max-width: 640px; }
.page h1 { font-family: var(--display); font-weight: 400; font-size: 32px; margin: 0; line-height: 1.15; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; max-width: 72ch; }
.page-head b { color: var(--ink); font-weight: 500; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile .lbl { font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.tile .num { font-family: var(--display); font-size: 28px; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: var(--gap); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card .note { margin: 0; font-size: 12.5px; color: var(--muted); max-width: 80ch; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card.danger { border-color: color-mix(in srgb, var(--down) 35%, var(--line)); }
.search { max-width: 260px; width: 100%; padding: 6px 10px; font-size: 13px; }

.chart { position: relative; min-height: 120px; }
.chart svg { display: block; overflow: visible; }
.chart text { font-family: var(--font); }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .lab { fill: var(--ink); font-size: 12px; }
.chart .val { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .sym { font-family: var(--mono); font-size: 11.5px; fill: var(--ink); }
.chart.tree { min-height: 420px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.tip { position: absolute; z-index: 10; pointer-events: none; background: var(--tip-bg); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 7px 10px; font-size: 12px; white-space: nowrap; display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.tip .h { color: var(--muted); }
.tip .r { display: flex; gap: 6px; align-items: center; }
.tip .sw { width: 8px; height: 8px; border-radius: 2px; }

.tablebox { max-height: 560px; overflow: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 500; text-align: right; padding: 8px; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; user-select: none; }
.table th[aria-sort="ascending"]::after { content: " ↑"; }
.table th[aria-sort="descending"]::after { content: " ↓"; }
.table td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.table .l { text-align: left; }
.table td.sym { font-family: var(--mono); font-weight: 500; }
.table td.name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.bar { display: inline-block; height: 6px; border-radius: 2px; background: var(--accent); opacity: .55; vertical-align: middle; margin-right: 6px; }

.notes { font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; }
.notes summary { cursor: pointer; color: var(--ink); font-weight: 500; }
.notes dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0; }
.notes dt { color: var(--ink); }
.notes dd { margin: 0; }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--r); padding: 40px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }
.empty p { margin: 0 0 8px; color: var(--muted); }

/* Invested vs current value */
.iv-figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 12px; margin: 6px 0 4px; }
.iv-figs > div { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--r); background: color-mix(in srgb, var(--ink) 3%, var(--panel)); min-width: 0; }
.iv-figs > div.em { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.iv-figs .lbl { font-size: 12px; color: var(--muted); }
.iv-figs .fig { font-family: var(--display); font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iv-key { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.iv-key i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* Accounts */
.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: var(--gap); }
.acct { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.acct-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.acct h3 { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.chip { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.acct dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
.acct dt { color: var(--muted); }
.acct dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.acct .acts { display: flex; flex-wrap: wrap; gap: 6px; }
.acct .msg { font-size: 12.5px; margin: 0; }
.acct.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
.acct .edit { display: flex; gap: 6px; flex-wrap: wrap; }
.acct .edit input { flex: 1 1 120px; padding: 6px 9px; }
.add-form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r); font-size: 13px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px); }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .tile .num { font-size: 24px; }
  .notes dl { grid-template-columns: 1fr; }
  .topbar-inner { gap: 10px; }
  .status { width: 100%; margin-left: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .card, .tile { animation: rise .35s ease-out both; }
  @keyframes rise { from { opacity: .001; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
