/* ── Tokens ──────────────────────────────────────────────────────────────
   Ledger green & brass. The complete light palette lives on bare :root;
   the dark blocks below redefine only these same tokens.               */
:root {
  --bg: #eff1ec;
  --surface: #fcfdfa;
  --surface-2: #f4f6f0;
  --ink: #131b16;
  --ink-2: #47564d;
  --muted: #77857c;
  --line: #dce1d8;
  --line-strong: #c4ccbf;
  --accent: #0b5c40;
  --accent-ink: #ffffff;
  --track: #d3e2d8;
  --brass: #8a6412;
  --crit: #a3392c;
  --shadow: 0 1px 2px rgba(19, 27, 22, .05), 0 8px 24px -16px rgba(19, 27, 22, .3);

  --sans: 'Familjen Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1411;
    --surface: #171e1a;
    --surface-2: #1d2621;
    --ink: #e7ede7;
    --ink-2: #aab8af;
    --muted: #7f8d85;
    --line: #28322c;
    --line-strong: #36423a;
    --accent: #4cc494;
    --accent-ink: #06251a;
    --track: #22362c;
    --brass: #d9a94a;
    --crit: #e8806f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1411;
  --surface: #171e1a;
  --surface-2: #1d2621;
  --ink: #e7ede7;
  --ink-2: #aab8af;
  --muted: #7f8d85;
  --line: #28322c;
  --line-strong: #36423a;
  --accent: #4cc494;
  --accent-ink: #06251a;
  --track: #22362c;
  --brass: #d9a94a;
  --crit: #e8806f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

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

html, body { height: 100%; }

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

[hidden] { display: none !important; }
img { max-width: 100%; }

h1, h2 { margin: 0; text-wrap: balance; letter-spacing: -0.015em; }

.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;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); }
.dot { color: var(--line-strong); padding: 0 .35em; }

:where(a, button, input, select, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:disabled { opacity: .55; cursor: default; }

.btn-primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
  background: var(--surface-2); color: var(--ink); border-color: var(--line-strong);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }

.btn-ghost {
  background: transparent; color: var(--ink-2);
  border-color: var(--line); padding: 7px 12px; font-size: 13px;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--line-strong); }

/* ── Forms ───────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }

.field label {
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-2);
}
.optional { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }

input[type="text"], input[type="password"], input[type="date"] {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
}
input[type="date"] { font-family: var(--mono); font-size: 14px; }
input::placeholder { color: var(--muted); }
input:focus-visible { border-color: var(--accent); }

.hint { margin: 0; font-size: 12.5px; color: var(--muted); }

.check { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--ink-2); margin-bottom: 18px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.form-error, .form-ok {
  margin: 0 0 12px;
  padding: 9px 12px;
  font-size: 13.5px;
  border-radius: var(--r-md);
  border: 1px solid;
}
.form-error { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 35%, transparent); background: color-mix(in srgb, var(--crit) 8%, transparent); }
.form-ok { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* Segmented unit switch */
.amount-row { display: flex; gap: 8px; align-items: stretch; }
.amount-row input { flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: 16px; }

.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 3px; gap: 2px; flex: 0 0 auto; }
.segmented label { display: flex; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid; place-items: center;
  min-width: 42px; padding: 0 9px;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  border-radius: var(--r-sm); cursor: pointer;
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Sign in ─────────────────────────────────────────────────────────── */
.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 40px 16px calc(40px + env(safe-area-inset-bottom, 0px));
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 30px 28px;
}

.gate-title { font-size: 25px; font-weight: 700; margin: 10px 0 6px; }
.gate-sub { margin: 0 0 24px; color: var(--ink-2); font-size: 14px; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 15px; height: 15px; border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: inset 0 0 0 2px var(--bg);
  flex: 0 0 auto;
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Layout shell ────────────────────────────────────────────────────── */
.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px calc(56px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Hero + meter ────────────────────────────────────────────────────── */
.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 26px 26px 22px;
  box-shadow: var(--shadow);
}

.hero-figure {
  margin: 10px 0 4px;
  font-size: clamp(42px, 8vw, 62px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.hero-sub { margin: 0 0 22px; color: var(--ink-2); font-size: 14.5px; }

.meter { margin-bottom: 14px; }

.meter-track {
  position: relative;
  height: 12px;
  background: var(--track);
  border-radius: 99px;
  overflow: visible;
}

.meter-fill {
  height: 100%;
  min-width: 0;
  background: var(--accent);
  border-radius: 99px 4px 4px 99px;
  transition: width .5s ease, background-color .3s ease;
}
.meter-fill.is-warn { background: var(--brass); }
.meter-fill.is-crit { background: var(--crit); }

.meter-pace {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  background: var(--ink-2);
  border-radius: 2px;
  transform: translateX(-1px);
}

.meter-pace-flag {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}

.hero-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13.5px;
  margin-top: 18px;
}

/* ── Pills ───────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px;
  border-radius: 99px;
  font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex: 0 0 auto;
}
.pill-quiet::before { display: none; }
.pill.is-good { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.pill.is-warn { color: var(--brass); border-color: color-mix(in srgb, var(--brass) 40%, transparent); background: color-mix(in srgb, var(--brass) 8%, transparent); }
.pill.is-crit { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); background: color-mix(in srgb, var(--crit) 8%, transparent); }

/* ── KPI tiles ───────────────────────────────────────────────────────── */
.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 18px;
}

.tile-label {
  margin: 0 0 8px;
  font-size: 11px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.tile-value { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.tile-note { margin: 5px 0 0; font-size: 12.5px; color: var(--muted); }

/* ── Cards & columns ─────────────────────────────────────────────────── */
.columns {
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.col-left { display: flex; flex-direction: column; gap: 14px; }

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

.card-title { font-size: 16px; font-weight: 600; }
.card > .card-title { margin-bottom: 18px; }
.card-head .card-title { margin-bottom: 0; }

.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}

.card-settings { padding: 0; }
.card-settings > summary {
  padding: 16px 22px;
  font-size: 13px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-2); cursor: pointer;
  list-style: none;
}
.card-settings > summary::-webkit-details-marker { display: none; }
.card-settings > summary::after { content: " +"; color: var(--muted); }
.card-settings[open] > summary::after { content: " −"; }
.card-settings[open] > summary { border-bottom: 1px solid var(--line); }
.card-settings form { padding: 20px 22px 22px; }

.empty {
  margin: 0; padding: 28px 20px;
  text-align: center; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line-strong); border-radius: var(--r-md);
}

/* ── Ledger table ────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }

.ledger th {
  text-align: left;
  font-size: 11px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
  padding: 0 12px 9px 0;
  border-bottom: 1px solid var(--line);
}

.ledger td {
  padding: 12px 12px 12px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: baseline;
}
.ledger tr:last-child td { border-bottom: 0; }

.ledger .num { text-align: right; padding-right: 0; }
.ledger td.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}
.ledger td.date { font-family: var(--mono); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.ledger td.detail { color: var(--ink-2); min-width: 120px; }

.ledger td.act { width: 1%; padding: 12px 0 12px 18px; text-align: right; }
.ledger td.detail.is-empty { color: var(--muted); }

.ledger tr.is-editing { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.ledger tr.is-editing td:first-child { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }

.tag-edited {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 6px;
  border-radius: 99px;
  border: 1px solid var(--line-strong);
  font-size: 10.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  vertical-align: 1px;
}

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.row-btn {
  font: inherit; font-size: 12.5px;
  background: none; border: 1px solid transparent;
  color: var(--muted); cursor: pointer;
  padding: 4px 9px; border-radius: var(--r-sm);
  white-space: nowrap;
}
.row-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.row-del:hover { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 35%, transparent); }
.row-del[data-armed="1"] { color: var(--crit); border-color: var(--crit); font-weight: 600; }

.edit-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 16px; padding: 9px 12px;
  font-size: 13px;
  border-radius: var(--r-md);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.link-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  background: none; border: 0; padding: 0;
  color: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .columns { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .shell { padding-inline: 16px; }
  .tiles { gap: 10px; }
  .tile { padding: 14px 15px; }
  .tile-value { font-size: 21px; }
  .segmented span { min-width: 36px; padding: 0 7px; font-size: 12px; }
  .topbar-inner { padding-inline: 16px; }
  .hero { padding: 20px 18px 18px; }
  .card { padding: 18px; }
  .card-settings form { padding: 18px; }
  .card-settings > summary { padding: 14px 18px; }
  .brand-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
