/*
 * Admin app shell — extends the design tokens in tokens.css (colors, .btn,
 * spacing) with the layout pieces the client-facing pages don't need:
 * sidebar nav, data tables, status badges, forms, audit timeline.
 */
.faint { color: var(--faint); font-weight: 400; }
.admin-shell { display: flex; min-height: 100vh; padding: 0; align-items: stretch; }
.admin-sidebar {
  width: 220px; flex: none; background: var(--card); border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.admin-sidebar .brand { font-size: 15.5px; font-weight: 700; margin-bottom: 20px; padding: 0 8px; display: flex; align-items: center; gap: 6px; }
.admin-sidebar .brand .leaf { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.admin-sidebar .brand .leaf svg { width: 15px; height: 15px; }
.admin-sidebar .brand .hub { color: #2e7d4f; font-weight: 500; }
.sidebar-toggle {
  background: none; border: none; cursor: pointer; font-size: 16px; color: var(--muted);
  padding: 4px 8px; margin-bottom: 8px;
}
.sidebar-toggle:hover { color: var(--ink); }
.admin-shell.sidebar-collapsed .admin-sidebar { display: none; }
.sidebar-reopen { display: none; }
.admin-shell.sidebar-collapsed .sidebar-reopen {
  display: inline-flex; position: fixed; top: 12px; left: 12px; z-index: 20;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 16px; color: var(--ink);
}
/* STORYBOOK.md "Nav search input" — plain nav box, not a Cmd-K palette. */
.nav-search { position: relative; margin-bottom: 16px; padding: 0 8px; }
.nav-search input {
  width: 100%; font: inherit; font-size: 12.5px; color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px 9px 30px;
  background: var(--ground) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a978d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 9px center;
}
.nav-search input::placeholder { color: var(--faint); }
.nav-search input:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); background-color: var(--card);
}
.admin-sidebar nav a {
  display: block; padding: 8px 10px; border-radius: 8px; font-size: 13.5px; font-weight: 550;
  color: var(--muted); text-decoration: none; margin-bottom: 2px;
}
.admin-sidebar nav a:hover { background: var(--ground); color: var(--ink); }
.admin-sidebar nav a.active { background: var(--accent-tint); color: var(--accent-dark); }
/* STORYBOOK.md "Nav count pill" — hidden entirely at zero (template omits the span). */
.nav-count-pill {
  margin-left: auto; background: var(--amber-tint); color: var(--amber); font-size: 10px; font-weight: 700;
  padding: 1px 7px; border-radius: 99px; line-height: 1.5;
}
.admin-sidebar .section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint);
  margin: 16px 8px 6px;
}
.admin-sidebar details.nav-settings > summary { cursor: pointer; user-select: none; }
.nav-group-summary { cursor: pointer; user-select: none; margin-bottom: 2px; }
.nav-group-summary > a { display: inline; padding: 0; margin: 0; }
.nav-subitem {
  display: block; padding: 8px 10px 8px 22px; border-radius: 8px; font-size: 13.5px; font-weight: 550;
  color: var(--muted); text-decoration: none; margin-bottom: 2px;
}
.nav-subitem:hover { background: var(--ground); color: var(--ink); }
.nav-subitem.active { background: var(--accent-tint); color: var(--accent-dark); }
.admin-user-menu { margin-top: 20px; padding: 10px 8px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.admin-user-menu form { margin-top: 6px; }
.admin-user-menu button.linklike {
  background: none; border: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline;
}
.sidebar-user-chip { display: flex; align-items: center; gap: 8px; }
.sidebar-user-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-tint); color: var(--accent-dark);
  display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-info form { margin-top: 0; }
.sidebar-user-name {
  font-weight: 650; color: var(--ink); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-logout.linklike {
  background: none; border: none; padding: 0; font: inherit; font-size: 11px; color: var(--faint); cursor: pointer; text-decoration: none;
}
.sidebar-user-logout.linklike:hover { color: var(--ink); text-decoration: underline; }
.admin-footer { margin-top: 12px; padding: 0 8px; font-size: 11.5px; color: var(--faint); }
.admin-footer a { color: var(--faint); }

.admin-main { flex: 1; padding: 28px 32px 64px; max-width: 1240px; }
.admin-main h1 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.admin-main .page-sub { font-size: 13px; color: var(--muted); margin-bottom: 20px; }

.admin-flash { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.admin-flash.success { background: var(--accent-tint); color: var(--accent-dark); }
.admin-flash.error { background: var(--red-tint); color: var(--red); }

/*
 * Shared toast — STORYBOOK.md "Toasts": dark pill, bottom-center, ~2s
 * auto-dismiss, error variant solid red. This is the ONE toast component for
 * every admin async action (resend/void/refund/mark-wire-received/retry-
 * sync/pause/resume/…) — server sets flashToast (routes/admin/middleware.ts
 * setFlashToast, or subscriptions.ts's renderDetail), base.njk renders it
 * once, public/js/admin.js auto-dismisses it. Never invent a page-scoped
 * toast variant — .cd-toast/.doc-toast were the old ad-hoc versions this
 * replaces at the shared level (BUG-030).
 */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #ffffff; font-size: 12.5px; font-weight: 600;
  border-radius: 99px; padding: 8px 16px; box-shadow: 0 8px 24px -8px rgba(23,37,28,.4);
  z-index: 80; white-space: nowrap; animation: toast-in .18s ease;
}
.toast.toast-error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@keyframes spin { to { transform: rotate(360deg); } }
.btn-spinner {
  display: inline-block;
  vertical-align: -2px;
  width: 13px;
  height: 13px;
  margin-right: 7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.filters { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.filters input[type=text] { flex: 1 1 auto; min-width: 220px; }
.filters select { flex: 0 0 auto; min-width: 150px; }
.filters .btn { flex: 0 0 auto; }

/*
 * Reports tab strip (_reports-tabs.njk) — underline tabs per BUILD_SPECS
 * "Reports-shell" + the live `repTabs` behavior in
 * docs/design/reference/v2/Admin v2 - Reports and Settings.dc.html
 * (repBase: 2px bottom border, transparent when inactive). Scoped to
 * [data-testid="reports-tabs"] so it overrides the generic pill `.tab` /
 * `.tab.active` rule inherited from tokens.css (client-page token file,
 * loaded on every admin page via base.njk) without touching that shared
 * rule's pill look used by invoices/clients/contracts/subscriptions status
 * chips and the cohorts revenue/logo toggle.
 */
nav[data-testid="reports-tabs"] {
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-bottom: 20px;
}
nav[data-testid="reports-tabs"] .tab {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 13px;
  margin-bottom: -1px;
}
nav[data-testid="reports-tabs"] .tab:hover {
  color: var(--ink);
  border-color: var(--border);
}
nav[data-testid="reports-tabs"] .tab.active {
  background: transparent;
  color: var(--accent-dark);
  font-weight: 650;
  border-bottom-color: var(--accent-dark);
}

.table-scroll { overflow-x: auto; }

table.data-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.data-table th, table.data-table td { padding: 10px 14px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
table.data-table th { background: var(--ground); font-weight: 650; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--ground); }
table.data-table a { color: var(--accent-dark); text-decoration: none; font-weight: 550; }
table.data-table a:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 650; }
.badge.gray { background: var(--border-faint); color: var(--muted); }
.badge.green { background: var(--accent-tint); color: var(--accent-dark); }
.badge.amber { background: var(--amber-tint); color: var(--amber); }
.badge.red { background: var(--red-tint); color: var(--red); }
.badge.blue { background: var(--blue-tint); color: var(--blue); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.card h2 { font-size: 15.5px; font-weight: 700; margin-bottom: 12px; }

.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 24px; font-size: 13px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { font-weight: 550; }

/* Shared v2 two-column detail-page layout (design v2 screens 7/11/12 — contract,
   invoice, subscription detail): primary column left, secondary/meta rail right.
   Generalized from contract-detail.njk's original page-local .cd-layout. */
.detail-two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.detail-two-col > .detail-two-col-main,
.detail-two-col > .detail-two-col-rail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; min-width: 0; }
@media (max-width: 1000px) { .detail-two-col { grid-template-columns: 1fr; } }

.timeline { list-style: none; padding: 0; }
.timeline li { padding: 8px 0 8px 20px; border-left: 2px solid var(--border); position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline li .action { font-weight: 650; }
.timeline li .meta { color: var(--faint); font-size: 12px; }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.actions-row form { display: inline; }

form.stack { display: flex; flex-direction: column; gap: 12px; max-width: 480px; }
form.stack label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
form.stack input, form.stack select, form.stack textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 13.5px;
}
form.stack .field { display: flex; flex-direction: column; }
form.stack .row { display: flex; gap: 12px; }
form.stack .row > .field { flex: 1; }

/*
 * Admin buttons are compact, not the client-facing pay-card's full-width
 * giant CTA (tokens.css's base .btn is `display:block; width:100%; padding:
 * 14px; font-size:15.5px` — correct for a $7,188.00 "Pay" button, wrong for
 * every "Save" in the admin app). This is the systemic fix for the "giant
 * full-width white Save buttons" flagged in the v2 client-detail rebuild —
 * every admin .btn/.btn.ghost inherits this override, not just client-detail.
 * STORYBOOK.md "Buttons": primary brand bg/white/650/radius 9-10, secondary
 * white + 1.5px border, inline-block sized to content.
 */
.btn { display: inline-block; width: auto; font-size: 13px; font-weight: 650; padding: 9px 15px; border-radius: 9px; margin-top: 0; letter-spacing: normal; }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--border); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: var(--red-deep); }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
form.stack .btn { align-self: flex-end; }

/* Resume-charging action (v2 Operations Pipeline reference) — green-tinted
   ghost variant shown in the action row when charging is frozen (paused). */
.btn.resume { background: var(--accent-tint); color: var(--accent-dark); border: 1px solid #cfe3d5; }
.btn.resume:hover { background: #dcebe1; }

.line-items-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.line-items-table th, .line-items-table td { padding: 6px 8px; font-size: 12.5px; text-align: left; border-bottom: 1px solid var(--border); }
.line-items-table td.num { text-align: right; }

/*
 * Login / TOTP screens (BUILD_SPECS.md §10, §10b — B-C. Admin App.dc.html
 * "10 · LOGIN" / "10b · TWO-FACTOR (TOTP)"). Centered 380px card, no sidebar
 * shell — login.njk/2fa-verify.njk/2fa-enroll.njk extend base.njk's `body`
 * block directly rather than `admin_body`.
 */
.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;
}
.login-wrap { width: 380px; max-width: 100%; margin: 80px auto; padding: 0 16px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 9px; margin-bottom: 22px; }
.login-brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent);
  display: grid; place-items: center; color: #ffffff;
}
.login-brand-mark svg { width: 19px; height: 19px; }
.login-brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.login-wrap .card { padding: 26px; }
.login-wrap h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 3px; }
.login-wrap .subtitle { font-size: 12.5px; color: var(--faint); margin-bottom: 18px; }
.login-wrap .helper-text { text-align: center; font-size: 12px; color: var(--faint); margin-top: 14px; }
.login-wrap .totp-links { display: flex; justify-content: space-between; margin-top: 14px; font-size: 12px; }
.login-wrap .totp-links button.linklike {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--faint); background: none; border: none;
  cursor: pointer; padding: 0;
}
.login-wrap .totp-links button.linklike:hover { color: var(--ink); }
.login-wrap .totp-links a.linklike {
  font-size: 12px; font-weight: 600; color: var(--accent-dark); text-decoration: none;
}
.login-wrap .totp-links a.linklike:hover { text-decoration: underline; }
.login-wrap input.code-input {
  width: 100%; font-size: 26px; font-weight: 700; letter-spacing: .45em; text-align: center;
  font-variant-numeric: tabular-nums; border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

/* Phase 7C — settings screens (E. Settings & Dashboard.dc.html) */

.badge.gray-outline { background: var(--card); color: var(--faint); border: 1px solid var(--border); }

.integration-card { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.integration-card.warning { border-color: var(--amber-border); border-width: 1.5px; }
.integration-card .icon {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  font-size: 14px; font-weight: 800; flex: none; background: var(--ground); color: var(--muted);
}
.integration-card .body { flex: 1; min-width: 220px; }
.integration-card .name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.integration-card .name-row strong { font-size: 14px; font-weight: 700; }
.integration-card .headline { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.integration-card .meta { display: block; font-size: 12px; color: var(--faint); margin-top: 6px; }

.health-feed-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 14px; }
.health-feed-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.health-feed-card .top-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.health-feed-card .name { font-size: 12.5px; font-weight: 700; }
.health-feed-card .detail { font-size: 11.5px; color: var(--faint); margin-top: 5px; line-height: 1.5; }

.event-row { display: flex; align-items: center; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.event-row:last-child { border-bottom: none; }
.event-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.event-row .dot.ok { background: var(--accent); }
.event-row .dot.error { background: var(--red); }
.event-row .at { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11px; color: var(--faint); width: 160px; flex: none; }
.event-row .event { font-weight: 600; flex: 1; min-width: 0; }
.event-row .source { color: var(--faint); font-size: 11.5px; white-space: nowrap; }

.filters select, .filters input { font: inherit; font-size: 12.5px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--card); }

/*
 * Frozen-client banner (STORYBOOK.md "Frozen client badge/banner") — client
 * detail page, informational-but-loud like danger-zone but not destructive.
 */
.frozen-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--red-tint); border: 1.5px solid var(--red-border); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 20px;
}
.frozen-banner .frozen-meta { font-size: 12px; color: var(--muted); }
.frozen-banner .actions { margin-left: auto; }

/*
 * Empty states — STORYBOOK.md "Empty states": dashed box, 40-44px circle icon
 * (gray for neutral, green tint + check for "all clear" — opted into per
 * instance via .empty-state.happy), 13-14px/650 title, 12px faint sub-line.
 * The circle+icon is a CSS-only ::before so all ~30 existing `.empty-state`
 * call sites across the admin app pick it up with zero template changes.
 */
.empty-state {
  text-align: center; padding: 40px 16px; color: var(--faint);
  border: 1px dashed var(--border); border-radius: 12px;
}
.empty-state::before {
  content: ''; display: block; width: 42px; height: 42px; margin: 0 auto 12px;
  border-radius: 50%; background: var(--border-faint);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%238a978d' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='m7 15 4-4 3 3 5-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center;
}
.empty-state.happy::before {
  background-color: var(--accent-tint);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%232e7d4f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
}
.empty-state .title { font-size: 14px; font-weight: 650; color: var(--ink); margin-bottom: 4px; }
.empty-state .sub { font-size: 12.5px; }

.pagination { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 12.5px; color: var(--faint); }
.pagination a { color: var(--accent-dark); text-decoration: none; font-weight: 600; }

/*
 * Communications section (STORYBOOK.md "Communications list rows" /
 * "Suppressed-sends banner") — client detail page.
 */
.comms-suppressed-banner {
  background: var(--border-faint); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 12.5px; color: var(--muted);
}
.comms-date { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11px; color: var(--faint); white-space: nowrap; }
.comms-subline { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.comms-dash { color: var(--faint); }
.comms-subheading { font-size: 14px; font-weight: 700; margin: 20px 0 10px; }

.kv-grid { display: grid; gap: 10px; font-size: 12.5px; }
.kv-grid .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px dashed var(--border); padding-bottom: 9px; }
.kv-grid .row:last-child { border-bottom: none; padding-bottom: 0; }
.kv-grid .row .sub { display: block; font-size: 11.5px; color: var(--faint); }

/*
 * Reports tab shell (STORYBOOK/BUILD_SPECS §30/30b, design_handoff v2
 * "Admin v2 - Reports and Settings.dc.html" screen 10) — underline tabs,
 * not the pill look `.tab`/`.tab.active` render everywhere else. Elements
 * keep the plain `.tab` class (8 live e2e locators select on it — see
 * _reports-tabs.njk's header comment); this block's `.report-tabs`-scoped
 * selectors override just enough (bg/border/radius/color) to read as an
 * underline strip without touching the shared rule other pages depend on.
 */
.report-tabs {
  display: flex; gap: 2px; overflow-x: auto; margin: 16px 0 20px;
  border-bottom: 1px solid var(--border); flex-wrap: nowrap;
}
.report-tabs .tab {
  font-size: 13px; font-weight: 600; padding: 10px 13px; white-space: nowrap;
  background: transparent; border: none; border-radius: 0;
  border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--muted);
}
.report-tabs .tab:hover { border-color: var(--border); color: var(--ink); background: transparent; }
.report-tabs .tab.active {
  background: transparent; color: var(--accent-dark); font-weight: 650;
  border-bottom-color: var(--accent);
}
