/* Payout Tracker: practical, calm, phone first. Tokens first, then layout, then components. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #0f172a;
  --muted: #5b6474;
  --border: #e1e5ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f1;
  --pos: #15803d;
  --neg: #b91c1c;
  --neg-soft: #fdecec;
  --warn-soft: #fff6e0;
  --pauls: #0f766e;
  --martins: #64748b;
  --revenue: #2563eb;
  --profit: #16a34a;
  --focus: #2563eb;
  --hero-bg: #0f766e;
  --hero-ink: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --nav-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.06), 0 1px 1px rgb(15 23 42 / 0.03);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1c2536;
    --text: #e6e9ef;
    --muted: #9aa5b8;
    --border: #273246;
    --accent: #2dd4bf;
    --accent-ink: #042f2e;
    --accent-soft: #0e2f2c;
    --pos: #4ade80;
    --neg: #f87171;
    --neg-soft: #3a1717;
    --warn-soft: #3a2e10;
    --pauls: #2dd4bf;
    --martins: #94a3b8;
    --revenue: #60a5fa;
    --profit: #4ade80;
    --focus: #93c5fd;
    --hero-bg: #12423d;
    --hero-ink: #ecfdf8;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  min-height: 100vh;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.45rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus, main:focus-visible { outline: none; }
::selection { background: var(--accent-soft); color: var(--text); }
input, textarea { caret-color: var(--accent); }
:root { accent-color: var(--accent); }
a { text-underline-offset: 0.18em; }
[hidden] { display: none !important; }
.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.small { font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
  outline: none;
}
body:not(.signed-in) main { padding-bottom: 32px; }
.page { display: grid; gap: var(--gap); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 4px; font-size: 0.9rem; text-decoration: none; }

.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .brand { display: none; }
.nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-h);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current] { color: var(--accent); }

@media (min-width: 900px) {
  body.signed-in { padding-left: 220px; }
  .nav {
    inset: 0 auto 0 0;
    width: 220px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 20px 12px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .nav .brand { display: block; font-weight: 700; padding: 4px 12px 18px; }
  .nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
  }
  .nav a[aria-current] { background: var(--accent-soft); }
  main { padding: 28px 32px 48px; }
}

/* ---------- surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.empty { color: var(--muted); padding: 16px 0; }
.empty-block { text-align: center; padding: 32px 16px; display: grid; gap: 12px; justify-items: center; }
.loading { color: var(--muted); padding: 32px 0; text-align: center; }
.note { background: var(--warn-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.9rem; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn-danger:hover { background: var(--neg-soft); }
.btn-block { width: 100%; }
.btn-small { min-height: 44px; padding: 0 12px; font-size: 0.85rem; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 12px 6px; margin: -12px -6px; min-height: 0; font: inherit; cursor: pointer; text-decoration: underline; }

.stack { display: grid; gap: 14px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 14px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

label { display: grid; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
label > span.hint { font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: 16px/1.3 var(--font);
}
textarea { min-height: 88px; resize: vertical; }
input[aria-invalid="true"] { border-color: var(--neg); background: var(--neg-soft); }
.form-error { color: var(--neg); font-weight: 600; }
.hint { color: var(--muted); font-size: 0.85rem; font-weight: 400; }

.segmented { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.segmented label, .segmented button {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 12px;
  margin: 0;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.segmented > :last-child { border-right: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.segmented label:has(input:checked), .segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }

/* ---------- auth ---------- */
.auth { min-height: 80vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; display: grid; gap: 18px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.3rem; }

/* ---------- lists ---------- */
.list { display: grid; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; gap: 2px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.list > :last-child { border-bottom: 0; }
a.row:hover, button.row:hover { background: var(--surface-2); }
button.row { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border); font: inherit; color: inherit; cursor: pointer; }
.row-main { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row-title { font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
.row-meta { color: var(--muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.row-amount { font-weight: 700; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.badge-custom { background: var(--warn-soft); color: var(--text); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.filters .search { grid-column: 1 / -1; }
@media (min-width: 720px) { .filters { grid-template-columns: 2fr 1fr 1fr; } .filters .search { grid-column: auto; } }
.summary-line { color: var(--muted); font-size: 0.9rem; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.summary-line strong { color: var(--text); }

/* ---------- KPIs ---------- */
.kpi-hero { display: grid; gap: 6px; background: var(--hero-bg); color: var(--hero-ink); border: 0; }
.kpi-hero .label { font-weight: 600; opacity: 0.9; }
.kpi-hero .value { font-size: 2.3rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-hero .sub { opacity: 0.9; font-size: 0.92rem; }
.kpi-hero .btn { justify-self: start; margin-top: 8px; background: var(--hero-ink); color: var(--hero-bg); border-color: transparent; }
.kpi-hero .btn:hover { background: var(--hero-ink); filter: brightness(0.94); }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
/* an odd last stat fills the row instead of leaving an empty cell */
@media (max-width: 899px) { .kpis > .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; } }
@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis > .kpi:last-child:nth-child(3n + 1) { grid-column: 1 / -1; }
  .kpis > .kpi:last-child:nth-child(3n + 2) { grid-column: span 2; }
}
.kpi { background: var(--surface); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.kpi .value { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }

/* ---------- toasts & dialogs ---------- */
.toasts { position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 900px) { .toasts { bottom: 24px; } }
.toast { background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: var(--radius-sm); box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); font-weight: 600; pointer-events: auto; }
.toast-error { background: var(--neg); color: #fff; }
dialog.confirm { border: 0; border-radius: var(--radius); padding: 0; width: min(92vw, 420px); background: var(--surface); color: var(--text); }
dialog.confirm::backdrop { background: rgb(15 23 42 / 0.45); }
dialog.confirm form { padding: 20px; display: grid; gap: 12px; }

/* ---------- charts (dataviz: thin marks, 4px rounded data ends, 2px gaps, recessive axes) ---------- */
:root { --chart-pauls: #0f766e; --chart-revenue: #2563eb; --chart-profit: #16a34a; }
@media (prefers-color-scheme: dark) { :root { --chart-pauls: #14b8a6; --chart-revenue: #3b82f6; --chart-profit: #16a34a; } }
.section-title { font-size: 1.05rem; }
.stack-sm { display: grid; gap: 8px; }
.kpi-accent .value { color: var(--accent); }
.chart { display: grid; gap: 8px; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); }
.chart-legend .key::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: currentColor; }
.chart-legend .key { color: var(--muted); }
.chart-legend .key.c-pauls::before { background: var(--chart-pauls); }
.chart-legend .key.c-revenue::before { background: var(--chart-revenue); }
.chart-legend .key.c-profit::before { background: var(--chart-profit); }
.chart-cols { display: flex; gap: 4px; align-items: stretch; }
.chart-col {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  gap: 6px;
  padding: 4px 0 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.chart-col:hover, .chart-col.is-selected { background: var(--surface-2); }
.chart-plot { display: flex; flex-direction: column; height: 160px; padding: 0 3px; }
.chart-pos, .chart-neg { display: flex; gap: 2px; justify-content: center; }
.chart-pos { align-items: flex-end; }
.chart-neg { align-items: flex-start; border-top: 1px solid var(--border); }
.bar { flex: 0 1 18px; min-width: 3px; }
@media (min-width: 900px) { .bar { flex-basis: 28px; } }
.chart-pos .bar { border-radius: 4px 4px 0 0; }
.chart-neg .bar { border-radius: 0 0 4px 4px; }
.bar.c-pauls { background: var(--chart-pauls); }
.bar.c-revenue { background: var(--chart-revenue); }
.bar.c-profit { background: var(--chart-profit); }
.chart-label { font-size: 0.72rem; color: var(--muted); text-align: center; overflow: hidden; text-overflow: clip; white-space: nowrap; }
.chart-caption { margin-top: 10px; color: var(--muted); font-size: 0.88rem; min-height: 1.3em; }
.chart-caption:not(:first-child) { font-variant-numeric: tabular-nums; }

.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.hbar a { color: inherit; text-decoration: none; display: grid; gap: 4px; }
.hbar:not(:has(a)) { display: grid; gap: 4px; }
.hbar a:hover .hbar-label { text-decoration: underline; }
.hbar-head { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.hbar-label { min-width: 0; overflow-wrap: anywhere; }
.hbar-sub { color: var(--muted); font-size: 0.82rem; }
.hbar-track { display: block; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 3px; background: var(--chart-pauls); }
.hbar.neg .hbar-fill { background: var(--neg); }
.list-flush { border: 0; border-radius: 0; margin: 0 -16px -16px; border-top: 1px solid var(--border); }

/* ---------- deal page ---------- */
.title-link { color: inherit; text-decoration: none; }
.title-link:hover { text-decoration: underline; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.totals-card { display: grid; gap: 14px; }
.totals-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.totals-grid > div, .split > div { display: grid; gap: 2px; min-width: 0; }
.totals-grid .label, .split .label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.totals-grid .money { font-weight: 700; overflow-wrap: anywhere; white-space: normal; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-top: 1px solid var(--border); padding-top: 14px; }
.split .value { font-size: 1.35rem; font-weight: 750; }
.split-pauls .value { color: var(--accent); }
.lines { display: grid; }
.line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.lines > .line:first-child, .lines > .line-group:first-child { border-top: 0; }
.line-main { display: grid; gap: 1px; min-width: 0; overflow-wrap: anywhere; }
.line-sub { color: var(--muted); font-size: 0.82rem; }
.line-group { border-top: 1px solid var(--border); padding: 9px 0 0; }
.line-group-head { display: flex; justify-content: space-between; gap: 12px; font-weight: 650; }
.line-group .line { padding-left: 14px; border-top: 0; padding-top: 6px; padding-bottom: 6px; }

/* ---------- deal form ---------- */
fieldset.field { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 0; }
fieldset.field legend { padding: 0; margin-bottom: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.card-inset { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.line-editors { display: grid; gap: 10px; margin: 10px 0 12px; }
.line-edit { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; display: grid; gap: 8px; background: var(--bg); }
.line-edit-grid { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.line-edit-grid .f-item { grid-column: 1 / -1; }
.line-edit-grid label { font-size: 0.78rem; gap: 4px; }
.line-edit-actions { display: flex; justify-content: space-between; gap: 8px; }
@media (min-width: 900px) {
  .line-edit-grid { grid-template-columns: 2fr 1.3fr 1.1fr 1.3fr 1.2fr; }
  .line-edit-grid .f-item { grid-column: auto; }
}
.sticky-totals {
  position: sticky;
  bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgb(15 23 42 / 0.12);
}
@media (min-width: 900px) { .sticky-totals { bottom: 12px; } }
.tot { display: grid; gap: 0; font-size: 0.78rem; color: var(--muted); }
.tot b { color: var(--text); font-size: 0.95rem; }
.tot-pauls b { color: var(--accent); }
.tot-warn { flex-basis: 100%; color: var(--neg); font-weight: 600; font-size: 0.85rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-error:not([hidden]) { background: var(--neg-soft); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- payouts / settings ---------- */
.spacer { flex: 1; }
.form-actions .btn-danger { margin-right: auto; }
.row-start { display: flex; gap: 8px; flex-wrap: wrap; }
.rules-grid { display: grid; gap: 14px; }
@media (min-width: 720px) { .rules-grid { grid-template-columns: repeat(3, 1fr); align-items: end; } }
.changes { list-style: none; margin: 0; padding: 0; display: grid; }
.changes li { display: grid; gap: 1px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 0.9rem; overflow-wrap: anywhere; }
.changes li:first-child { border-top: 0; }
.changes .muted { font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.btn[aria-busy="true"] { cursor: progress; }
