/* Cloud Bill Spikes · theme.css · "Month-end ledger"
   Written by the designer (DESIGN.md). Loaded after styles.css, so these rules win.
   Signature: the accounting double rule under each unassigned balance.
   Contrast ratios (WCAG 2.x) are noted beside each text colour. */

:root {
  color-scheme: light dark;

  /* Palette, light */
  --bg: #f6f4ee;            /* warm paper */
  --surface: #ffffff;
  --raised: #efece3;
  --text: #1b1f1d;          /* 15.9:1 on surface, 14.4:1 on bg */
  --muted: #4f5752;         /* 7.5:1 on surface, 6.8:1 on bg, 6.1:1 on raised */
  --border: #d6d1c4;        /* edges only */
  --border-strong: #8f897b; /* 3.5:1 on surface: control outlines */
  --accent: #0e5a49;        /* 8.2:1 on surface, 7.4:1 on bg */
  --accent-hover: #0b4a3c;
  --accent-active: #083a2f;
  --accent-tint: #e3efe9;   /* accent text on it 7.1:1 */
  --on-accent: #ffffff;     /* 8.2:1 on accent */
  --success: #1e6b3a;       /* 6.5:1 on surface */
  --success-tint: #e4f2e8;  /* success on it 5.7:1 */
  --warning: #8a4b00;       /* 6.8:1 on surface */
  --warning-tint: #fbf0dc;  /* warning on it 6.0:1 */
  --rule: #c98a1c;          /* amber double rule, decoration only */
  --danger: #a32020;        /* 7.5:1 on surface */
  --danger-tint: #fbe9e7;   /* danger on it 6.5:1 */
  --focus-halo: #0e5a4933;

  /* Type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-label: 0.8125rem;  /* 13px caps labels */
  --fs-small: 0.9375rem;  /* 15px hints, tables */
  --fs-body: 1.0625rem;   /* 17px */
  --fs-lede: 1.3125rem;   /* 21px lede, h2 */
  --fs-head: 1.625rem;    /* 26px results heading */
  --fs-figure: clamp(2rem, 5vw, 2.75rem); /* balance figures */
  --fs-title: clamp(1.875rem, 5vw, 2.625rem);

  /* Space */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* Shape */
  --r1: 6px; --r2: 10px; --r3: 16px;
  --shadow-1: 0 1px 2px #1b1f1d14, 0 2px 8px #1b1f1d0d;
  --shadow-2: 0 4px 12px #1b1f1d1a, 0 12px 32px #1b1f1d14;

  --speed: 160ms;
  --ease: cubic-bezier(.2, .7, .2, 1);

  /* Template variables, aligned to the palette */
  --line: var(--border);
  --accent-text: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --surface: #1c211f;
    --raised: #252b28;
    --text: #ebe8df;          /* 14.6:1 on surface */
    --muted: #b3b9b2;         /* 8.2:1 on surface, 7.0:1 on raised */
    --border: #343c38;
    --border-strong: #6e7871; /* 3.5:1 on surface */
    --accent: #6fcfae;        /* 8.7:1 on surface */
    --accent-hover: #8adcbf;
    --accent-active: #a5e6cf;
    --accent-tint: #18332b;   /* accent on it 7.6:1 */
    --on-accent: #0b1f19;     /* 9.2:1 on accent */
    --success: #8fd6a0;       /* 9.0:1 on surface */
    --success-tint: #183020;
    --warning: #f0b45a;       /* 8.9:1 on surface */
    --warning-tint: #3a2c14;  /* warning on it 7.3:1 */
    --rule: #d99b3a;
    --danger: #ff9c8f;        /* 7.9:1 on surface */
    --danger-tint: #3b1a17;   /* danger on it 6.9:1 */
    --focus-halo: #6fcfae40;
    --shadow-1: 0 1px 2px #0006, 0 2px 8px #0004;
    --shadow-2: 0 4px 12px #0008, 0 12px 32px #0006;
  }
}

/* ---------- Page ---------- */
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs-body)/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
header, main, footer { max-width: 60rem; padding-left: var(--s5); padding-right: var(--s5); }
header { border-bottom: 1px solid var(--border); padding-top: var(--s3); padding-bottom: var(--s3); }
.brand {
  display: inline-flex; align-items: center; gap: var(--s3);
  font-weight: 750; letter-spacing: -0.01em; color: var(--text);
}
.brand::before {
  content: ""; width: 28px; height: 28px; flex: none;
  background: url("icons/favicon.svg") center / contain no-repeat;
}
header nav a { padding: 0 var(--s3); border-radius: var(--r1); color: var(--muted); text-decoration: none; font-weight: 600; }
header nav a:hover { color: var(--text); background: var(--raised); }

a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }

main { padding-top: var(--s6); }
h1 { font-size: var(--fs-title); font-weight: 800; letter-spacing: -0.02em; margin: 0 0 var(--s3); color: var(--text); }
.lede { font-size: var(--fs-lede); line-height: 1.45; color: var(--muted); max-width: 46ch; margin: 0 0 var(--s6); }
main > h2 { font-size: var(--fs-lede); margin: var(--s7) 0 var(--s3); letter-spacing: -0.01em; }
main > h3 { font-size: var(--fs-body); margin: var(--s5) 0 var(--s1); }
main > p, main > ol, main > ul { max-width: 68ch; }
main > ol li, main > ul li { margin-bottom: var(--s2); }
code, pre, kbd { font-family: var(--mono); font-size: 0.92em; }
:not(pre) > code { background: var(--raised); padding: 1px 5px; border-radius: var(--r1); }

/* ---------- Inputs panel ---------- */
.tool { margin: 0 0 var(--s7); }
.inputs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r3);
  box-shadow: var(--shadow-1);
  padding: var(--s5);
}
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); }
.field { display: flex; flex-direction: column; min-width: 0; }
.field-label {
  display: flex; align-items: center; gap: var(--s2);
  margin: 0 0 var(--s1);
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text);
}
.step {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); color: var(--on-accent);
  font-size: 0.75rem; letter-spacing: 0; font-variant-numeric: tabular-nums;
}
.hint { margin: 0 0 var(--s3); font-size: var(--fs-small); line-height: 1.5; color: var(--muted); }
.hint strong { color: var(--text); }

/* Drop zone */
.drop {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 11rem; margin: 0; padding: var(--s5) var(--s4);
  border: 2px dashed var(--border-strong);
  border-radius: var(--r2);
  background: var(--bg);
  text-align: center;
  transition: background-color var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.drop span { display: inline; font-weight: inherit; margin: 0; } /* undo template .drop span */
.drop:hover { border-color: var(--accent); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 0 6px var(--focus-halo); }
.drop.over { border-style: solid; border-color: var(--accent); background: var(--accent-tint); }
.drop.has-file { border-style: solid; border-color: var(--accent); background: var(--accent-tint); }
.drop.invalid, .field.invalid .drop { border-style: solid; border-color: var(--danger); background: var(--danger-tint); }
.drop.locked { opacity: .6; pointer-events: none; }
.drop-icon { width: 32px; height: 32px; color: var(--accent); }
.drop-text { display: flex; flex-direction: column; gap: 2px; }
.drop-title { font-size: var(--fs-body); font-weight: 650; color: var(--text); }
.drop .drop-sub { font-size: var(--fs-small); color: var(--muted); }
.file-input {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Chosen file */
.file-chip {
  display: flex; align-items: center; gap: var(--s2);
  max-width: 100%; padding: var(--s2) var(--s3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r1);
  font-family: var(--mono); font-size: var(--fs-small);
}
.chip-icon { width: 20px; height: 20px; flex: none; color: var(--success); }
.field.invalid .chip-icon { color: var(--danger); }
.drop .chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--text); }
.drop .chip-size { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }

.field-error {
  min-height: 1.5em; margin: var(--s2) 0 0;
  font-size: var(--fs-small); line-height: 1.5; font-weight: 600; color: var(--danger);
  overflow-wrap: anywhere;
}

/* Map format sample */
.sample { margin: var(--s2) 0 0; }
.sample figcaption {
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: var(--s1);
}
.sample pre {
  margin: 0; padding: var(--s3) var(--s4);
  background: var(--raised); border-left: 3px solid var(--accent); border-radius: 0 var(--r1) var(--r1) 0;
  font-size: 0.875rem; line-height: 1.6; color: var(--text); overflow-x: auto;
}

/* ---------- Buttons ---------- */
.actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2);
  margin: var(--s5) 0 0; padding-top: var(--s5); border-top: 1px solid var(--border);
}
.actions .push { margin-left: auto; }
.btn, .actions button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: var(--s2) var(--s5);
  border: 1px solid transparent; border-radius: var(--r2);
  font: inherit; font-size: var(--fs-body); font-weight: 650; line-height: 1.2;
  text-decoration: none; cursor: pointer;
  transition: background-color var(--speed) var(--ease), border-color var(--speed) var(--ease), color var(--speed) var(--ease), transform var(--speed) var(--ease);
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { min-height: 48px; background: var(--accent); color: var(--on-accent); border-color: var(--accent); box-shadow: var(--shadow-1); }
#run { min-width: 12.5rem; } /* "Allocate charges" and "Allocating…" share one width */
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-active); }
.btn.secondary { background: var(--surface); color: var(--accent); border-color: var(--border-strong); }
.btn.secondary:hover { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); }
.btn.quiet { background: transparent; color: var(--muted); border-color: transparent; }
.btn.quiet:hover { background: var(--raised); color: var(--text); }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: .5; box-shadow: none; transform: none; }
.btn.primary:disabled:hover { background: var(--accent); }
.pick { min-height: 44px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 0 6px var(--focus-halo); }
.btn:focus-visible { outline-offset: 3px; }

/* ---------- Status ---------- */
#status {
  min-height: 1.6em; margin: var(--s4) 0 var(--s3);
  font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums;
}
#status.ok { color: var(--success); }
#status.error { color: var(--danger); }

#output { min-height: 9rem; }

/* Empty state */
.empty-state {
  display: flex; gap: var(--s4); align-items: flex-start;
  padding: var(--s5); border: 1px dashed var(--border-strong); border-radius: var(--r3);
  color: var(--muted);
}
.empty-state svg { width: 40px; height: 40px; flex: none; color: var(--accent); }
.empty-state strong { display: block; color: var(--text); margin-bottom: var(--s1); }
.empty-state p { margin: 0; max-width: 60ch; font-size: var(--fs-small); }

/* Progress checklist */
.stages {
  list-style: none; margin: 0; padding: var(--s4) var(--s5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r3);
  font-variant-numeric: tabular-nums;
}
.stages li {
  position: relative; display: flex; align-items: center; gap: var(--s3);
  min-height: 36px; color: var(--muted); font-size: var(--fs-small);
}
.stages li::before {
  content: ""; width: 14px; height: 14px; flex: none; box-sizing: border-box;
  border: 2px solid var(--border-strong); border-radius: 50%;
}
.stages li.done { color: var(--text); }
.stages li.done::before { border-color: var(--success); background: var(--success); }
.stages li.done::after {
  content: ""; position: absolute; left: 4.5px; top: 50%;
  width: 3px; height: 6px; margin-top: -4.5px;
  border: solid var(--surface); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.stages li.active { color: var(--text); font-weight: 650; }
.stages li.active::before { border-color: var(--accent); border-top-color: transparent; animation: cbs-spin 0.9s linear infinite; }
.stages li.failed { color: var(--danger); font-weight: 650; }
.stages li.failed::before { border-color: var(--danger); background: var(--danger-tint); }
.stages li.failed::after { content: "×"; position: absolute; left: 3px; font-weight: 800; line-height: 1; color: var(--danger); }
@keyframes cbs-spin { to { transform: rotate(360deg); } }

/* ---------- Results ---------- */
.results {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r3);
  box-shadow: var(--shadow-2); padding: var(--s5) var(--s5) var(--s6);
  animation: cbs-rise 180ms var(--ease) both;
}
@keyframes cbs-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s3) var(--s5); }
.results-head h2 { margin: 0; font-size: var(--fs-head); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tally { display: flex; flex-wrap: wrap; gap: var(--s2); list-style: none; margin: 0; padding: 0; }
.tally li {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: var(--s1) var(--s3); border-radius: 999px;
  background: var(--raised); color: var(--muted);
  font-family: var(--mono); font-size: 0.875rem;
}
.tally b { color: var(--text); font-variant-numeric: tabular-nums; }
.tally .t-unassigned { background: var(--warning-tint); color: var(--warning); }
.tally .t-unassigned b { color: var(--warning); }

.balances { margin-top: var(--s5); padding-top: var(--s5); border-top: 1px solid var(--border); }
.balances h3 {
  margin: 0 0 var(--s4);
  font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--warning);
}
.balance-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: var(--s4);
  list-style: none; margin: 0; padding: 0;
}
.balance {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2);
  min-width: 0; padding: var(--s4) var(--s5) var(--s5);
  background: var(--warning-tint); border-radius: var(--r2);
}
.balance .cur {
  font-family: var(--mono); font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.12em;
  color: var(--warning);
}
.balance .amount {
  display: inline-block; max-width: 100%;
  font-family: var(--mono); font-size: var(--fs-figure); font-weight: 700; line-height: 1.1;
  letter-spacing: -0.02em; color: var(--text);
  font-variant-numeric: tabular-nums slashed-zero;
  overflow-wrap: anywhere;
  padding-bottom: var(--s1);
  border-bottom: 7px double var(--rule); /* the signature: accountant's double rule */
}
.balance .count { font-size: var(--fs-small); color: var(--warning); font-weight: 600; font-variant-numeric: tabular-nums; }
.balance.credit .amount { color: var(--text); }
.balance.zero { background: var(--raised); }
.balance.zero .cur, .balance.zero .count { color: var(--muted); }
.balance.zero .amount { color: var(--muted); border-bottom-color: var(--border-strong); }
.balance-note { margin: var(--s4) 0 0; max-width: 68ch; font-size: var(--fs-small); color: var(--muted); }

.download {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4);
  margin-top: var(--s5); padding-top: var(--s5); border-top: 1px solid var(--border);
}
.download .btn { overflow-wrap: anywhere; text-align: left; }
#download .download-name { font-family: var(--mono); }
.download-meta { margin: 0; font-size: var(--fs-small); color: var(--muted); font-variant-numeric: tabular-nums; }

/* Generic tables (reading section, if any) */
main table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); font-variant-numeric: tabular-nums; }
main th { text-align: left; font-size: var(--fs-label); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
main th, main td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }

/* ---------- Template blocks: styled, not resized ---------- */
.ad-slot { background: var(--raised); border: 1px solid var(--border); }
.ad-label { color: var(--muted); opacity: 1; }
.house-card { background: var(--surface); border: 1px solid var(--border); transition: border-color var(--speed) var(--ease); }
.house-card:hover { border-color: var(--accent); }
.house-card strong { color: var(--accent); }
.consent { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r3); box-shadow: var(--shadow-2); }
.consent button { border-color: var(--border-strong); border-radius: var(--r2); color: var(--text); background: var(--surface); transition: background-color var(--speed) var(--ease); }
.consent button:hover { background: var(--accent-tint); border-color: var(--accent); }
footer { opacity: 1; color: var(--muted); border-top: 1px solid var(--border); padding-top: var(--s5); padding-bottom: var(--s6); font-size: var(--fs-small); }
footer a { color: var(--accent); }

/* ---------- Phone ---------- */
@media (max-width: 46rem) {
  header, main, footer { padding-left: var(--s4); padding-right: var(--s4); }
  main { padding-top: var(--s5); }
  .lede { font-size: var(--fs-body); margin-bottom: var(--s5); }
  .inputs { padding: var(--s4); }
  .fields { grid-template-columns: 1fr; gap: var(--s2); }
  .drop { min-height: 9rem; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions #run { grid-column: 1 / -1; min-width: 0; }
  .actions .push { margin-left: 0; grid-column: 1 / -1; }
  .actions #cancel:not([hidden]) ~ .push { grid-column: auto; }
  .results { padding: var(--s4) var(--s4) var(--s5); }
  .balance-list { grid-template-columns: 1fr; }
  .download .btn { width: 100%; justify-content: center; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .btn:active { transform: none; }
}
