/* Dark-only baseline (URS §2): one phone-width column, centered on desktop.
   Tokens up front so later phases restyle by changing variables, not rules. */
:root {
  color-scheme: dark;
  --bg: #12161b;
  --surface: #1a2027;
  --border: #2a323c;
  --fg: #e7eaee;
  --muted: #98a2ad;
  --accent: #56c288;
  --accent-fg: #0c1f16;
  /* Second categorical hue (combined view): lightness-matched to the
     accent; the pair validates at CVD dE 18.7 and >=3:1 on --bg. */
  --accent2: #6ea8fe;
  /* Third to fifth categorical hues (scenario overlays): lightness-matched
     to the accents; the five validate in order at worst adjacent CVD dE
     15.2, normal dE 16.9, all >=3:1 on --bg. The dashed --muted baseline
     stays distinguishable without color. */
  --accent3: #e8a05c;
  --accent4: #b48cfa;
  --accent5: #ee7f96;
  --danger: #e5695e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  max-width: 26rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

h1 { font-size: 1.4rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
a { color: var(--accent); }

/* --- Header ----------------------------------------------------------- */

header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar {
  max-width: 26rem;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.topbar .brand {
  font-weight: 650;
  color: var(--fg);
  text-decoration: none;
  margin-right: auto;
}

.topbar a { text-decoration: none; }
.nav-user { color: var(--muted); font-size: 0.9rem; }

/* --- Bottom navigation ------------------------------------------------------- */
/* Fixed to the bottom edge — thumb reach beats a header on a phone. The
   body reserves clearance for it plus the iOS home-indicator inset. */

body.has-nav {
  padding-bottom: calc(3.8rem + env(safe-area-inset-bottom));
}

.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottomnav-inner {
  max-width: 26rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.bottomnav a,
.bottomnav summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0 0.4rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.65rem;
  cursor: pointer;
  list-style: none;
}

.bottomnav summary::-webkit-details-marker { display: none; }
.bottomnav svg { width: 1.4rem; height: 1.4rem; }
.bottomnav a.active { color: var(--accent); }

/* The ☰ popup: a card that opens upward from the bar. Tapping any link
   navigates (which closes it); tapping ☰ again closes it too. */
.nav-menu { position: relative; }

.nav-menu-panel {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0.5rem;
  min-width: 11rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
}

.nav-menu-panel a,
.nav-menu-panel .linklike {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.95rem;
}

.nav-menu-panel a:hover,
.nav-menu-panel .linklike:hover { background: var(--bg); }

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

form { margin: 0; }

label {
  display: block;
  margin: 0.9rem 0 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.1rem;
}

button {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.danger { background: var(--danger); color: #24100e; }

button.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 400;
}

.button-secondary { color: var(--muted); }

/* --- Flash messages ---------------------------------------------------- */

.flash {
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.flash.error { border-color: var(--danger); }
.flash.info  { border-color: var(--accent); }

/* --- Sections ----------------------------------------------------------- */

section {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.danger-zone h2 { color: var(--danger); }

/* --- Row lists (FSPs, accounts, holdings) -------------------------------- */

ul.rows {
  list-style: none;
  margin: 0.75rem 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

ul.rows li { border-top: 1px solid var(--border); }
ul.rows li:first-child { border-top: none; }

.row-main {
  display: block;
  padding: 0.7rem 0.8rem;
  color: var(--fg);
  text-decoration: none;
  background: var(--surface);
}

.row-main:hover { background: var(--bg); }

.row-title { display: block; font-weight: 500; }

.row-sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-top: 0.15rem;
  font-size: 0.9rem;
}

.row-meta { min-width: 0; }

.row-value {
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
}

.row-more {
  padding: 0 0.8rem 0.5rem;
  background: var(--surface);
}

.row-more summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
}

.badge {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--muted);
  vertical-align: middle;
}

.crumbs { margin: 0 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
.crumbs a { color: var(--muted); }

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

.scroll-x { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; white-space: nowrap; }

.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }

/* --- Compound form layouts -------------------------------------------------- */

select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
}

.pair, .triple { display: flex; gap: 0.75rem; }
.pair > div, .triple > div { flex: 1; min-width: 0; }

.inline { display: flex; gap: 0.5rem; align-items: center; margin: 0.4rem 0; }
.inline input { flex: 1; }

.inline-add { display: flex; gap: 0.5rem; margin: 0.5rem 0; flex-wrap: wrap; }
.inline-add input, .inline-add select { flex: 1; min-width: 9rem; }

.filter { display: flex; gap: 0.5rem; margin: 0.75rem 0; }
.filter input { flex: 1; }

button.small { padding: 0.4rem 0.7rem; font-weight: 500; }
.danger-text { color: var(--danger); }

.check { display: flex; gap: 0.5rem; align-items: center; color: var(--fg); }
.check input { width: auto; }

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1rem 0 0;
  padding: 0.75rem;
}

legend { color: var(--muted); font-size: 0.85rem; padding: 0 0.4rem; }

.weight-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.weight-row select { flex: 2; min-width: 0; }
.weight-row input { flex: 1; min-width: 3.5rem; }

details > summary { cursor: pointer; color: var(--muted); }

/* --- CompoundUs ------------------------------------------------------------- */

.scope-switch { display: flex; gap: 0.4rem; margin: 0.75rem 0; }

.scope-switch button {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
}

.scope-switch button.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

/* --- Title rows, add/edit affordances --------------------------------------- */

.title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0 1rem;
  flex-wrap: wrap;
}

.title-row h1 { margin: 0; flex: 1; min-width: 0; }

.add-btn {
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 1rem;
}

.hero-line { font-size: 1.15rem; margin: 0.25rem 0 1rem; }

/* --- Dashboard & charts ------------------------------------------------------ */

.hero {
  font-size: 2.6rem;
  font-weight: 650;
  line-height: 1.1;
  margin: 0.75rem 0 0.25rem;
}

.chart {
  width: 100%;
  height: auto;
  display: block;
  margin: 0.5rem 0;
  font-family: inherit;
}

.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.75rem 0; }

.tabs a {
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.85rem;
}

.tabs a.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.plan-row { display: flex; align-items: center; gap: 0.75rem; margin: 0.4rem 0; }
.plan-row label { flex: 1; margin: 0; color: var(--fg); }
.plan-row input { width: 6rem; text-align: right; }

.linkbox code {
  display: block;
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  word-break: break-all;
  user-select: all;
}

/* --- Chart legend (two-series stacked bars) ---------------------------------- */

.legend {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 0.4rem 0 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  margin-right: 0.35rem;
  vertical-align: -1px;
}

/* Swatch colours live in classes because the strict CSP drops inline
   style attributes. */
.swatch-a { background: var(--accent); }
.swatch-b { background: var(--accent2); }
.swatch-c { background: var(--accent3); }
.swatch-d { background: var(--accent4); }
.swatch-e { background: var(--accent5); }
.swatch-muted { background: var(--muted); }

/* --- Scenario planning ------------------------------------------------------- */

/* Scenario comparison cards: one card per scenario, no sideways scroll. */
ul.cards {
  list-style: none;
  margin: 0.75rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
}

.card-head { display: flex; align-items: center; gap: 0.5rem; }
.card-name { flex: 1; min-width: 0; font-weight: 500; }
.card-base-value { white-space: nowrap; }
.card-baseline .card-head { color: var(--muted); }

.card-actions { display: flex; gap: 0.4rem; }
.card-actions form { display: inline; }

button.icon-btn { background: transparent; padding: 0; font-weight: 400; }

.card-cost {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0.55rem 0 0.1rem;
}

.card-cost-label { color: var(--muted); font-size: 0.85rem; }
.card-cost-value { font-weight: 650; font-size: 1.1rem; white-space: nowrap; }
.loss { color: var(--danger); }
.gain { color: var(--accent); }

.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 1rem;
  margin: 0.45rem 0 0;
  font-size: 0.9rem;
}

.card-stats div { display: flex; justify-content: space-between; gap: 0.5rem; }
.card-stats dt { color: var(--muted); }
.card-stats dd { margin: 0; white-space: nowrap; }

input.cell { width: 7rem; text-align: right; padding: 0.35rem 0.5rem; }

/* Collapsed-by-default reveals (allocation vs plan). */
details.reveal summary {
  cursor: pointer;
  list-style: none;
  color: var(--accent);
  font-weight: 500;
}

details.reveal summary::before { content: "▸ "; }
details.reveal[open] summary::before { content: "▾ "; }
details.reveal summary::-webkit-details-marker { display: none; }

/* The repayment slider: native range control in the app accent. */
input[type="range"] {
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}
h3.muted { font-size: 0.9rem; font-weight: 500; margin: 0.75rem 0 0.25rem; }

/* --- Growth defaults --------------------------------------------------------- */

.growth-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.35rem 0;
}

.growth-row .growth-name { flex: 1; min-width: 0; }
.growth-row input { width: 4.6rem; text-align: right; padding: 0.35rem 0.4rem; }
