:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --ink: #17191c;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2b6cb0;
  --owed: #b45309;
  --credit: #0f766e;
  --danger: #b91c1c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- topbar -- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; color: var(--ink); }
.topbar nav { display: flex; gap: 18px; margin-right: auto; }
.topbar nav a { color: var(--muted); }
.topbar nav a.on { color: var(--ink); font-weight: 600; }

main { max-width: 1080px; margin: 0 auto; padding: 28px 24px 80px; }

h1 { font-size: 24px; margin: 0 0 20px; }
h2 { font-size: 16px; margin: 32px 0 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
h3 { font-size: 13px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 20px; display: flex; align-items: center; gap: 10px; }
.count { font-size: 14px; font-weight: 400; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; margin-bottom: 20px; }
.actions form { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.owed { color: var(--owed); font-weight: 600; }
.credit { color: var(--credit); font-weight: 600; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }

/* ----------------------------------------------------------------- cards -- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; align-items: start; }
@media (max-width: 720px) { .cols { grid-template-columns: 1fr; } }
.narrow { max-width: 520px; }

.card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 20px; margin: 0; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; }
.totals dd { font-variant-numeric: tabular-nums; }
.address { white-space: pre-line; color: var(--muted); }

/* ----------------------------------------------------------------- stats -- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin: 20px 0; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat strong { display: block; font-size: 24px; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- tables -- */
.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.grid th, .grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fbfbfc; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: #fafbfc; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .subject { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* keep an "Open + review" pair on one line so rows stay the same height */
.grid td:last-child { white-space: nowrap; }
.grid.compact td, .grid.compact th { padding: 6px 12px; }

/* ----------------------------------------------------------------- pills -- */
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef0f3;
  color: #4b5563;
  white-space: nowrap;
}
.pill.paid    { background: #e7f5ee; color: #0f766e; }
.pill.open    { background: #e8f0fb; color: #1d4ed8; }
.pill.overdue { background: #fdecec; color: #b91c1c; }
.pill.partial { background: #fdf1e0; color: #b45309; }
.pill.credit  { background: #e6f6f4; color: #0f766e; }
.pill.draft   { background: #eef0f3; color: #4b5563; }
.pill.void    { background: #eef0f3; color: #9ca3af; text-decoration: line-through; }
.pill.review  { background: #fdf1e0; color: #b45309; }
.pill.quiet   { background: #f1f2f4; color: #9ca3af; font-weight: 400; }

/* --------------------------------------------------------------- buttons -- */
.btn, button {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover, button:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover, button.primary:hover { background: #245a94; }
.btn.danger, button.danger { color: var(--danger); border-color: #f0d0d0; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.linkish { border: 0; background: none; color: var(--muted); padding: 0; font-size: 13px; text-decoration: underline; }
.linkish:hover { background: none; color: var(--danger); }

/* ----------------------------------------------------------------- forms -- */
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=email], input[type=date], input[type=search], select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #cddffa; border-color: var(--accent); }
textarea { resize: vertical; }
.stack .actions { margin-top: 4px; margin-bottom: 0; }
form.inline { display: inline-flex; gap: 6px; margin-left: 8px; }

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filters input, .filters select { margin-top: 0; width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 240px; flex: 1; }
.filters label.check { display: flex; align-items: center; gap: 6px; margin: 0; }
.filters label.check input { width: auto; min-width: 0; margin: 0; }  /* not a 150px-wide checkbox */

.lines input { margin-top: 0; background: #fcfcfd; }
.lines input:focus { background: #fff; }
.lines td { padding: 6px 8px; vertical-align: middle; }
.lines .qty { max-width: 90px; margin-left: auto; }
.lines .price { max-width: 130px; margin-left: auto; }
.lines input.num { text-align: right; }
.lines .amount { color: var(--muted); font-variant-numeric: tabular-nums; }
#add-line { margin-top: 10px; }

/* -------------------------------------------------------------- messages -- */
.flash, .notice {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin: 0 0 20px;
}
.flash  { background: #e7f5ee; border: 1px solid #bfe3d2; color: #14603f; }
.notice { background: #fdf6e8; border: 1px solid #f0dfb8; color: #7a5a15; }
.notice a { color: #7a5a15; text-decoration: underline; }
.empty { color: var(--muted); padding: 16px 0; }
.hidden { display: none; }

/* ------------------------------------------------------------------ tabs -- */
.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 16px;
  border-bottom: 1px solid var(--line);
}
.tabs a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  color: var(--muted);
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tab-count {
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef0f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.tabs a.on .tab-count { background: #e8f0fb; color: var(--accent); }

/* -------------------------------------------------------------- overview -- */
/* Two stat tiles beside a full-width chart, as Harvest lays it out. */
.overview {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 860px) { .overview { grid-template-columns: 1fr; } }
.tiles { display: grid; gap: 16px; align-content: start; }
.tiles .stat { margin: 0; }

/* ----------------------------------------------------------------- chart -- */
/* Series colours validated for colour-vision deficiency against the white card:
   #159c72 / #d9631f — CVD ΔE 11.0, normal-vision ΔE 25.3, both >= 3:1 contrast. */
.chart-card { --paid: #159c72; --open: #d9631f; padding: 14px 18px 6px; }
.chart-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.chart-title { margin: 0; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 600; }
.chart-nav { display: flex; gap: 4px; }
.stepper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 13px;
}
.stepper:hover { background: #f2f4f7; text-decoration: none; }
.stepper.off { color: #c9ced5; pointer-events: none; }

.legend { display: flex; gap: 14px; margin: 0 0 0 auto; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.paid { background: var(--paid); }
.swatch.open { background: var(--open); }

.chart { width: 100%; height: auto; display: block; }
.chart .bar-paid { fill: var(--paid); }
.chart .bar-open { fill: var(--open); }
.chart .bar-paid:hover, .chart .bar-open:hover { opacity: .82; }
.chart .gridline { stroke: #e9ebef; stroke-width: 1; }
.chart .axis { stroke: #c9ced5; stroke-width: 1; }
.chart .tick, .chart .month { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- ledger -- */
.ledger td { vertical-align: middle; }
.ledger .who { max-width: 420px; }
.ledger .client { display: block; font-weight: 600; color: var(--ink); }
.ledger .subject {
  display: block;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted);
}
.ledger .late { color: var(--danger); font-weight: 600; }
.ledger tfoot td { border-top: 1px solid var(--line); border-bottom: 0; font-weight: 700; background: #fbfbfc; }
.ledger .total-label { text-align: right; font-weight: 700; }
.ledger .total-label .muted { font-weight: 400; }
/* the ledger's own status column is first, so undo the generic last-column rule */
.ledger td:last-child { white-space: nowrap; }

/* ----------------------------------------------------------------- login -- */
.signout { margin: 0 0 0 4px; }
.login-page { background: var(--bg); }
.login { max-width: 340px; margin: 12vh auto; padding: 0 20px; }
.login h1 { font-size: 20px; margin-bottom: 18px; text-align: center; }
.login .stack { margin: 0; }
.login button { width: 100%; }
.notice.error { background: #fdecec; border-color: #f3cccc; color: #a32020; }
