/* ============================================================
   Chef Natasha Williams — Invoices
   Private-table restraint: paper, ink, herb, brass. No clipart.
   ============================================================ */

:root {
  color-scheme: light dark;

  --paper: #f5f1e8;
  --card: #fbf8f2;
  --ink: #26221c;
  --ink-soft: #4c463c;
  --muted: #6b6457;
  --herb: #3c5741;
  --herb-dp: #2c4331;
  --brass: #9a6b33;
  --brass-ink: #704a1e;
  --line: #e0d9ca;
  --line-strong: #c9bfab;
  --herb-soft: #e4ebe2;
  --brass-soft: #f1e6d4;
  --danger: #9b3b2e;
  --danger-soft: #f3e2dd;

  --masthead: #2c4331;
  --on-masthead: #f1ece1;
  --on-masthead-soft: #c6d3c3;
  --btn-primary: #2c4331;
  --on-btn-primary: #f1ece1;
  --paid: #3c5741;

  --serif: "Hoefler Text", "Iowan Old Style", "Palatino Linotype", Palatino, Baskerville, Georgia, serif;
  --sans: "Optima", "Gill Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius: 14px;
  --radius-sm: 10px;
  --control-h: 50px;
  --tabbar-h: 64px;
  --shadow: 0 1px 2px rgba(38, 34, 28, 0.05), 0 6px 20px rgba(38, 34, 28, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191510;
    --card: #221c15;
    --ink: #f1ece1;
    --ink-soft: #d3cabb;
    --muted: #9a9082;
    --herb: #8fb08f;
    --herb-dp: #a9c6a7;
    --brass: #cd9a56;
    --brass-ink: #d9ac6c;
    --line: #342c22;
    --line-strong: #4a4033;
    --herb-soft: #24302a;
    --brass-soft: #3a2d1c;
    --danger: #e08a7a;
    --danger-soft: #3b2420;

    --masthead: #130f0b;
    --on-masthead: #f1ece1;
    --on-masthead-soft: #a9c6a7;
    --btn-primary: #a9c6a7;
    --on-btn-primary: #16201a;
    --paid: #8fb08f;
    --shadow: none;
  }
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { margin: 0 0 10px; }
a { color: var(--herb); }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; }

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass-ink);
}

.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.serif { font-family: var(--serif); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- Masthead ---------- */

.masthead {
  background: var(--masthead);
  color: var(--on-masthead);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
@media (prefers-color-scheme: dark) {
  .masthead { border-bottom: 1px solid var(--line); }
}

.wordmark {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.wordmark-name { font-family: var(--serif); font-size: 19px; letter-spacing: 0.01em; }
.wordmark-sub {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--on-masthead-soft);
  margin-top: 3px;
}

.topnav { display: none; gap: 4px; }
.topnav a {
  color: var(--on-masthead-soft);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 15px;
}
.topnav a[aria-current="page"] { color: var(--on-masthead); background: rgba(255, 255, 255, 0.1); }

/* ---------- Layout ---------- */

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 96px);
}

.screen-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.screen-head .sub { color: var(--ink-soft); font-size: 15px; margin-top: 4px; }

.backlink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--herb);
  text-decoration: none;
  font-size: 15px;
  margin-bottom: 10px;
  min-height: 32px;
}

/* ---------- Tab bar (phone) ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 20;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 11.5px;
  letter-spacing: 0.04em;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--herb-dp); }

@media (min-width: 760px) {
  .tabbar { display: none; }
  .topnav { display: flex; }
  .app { padding-bottom: 80px; padding-top: 32px; }
  .masthead { padding-left: 28px; padding-right: 28px; }
}

/* ---------- Cards + lists ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

.section { margin-top: 22px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.section-head h2 { font-size: 18px; }
.section-head .eyebrow { margin: 0; }

.stat {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.stat-number {
  font-family: var(--serif);
  font-size: 40px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}
.stat-side { text-align: right; font-size: 14px; color: var(--ink-soft); }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  text-decoration: none;
  color: inherit;
  min-height: 64px;
}
.row:active { background: var(--herb-soft); }
.row-title { font-weight: 600; font-size: 16px; line-height: 1.25; }
.row-sub { color: var(--ink-soft); font-size: 14px; }
.row-amount {
  font-family: var(--serif);
  font-size: 18px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 36px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty h3 { font-weight: 500; margin-bottom: 6px; color: var(--ink); }

/* ---------- Chips ---------- */

.chip {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
  background: transparent;
  white-space: nowrap;
}
.chip-sent { color: var(--brass-ink); border-color: var(--brass); }
.chip-partly_paid { color: var(--brass-ink); background: var(--brass-soft); border-color: transparent; }
.chip-paid { color: var(--on-btn-primary); background: var(--btn-primary); border-color: transparent; }
.chip-overdue { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.chip-void { color: var(--muted); text-decoration: line-through; }
.chip-draft { color: var(--ink-soft); }

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius-sm);
  min-height: 46px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--btn-primary); color: var(--on-btn-primary); border-color: var(--btn-primary); }
.btn-quiet { background: transparent; }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-block { width: 100%; }
.btn-big { min-height: 54px; font-size: 17px; }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn-link { border: 0; background: none; color: var(--herb); padding: 0; min-height: 32px; }

.fab {
  position: fixed;
  left: 16px; right: 16px;
  width: auto;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 15;
  box-shadow: 0 8px 24px rgba(38, 34, 28, 0.22);
}
@media (min-width: 760px) {
  .fab { position: static; width: 100%; box-shadow: none; margin-top: 22px; }
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 auto; }

/* Sticky bar on the editor */
.actionbar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  z-index: 15;
}
.actionbar-inner {
  max-width: 680px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
}
.actionbar-balance { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-soft); }
.actionbar-balance strong { font-family: var(--serif); font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
/* The fixed action bar is ~104px tall (more with larger text), so screens that
   show it need room to scroll their last section clear of it. */
.app:has(.actionbar) { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 170px); }
@media (min-width: 760px) {
  .actionbar { bottom: 0; }
  .app:has(.actionbar) { padding-bottom: 170px; }
}

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

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > label, .label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.help { font-size: 13.5px; color: var(--ink-soft); line-height: 1.4; }

input[type="text"], input[type="date"], input[type="email"], input[type="tel"],
input[type="number"], input[type="search"], input:not([type]), select, textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 10px 13px;
  font-size: 17px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 84px; line-height: 1.4; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--herb); box-shadow: 0 0 0 3px var(--herb-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[inputmode="decimal"], input[inputmode="numeric"] { font-variant-numeric: tabular-nums; text-align: right; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}
input[type="date"] { min-width: 0; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }

.money { position: relative; }
.money::before {
  content: "$";
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.money input { padding-left: 28px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 6px 0;
}
.switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 50px; height: 30px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  flex: none;
  cursor: pointer;
  margin: 0;
}
.switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch input[type="checkbox"]:checked { background: var(--btn-primary); }
.switch input[type="checkbox"]:checked::after { transform: translateX(20px); }

/* ---------- Invoice editor ---------- */

.line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.line:first-child { border-top: 0; padding-top: 0; }
.line-main { display: grid; gap: 8px; min-width: 0; }
.line-nums { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.line-nums .times { color: var(--muted); font-size: 18px; text-align: center; }
.line-total {
  font-family: var(--serif);
  font-size: 18px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  align-self: start;
  padding-top: 12px;
  min-width: 84px;
}
.line-remove {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  justify-self: end;
}
.line-remove:active { background: var(--danger-soft); color: var(--danger); }
.line-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.add-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.add-row .btn { flex: 1 1 140px; }

.receipt {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
}
.receipt img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.receipt input[type="file"] { display: none; }

.totals { display: grid; gap: 8px; }
.totals-row { display: flex; justify-content: space-between; gap: 12px; font-size: 15.5px; color: var(--ink-soft); }
.totals-row span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); }
.totals-row.total { font-weight: 600; color: var(--ink); font-size: 17px; padding-top: 8px; border-top: 1px solid var(--line); }
.totals-row.credit span:last-child { color: var(--herb); }
.totals-balance {
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--btn-primary);
  color: var(--on-btn-primary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.totals-balance .eyebrow { color: inherit; opacity: 0.85; }
.totals-balance strong { font-family: var(--serif); font-size: 26px; font-variant-numeric: tabular-nums; }

.payments { display: grid; gap: 6px; }
.payment { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; align-items: center; }
.payment .num { font-variant-numeric: tabular-nums; }

.client-pick { display: grid; gap: 8px; }
.client-pick .row { min-height: 54px; padding: 10px 14px; cursor: pointer; }
.client-pick .row.selected { border-color: var(--herb); background: var(--herb-soft); }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--ink-soft);
  font-size: 14px;
}
.status-line > span + span::before { content: "·"; margin-right: 8px; color: var(--muted); }

.notice {
  background: var(--brass-soft);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14.5px;
  line-height: 1.4;
  margin-bottom: 12px;
}
.notice a { color: var(--brass-ink); font-weight: 600; }
.notice-danger { background: var(--danger-soft); }

/* ---------- Sheet (dialog) ---------- */

.sheet {
  border: 0;
  padding: 0;
  margin: auto;
  width: min(100%, 560px);
  max-height: 92dvh;
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
}
.sheet::backdrop { background: rgba(20, 16, 10, 0.45); }
.sheet-inner { padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px)); }
.sheet h2 { margin-bottom: 14px; }
.sheet .actions { margin-top: 16px; }
@media (max-width: 759px) {
  .sheet { margin: auto 0 0; width: 100%; max-width: none; }
}
@media (min-width: 760px) {
  .sheet { border-radius: var(--radius); }
}
.sheet .error { color: var(--danger); font-size: 14.5px; margin-top: 8px; }

/* ---------- PDF preview ---------- */

.preview[hidden] { display: none; }
.preview {
  position: fixed; inset: 0;
  z-index: 40;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.preview-title { font-family: var(--serif); font-size: 17px; }
.preview iframe { flex: 1; border: 0; width: 100%; background: #8a8580; }

/* ---------- Toast ---------- */

.toast[hidden] { display: none; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 150px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14.5px;
  z-index: 50;
  max-width: calc(100% - 32px);
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* ---------- Settings ---------- */

.settings-group { margin-top: 22px; }
.settings-group h2 { font-size: 18px; margin-bottom: 10px; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; padding: 6px 0; color: var(--ink-soft); }
.kv span:last-child { color: var(--ink); }

/* ---------- Client page ---------- */

.client-meta { display: grid; gap: 4px; color: var(--ink-soft); font-size: 15px; }
.client-meta a { color: var(--herb); text-decoration: none; }

/* ---------- Validation ---------- */

input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
