:root {
  --bg: #f8fafb;
  --surface: #ffffff;
  --ink: #0f1c23;
  --muted: #5c6b73;
  --line: #dfe7ec;
  --brand: #0e7490;
  --brand-ink: #ffffff;
  --brand-soft: #e0f2f7;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: var(--brand); }
img { vertical-align: middle; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--brand); color: var(--brand-ink);
  padding: .5rem 1rem; border-radius: 0 0 8px 0; z-index: 10;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .8rem 1.2rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand strong { display: block; line-height: 1.2; }
.brand .tagline { display: block; color: var(--muted); font-size: .8rem; }
.controls { display: flex; gap: .5rem; }

select {
  padding: .45rem .6rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font: inherit; color: var(--ink);
}

/* ---------- layout ---------- */
main { max-width: 900px; margin: 0 auto; padding: 1.2rem; display: grid; gap: 1.1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  box-shadow: 0 1px 2px rgba(15, 28, 35, .04);
}

.hero h1 { margin: 0 0 .4rem; font-size: clamp(1.35rem, 3vw, 1.9rem); letter-spacing: -.02em; }
.hero p { margin: 0 0 .8rem; color: var(--muted); max-width: 60ch; }
.card h2 { margin: 0 0 .8rem; font-size: 1.15rem; letter-spacing: -.01em; }
.subhead { margin: 1rem 0 .5rem; font-size: .92rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; }
.tab {
  padding: .5rem .95rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font: inherit; cursor: pointer; color: var(--muted);
}
.tab.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* ---------- forms ---------- */
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; align-items: end; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .25rem; font-weight: 600; }
.field input {
  width: 100%; padding: .55rem .65rem;
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: var(--surface); color: var(--ink);
}
.field input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.btn {
  padding: .55rem 1.05rem; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; font: inherit; font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- results & lists ---------- */
.result { margin-top: 1rem; border-top: 1px dashed var(--line); padding-top: .9rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin: 0; }
.stats > div { background: var(--bg); border-radius: 10px; padding: .55rem .75rem; }
.stats dt { font-size: .76rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: .15rem 0 0; font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }
.stats .highlight { background: var(--brand-soft); }
.stats .highlight dd { color: var(--brand); font-size: 1.12rem; }

.invoice-list, .health-list { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .5rem; }
.invoice-item {
  display: flex; justify-content: space-between; align-items: center; gap: .7rem; flex-wrap: wrap;
  background: var(--bg); border-radius: 10px; padding: .55rem .8rem;
}
.inv-main { flex: 1 1 220px; }
.saved-detail { display: block; color: var(--muted); font-size: .84rem; }
.health-list .saved-item { background: var(--bg); border-radius: 10px; padding: .55rem .8rem; }

.chip { padding: .18rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--line); white-space: nowrap; }
.chip.paid, .chip.great { background: var(--good-soft); color: var(--good); }
.chip.partial, .chip.good { background: var(--brand-soft); color: var(--brand); }
.chip.overdue, .chip.risky { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.sent { background: var(--line); color: var(--muted); }

.hint { color: var(--muted); font-size: .85rem; }
.error { color: var(--bad); font-weight: 600; }

/* ---------- header row / footer / toast ---------- */
.saved-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
.saved-head h2 { margin: 0; font-size: 1.05rem; }
.row-gap { display: flex; gap: .4rem; }

.footer {
  max-width: 900px; margin: 0 auto; padding: 1rem 1.2rem 2.2rem;
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  color: var(--muted); font-size: .85rem;
}
.toast {
  border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem 1.1rem; box-shadow: 0 6px 24px rgba(15, 28, 35, .15);
  margin: auto; top: auto;
}
.toast::backdrop { background: transparent; }

.mini.danger {
  border: none; background: none; color: var(--bad); cursor: pointer;
  font: inherit; font-size: .85rem; font-weight: 600; white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
