:root {
  --pink: #ff32ab;
  --pink-dark: #d81b8c;
  --pink-soft: #ffe7ec;
  --blush: #f8f1f4;
  --ink: #141416;
  --ink-2: #4a4a50;
  --muted: #737376;
  --line: #ebe3e7;
  --card: #ffffff;
  --bg: #f8f1f4;
  --green: #2f7a53;
  --green-soft: #e4f2ea;
  --amber: #8a5a00;
  --amber-soft: #fff1cc;
  --red: #c62a29;
  --red-soft: #fde8e7;
  /* Report palette (user-provided): header green, accents, decline red, total-row blush. No blue. */
  --rep-head: #5ba881;
  --rep-head-ink: #141416;
  --rep-accent: #fed57d;
  --rep-olive: #9ca362;
  --rep-total: #fceded;
  --bar: #5ba881;
  --bar-hi: #3f8a64;
  --grey-soft: #f0eef0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 22, .05), 0 4px 16px rgba(20, 20, 22, .04);
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Josefin Sans", var(--font);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}
body.has-nav { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
a { color: var(--pink-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .01em; margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin-bottom: 12px; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.neg { color: var(--red) !important; font-weight: 600; }

/* ---------- Layout ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { height: 22px; width: auto; }
.brand span { font-family: var(--display); font-weight: 600; font-size: 1rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); padding-top: 3px; }
.topnav { display: none; gap: 4px; }
.topnav a { padding: 8px 14px; border-radius: 999px; color: var(--ink-2); font-weight: 500; }
.topnav a:hover { background: var(--blush); text-decoration: none; }
.topnav a.on { background: var(--pink-soft); color: var(--pink-dark); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: .72rem; font-weight: 600; }
.tabbar a:hover { text-decoration: none; }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--pink); }

@media (min-width: 820px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  body.has-nav { padding-bottom: 32px; }
  .wrap { padding: 24px; }
}

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.page-head .actions, .btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back { display: inline-block; margin-bottom: 8px; font-weight: 500; }
.sub { margin: 4px 0 0; color: var(--ink-2); }
.mono-title { font-family: var(--mono); font-size: 1.35rem; letter-spacing: 0; word-break: break-all; }
.mono { font-family: var(--mono); font-size: .85rem; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.card.empty { text-align: center; padding: 32px; color: var(--muted); }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: 600 .95rem var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: #d9cfd4; }
.btn-primary { background: var(--pink); border-color: var(--pink); color: #fff; }
.btn-primary:hover { background: var(--pink-dark); border-color: var(--pink-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--pink-dark); }
.btn-danger { color: var(--red); border-color: #f1c4cb; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.inline-form { display: inline; margin: 0; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .filter-grid label { font-size: .85rem; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font: 16px var(--font); color: var(--ink);
  background: #fff; border: 1px solid #dcd2d7; border-radius: 10px;
  -webkit-appearance: none; appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23737376' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255, 50, 171, .18); }
.hint { margin: 0; font-size: .8rem; color: var(--muted); }
.err { margin: 0; font-size: .82rem; color: var(--red); font-weight: 600; }
.has-error input, .has-error select { border-color: var(--red); }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 500; }
.flash-ok { background: var(--green-soft); color: #1f5c3d; }
.flash-error { background: var(--red-soft); color: var(--red); }

.savebar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 16px; background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-radius: 999px; box-shadow: 0 6px 24px rgba(20, 20, 22, .12); margin: 8px 0 18px;
}
@media (min-width: 820px) { .savebar { bottom: 16px; } }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--green-soft); color: var(--green); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-grey { background: var(--grey-soft); color: var(--ink-2); }
.pill { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: rgba(20, 20, 22, .08); font-size: .75rem; }

/* ---------- Users ---------- */
.user-list { list-style: none; margin: 0; padding: 0; }
.user-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.user-list li:last-child { border-bottom: 0; }
.row-end { display: flex; gap: 8px; align-items: center; }

/* ---------- Auth ---------- */
body.bare { background: linear-gradient(180deg, var(--pink-soft), var(--blush) 60%); min-height: 100vh; }
.auth { max-width: 400px; margin: 6vh auto 0; background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 28px 22px; }
.auth-logo { display: block; width: 170px; height: auto; margin: 0 auto 14px; }
.auth h1 { text-align: center; margin-bottom: 14px; font-size: 1.3rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.auth .muted { text-align: center; }

/* ---------- Search ---------- */
.search { margin-bottom: 12px; }
.search input[type=search] { min-height: 50px; font-size: 17px; border-radius: 14px; padding-left: 44px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23737376' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 14px center; }
.count { margin: 4px 2px 10px; color: var(--muted); font-weight: 600; font-size: .9rem; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.tabs a { padding: 8px 14px; border-radius: 999px; background: #fff; color: var(--ink-2); font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); }
.tabs a:hover { text-decoration: none; }
.tabs a.on { background: var(--ink); color: #fff; }
.tabs a.on .pill { background: rgba(255, 255, 255, .2); }

/* ---------- Report tables ---------- */
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap.flat { box-shadow: none; border-radius: 10px; border: 1px solid var(--line); }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--rep-head-ink); background: var(--rep-head); padding: 9px 10px; white-space: nowrap; font-weight: 700; }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover td { background: #fbf8f9; }
.table tfoot td, .table tr.total td { background: var(--rep-total); font-weight: 700; border-bottom: 0; }
.table tr.sub td { background: #f7f5f6; }
.table.matrix td:first-child, .table.matrix th:first-child { position: sticky; left: 0; z-index: 1; }
.table.matrix td:first-child { background: #fff; min-width: 140px; }
.table.matrix tfoot td:first-child, .table.matrix tr.total td:first-child { background: var(--rep-total); }
.table.matrix tr.sub td:first-child { background: #f7f5f6; }
.table.matrix th:first-child { background: var(--rep-head); }
.table td.partial { background: #fff8e1; }
.table td.changed { color: var(--pink-dark); }
.table.compare { margin: 10px 0; font-size: .85rem; }
.table.compare th { background: #eef4f0; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red) !important; font-weight: 600; }
.note-cell { min-width: 220px; max-width: 360px; font-size: .82rem; color: var(--ink-2); }
.inline-edit summary { cursor: pointer; list-style: none; }
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit[open] summary { margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .85rem; font-weight: 600; }
.check input { width: 18px; min-height: 18px; height: 18px; -webkit-appearance: checkbox; appearance: auto; }
.note-dot { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--rep-accent); color: var(--ink); font-size: .65rem; font-weight: 700; cursor: help; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; border-top: 4px solid var(--rep-head); }
.kpi span { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi b { font-family: var(--display); font-size: 1.6rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi small { font-size: .8rem; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 960px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.chart { width: 100%; height: auto; display: block; margin: 4px 0 2px; }
.chart .bar { fill: var(--bar); }
.chart .bar-hi { fill: var(--bar-hi); }
.chart .bar:hover { fill: var(--bar-hi); }
.chart .axis { stroke: #d9d2d6; stroke-width: 1; }
.chart text { font: 600 12px var(--font); fill: var(--ink-2); text-anchor: middle; }
.chart .val { fill: var(--ink); font-size: 13px; }
.chart-cap { margin: 0 0 12px; font-size: .78rem; color: var(--muted); }
.flash-warn { background: var(--amber-soft); color: #5c3d00; }
.flash-warn a { color: inherit; text-decoration: underline; }
.page-head.inner { margin: 0 0 10px; align-items: center; }
.page-head.inner h2 { margin: 0; }
.inline-select { display: flex; align-items: center; gap: 8px; }
.inline-select select, .inline-select input { min-height: 38px; padding: 6px 10px; width: auto; font-size: 15px; }
.inline-select select { padding-right: 34px; }
h3.mt { margin-top: 18px; }

/* ---------- Checklist ---------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.checklist li:last-child { border-bottom: 0; }

/* ---------- Upload ---------- */
.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 130px; padding: 18px; border: 2px dashed #e2bfd2; border-radius: 14px; background: var(--blush); text-align: center; cursor: pointer; }
.dropzone.over { border-color: var(--pink); background: var(--pink-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.dropzone span { font-size: .95rem; word-break: break-word; }
.dropzone small { color: var(--muted); }
.section-title { margin: 20px 2px 10px; font-size: 1.2rem; }
.staged { border-left: 4px solid var(--rep-head); }
.staged-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px 16px; margin: 0 0 8px; }
.summary div { border-bottom: 1px dashed var(--line); padding: 4px 0; }
.summary dt { font-size: .75rem; color: var(--muted); font-weight: 600; }
.summary dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.map-table input { min-height: 36px; padding: 6px 10px; font-size: 15px; min-width: 160px; }
.map-table input.empty::placeholder { color: var(--red); }
.btn-row.spread { justify-content: space-between; margin-top: 12px; }
.help summary { cursor: pointer; }
.help ul { margin: 10px 0 0; padding-left: 18px; }
.help li { margin-bottom: 4px; }

/* ---------- Statements ---------- */
.pdf-pick { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 6px 0 14px; position: relative; }
.pdf-pick input { position: absolute; width: 1px; height: 1px; opacity: 0; min-height: 0; }
.pdf-pick .btn { pointer-events: none; }
.pdf-pick { cursor: pointer; }
.pdf-pick input:focus-visible + .btn { outline: 3px solid rgba(255, 50, 171, .35); }
.stmt-grid { display: grid; grid-template-columns: 1fr; gap: 6px; max-width: 620px; }
.stmt-group { margin: 12px 0 2px; display: flex; justify-content: space-between; color: var(--ink-2); }
.stmt-group span { font-variant-numeric: tabular-nums; color: var(--ink); text-transform: none; letter-spacing: 0; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field.row label { font-weight: 500; }
.field.row input { max-width: 180px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Brand map ---------- */
.kv-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 340px; overflow-y: auto; }
.kv-list li { display: grid; grid-template-columns: 1fr 1fr auto; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.inline-add { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-add input { flex: 1 1 140px; min-height: 38px; padding: 6px 10px; font-size: 15px; }
