/* FindPet Finance — FR-22 layout (the UX concept v2.1, docs/UX_CONCEPT.md):
   a dark side menu, a top bar with the app's state, one service-period bar,
   pages of cards and tables. No inline styles anywhere — the CSP is
   style-src 'self' only. Colours are the prototype's; every state is told
   by text as well as colour (WCAG AA). */
:root {
  --ink: #172b3a;
  --sub: #536473;
  --muted: #6a7885;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --line: #dce4e8;
  --line-soft: #e6ecee;
  --head: #f8fafb;
  --nav: #122e3a;
  --nav2: #1c4350;
  --nav-ink: #cbdde1;
  --teal: #087c78;
  --teal-dark: #066662;
  --teal2: #e5f4f0;
  --orange: #9b5a00;
  --orange2: #fff1d9;
  --orange-line: #f0d6a3;
  --red: #ae3438;
  --red2: #fff0ee;
  --red-line: #eac2c0;
  --blue: #285f9d;
  --blue2: #eaf2ff;
  --green: #217246;
  --green2: #e7f5eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(17, 48, 58, 0.12);
  --focus: #f7ad29;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
a { color: var(--teal); }
h1, h2, h3, p { margin-top: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ── Forms ──────────────────────────────────────────────────────────── */
input, select {
  padding: 8px 10px;
  border: 1px solid #cbd6dc;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  min-height: 38px;
}
textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid #cbd6dc;
  border-radius: var(--radius-sm);
  resize: vertical;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  background: #fff;
  border: 1px solid #c9d7dc;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: 37px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.btn:hover { background: #f0f6f5; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #8e2c31; }
.btn-soft { background: var(--teal2); border-color: #b9e3d9; color: #086a66; }
.btn-ghost { background: none; border: none; color: var(--sub); font-weight: 500; }
.btn-ghost:hover { color: var(--ink); background: none; }
.btn:disabled, .icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn {
  display: inline-block;
  background: #fff;
  border: 1px solid #c9d7dc;
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  min-height: 31px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin: 2px 4px 2px 0;
  text-decoration: none;
}
.icon-btn:hover { background: #f0f6f5; }
.icon-btn.danger { color: var(--red); border-color: #e7b1b0; }
.icon-btn.danger:hover { background: var(--red2); }

/* ── Sign-in ─────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, var(--nav2), var(--nav));
}
.login-box {
  background: var(--panel);
  padding: 32px 36px;
  border-radius: var(--radius);
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow);
}
.login-box h1 { margin: 0 0 4px; font-size: 20px; }
.login-box .sub { margin: 0 0 16px; color: var(--sub); font-size: 13px; }
.login-box label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--sub); }
.login-box input { width: 100%; margin-top: 4px; }
.login-box .btn { width: 100%; margin-top: 6px; padding: 10px 14px; }
.setup-steps { margin: 0 0 16px; padding-left: 20px; font-size: 13px; }
.setup-steps li { margin-bottom: 10px; }
.setup-key {
  display: block;
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.5px;
  word-spacing: 2px;
  overflow-wrap: normal;
  user-select: all;
}
.setup-actions { display: flex; gap: 6px; flex-wrap: wrap; }
#totp-code { font-size: 20px; letter-spacing: 6px; text-align: center; font-family: var(--mono); }

/* ── The shell: side menu, top bar, period bar ───────────────────────── */
.app { min-height: 100vh; display: grid; grid-template-columns: 218px minmax(0, 1fr); }
.sidebar { background: var(--nav); color: var(--nav-ink); padding: 22px 12px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px; color: #fff; font-size: 18px; font-weight: 750; letter-spacing: -0.02em; }
.brand-mark { background: #42b8a8; color: #073333; border-radius: 10px; padding: 4px 9px; font-weight: 900; }
.brand-sub { display: block; font-size: 11px; color: #9eb9c1; font-weight: 500; letter-spacing: 0.08em; }
.nav { display: grid; gap: 3px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--nav-ink);
  text-decoration: none;
}
.nav-link:hover, .nav-link.active { background: var(--nav2); color: #fff; }
.nav-ico { width: 20px; text-align: center; font-size: 15px; }
.nav-count { margin-left: auto; background: #f2bd57; color: #26333a; border-radius: 8px; padding: 1px 6px; font-size: 11px; font-weight: 700; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #35525e; padding: 16px 10px 0; font-size: 12px; color: #abc4c9; }
.sidebar-foot strong { display: block; color: #fff; font-size: 13px; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 26px;
  flex-wrap: wrap;
  position: relative;
}
.crumb { font-weight: 650; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--sub); font-size: 12px; }
.topbar-right .btn-ghost { font-size: 12px; padding: 4px 6px; min-height: 0; }
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: #fff;
  color: var(--sub);
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  min-height: 0;
}
.status-chip:hover { background: #f0f6f5; }
.popover {
  position: absolute;
  right: 26px;
  top: calc(100% + 4px);
  z-index: 30;
  width: min(420px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  color: var(--ink);
  font-size: 13px;
}
.popover dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.popover dt { color: var(--sub); }
.popover dd { margin: 0; }

.periodbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: #fff;
  border: 1px solid #b8d7d3;
  border-radius: 10px;
  padding: 10px 13px;
  margin: 18px 26px 0;
  box-shadow: 0 2px 8px rgba(17, 48, 58, 0.05);
}
.periodbar strong { margin-right: auto; }
.periodbar select { min-width: 150px; }
.periodbar .btn { min-height: 35px; padding: 6px 10px; }
.periodbar .small { width: 100%; }

.content { padding: 22px 26px 60px; max-width: 1600px; width: 100%; }
.page:focus { outline: none; }
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead h1 { font-size: 24px; letter-spacing: -0.03em; margin: 0; }
.pagehead h1:focus { outline: none; }
.pagehead p { margin: 4px 0 0; color: var(--sub); max-width: 820px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Cards, KPIs, work queue ─────────────────────────────────────────── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel { padding: 18px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.kpi { padding: 16px 18px; min-height: 112px; }
.kpi .label, .label { font-size: 11px; letter-spacing: 0.055em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.kpi .value { font-size: 26px; font-weight: 750; letter-spacing: -0.04em; margin-top: 8px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .helper { color: var(--sub); font-size: 12px; margin-top: 8px; }
.scope { font-size: 12px; font-weight: 700; color: var(--sub); margin: 4px 0 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.two-col { grid-template-columns: minmax(0, 1.55fr) minmax(290px, 0.85fr); }
.queue-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.queue-row:first-child { border-top: 0; }
.queue-left { display: flex; gap: 12px; align-items: center; }
.queue-num { min-width: 40px; height: 40px; padding: 0 6px; display: grid; place-items: center; background: #ecf4f3; border-radius: 10px; font-weight: 750; font-size: 17px; color: #126e69; }
.queue-row strong { display: block; }
.queue-row .small { display: block; }
.mini-stat { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mini-stat:last-child { border-bottom: 0; }
.small { font-size: 12px; color: var(--sub); }

/* ── Toolbars, tables ────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar-count { color: var(--sub); margin-left: auto; font-size: 13px; }
.search-input { width: 260px; max-width: 100%; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { background: var(--head); color: var(--sub); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.035em; white-space: nowrap; }
tbody tr:hover { background: #f8fbfa; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 650; background: var(--head); border-top: 1px solid var(--line); }
td.empty-row { text-align: center; color: var(--sub); padding: 30px; }
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.num-strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.muted { color: var(--sub); }
.mono { font-family: var(--mono); font-size: 12px; }
.hint { margin: -4px 0 12px; font-size: 12px; color: var(--sub); }
.actions-cell { white-space: nowrap; }
.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; justify-content: flex-end; color: var(--sub); font-size: 13px; }
.section-title { margin: 24px 0 8px; font-size: 15px; }
/* a link to a part of a page (#invoices/cases, the Help's contents) stops below the sticky period bar / menu strip */
.section-title, .help-doc h2, .help-doc h3 { scroll-margin-top: 96px; }
.org-cell .org-name { display: block; font-weight: 650; }
.org-cell .org-id, .org-id { font-family: var(--mono); font-size: 11px; color: var(--sub); }
a.stripe-link { color: var(--teal); text-decoration: none; font-family: var(--mono); font-size: 12px; }
a.stripe-link:hover { text-decoration: underline; }
.store-link { color: #174454; font-weight: 700; text-decoration: none; }
.store-link:hover { text-decoration: underline; }
.diff-up { color: var(--green); }
.diff-down { color: var(--red); }
.state-removed td:not(.actions-cell) { text-decoration: line-through; color: var(--sub); }
.inv-note { display: block; font-size: 11px; color: var(--sub); margin-top: 3px; max-width: 340px; white-space: normal; }
.inv-note.err { color: var(--red); }
.amount-note, .price-cell .pc-note { display: block; font-size: 11px; color: var(--sub); margin-top: 2px; white-space: nowrap; }
.price-cell .pc-prices { font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv-links a { margin-right: 6px; }
.inv-actions { white-space: normal; min-width: 150px; }
.ov-inv { display: block; margin-bottom: 4px; }
.ov-inv:last-child { margin-bottom: 0; }
.pastdue-days { font-weight: 700; color: var(--red); }
.man-month { white-space: nowrap; }
.status-cell { min-width: 150px; }
.status-note { margin-top: 4px; font-size: 12px; color: var(--sub); }
.status-action { margin-top: 6px; }
.only-narrow { display: none; }
.debtor-note { display: block; margin-top: 3px; }
.tl-kind { font-weight: 650; }
.tl-table, .od-table, .oh-table { max-height: 55vh; }

/* ── Badges ──────────────────────────────────────────────────────────── */
/* FR-22 stage 8: the audit log's filters */
.au-filters { flex-wrap: wrap; gap: 8px 10px; }
.au-filters input, .au-filters select { min-width: 0; }
#au-action, #au-target, #au-text { flex: 1 1 180px; }

/* FR-22 stage 7: Registrations & revenue → Monthly matrix */
.reg-views { margin: 0 0 14px; }
.mx-toolbar { flex-wrap: wrap; gap: 8px 10px; }
.inline-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--sub); }
.mx-wrap { max-height: 70vh; overflow: auto; }
.mx-table { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.mx-table thead th { position: sticky; top: 0; z-index: 2; background: var(--head, #f7fafb); white-space: nowrap; }
.mx-table .mx-shop { position: sticky; left: 0; z-index: 1; background: var(--panel, #fff); min-width: 190px; max-width: 260px; text-align: left; box-shadow: 1px 0 0 var(--line); }
.mx-table thead .mx-shop { z-index: 3; background: var(--head, #f7fafb); }
/* the row heads are <th scope=row>: not the look of the column heads */
.mx-table tbody th, .mx-table tfoot th { text-transform: none; letter-spacing: normal; font-size: 13px; color: var(--ink); font-weight: 600; }
.mx-table tbody th .org-id { white-space: normal; overflow-wrap: anywhere; font-weight: 400; }
.mx-table tfoot th, .mx-table tfoot td { font-weight: 600; background: var(--head, #f7fafb); }
.mx-cell { padding: 0; min-width: 96px; vertical-align: top; }
.mx-link { display: block; padding: 8px 10px; color: inherit; text-decoration: none; text-align: right; }
.mx-link:hover, .mx-link:focus-visible { background: #eef6f5; outline: none; }
.mx-count { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.mx-line { display: block; font-size: 11px; color: var(--sub); white-space: nowrap; }
.mx-muted .mx-count, .mx-muted .mx-line { color: var(--muted); font-weight: 400; }
.mx-progress .mx-link { border: 1px dashed var(--line); }
.mx-ok .mx-line { color: var(--green); }
.mx-warn .mx-line { color: var(--orange); font-weight: 600; }
.mx-err .mx-line, .mx-stale { color: var(--red) !important; font-weight: 600; }
.mx-info .mx-line { color: var(--blue); }
@media (max-width: 680px) {
  .mx-table .mx-shop { min-width: 130px; max-width: 150px; }
  .mx-cell { min-width: 84px; }
}

/* FR-22: a store's page */
.back-link { margin: 0 0 8px; font-size: 13px; }
.back-link a { color: var(--teal); text-decoration: none; font-weight: 600; }
.store-head { align-items: flex-start; }
.store-head .ic-badges { margin-top: 6px; }
.st-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0 16px; overflow-x: auto; scrollbar-width: none; }
.st-tab { background: none; border: none; border-bottom: 3px solid transparent; padding: 10px 14px; font-weight: 600; color: var(--sub); cursor: pointer; white-space: nowrap; font: inherit; font-weight: 600; }
.st-tab:hover { color: var(--ink); }
.st-tab[aria-selected="true"] { color: var(--teal); border-bottom-color: var(--teal); }
.st-panel { min-width: 0; }
.st-tiles { margin-bottom: 16px; }
.st-card { padding: 16px 18px; margin-bottom: 16px; }
.st-card .section-title { margin-top: 0; }
.st-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.st-panel-actions { margin-bottom: 12px; }
.ready-sum { font-weight: 600; margin: 0 0 8px; }
.ready-sum.ok { color: var(--green); }
.ready-sum.err { color: var(--red); }
.ready-list { list-style: none; margin: 0 0 8px; padding: 0; }
.ready-item { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.ready-item:first-child { border-top: 0; }
.ready-item .badge { flex: none; min-width: 58px; text-align: center; }
.sim-head { margin: 0 0 6px; }
.sim-plan { margin: 8px 0; }
.org-link { color: var(--ink); text-decoration: none; }
.org-link:hover { color: var(--teal); text-decoration: underline; }
.se-table input, .se-table select { width: 100%; min-width: 90px; margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
#se-add { margin: 8px 0 4px; }
@media (max-width: 680px) {
  .form-grid { grid-template-columns: 1fr; }
  .store-head { flex-direction: column; }
  .st-tabs { flex-wrap: wrap; overflow-x: visible; }
  .st-tab { padding: 8px 10px; }
}

/* FR-22: Charge by hand — the saved payment methods as a radio list */
.cm-options { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 12px 0 4px; min-width: 0; }
.cm-options legend { font-weight: 600; padding: 0 4px; }
/* .modal-box label / input make every label a block and every input full width: these win over them */
.modal-box .cm-option { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; margin: 0; color: var(--ink); font-size: 14px; }
.modal-box .cm-option:first-child, .modal-box legend + .cm-option { border-top: 0; }
.modal-box .cm-option input { flex: none; width: auto; min-height: 0; margin: 3px 0 0; padding: 0; }
.cm-text { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; min-width: 0; }
.cm-text .inv-note { flex-basis: 100%; }
.modal-box .cm-off { cursor: default; color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  margin: 0 4px 2px 0;
  border: 1px solid transparent;
}
.badge-ok { color: var(--green); background: var(--green2); }
.badge-warn { color: var(--orange); background: var(--orange2); }
.badge-err { color: var(--red); background: var(--red2); }
.badge-info { color: var(--blue); background: var(--blue2); }
.badge-neutral { color: #445869; background: #edf1f3; }
.badge-test { color: #885700; background: #ffedc9; border-color: #eec271; }
.badge-live { color: #9a2630; background: #ffe5e5; border-color: #f0b7b7; }

/* ── Notices ─────────────────────────────────────────────────────────── */
.status-card {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 14px;
}
.status-card .badge { margin: 0; }
.notice-card { background: #fff8e9; border-color: var(--orange-line); color: #644718; }
.callout { border-radius: 9px; padding: 11px 14px; margin: 0 0 14px; font-size: 13px; }
.callout-warn { background: #fff8e9; border: 1px solid var(--orange-line); color: #644718; }
.callout-err { background: var(--red2); border: 1px solid var(--red-line); color: #8e2c31; }
.callout-info { background: #eef6f5; border: 1px solid #c6e5de; color: #235453; }
.error-msg { background: var(--red2); border: 1px solid var(--red-line); color: #8e2c31; padding: 8px 10px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }

/* ── Dialogs (native <dialog>: Esc, backdrop, focus) ─────────────────── */
dialog.modal { border: none; padding: 0; background: transparent; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow: visible; }
dialog.modal::backdrop { background: rgba(15, 35, 44, 0.5); }
.modal-box {
  background: var(--panel);
  padding: 24px 26px;
  border-radius: 14px;
  width: 460px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-box-lg { width: 900px; }
.modal-box h2 { margin: 0 0 14px; font-size: 18px; }
.modal-box .sub { margin: -6px 0 14px; color: var(--sub); font-size: 13px; }
.modal-box label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--sub); }
.modal-box input, .modal-box select { width: 100%; margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.review-lines { margin: 0 0 12px; padding: 10px 14px; background: var(--head); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px; }
.review-lines p { margin: 4px 0; }
.review-lines p:first-child { margin-top: 0; }
.review-lines p:last-child { margin-bottom: 0; }
.check-label { display: flex !important; align-items: center; gap: 8px; color: var(--ink) !important; }
.check-label input { width: auto !important; min-height: 0; margin: 0 !important; }

/* ── Settings, prices, groups ─────────────────────────────────────────── */
.settings-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 26px; max-width: 860px; }
.settings-card + .settings-card { margin-top: 16px; }
.settings-card h2 { margin: 0 0 4px; font-size: 17px; }
.settings-card h3 { margin: 18px 0 6px; font-size: 14px; }
.settings-card .sub { margin: 0 0 14px; color: var(--sub); font-size: 13px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn { background: #fff; border: none; border-right: 1px solid var(--line); padding: 8px 18px; cursor: pointer; color: var(--sub); font-weight: 600; }
.seg-btn:last-child { border-right: none; }
.seg-btn:hover:not(:disabled):not(.active) { background: #f0f6f5; color: var(--ink); }
.seg-btn.active { background: var(--teal); color: #fff; }
.seg-btn.active.seg-auto { background: #b45309; }
.seg-btn:disabled { cursor: default; }
.seg-btn:disabled:not(.active) { opacity: 0.6; }
.mode-explain { margin: 16px 0 8px; font-size: 13px; }
.mode-explain dt { font-weight: 650; margin-top: 10px; }
.mode-explain dd { margin: 2px 0 0; }
.inline-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--sub); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0 6px; }
.inline-form input { width: 110px; }
.price-tiles { display: flex; gap: 12px; flex-wrap: wrap; }
.price-tile { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; min-width: 150px; background: #fff; }
.price-tile .pt-label { font-size: 12px; color: var(--sub); }
.price-tile .pt-value { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; }
.price-tile .pt-note { font-size: 12px; color: var(--sub); }
.sub-form { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 6px; }
.sub-form label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--sub); }
.sub-form input, .sub-form textarea { width: 100%; margin-top: 4px; }
.form-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; }
.op-mode { margin: 4px 0 12px; }
.invoice-preview { font-size: 13px; background: var(--head); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 12px; }
.invoice-preview div { margin: 2px 0; }
.invoice-preview .ip-total { font-weight: 700; }
.group-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.group-option { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
.group-option.is-current { border-color: var(--teal); background: #f2faf8; }
.group-option .check-label { margin: 0; cursor: pointer; align-items: flex-start; }
.go-title { font-weight: 650; }
.go-note { display: block; font-size: 12px; color: var(--sub); margin-top: 2px; }
.go-members { margin: 6px 0 0 24px; }
.go-members summary { cursor: pointer; color: var(--teal); font-size: 12px; }
.go-members ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; columns: 2; column-gap: 24px; }
.go-members li { break-inside: avoid; margin-bottom: 2px; }
.transfers-box { margin: 14px 0 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--head); }
.transfers-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; font-size: 13px; }
.oh-tiles { margin-bottom: 4px; }
.oh-month-current { color: var(--sub); font-size: 11px; display: block; }
.details-toggle { cursor: pointer; color: var(--teal); font-size: 12px; }
.details-json { white-space: pre-wrap; font-family: var(--mono); font-size: 11px; background: var(--head); border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-top: 6px; max-width: 420px; }
.role-select { min-height: 32px; padding: 4px 8px; }

/* ── Help ────────────────────────────────────────────────────────────── */
.docs { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 30px; max-width: 900px; line-height: 1.6; }
.docs p { margin: 8px 0; }
.docs ol, .docs ul { margin: 8px 0 16px; padding-left: 22px; }
.docs li { margin-bottom: 6px; }
.help-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.help-toc { padding: 16px 24px; margin-bottom: 16px; }
.help-toc-title { font-weight: 650; margin-bottom: 6px; }
.help-toc-list { margin: 0; padding-left: 22px; columns: 2; column-gap: 32px; }
.help-toc-list li { break-inside: avoid; margin-bottom: 4px; }
.help-toc a, .help-doc a { color: var(--teal); }
.help-doc h1 { margin: 0 0 6px; font-size: 22px; }
.help-doc h2 { margin: 28px 0 10px; font-size: 18px; padding-top: 6px; border-top: 1px solid var(--line); }
.help-doc h3 { margin: 18px 0 6px; font-size: 15px; }
.help-doc code { font-family: var(--mono); font-size: 12px; background: var(--head); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.help-lead { color: var(--sub); font-size: 15px; }
.help-note, .help-warn { border-radius: var(--radius-sm); padding: 10px 14px; margin: 12px 0; font-size: 13px; }
.help-note { background: #eef6f5; border: 1px solid #c6e5de; }
.help-warn { background: #fff8e9; border: 1px solid var(--orange-line); }
.help-note ul { margin: 6px 0 0; }
.help-table { margin: 10px 0 14px; border: 1px solid var(--line); }
.help-table th { text-transform: none; font-size: 12px; letter-spacing: 0; }
.help-table th, .help-table td { font-size: 13px; }
.help-faq dt { font-weight: 650; margin-top: 10px; }
.help-faq dd { margin: 2px 0 0 0; }

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 100;
  background: #113d43;
  color: #fff;
  border-radius: 9px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100vw - 32px));
  font-size: 13px;
}
.toast.err { background: #8e2c31; }

/* ── Invoices workspace (FR-22) ─────────────────────────────────────── */
.views { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.view-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink);
  padding: 5px 11px; font-size: 12.5px; font-weight: 600; cursor: pointer; min-height: 32px;
}
.view-chip:hover { background: #f0f6f5; }
.view-chip.active { background: var(--nav); border-color: var(--nav); color: #fff; }
.view-count { background: var(--head); color: var(--sub); border-radius: 999px; padding: 0 7px; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.view-chip.warn .view-count { background: var(--red2); color: var(--red); }
.view-chip.active .view-count { background: rgba(255, 255, 255, 0.18); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.check input { width: auto; min-height: 0; margin: 0; }
.selbar {
  position: sticky; bottom: 12px; z-index: 15;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--nav); color: #fff; border-radius: 10px; padding: 9px 14px; margin: 8px 0; box-shadow: var(--shadow);
}
.selbar .btn-ghost { color: #d7e6ea; }
.inv-table th.sel, .inv-table td.sel { width: 34px; text-align: center; padding-right: 0; }
.inv-table th.sel { vertical-align: middle; }
.inv-table th.sel input { width: 18px; height: 18px; min-height: 0; margin: 0; }
.cases-more { justify-self: start; }
.inv-table td.sel input { width: 18px; height: 18px; min-height: 0; margin: 0; }
.link-btn { background: none; border: none; padding: 0; min-height: 0; color: var(--ink); font-weight: 650; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: #b8c6cc; text-underline-offset: 3px; }
.link-btn:hover { color: var(--teal); }
.org-cell .link-btn { display: block; }
.icon-btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.icon-btn.primary:hover { background: var(--teal-dark); }
.icon-btn.warn { color: var(--red); border-color: #e7b1b0; }
.cases { display: grid; gap: 10px; margin-bottom: 8px; }
.case-card { padding: 12px 14px; }
.case-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.case-latest { margin: 6px 0; font-size: 13px; }
.case-alerts { font-size: 12.5px; color: var(--sub); margin-bottom: 6px; }
.case-alerts ul { margin: 6px 0 0; padding-left: 18px; }
.case-alerts li { margin-bottom: 4px; }

/* the invoice's card: a panel from the right */
dialog.drawer {
  margin: 0 0 0 auto; padding: 0; border: none; border-left: 1px solid var(--line);
  width: min(590px, 100vw); max-width: 100vw; height: 100vh; max-height: 100vh;
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
}
dialog.drawer::backdrop { background: rgba(15, 35, 44, 0.45); }
.drawer-box { padding: 20px 22px 32px; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.drawer-head h2 { margin: 0; font-size: 19px; }
.drawer-head .sub { margin: 3px 0 0; color: var(--sub); font-size: 12.5px; }
.ic-badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 12px; }
.ic-actions { margin: 10px 0 16px; }
.ic-section { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.ic-section h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.ic-lines td { padding: 6px 4px; font-size: 13px; }
.ic-lines .ic-total td { font-weight: 700; border-top: 1px solid var(--line); }
.ic-dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.ic-dl dt { color: var(--sub); }
.ic-dl dd { margin: 0; }
.ic-docs { display: flex; flex-wrap: wrap; gap: 8px; }
.ic-rebuild { display: grid; gap: 2px; margin-bottom: 10px; font-size: 13px; }
.ic-compare { margin: 8px 0; font-size: 12.5px; background: #fff; }
.ic-compare th, .ic-compare td { padding: 5px 8px; vertical-align: top; text-transform: none; letter-spacing: 0; }

/* ── Narrow screens ──────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app { grid-template-columns: 64px minmax(0, 1fr); }
  .sidebar { padding: 18px 6px; }
  .brand-text, .nav-text, .sidebar-foot { display: none; }
  .brand { justify-content: center; padding: 4px; }
  .nav-link { justify-content: center; padding: 10px 6px; }
  .nav-count { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .app { display: block; }
  .sidebar { padding: 6px 8px; flex-direction: row; gap: 6px; position: sticky; top: 0; z-index: 25; height: auto; overflow: visible; }
  .brand { display: none; }
  .nav { display: flex; overflow-x: auto; gap: 2px; }
  .nav-link { padding: 7px 9px; gap: 6px; flex: 0 0 auto; }
  .nav-text { display: inline; font-size: 12px; }
  .nav-ico { width: auto; font-size: 13px; }
  .topbar { padding: 10px 14px; }
  .topbar { gap: 8px; }
  .crumb { display: none; } /* the page's own heading says it */
  .periodbar { margin: 12px 12px 0; position: static; }
  .periodbar strong { width: 100%; margin-right: 0; }
  .periodbar select { flex: 1; min-width: 0; }
  #pb-current { width: 100%; }
  .content { padding: 16px 12px 44px; }
  .pagehead { display: block; }
  .pagehead .actions { margin-top: 12px; }
  .kpi { padding: 13px; min-height: 100px; }
  .kpi .value { font-size: 20px; }
  .search-input { width: 100%; }
  .toolbar select { max-width: 100%; }
  .login-box { padding: 24px 20px; }
  .docs { padding: 20px 18px; }
  .settings-card { padding: 20px 18px; }
  .segmented { display: flex; }
  .seg-btn { flex: 1; }
  .form-row { grid-template-columns: 1fr; }
  .go-members ul { columns: 1; }
  .price-tile { flex: 1 1 100%; }
  .modal-box { padding: 20px 18px; }
  .help-toc { padding: 14px 16px; }
  .help-toc-list { columns: 1; }
  .help-table th, .help-table td { padding: 8px; }
  .popover { right: 12px; }
  /* FR-22: Billing runs → Runs: Details folds into the run's cell */
  .runs-table th:nth-child(4), .runs-table td:nth-child(4) { display: none; }
  .runs-table .only-narrow { display: block; margin-top: 6px; }
  /* Stores: registrations, paid, owed, past due and the actions fold into the shop's cell */
  .ov-table th:nth-child(2), .ov-table td:nth-child(2),
  .ov-table th:nth-child(3), .ov-table td:nth-child(3),
  .ov-table th:nth-child(5), .ov-table td:nth-child(5),
  .ov-table th:nth-child(6), .ov-table td:nth-child(6),
  .ov-table th:nth-child(7), .ov-table td:nth-child(7),
  .ov-table th:nth-child(8), .ov-table td:nth-child(8) { display: none; }
  .ov-table .only-narrow { display: block; margin-top: 4px; }
  /* hand-made invoices: amount, Stripe and month fold into the organization's cell */
  .man-table th:nth-child(3), .man-table td:nth-child(3),
  .man-table th:nth-child(4), .man-table td:nth-child(4),
  .man-table th:nth-child(5), .man-table td:nth-child(5) { display: none; }
  .man-table .only-narrow { display: block; margin-top: 4px; }
  /* FR-22 stage 9: pets without an organization — the record, the transfers and the rules fold under the pet */
  .ua-table th:nth-child(2), .ua-table td:nth-child(2),
  .ua-table th:nth-child(3), .ua-table td:nth-child(3),
  .ua-table th:nth-child(4), .ua-table td:nth-child(4) { display: none; }
  .ua-table .only-narrow { display: block; margin-top: 6px; }
  /* org detail: the date moves under the microchip */
  .od-table th:nth-child(2), .od-table td:nth-child(2) { display: none; }
  .od-table .only-narrow { display: block; }
  /* org pricing: prices, dates and status fold into the first column */
  .op-table th:nth-child(2), .op-table td:nth-child(2),
  .op-table th:nth-child(3), .op-table td:nth-child(3),
  .op-table th:nth-child(4), .op-table td:nth-child(4) { display: none; }
  .op-table .only-narrow { display: block; margin-top: 4px; }
  /* Invoices: the service month, the money and the payment fold into the shop's cell */
  .inv-table th:nth-child(3), .inv-table td:nth-child(3),
  .inv-table th:nth-child(4), .inv-table td:nth-child(4),
  .inv-table th:nth-child(5), .inv-table td:nth-child(5) { display: none; }
  .inv-table .only-narrow { display: block; margin-top: 4px; }
  .views { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; } /* the views slide sideways on a phone */
  .view-chip { flex: 0 0 auto; }
  .drawer-box { padding: 16px 14px 28px; }
  .selbar { bottom: 8px; }
}
/* FR-68: Link Stripe customers — a shop's candidates unfold under its row */
.cl-detail > td { background: var(--head); }
.cl-cands { display: grid; gap: 10px; }
.cl-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.cl-card.cl-linked { border-color: var(--teal); box-shadow: inset 3px 0 0 var(--teal); }
.cl-card p { margin: 4px 0; }
.cl-head { overflow-wrap: anywhere; }
.cl-why { margin: 4px 0 6px; padding-left: 18px; font-size: 13px; color: var(--sub); }
.cl-card .btn { margin-top: 6px; }
@media (max-width: 680px) {
  .cl-table th:nth-child(2), .cl-table td:nth-child(2):not([colspan]) { display: none; }
  .cl-table .only-narrow { display: block; margin-top: 4px; overflow-wrap: anywhere; }
  .cl-detail > td { padding: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
