/* ============================================================
   Site Ledger — design tokens
   ============================================================ */
:root {
  --accent: #006a5d;
  --accent-strong: #00473e;
  --accent-soft: #c9e5ff;
  --accent-tint: #f3faf7;

  --status-paid-bg: #3ec08a;
  --status-paid-fg: #003823;
  --status-partial-bg: #ebd94f;
  --status-partial-fg: #373000;
  --status-pending-bg: #ff8b5c;
  --status-pending-fg: #5a1c00;

  --bg: #f6f8f9;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --border: #dde4e2;
  --text: #161c1a;
  --text-muted: #5b6b66;
  --text-on-accent: #ffffff;
  --danger: #d1453d;
  --danger-tint: #fdeceb;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-1: 0 1px 2px rgba(15, 30, 26, 0.06), 0 1px 1px rgba(15, 30, 26, 0.04);
  --shadow-2: 0 8px 24px rgba(15, 30, 26, 0.12);
  --nav-h: 64px;
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --accent: #3ec08a;
  --accent-strong: #63d6a5;
  --accent-soft: #123b34;
  --accent-tint: #10231f;
  --bg: #0e1613;
  --surface: #16201d;
  --surface-2: #1c2925;
  --border: #2a3733;
  --text: #eef4f1;
  --text-muted: #9db3ac;
  --text-on-accent: #04231e;
  --danger: #ff6b62;
  --danger-tint: #2c1513;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #3ec08a;
    --accent-strong: #63d6a5;
    --accent-soft: #123b34;
    --accent-tint: #10231f;
    --bg: #0e1613;
    --surface: #16201d;
    --surface-2: #1c2925;
    --border: #2a3733;
    --text: #eef4f1;
    --text-muted: #9db3ac;
    --text-on-accent: #04231e;
    --danger: #ff6b62;
    --danger-tint: #2c1513;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--text-on-accent);
  padding: 10px 16px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--accent);
  color: var(--text-on-accent);
}
.topbar__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.topbar__logo { border-radius: 6px; }
.topbar__actions { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: transparent; color: inherit; display: grid; place-items: center;
  cursor: pointer; transition: background 0.15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.16); }
.icon-btn:focus-visible { outline: 2px solid var(--text-on-accent); outline-offset: 2px; }

/* ---------- Navigation ---------- */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--text-muted);
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.01em;
  transition: color 0.15s ease;
}
.nav__item.is-active { color: var(--accent); }
.nav__item svg { transition: transform 0.15s ease; }
.nav__item.is-active svg { transform: translateY(-1px); }

/* ---------- Layout / view ---------- */
.view {
  min-height: calc(100vh - var(--topbar-h) - var(--nav-h));
  padding: 16px 16px calc(var(--nav-h) + 24px);
  max-width: 1080px;
  margin: 0 auto;
}
.view:focus { outline: none; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.3rem; }
.page-header__sub { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }

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

.stat-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 14px;
}
.stat-card {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}
.stat-card--accent { background: var(--accent-tint); border-color: var(--accent-soft); }
.stat-card__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; }
.stat-card__value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; }
.stat-card__value.currency { font-variant-numeric: tabular-nums; }
.stat-card--danger .stat-card__value { color: var(--danger); }

/* ---------- Section headings ---------- */
.section-title {
  font-size: 0.95rem; font-weight: 700; margin: 20px 0 10px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge--paid { background: var(--status-paid-bg); color: var(--status-paid-fg); }
.badge--partial { background: var(--status-partial-bg); color: var(--status-partial-fg); }
.badge--pending { background: var(--status-pending-bg); color: var(--status-pending-fg); }

/* ---------- Toolbar (search / filter / sort) ---------- */
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center;
}
.search-input {
  flex: 1 1 200px; position: relative;
}
.search-input input { width: 100%; padding-left: 36px; }
.search-input svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
select, input[type="text"], input[type="number"], input[type="date"], input[type="search"], textarea {
  font-family: inherit; font-size: 0.9rem;
  padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); }
.field__error { font-size: 0.75rem; color: var(--danger); min-height: 1em; }
.field textarea { resize: vertical; min-height: 60px; }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 0.78rem; font-weight: 600; cursor: pointer;
  color: var(--text-muted);
}
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 0.88rem; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-outline { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-sm { padding: 6px 11px; font-size: 0.78rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Lists / rows ---------- */
.row-list { display: flex; flex-direction: column; gap: 8px; }
.entity-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px; cursor: pointer; text-align: left; width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.entity-row:hover { border-color: var(--accent); box-shadow: var(--shadow-1); }
.entity-row__avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--accent-soft); color: var(--accent-strong);
  display: grid; place-items: center; font-weight: 800; font-size: 0.95rem;
}
.entity-row__body { flex: 1; min-width: 0; }
.entity-row__title { font-weight: 700; font-size: 0.94rem; display: flex; align-items: center; gap: 8px; }
.entity-row__sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-row__meta { text-align: right; flex: none; }
.entity-row__amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.entity-row__balance { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }

.empty-state {
  text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.empty-state svg { margin-bottom: 10px; opacity: 0.5; }
.empty-state h3 { color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 0.86rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; font-size: 0.85rem; }
.pagination__pages { color: var(--text-muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 18, 15, 0.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade-in 0.15s ease;
  backdrop-filter: blur(1px);
}
@media (min-width: 640px) { .modal-overlay { align-items: center; } }
.modal {
  background: var(--surface); width: 100%; max-width: 480px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 92vh; overflow-y: auto;
  animation: slide-up 0.2s ease;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .modal { border-radius: var(--radius-lg); animation: pop-in 0.16s ease; }
}
.modal__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal__header h2 { font-size: 1.1rem; }
.modal__footer { display: flex; gap: 10px; margin-top: 6px; }
.modal__footer .btn { flex: 1; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 60; pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 0.84rem; font-weight: 600;
  box-shadow: var(--shadow-2);
  animation: toast-in 0.2s ease;
}
.toast--error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--text-on-accent);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: transform 0.12s ease;
}
.fab:active { transform: scale(0.93); }
.fab[hidden] { display: none; }

/* ---------- Table (contractor / reports) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 480px; }
th, td { padding: 10px 14px; text-align: left; white-space: nowrap; }
thead th { background: var(--accent); color: var(--text-on-accent); font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Charts ---------- */
.chart-card canvas { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; font-size: 0.78rem; }
.legend__item { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- Utility ---------- */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Skeleton loading ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: skeleton 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Desktop layout ---------- */
@media (min-width: 860px) {
  .nav {
    position: sticky; top: var(--topbar-h); left: 0; height: calc(100vh - var(--topbar-h));
    width: 220px; flex-direction: column; border-top: none; border-right: 1px solid var(--border);
    padding: 18px 10px; gap: 4px; align-items: stretch;
  }
  .nav__item { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.86rem; }
  .nav__item.is-active { background: var(--accent-tint); }
  .app-shell { display: flex; }
  .view { flex: 1; min-width: 0; padding: 24px 32px calc(var(--nav-h)); max-width: 960px; }
  .fab { bottom: 24px; }
}

/* ---------- Print ---------- */
.print-only { display: none; }
@media print {
  .topbar, .nav, .fab, .toast-root, #modal-root { display: none !important; }
  #app-view { display: none !important; }
  .print-only { display: block !important; }
  body { background: #fff; color: #000; }
  .print-only h1 { font-size: 1.3rem; margin-bottom: 4px; }
  .print-only table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.82rem; }
  .print-only th, .print-only td { border: 1px solid #999; padding: 6px 8px; text-align: left; }
  .print-only th { background: #eee; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
