/* Portfolio — dark dashboard, cyan accent. Shares the visual language of the
   other iamrdt apps (Courtman, Cargirl) so they read as one family. */
:root {
  --bg: #12141a;
  --card: #1b1e27;
  --card2: #222633;
  --text: #eceef4;
  --muted: #8b91a3;
  --accent: #22d3ee;
  --accent-soft: rgba(34, 211, 238, 0.15);
  --green: #63c489;
  --red: #e0715c;
  --amber: #d9a441;
  --line: #2c3140;

  /* Categorical series palette — fixed slot order, never cycled. Validated
     against the --card surface: all eight clear the lightness band, chroma
     floor, adjacent CVD separation (worst ΔE 8.4) and 3:1 contrast. Charts cap
     at eight active series; beyond that names fall back to context grey. */
  --s1: #3987e5;  /* blue    */
  --s2: #d95926;  /* orange  */
  --s3: #199e70;  /* aqua    */
  --s4: #c98500;  /* yellow  */
  --s5: #d55181;  /* magenta */
  --s6: #008300;  /* green   */
  --s7: #9085e9;  /* violet  */
  --s8: #e66767;  /* red     */
  --ctx: #454b5e; /* unselected context lines */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 40px;
}

header { padding: 22px 18px 8px; max-width: 980px; margin: 0 auto; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
h1 { font-size: 26px; letter-spacing: 0.5px; }
h1::after {
  content: ""; display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); margin-left: 8px; vertical-align: middle;
}
.subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }

.ccy-toggle {
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 7px 15px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.ccy-toggle.local { border-color: var(--amber); color: var(--amber); }
.ccy-toggle:not(.local) { border-color: var(--accent); color: var(--accent); }

nav#tabs {
  display: flex; gap: 6px; padding: 12px 18px; max-width: 980px; margin: 0 auto;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tab {
  background: var(--card); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 16px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

main { max-width: 980px; margin: 0 auto; padding: 0 18px; }
#loading { color: var(--muted); padding: 30px 0; text-align: center; }
.error { color: var(--red); padding: 20px 0; line-height: 1.6; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; margin-bottom: 14px;
}
.card h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.card h3 .h3-sub { font-weight: 400; color: var(--muted); opacity: 0.8; }
.note { color: var(--muted); font-size: 12px; line-height: 1.55; margin-top: 10px; }
.note b { color: var(--text); font-weight: 600; }

/* ---- stat tiles ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 13px; }
.stat-val { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-val.good { color: var(--green); }
.stat-val.bad { color: var(--red); }
.stat-label { font-size: 12.5px; color: var(--text); margin-top: 3px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.headline .total { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
.headline .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.delta { font-weight: 600; font-size: 14px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

/* ---- charts ---- */
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.chart-title { font-size: 14px; color: var(--muted); }
.ranges { display: flex; gap: 4px; flex-wrap: wrap; }
.range-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.range-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.tooltip {
  position: absolute; pointer-events: none; background: #0d0f14;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  font-size: 12px; white-space: nowrap; display: none; z-index: 5; min-width: 140px;
}
.tooltip .tt-day { color: var(--muted); margin-bottom: 4px; }
.tt-row { display: flex; justify-content: space-between; gap: 14px; line-height: 1.55; }
.tt-key { color: var(--muted); }
.tt-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.dotmark { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.leg { font-size: 12px; color: var(--muted); }

/* ---- chips / pickers ---- */
.chips { display: flex; gap: 6px; margin: 10px 0 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chip {
  flex-shrink: 0; background: var(--card2); border: 1px solid var(--line);
  color: var(--muted); border-radius: 999px; padding: 5px 13px; font-size: 13px; cursor: pointer;
}
.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.picker { margin-top: 12px; }
.picker-actions { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; align-items: center; }
.mini-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.picker-hint { font-size: 11.5px; color: var(--muted); margin-left: auto; }
.pick-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pick {
  background: var(--card2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 6px 11px; font-size: 12.5px; cursor: pointer; text-align: left;
  display: inline-flex; align-items: center; gap: 6px;
}
.pick.on { color: var(--text); background: #262b3a; }
.pick:disabled { opacity: 0.4; cursor: not-allowed; }

.dd-select {
  width: 100%; background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b91a3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 38px;
}
.dd-select:focus { outline: none; border-color: var(--accent); }
.dd-select option { background: var(--card); color: var(--text); }
.dd-small { width: auto; flex: 1; padding: 8px 34px 8px 12px; font-size: 13px; }
.ctl-row { display: flex; gap: 6px; align-items: stretch; margin-bottom: 12px; flex-wrap: wrap; }

/* ---- tables ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: right; color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px; padding: 5px 6px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
th:first-child { text-align: left; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--accent); }
th .arrow { font-size: 9px; margin-left: 2px; }
td {
  padding: 8px 6px; text-align: right; border-bottom: 1px solid rgba(44, 49, 64, 0.55);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
td:first-child { text-align: left; white-space: normal; min-width: 130px; }
tr:last-child td { border-bottom: none; }
tr.total-row td { font-weight: 700; border-top: 1px solid var(--line); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(34, 211, 238, 0.05); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.dim { color: var(--muted); }
.nm { font-weight: 600; }
.tk { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 5px; }
.spark { vertical-align: middle; }

/* An estimated date is never shown as if it were confirmed. */
.est { border-bottom: 1px dotted var(--muted); }
.badge {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.4px; font-weight: 700;
  border-radius: 4px; padding: 1px 5px; margin-left: 5px; vertical-align: middle;
}
.badge.soon { background: rgba(34, 211, 238, 0.16); color: var(--accent); }
.badge.est { background: rgba(217, 164, 65, 0.16); color: var(--amber); }
.badge.held { background: rgba(99, 196, 137, 0.16); color: var(--green); }

/* ---- diverging bars (return by period) ---- */
.waterfall { display: flex; flex-direction: column; gap: 7px; margin-top: 4px; }
.wf-row { display: grid; grid-template-columns: 54px 1fr 64px; align-items: center; gap: 8px; font-size: 12.5px; }
.wf-label { color: var(--text); line-height: 1.25; }
.wf-track { position: relative; height: 20px; background: var(--card2); border-radius: 5px; }
.wf-zero { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--muted); opacity: 0.55; }
.wf-bar { position: absolute; top: 3px; bottom: 3px; }
.wf-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- allocation bars ---- */
.alloc { display: flex; flex-direction: column; gap: 9px; }
.alloc-row { display: grid; grid-template-columns: 1fr; gap: 3px; }
.alloc-label { font-size: 13px; }
.alloc-track { background: var(--card2); border-radius: 6px; height: 11px; overflow: hidden; }
.alloc-fill { height: 100%; border-radius: 6px; }
.alloc-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.alloc-pct { color: var(--text); font-weight: 600; margin-left: 8px; font-variant-numeric: tabular-nums; }

/* ---- calendar / timeline ---- */
.tl { display: flex; flex-direction: column; gap: 2px; }
.tl-month {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent);
  font-weight: 700; margin: 14px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line);
}
.tl-month:first-child { margin-top: 0; }
.tl-row {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid rgba(44, 49, 64, 0.4); font-size: 13.5px;
}
.tl-row:last-child { border-bottom: none; }
.tl-date { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tl-what { color: var(--muted); font-size: 12px; text-align: right; }
.tl-kind { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 7px; }
.tl-past { opacity: 0.5; }

/* ---- drawer ---- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(6, 8, 12, 0.68); }
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%);
  background: var(--bg); border-left: 1px solid var(--line);
  overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 18px 18px 40px;
}
.drawer-close {
  position: sticky; top: 0; float: right; background: var(--card); border: 1px solid var(--line);
  color: var(--muted); border-radius: 8px; width: 30px; height: 30px; font-size: 19px;
  line-height: 1; cursor: pointer; z-index: 2;
}
.drawer-close:hover { border-color: var(--accent); color: var(--accent); }
.dw-name { font-size: 20px; font-weight: 700; }
.dw-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; line-height: 1.5; }
.dw-px { font-size: 27px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin-top: 4px; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- holdings editor ---- */
.hold-head, .hold-row {
  display: grid; grid-template-columns: 1.6fr 0.95fr 0.95fr 1fr 0.9fr;
  gap: 6px; min-width: 620px; align-items: center;
}
.hold-head {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted);
  padding: 0 2px 6px; border-bottom: 1px solid var(--line);
}
.hold-head span:not(:first-child), .hold-row > :not(:first-child) { text-align: right; }
.hold-row { padding: 5px 0; }
.hold-row input {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 8px; font-size: 13px; width: 100%; text-align: right;
  font-variant-numeric: tabular-nums;
}
.hold-row input:focus { outline: none; border-color: var(--accent); }
.hold-row .hold-name { font-size: 13px; }
.hold-row .hold-calc { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); }
.save-btn {
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 8px; padding: 9px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.save-btn:hover { background: rgba(34, 211, 238, 0.26); }
.save-btn:disabled { opacity: 0.5; cursor: default; }
.save-row { display: flex; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.save-msg { font-size: 12.5px; color: var(--muted); }
.save-msg.ok { color: var(--green); }
.save-msg.err { color: var(--red); }

/* ---- event editor ---- */
.ev-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.ev-form label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--muted); }
.ev-form input, .ev-form select {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.ev-form input:focus, .ev-form select:focus { outline: none; border-color: var(--accent); }
.ev-form .grow { flex: 1; min-width: 130px; }
.del-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; width: 24px; height: 24px; line-height: 1; font-size: 15px; cursor: pointer;
}
.del-btn:hover { border-color: var(--red); color: var(--red); }

footer { max-width: 980px; margin: 6px auto 0; padding: 0 18px; }
#footnote { color: var(--muted); font-size: 11.5px; line-height: 1.55; }

@media (max-width: 620px) {
  th.hide-sm, td.hide-sm { display: none; }
  .headline .total { font-size: 27px; }
  .drawer-panel { padding: 14px 14px 40px; }
}
@media (max-width: 420px) {
  th.hide-xs, td.hide-xs { display: none; }
}
