:root {
  color-scheme: light dark;
  --accent: #1a7f5a;
  --danger: #b3261e;
  --line: color-mix(in srgb, currentColor 18%, transparent);
  --soft: color-mix(in srgb, currentColor 6%, transparent);
}

* { box-sizing: border-box; }

/* Author styles beat the UA stylesheet regardless of specificity, so any rule
   setting `display` on an element that also uses the `hidden` attribute
   silently defeats it. `.gate { display: flex }` did exactly that and stacked
   the sign-in screen on top of the app. This must stay above those rules. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Respects the dock window's title bar and the iPhone notch. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- sign-in gates -------------------------------------------------------- */
.gate {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .75rem; padding: 2rem; text-align: center;
}
.gate h1 { margin: .25rem 0 0; font-size: 1.5rem; }
.gate p { margin: 0; max-width: 26rem; }

/* --- shell ---------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; backdrop-filter: blur(8px); z-index: 2;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.tabs {
  display: flex; gap: .25rem; padding: .5rem 1rem 0; overflow-x: auto;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; font: inherit; padding: .5rem .8rem; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; opacity: .65;
}
.tabs button.active { border-bottom-color: var(--accent); opacity: 1; font-weight: 600; }

.panel { padding: 1rem; }
.panel-actions { display: flex; gap: .5rem; align-items: center; margin-bottom: .75rem; flex-wrap: wrap; }

/* --- controls ------------------------------------------------------------- */
button, select, input {
  font: inherit; padding: .4rem .7rem; border-radius: 8px;
  border: 1px solid var(--line); background: transparent; color: inherit;
}
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { border: 0; padding: .3rem .4rem; opacity: .75; text-decoration: underline; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; }
.field { display: grid; gap: .2rem; margin-bottom: .7rem; }
.field > span { font-size: .82rem; opacity: .7; }

/* --- tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; opacity: .6; }
tbody tr:hover { background: var(--soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- feedback ------------------------------------------------------------- */
.muted { opacity: .6; }
.error { color: var(--danger); }
.badge {
  font-size: .72rem; padding: .1rem .45rem; border-radius: 999px;
  border: 1px solid var(--danger); color: var(--danger);
}
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: Canvas; box-shadow: 0 6px 24px rgb(0 0 0 / .18); z-index: 5; max-width: 90vw;
}
.toast.error { border-color: var(--danger); color: var(--danger); }

/* --- modal ---------------------------------------------------------------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem;
  min-width: min(26rem, 92vw); color: inherit; background: Canvas;
}
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog h2 { margin: 0 0 .8rem; font-size: 1.1rem; }
dialog menu { display: flex; justify-content: flex-end; gap: .5rem; padding: 0; margin: 1rem 0 0; }
ul.plan { margin: 0 0 .5rem; padding-left: 1.1rem; }
ul.plan .warn { color: var(--danger); font-weight: 600; }
.warnings p { margin: .4rem 0; font-size: .88rem; opacity: .8; }

/* --- summary cards & row actions ------------------------------------------ */
.cards { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.card {
  display: grid; gap: .1rem; padding: .55rem .9rem; min-width: 8rem;
  border: 1px solid var(--line); border-radius: 10px;
}
.card-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; opacity: .6; }
.card strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

/* Two scenarios inside one card. The value column is right-aligned so the two
   figures share a decimal point and can be compared at a glance — the entire
   reason the pair sits in one card rather than two. */
.card-split { display: grid; grid-template-columns: auto 1fr; gap: .05rem .6rem; align-items: baseline; }
.card-split .card-scenario { font-size: .72rem; opacity: .6; }
.card-split strong { text-align: right; }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }
.row-actions button { white-space: nowrap; }

/* --- charts --------------------------------------------------------------- */
.chart { margin-bottom: 1rem; min-height: 0; }

/* DO NOT add a `fill` rule for .chart svg text.
   Google Charts sets the colour inline on each <text> element from
   legend.textStyle / pieSliceTextStyle / hAxis.textStyle. A stylesheet rule
   overrides those inline values, and `fill: inherit` in particular makes the
   text inherit the <svg>'s default fill — black — so every label went dark
   while the slice colours (set as element fills, not text) still worked.
   Theme the charts through the options object in chartTheme(), not from here. */
