/* Debt Tracker. Visual language borrowed from the Drive Now leads app:
   pure white surface, bottle-green primary, red reserved for overdue. */

:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.976 0.004 160);
  --surface-2: oklch(0.956 0.006 160);
  --ink: oklch(0.205 0.015 165);
  --muted: oklch(0.455 0.02 165);
  --line: oklch(0.906 0.008 160);
  --line-strong: oklch(0.86 0.01 160);

  --primary: oklch(0.42 0.1 162);
  --primary-hover: oklch(0.36 0.1 162);
  --primary-soft: oklch(0.946 0.028 162);
  --primary-soft-ink: oklch(0.33 0.09 162);

  --amber-soft: oklch(0.945 0.05 80);
  --amber-ink: oklch(0.43 0.11 70);
  --danger: oklch(0.5 0.185 27);
  --danger-hover: oklch(0.44 0.18 27);
  --danger-soft: oklch(0.955 0.028 25);
  --danger-line: oklch(0.86 0.07 25);
  --danger-ink: oklch(0.42 0.16 27);
  --gray-soft: oklch(0.945 0.004 160);
  --gray-ink: oklch(0.42 0.015 165);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-pop: 0 12px 32px oklch(0.2 0.02 165 / 0.18);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; text-wrap: balance; overflow-wrap: anywhere; }
.notes, .notes-cell, .row-sub, .contact a, .dialog-context, .empty, .confirm-text, .banner { overflow-wrap: anywhere; }
.show-sm { display: none; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
p { margin: 0; }
.num, td.num, .stats dd { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-amber { color: var(--amber-ink); font-weight: 500; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 16px; height: 16px; flex-shrink: 0; }
[hidden] { display: none !important; }

.boot { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1.25rem;
  height: 56px; padding: 0 1.25rem;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 0.9375rem; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--primary); color: #fff; font-size: 0.875rem; font-weight: 700;
}
.topnav { display: flex; align-self: stretch; gap: 0.25rem; }
.topnav a, .tabbar a {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--muted); font-weight: 500;
}
.topnav a { padding: 0 0.75rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.topnav a .icon { display: none; }
.topnav a:hover, .tabbar a:hover { color: var(--ink); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--primary); }
.topbar-spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 0.25rem; }
.mock-switch {
  font: inherit; font-size: 0.75rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 0.3rem 0.4rem;
}

.tabbar { display: none; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 38px; padding: 0 0.9rem;
  font: inherit; font-weight: 600; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
.btn:hover { background: var(--surface); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-quiet-danger { color: var(--danger-ink); }
.btn-quiet-danger:hover { background: var(--danger-soft); border-color: var(--danger-line); }
.btn-sm { min-height: 32px; padding: 0 0.7rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn .icon { width: 18px; height: 18px; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; color: var(--primary); cursor: pointer; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

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

.page { max-width: 1080px; margin: 0 auto; padding: 1.75rem 2rem 5rem; }
.page-head { margin-bottom: 1.25rem; }
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.page-title { font-size: 1.5625rem; font-weight: 700; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.page-sub { color: var(--muted); margin-top: 0.25rem; max-width: 60ch; }
.back-link { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--muted); font-weight: 500; margin-bottom: 1rem; }
.back-link:hover { color: var(--ink); text-decoration: none; }
.meta { color: var(--muted); font-size: 0.8125rem; margin-top: 1.5rem; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin: 0 0 1.25rem; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats > div { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem 1rem; background: var(--bg); }
.stats dt { color: var(--muted); font-size: 0.8125rem; font-weight: 500; }
.stats dd { margin: 0.1rem 0 0; font-size: 1.375rem; font-weight: 700; }
.stats small { color: var(--muted); font-size: 0.8125rem; }
.stats .stat-danger { background: var(--danger-soft); border-color: var(--danger-line); }
.stats .stat-danger dt, .stats .stat-danger dd, .stats .stat-danger small { color: var(--danger-ink); }

.search {
  display: flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0 0.75rem; margin-bottom: 1.25rem; color: var(--muted); background: var(--bg);
}
.search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.search input { flex: 1; border: 0; outline: 0; font: inherit; padding: 0.6rem 0; background: none; color: var(--ink); }

.list-section + .list-section { margin-top: 1.75rem; }
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.6rem; display: flex; align-items: center; gap: 0.5rem; }
.section-danger { color: var(--danger-ink); }
.count {
  display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: 0.75rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.section-danger .count { background: var(--danger); color: #fff; }
.section-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.75rem 0 0.75rem; }
.section-bar .section-title { margin: 0; }

/* ------------------------------------------------------------------- rows */

.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 0.5rem; padding-right: 0.75rem; background: var(--bg); }
.row + .row { border-top: 1px solid var(--line); }
.row-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.85rem;
  padding: 0.8rem 0.5rem 0.8rem 1rem; color: inherit;
}
a.row-main:hover { text-decoration: none; }
.row:has(a.row-main:hover) { background: var(--surface); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.row-title { font-weight: 600; font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 0.8125rem; }
.row-amount { display: flex; flex-direction: column; align-items: flex-end; }
.row-amount .num { font-weight: 700; font-size: 0.9375rem; }
.row-amount small { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.row-muted { opacity: 0.6; }
.call-spacer { width: 36px; }

/* Overdue: unmistakable red row with a strong left edge. */
.rows .row-overdue { background: var(--danger-soft); box-shadow: inset 4px 0 0 var(--danger); }
.rows .row-overdue + .row-overdue { border-top-color: var(--danger-line); }
.row-overdue:has(a.row-main:hover) { background: oklch(0.935 0.04 25); }
.row-overdue .row-title, .row-overdue .row-amount .num { color: var(--danger-ink); }
.call-btn.call-danger { background: var(--danger); color: #fff; }
.call-btn.call-danger:hover { background: var(--danger-hover); color: #fff; }

.avatar {
  display: grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-soft-ink); font-size: 0.75rem; font-weight: 600;
}
.avatar-danger { background: var(--danger); color: #fff; }
.avatar-done { background: var(--primary); color: #fff; }
.avatar-lg { width: 52px; height: 52px; font-size: 1rem; }

/* ------------------------------------------------------------------ pills */

.pill {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.1rem 0.55rem;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap;
  background: var(--gray-soft); color: var(--gray-ink); font-variant-numeric: tabular-nums;
}
.pill-green { background: var(--primary-soft); color: var(--primary-soft-ink); }
.pill-amber { background: var(--amber-soft); color: var(--amber-ink); }
.pill-danger { background: var(--danger); color: #fff; }
.pill-done { background: var(--primary); color: #fff; }
.page-title .pill { font-size: 0.8125rem; }

/* ----------------------------------------------------------- customer page */

.customer-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.customer-id { flex: 1; min-width: 0; }
.contact { display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; margin-top: 0.3rem; }
.contact a, .contact span { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 500; }
.head-actions { display: flex; gap: 0.5rem; }

.banner {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 1rem;
  padding: 0.8rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; border: 1px solid;
}
.banner .btn { margin-left: auto; }
.banner-danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger-ink); }
.banner-done { background: var(--primary-soft); border-color: oklch(0.86 0.05 162); color: var(--primary-soft-ink); }

.debt { border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.debt-overdue { border-color: var(--danger-line); box-shadow: inset 4px 0 0 var(--danger); }
.debt-done { background: var(--surface); }
.debt-done .notes { background: var(--bg); }
.debt-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.debt-head h3 { font-size: 1.0625rem; font-weight: 600; }
.debt-head p { font-size: 0.8125rem; }
.debt-figures { display: flex; gap: 2rem; margin-top: 0.9rem; align-items: baseline; }
.debt-figures div { display: flex; flex-direction: column; }
.debt-figures strong { font-size: 1.375rem; }
.label { color: var(--muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); margin: 0.6rem 0 0.9rem; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.debt-overdue .progress span { background: var(--danger); }
.plan-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; }
.notes { margin-top: 0.6rem; padding: 0.6rem 0.8rem; background: var(--surface); border-radius: var(--radius-sm); white-space: pre-wrap; }
.debt-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

details.sub { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.75rem; }
details.sub summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; list-style: none; }
details.sub summary::-webkit-details-marker { display: none; }
details.sub summary::before { content: '›'; display: inline-block; width: 0.75rem; color: var(--muted); transition: transform 150ms ease-out; }
details.sub[open] summary::before { transform: rotate(90deg); }
.pad { padding: 0.5rem 0; }

.table-wrap { overflow-x: auto; margin-top: 0.6rem; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); }
td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.r { text-align: right; }
.notes-cell { color: var(--ink); min-width: 10rem; }
.tr-overdue td { background: var(--danger-soft); }

.empty { text-align: center; padding: 2.5rem 1rem; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); display: grid; gap: 1rem; justify-items: center; }

/* ----------------------------------------------------------------- dialogs */

.dialog {
  width: min(520px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  padding: 0; border: 0; border-radius: var(--radius); box-shadow: var(--shadow-pop); color: var(--ink);
}
.dialog::backdrop { background: oklch(0.2 0.02 165 / 0.4); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem 0.5rem; }
.dialog-head h2 { font-size: 1.125rem; }
.dialog-body { padding: 0.5rem 1.25rem; overflow-y: auto; display: grid; gap: 0.9rem; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); margin-top: 0.5rem; }
.dialog .form-error { margin: 0.5rem 1.25rem 0; }
.dialog .dup-link { margin: 0.5rem 1.25rem 0; font-weight: 600; }
.dialog-context { color: var(--muted); }
.confirm-text { line-height: 1.6; }
.credentials { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; margin: 0; padding: 0.8rem 1rem; background: var(--surface); border-radius: var(--radius-sm); }
.credentials dt { color: var(--muted); }
.credentials dd { margin: 0; font-weight: 600; word-break: break-all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875rem; }

.field { display: grid; gap: 0.3rem; }
.field > span { font-weight: 600; font-size: 0.8125rem; }
.field input, .field select, .field textarea, .money-input {
  width: 100%; font: inherit; color: var(--ink);
  padding: 0.55rem 0.7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg);
}
.field input, .field select, .money-input { min-height: 40px; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .money-input:focus-within {
  outline: 0; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary);
}
.money-input { display: flex; align-items: center; gap: 0.3rem; }
.money-input span { color: var(--muted); }
.money-input input { min-height: 0; border: 0; padding: 0; outline: 0; box-shadow: none !important; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 0.8125rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
fieldset.plan { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.75rem 0.9rem 0.9rem; margin: 0; display: grid; gap: 0.9rem; }
fieldset.plan legend { font-weight: 600; padding: 0 0.3rem; }
.plan-preview { color: var(--primary-soft-ink); font-weight: 500; min-height: 1.3em; }
.plan-preview:empty { display: none; }
.form-error { color: var(--danger-ink); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 0.55rem 0.75rem; font-weight: 500; }

/* ----------------------------------------------------------------- sign-in */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: var(--surface); }
.signin-card { width: min(380px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem 1.75rem; display: grid; gap: 1rem; }
.signin-card h1 { font-size: 1.375rem; }
.signin-card form { display: grid; gap: 0.9rem; }
.signin-card .link-btn { justify-self: start; }
.signin-foot { color: var(--muted); font-size: 0.8125rem; }

/* ------------------------------------------------------------------ toasts */

.toasts { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 60; display: grid; gap: 0.5rem; width: max-content; max-width: calc(100vw - 2rem); }
.toast { background: var(--ink); color: #fff; padding: 0.65rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); font-weight: 500; animation: toast-in 180ms ease-out; transition: opacity 250ms ease-out; }
.toast-error { background: var(--danger); }
.toast.leaving { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 720px) {
  .topbar { gap: 0.75rem; padding: 0 1rem; }
  .topnav { display: none; }
  .brand-name { display: none; }
  .add-btn span { display: none; }
  .add-btn { width: 40px; padding: 0; border-radius: 50%; }
  .add-btn .icon { width: 20px; height: 20px; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--bg); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { flex: 1; flex-direction: column; gap: 0.15rem; padding: 0.5rem 0; font-size: 0.75rem; }
  .tabbar a .icon { width: 20px; height: 20px; }
  .tabbar a[aria-current="page"] { color: var(--primary); font-weight: 600; }
  .page { padding: 1.25rem 1rem 6rem; }
  .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats dd { font-size: 1.2rem; }
  .row-main { padding-left: 0.85rem; gap: 0.7rem; }
  .row-sub .pill { white-space: normal; border-radius: 8px; }
  .customer-head { flex-wrap: wrap; }
  .customer-head .avatar-lg { display: none; }
  .head-actions { width: 100%; }
  .head-actions .btn:first-child { flex: 1; }
  .debt { padding: 1rem; }
  .debt-head { flex-direction: column; gap: 0.5rem; }
  .debt-actions .btn-primary { flex: 1; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-head-row { flex-direction: column; }
  .banner .btn { margin-left: 0; }
  .row-team { flex-wrap: wrap; padding-bottom: 0.6rem; }
  .row-team .row-main { flex-basis: 100%; }
  .row-team .row-title { white-space: normal; }
  .row-team .row-actions { width: 100%; padding-left: 0.85rem; justify-content: flex-start; }
  .notes-cell { min-width: 0; }
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  th, td { padding: 0.45rem 0.4rem; }
  .toasts { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
}
