:root {
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2b4fd6;
  --brand-soft: #eef2ff;
  --green: #15803d;
  --bg: #f3f4f8;
  --err: #b42318;
  --ok: #067647;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.05rem; margin-right: auto; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
}
.tabs {
  display: flex; gap: 8px; overflow-x: auto;
  max-width: 640px; margin: 0 auto; padding: 12px 16px 0;
}
.tabs a {
  white-space: nowrap; padding: 8px 14px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.9rem;
}
main { max-width: 640px; margin: 0 auto; padding: 16px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.narrow { max-width: 400px; margin: 32px auto; }
h1 { font-size: 1.2rem; margin: 0 0 12px; }
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 12px;
  font-size: 16px; font-family: inherit; color: var(--ink);
  border: 1px solid #d1d5db; border-radius: 10px; background: #fff;
}
button, .button {
  display: inline-block; padding: 12px 18px; border: 0; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.primary { background: var(--brand); color: #fff; width: 100%; }
.button.primary { width: auto; }
button.secondary { display: block; width: 100%; margin-top: 10px; background: var(--brand-soft); color: var(--brand); }
.excel { background: var(--green); color: #fff; }
button.danger { display: block; width: 100%; margin-top: 10px; background: var(--err); color: #fff; }
.button.small { padding: 8px 12px; font-size: 14px; background: var(--brand-soft); color: var(--brand); margin-top: 8px; }
.name { color: var(--brand); font-weight: 700; text-decoration: none; }
.warn { color: var(--err); font-weight: 600; }
.link { background: none; color: var(--brand); padding: 0; font-weight: 600; }
.inline { display: inline; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.center { text-align: center; }
.flash { padding: 12px; border-radius: 10px; margin-bottom: 12px; background: #ecfdf3; color: var(--ok); }
.flash.error { background: #fef3f2; color: var(--err); }
.filter { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.filter label:first-child, .filter button { grid-column: 1 / -1; }
.filter label { margin-bottom: 0; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi strong { font-size: 1.15rem; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.line { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item { margin-bottom: 10px; }
.meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.grid th, table.grid td {
  padding: 10px 8px; border-bottom: 1px solid var(--line);
  text-align: right; white-space: nowrap;
}
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid th {
  color: var(--muted); font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; background: #f9fafb;
}
table.grid a { color: var(--brand); font-weight: 600; text-decoration: none; }
.bar-row { margin-bottom: 12px; }
.track { height: 8px; background: var(--brand-soft); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.fill { height: 100%; background: var(--brand); border-radius: 999px; }
.badge { font-size: 0.8rem; padding: 3px 8px; border-radius: 999px; background: #eef2f6; }
.badge.submitted { background: #fff6e5; color: #8a5300; }
.badge.approved { background: #ecfdf3; color: var(--ok); }
.badge.rejected { background: #fef3f2; color: var(--err); }
.badge.paid { background: var(--brand-soft); color: #1e3a8a; }
.badge.off { background: #f2f4f7; color: var(--muted); }
[hidden] { display: none !important; }
.hint { color: var(--muted); font-size: 0.85rem; margin: -6px 0 14px; }
/* The total line after a filter grid, and the description after a heading-and-button row:
   both need real space, or the text sits under the last control. */
.filter + .hint, .row + .hint { margin-top: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink); }
.check input { display: inline-block; width: auto; margin: 0; }
details { margin-top: 10px; }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; }
details form { margin-top: 12px; }
/* Account settings: forms stacked one under another get room between them. */
.owner-account form + form { margin-top: 18px; }

/* ---- management pages: sidebar on wide screens ---- */
.sidebar { display: none; }
@media (min-width: 900px) {
  .app.with-side { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
  .app.with-side .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    background: #1c1a3d; color: #c5c8e6; padding: 22px 14px;
  }
  .app.with-side .topbar, .app.with-side .tabs { display: none; }
  .app.with-side main { max-width: 820px; margin: 0; padding: 28px 32px 48px; }
  .app.with-side main.wide { max-width: none; }
  .app.with-side main.wide .two-col { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
}
@media (min-width: 1300px) {
  .app.with-side main.wide .kpis.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.side-brand .avatar { background: #6d5dfc; }
.side-brand strong { display: block; color: #fff; font-size: 1.05rem; }
.side-brand small { color: #9ea3cc; font-size: 0.8rem; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px;
  color: #c5c8e6; text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.side-nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.side-nav a.active { background: rgba(255, 255, 255, 0.13); color: #fff; }
.side-nav .divider { height: 1px; background: rgba(255, 255, 255, 0.1); margin: 10px 4px; }
.side-nav .badge { background: #6d5dfc; color: #fff; }
.side-nav svg, .kpi-icon svg {
  width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.side-foot { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.side-foot strong { display: block; color: #fff; }
.side-foot small { color: #9ea3cc; font-size: 0.8rem; }
.side-foot .link { display: block; color: #a9b8ff; margin-top: 8px; }

/* ---- mobile: the sidebar becomes a slide-in drawer behind a hamburger button ---- */
.nav-toggle { display: none; }
.nav-backdrop { display: none; }
@media (max-width: 899px) {
  .app.with-side .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; margin-right: 4px; padding: 0;
    background: var(--brand); color: #fff; border: 0; border-radius: 10px; cursor: pointer;
  }
  .nav-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  /* The drawer: off-canvas to the left, slides over the page when open. */
  .app.with-side .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; top: 0; bottom: 0; left: 0; width: 272px; z-index: 40;
    overflow-y: auto; padding: 22px 14px;
    background: #1c1a3d; color: #c5c8e6;
    transform: translateX(-102%); transition: transform 0.2s ease;
  }
  .app.with-side .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(12, 10, 40, 0.45); opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .app.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  /* With the drawer, the scrolled chip row under the topbar is gone. */
  .app.with-side .tabs { display: none; }
}
@media (min-width: 900px) {
  /* The drawer pieces have no place on a wide screen. */
  .app .nav-toggle, .app .nav-backdrop { display: none !important; }
}

/* ---- owner viewing as someone else: read-only ---- */
.viewing {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: #fff7ed; color: #9a3412; border-bottom: 1px solid #fed7aa;
  font-size: 0.9rem;
}
.viewing .link { color: #9a3412; text-decoration: underline; }

/* ---- dashboard ---- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.period { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.period select, .period input { width: auto; margin: 0; padding: 10px 12px; background: #fff; }
.period-label { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.kpi-icon {
  width: 38px; height: 38px; border-radius: 10px; margin-bottom: 6px;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.kpi .label { color: var(--muted); font-size: 0.82rem; font-weight: 600; line-height: 1.3; }
.kpi .value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.kpi .sub { color: var(--muted); font-size: 0.75rem; }
a.kpi { color: inherit; text-decoration: none; transition: border-color 0.15s, box-shadow 0.15s; }
a.kpi:hover { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.kpi .more { margin-top: auto; padding-top: 6px; color: var(--brand); font-size: 0.8rem; font-weight: 600; }
.kpis.six, .kpis.four { grid-template-columns: 1fr 1fr; }
@media (min-width: 600px) {
  .kpis.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.neg, .value.neg, td.neg { color: var(--err); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { font-size: 1.05rem; margin: 0 0 2px; }
.card-head p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.two-col { display: grid; gap: 16px; }
table.grid tr.total td { font-weight: 700; background: #f9fafb; }
table.grid td.left, table.grid th.left { text-align: left; }
@media (max-width: 599px) {
  .hide-phone { display: none; }
  table.grid { font-size: 0.85rem; }
  table.grid th, table.grid td { padding: 9px 6px; }
  table.grid th { white-space: normal; line-height: 1.25; }
  /* Detail tables: on phones each row becomes a stack of label/value lines, so nothing is cut off. */
  table.grid.detail thead { display: none; }
  table.grid.detail, table.grid.detail tbody, table.grid.detail tfoot,
  table.grid.detail tr, table.grid.detail td { display: block; width: 100%; }
  table.grid.detail tbody tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.grid.detail tfoot tr {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 10px 0; background: #f9fafb;
  }
  table.grid.detail tfoot td { display: block; width: auto; padding: 0; }
  table.grid.detail td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 4px 0; border: 0; text-align: right; white-space: normal;
  }
  table.grid.detail td::before {
    content: attr(data-label); color: var(--muted); font-size: 0.75rem;
    font-weight: 600; text-transform: uppercase; text-align: left;
  }
  table.grid.detail tfoot td::before { content: none; }
  table.grid.detail td.hide-phone, table.grid.detail td:empty { display: none; }
}
@media (min-width: 600px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .filter { grid-template-columns: 1.4fr 1fr 1fr auto; }
  .filter label:first-child, .filter button { grid-column: auto; }
  .filter button { width: auto; }
}

/* The hidden attribute must hide elements even where a class sets display. */
[hidden] { display: none !important; }

/* Paid To / Received From picker and the + Add New dialog (v10.5) */
.recipient-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 2px; margin-bottom: 14px; background: #fafbff; }
.combo { position: relative; margin-bottom: 14px; }
.combo-input { margin-bottom: 0; }
.combo-list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 20; max-height: 260px;
  overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.12); padding: 6px; }
.combo-item { display: block; width: 100%; text-align: left; background: none; color: var(--ink); font-weight: 500;
  padding: 10px; margin: 0; border-radius: 8px; }
.combo-item:hover, .combo-item:focus { background: var(--brand-soft); outline: none; }
.combo-add { color: var(--brand); font-weight: 700; border-top: 1px solid var(--line); border-radius: 0; margin-top: 4px; }
.combo-empty { padding: 10px; color: var(--muted); font-size: 0.9rem; }
.error-text { color: var(--err); font-weight: 600; }
dialog.add-person { width: min(92vw, 420px); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
dialog.add-person::backdrop { background: rgba(17, 24, 39, 0.35); }
dialog.add-person h2 { margin: 0 0 12px; font-size: 1.1rem; }

/* ---- v10.6: roles, claims, sites and approvals ---- */
.badge.pending { background: #fff6e5; color: #8a5300; }
.badge.under_review { background: #eef4ff; color: #1d4ed8; }
.badge.removed { background: #f2f4f7; color: #7a271a; }
.kpis.five { grid-template-columns: 1fr 1fr; }
@media (min-width: 600px) { .kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.notice { background: #f9fafb; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 12px 0; font-size: 0.92rem; }
.notice.bad { background: #fef3f2; border-color: #fecdca; color: var(--err); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.actions form { margin: 0; }
.actions .button.small { margin-top: 0; }
button.quiet, button.danger-soft, button.ok {
  display: inline-block; width: auto; margin-top: 0; padding: 9px 14px; font-size: 14px;
}
button.quiet { background: var(--brand-soft); color: var(--brand); }
button.danger-soft { background: #fef3f2; color: var(--err); }
button.ok { background: var(--green); color: #fff; }
.add-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.add-row label { flex: 1 1 220px; margin-bottom: 0; }
.add-row button { width: auto; margin-top: 0; }
ol.steps { list-style: none; padding: 0; margin: 0; }
ol.steps li { position: relative; padding: 8px 0 8px 26px; color: var(--muted); font-size: 0.95rem; }
ol.steps li::before { content: ""; position: absolute; left: 4px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
ol.steps li.done { color: var(--ink); }
ol.steps li.done::before { background: var(--green); }
ol.steps li.bad { color: var(--err); }
ol.steps li.bad::before { background: var(--err); }
table.grid td.wrap { white-space: normal; min-width: 220px; }
