/*
  Admin dashboard styles. The design system lives in docs/design-system/: DESIGN.md has the rules,
  design-tokens.json the values, design-preview.html renders both.

  Rules use tokens only: no raw px for font size, spacing or radius, no raw colors. Need a value
  the scale lacks? Change the scale in DESIGN.md first. Layout widths (rail, max-width, grid
  minimums) and hairlines (1px borders, 2px focus ring) are the exceptions.
*/
:root {
  --ground: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --border: #d9dce4;
  --border-strong: #878da3;
  --text: #1c2030;
  --muted: #626982;
  --faint: #8b91a7;
  --accent: #3f4bd6;
  --accent-ink: #ffffff;
  --accent-soft: #e7e9fb;
  --good: #157a4b;
  --good-soft: #e0f4ea;
  --warn: #8c5804;
  --warn-soft: #fbeed6;
  --bad: #c33636;
  --bad-soft: #fbe3e3;
  --danger-solid: #c33636;
  --overlay: rgba(15, 17, 25, .5);

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --text-label: 10px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 22px;
  --text-display: 26px;
  --w-regular: 400;
  --w-semibold: 600;
  --w-bold: 700;
  --tracking-tight: -.02em;
  --tracking-wide: .08em;

  --sp-2: 2px;
  --sp-4: 4px;
  --sp-6: 6px;
  --sp-8: 8px;
  --sp-12: 12px;
  --sp-16: 16px;
  --sp-20: 20px;
  --sp-24: 24px;
  --sp-32: 32px;
  --sp-48: 48px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .05);
  --shadow-overlay: 0 8px 32px rgba(20, 24, 40, .18);
  --transition: 120ms ease;
  --envbar-h: 26px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #14161f;
    --surface: #1c1f2b;
    --surface-2: #242838;
    --border: #333849;
    --border-strong: #666d8a;
    --text: #e7e9f2;
    --muted: #9aa1ba;
    --faint: #6b7189;
    --accent: #7d88f0;
    --accent-ink: #0f1119;
    --accent-soft: #262a45;
    --good: #46c085;
    --good-soft: #163027;
    --warn: #e0a23f;
    --warn-soft: #322611;
    --bad: #ea6d6d;
    --bad-soft: #341c1e;
    --overlay: rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--text); font-family: var(--sans);
  font-size: var(--text-base); line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { margin: 0; font-weight: var(--w-bold); line-height: 1.25; text-wrap: balance;
  letter-spacing: var(--tracking-tight); }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
/* Secondary copy ("none", "No plans linked"). Muted, not --faint: faint fails contrast as text. */
.faint { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Uppercase micro label: table heads, nav sections, field names inside cards. */
.label, th { font-size: var(--text-label); font-weight: var(--w-bold); text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--muted); }

/* env banner: pinned, so the production warning never scrolls away. Sticky elements below it
   (rail, hub header) sit at top: var(--envbar-h). */
.envbar { position: sticky; top: 0; z-index: 40; height: var(--envbar-h); display: flex; align-items: center;
  justify-content: center; padding: 0 var(--sp-12); background: var(--danger-solid); color: #fff;
  font-weight: var(--w-bold); font-size: var(--text-xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; white-space: nowrap; overflow: hidden; }
.envbar-staging { background: var(--warn-soft); color: var(--warn); }
.envbar-local { background: var(--accent-soft); color: var(--accent); }

.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: calc(100vh - var(--envbar-h)); }

/* rail */
.rail { border-right: 1px solid var(--border); background: var(--surface); padding: var(--sp-20) var(--sp-12);
  display: flex; flex-direction: column; gap: var(--sp-4); position: sticky; top: var(--envbar-h);
  align-self: start; height: calc(100vh - var(--envbar-h)); }
.brand { display: flex; align-items: center; gap: var(--sp-8); padding: var(--sp-4) var(--sp-8) var(--sp-16);
  color: var(--text); text-decoration: none; }
.brand .logo { display: block; width: 32px; height: 32px; }
.brand b { font-size: var(--text-base); }
.brand span { font-size: var(--text-xs); color: var(--muted); display: block; }
/* Nav: section labels are .label (small, muted, uppercase); items are full-size text in --text, so
   a link never reads like a heading. */
.navsec { padding: var(--sp-16) var(--sp-8) var(--sp-4); }
.navitem { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-8);
  padding: var(--sp-6) var(--sp-8); border-radius: var(--radius-sm); color: var(--text); border: none;
  background: none; width: 100%; text-align: left; font-weight: var(--w-regular); text-decoration: none;
  transition: background var(--transition), color var(--transition); }
.navitem:hover { background: var(--surface-2); }
.navitem.active { background: var(--accent-soft); color: var(--accent); font-weight: var(--w-semibold); }
/* Account row pinned to the rail bottom: avatar, who + role, quiet logout icon (red on hover). */
.acct { margin-top: auto; display: flex; align-items: center; gap: var(--sp-8);
  padding: var(--sp-12) var(--sp-4) 0 var(--sp-8); border-top: 1px solid var(--border); }
.avatar { width: 28px; height: 28px; border-radius: var(--radius-full); display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: var(--text-xs); font-weight: var(--w-bold);
  flex: none; }
.acct .who { min-width: 0; flex: 1; line-height: 1.3; }
.acct .who b { display: block; font-size: var(--text-xs); font-weight: var(--w-semibold); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.acct .who span { font-size: var(--text-xs); color: var(--muted); }
.acct-out { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: none; background: none; color: var(--muted); flex: none; cursor: pointer;
  transition: background var(--transition), color var(--transition); }
.acct-out:hover { background: var(--bad-soft); color: var(--bad); }
.acct-out:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.acct-out .ico { width: 16px; height: 16px; }

/* main */
.main { padding: var(--sp-24) var(--sp-32) var(--sp-48); max-width: 1080px; min-width: 0; }
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-16);
  margin-bottom: var(--sp-20); }
.pagehead h1 { font-size: var(--text-xl); }
.pagehead .sub { color: var(--muted); font-size: var(--text-sm); margin-top: var(--sp-4); }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: var(--sp-6); padding: var(--sp-8) var(--sp-12);
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-weight: var(--w-semibold);
  transition: border-color var(--transition), background var(--transition); }
.btn:hover { border-color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent);
  padding: var(--sp-6) var(--sp-8); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.ghost.danger { color: var(--bad); }
.btn.ghost.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: var(--sp-4) var(--sp-8); font-size: var(--text-sm); }

/* An htmx save in flight: the requesting form or button dims until the swap lands. */
.htmx-request { opacity: .6; pointer-events: none; transition: opacity var(--transition); }

/* pills */
.pill { display: inline-flex; align-items: center; gap: var(--sp-4); padding: var(--sp-2) var(--sp-8);
  border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--w-bold); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.active { background: var(--good-soft); color: var(--good); }
.pill.draft { background: var(--warn-soft); color: var(--warn); }
.pill.cancelled { background: var(--bad-soft); color: var(--bad); }

/* cards & tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
th { text-align: left; padding: var(--sp-12) var(--sp-16); border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; }
td { padding: var(--sp-12) var(--sp-16); border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { transition: background var(--transition); }
tbody tr.clickable:hover { background: var(--surface-2); cursor: pointer; }
td .slug { font-family: var(--mono); font-size: var(--text-sm); color: var(--muted); }
td.num, th.num { text-align: right; }
td .none { color: var(--muted); }
/* a table body per group: tr.grp is the group's header row, with its count and an action */
tr.grp td { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); padding: var(--sp-8) var(--sp-16); }
tr.grp .grp-in { display: flex; align-items: center; gap: var(--sp-8); }
tr.grp b { font-weight: var(--w-semibold); }
tr.grp .n { color: var(--muted); font-size: var(--text-sm); }
tr.grp .btn { margin-left: auto; }

/* A clickable row's link stretches over the whole row, so a click anywhere follows it, no JS. */
tr.clickable { position: relative; }
tr.clickable a.rowlink { color: inherit; font-weight: var(--w-semibold); text-decoration: none; }
tr.clickable a.rowlink::after { content: ""; position: absolute; inset: 0; }

.empty { text-align: center; padding: var(--sp-48) var(--sp-20); color: var(--muted); }
.empty .big { font-size: var(--text-lg); font-weight: var(--w-semibold); color: var(--text);
  margin-bottom: var(--sp-4); }

/* breadcrumbs */
.crumbs { display: flex; align-items: center; gap: var(--sp-6); font-size: var(--text-sm); color: var(--muted);
  margin-bottom: var(--sp-12); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs .sep { color: var(--faint); }

/* hub: sticky product header carries identity (and, from ticket 11, the activation control) */
.hubheader { position: sticky; top: var(--envbar-h); z-index: 20; background: var(--ground);
  display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-16); flex-wrap: wrap;
  padding: var(--sp-12) 0; margin-bottom: var(--sp-8); border-bottom: 1px solid var(--border); }
.hh-id h1 { font-size: var(--text-xl); display: flex; align-items: center; gap: var(--sp-12); }
.hh-id .sub { color: var(--muted); font-size: var(--text-sm); margin-top: var(--sp-4); display: flex;
  align-items: center; gap: var(--sp-8); }
.hh-act { display: flex; align-items: center; gap: var(--sp-12); flex: none; }

/* hub sections */
.section { border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: none; }
.section-head { display: flex; align-items: center; gap: var(--sp-12); padding: var(--sp-16) var(--sp-20); }
.section-head .stat { width: 22px; height: 22px; border-radius: 50%; display: grid;
  place-items: center; font-size: var(--text-sm); font-weight: var(--w-bold); flex: none; }
.stat.done { background: var(--good-soft); color: var(--good); }
.stat.todo { background: var(--warn-soft); color: var(--warn); }
.stat.na { background: var(--surface-2); color: var(--muted); }
.section-head .titles { flex: 1; }
.section-head h3 { font-size: var(--text-lg); }
.section-head .meta { font-size: var(--text-sm); color: var(--muted); }
/* Left padding lines the body up with the title: head padding + stat badge + gap. */
.section-body { padding: 0 var(--sp-20) var(--sp-20) calc(var(--sp-20) + 22px + var(--sp-12));
  display: flex; flex-direction: column; gap: var(--sp-12); }

/* coverage matrix: plans are columns, merchant accounts rows, a ticked cell is a link. The table
   scrolls inside .matrix, so the header row, account column and Sold-by row stay pinned. */
.section-actions { display: flex; gap: var(--sp-8); flex: none; }
.coverage-errors:empty { display: none; }
.coverage-errors { padding: 0 var(--sp-20); }
.matrix { overflow: auto; max-height: calc(100vh - 240px); border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.matrix table { border-collapse: separate; border-spacing: 0; font-size: var(--text-sm); }
.matrix th, .matrix td { padding: var(--sp-8) var(--sp-6); text-align: center; background: var(--surface);
  border-left: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; z-index: 1; text-align: left;
  min-width: 200px; max-width: 300px; padding-left: var(--sp-20); border-left: none;
  box-shadow: 1px 0 0 var(--border); }
.matrix td.empty { position: static; max-width: none; text-align: center; box-shadow: none; }
.matrix thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); vertical-align: bottom; }
.matrix tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--surface-2); border-bottom: none;
  font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }
.matrix tfoot td:first-child { font-size: var(--text-label); font-weight: var(--w-bold); text-transform: uppercase;
  letter-spacing: var(--tracking-wide); }
.matrix thead th:first-child, .matrix tfoot td:first-child { z-index: 3; }
.plan-head { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); width: 100%;
  padding: var(--sp-4) var(--sp-6); border: none; border-radius: var(--radius-sm); background: none;
  color: var(--text); white-space: nowrap; text-transform: none; letter-spacing: 0; }
.plan-head:hover { background: var(--accent-soft); }
.plan-head .amount { font: var(--w-bold) var(--text-sm)/1.2 var(--mono); }
.plan-head .terms { font-size: var(--text-xs); font-weight: var(--w-regular); color: var(--muted); }
.matrix .account b { font-weight: var(--w-semibold); }
.account-meta { font-size: var(--text-xs); color: var(--muted); overflow-wrap: anywhere; }
/* One line per PSP on the account: code, then its MID tag. */
.psp-tags { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-2) var(--sp-8);
  align-items: baseline; margin: var(--sp-4) 0 0; font-size: var(--text-xs); }
.psp-tags dt { font-size: var(--text-label); font-weight: var(--w-bold); letter-spacing: var(--tracking-wide);
  color: var(--muted); }
.psp-tags dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.psp-tags > dd:only-child { grid-column: 1 / -1; }
.row-actions { float: right; width: 24px; height: 24px; margin-left: var(--sp-8); border: none;
  border-radius: var(--radius-sm); background: none; color: var(--muted); line-height: 1; }
.row-actions:hover { background: var(--surface-2); color: var(--text); }
/* A cell keeps its 28px box in every state, so the grid never shifts. */
.cell { display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0;
  border: 1px dashed var(--border); border-radius: var(--radius-sm); background: transparent;
  color: var(--accent); font-weight: var(--w-bold); vertical-align: middle; }
.cell[aria-pressed="true"] { border: 1px solid transparent; background: var(--good-soft); color: var(--good); }
.cell[aria-pressed="true"]::after { content: "✓"; }
button.cell:not([aria-pressed="true"]):hover::after, button.cell:not([aria-pressed="true"]):focus-visible::after { content: "+"; }
button.cell:hover { border-color: var(--accent); }
span.cell:not([aria-pressed="true"]) { visibility: hidden; }
.cell.htmx-request { opacity: 1; border: 1px solid var(--border-strong); background: transparent; }
.cell.htmx-request::after { content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cell.htmx-request::after { animation: none; } }
/* A plan no account sells is the gap the matrix exists to show: tint its whole column. */
.matrix .unsold { background: color-mix(in srgb, var(--warn-soft) 60%, var(--surface)); }
.matrix thead th.unsold { box-shadow: inset 0 3px 0 var(--warn); }
.matrix tfoot .zero { background: var(--warn-soft); color: var(--warn); font-weight: var(--w-bold); }
.matrix tfoot .one { color: var(--warn); font-weight: var(--w-bold); }
/* Crosshair: the hovered row via :hover, its column via .hl from admin.js. */
.matrix tbody tr:hover td, .matrix .hl { background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); }
.matrix tr.inactive td:not(:first-child) { background-image: repeating-linear-gradient(135deg,
  transparent 0 6px, var(--surface-2) 6px 7px); }
.matrix tr.inactive .account b { color: var(--muted); }
/* Undo after a link. Swapped out with the section on the next save; fades after 8s otherwise. */
.toast { position: fixed; left: calc(224px + var(--sp-32)); bottom: var(--sp-24); z-index: 30; display: flex;
  align-items: center; gap: var(--sp-12); padding: var(--sp-8) var(--sp-12); border-radius: var(--radius-md);
  background: var(--text); color: var(--surface); font-size: var(--text-sm); box-shadow: var(--shadow-overlay);
  animation: toast-out var(--transition) 8s forwards; }
.toast button { padding: 0; border: none; background: none; color: inherit; font-weight: var(--w-bold);
  text-decoration: underline; }
@keyframes toast-out { to { opacity: 0; visibility: hidden; } }
.psp-actions { display: flex; justify-content: space-between; align-items: center; }
.modal .dialog-subhead { font-size: var(--text-base); margin: var(--sp-20) 0 var(--sp-8); }
.modal .psp-sub { margin-bottom: var(--sp-8); }
.modal .psp-sub .field { margin-bottom: var(--sp-8); }

/* copyable ids: block field in dialogs, .inline next to a heading */
.idrow { display: flex; flex-direction: column; gap: var(--sp-4); border-top: 1px solid var(--border);
  padding-top: var(--sp-12); }
.copyid { display: flex; align-items: center; gap: var(--sp-6); width: 100%; text-align: left;
  padding: var(--sp-4) var(--sp-8); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted); transition: border-color var(--transition); }
.copyid .mono { font-size: var(--text-xs); word-break: break-all; line-height: 1.35; }
.copyid .ci { margin-left: auto; color: var(--faint); flex: none; }
.copyid:hover { border-color: var(--accent); color: var(--text); }
.copyid.copied { border-color: var(--good); color: var(--good); }
.copyid.copied .ci { color: var(--good); }
.copyid.inline { display: inline-flex; width: auto; padding: var(--sp-2) var(--sp-8); background: transparent;
  vertical-align: middle; }
.copyid.inline .mono { font-size: var(--text-sm); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: var(--sp-4); padding: var(--sp-2) var(--sp-8);
  border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: var(--w-semibold);
  background: var(--surface-2); color: var(--muted); }
.warn-t { color: var(--warn); font-weight: var(--w-semibold); font-size: var(--text-xs); }

/* PSP block inside an account dialog */
.psp-sub { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--sp-12); display: flex; flex-direction: column; gap: var(--sp-8); }
/* notices: inline messages, neutral by default, with a tone. .form-errors is the bad tone as a list. */
.notice, .form-errors { padding: var(--sp-8) var(--sp-12); border-radius: var(--radius-md);
  font-size: var(--text-sm); background: var(--surface-2); color: var(--muted); }
.notice { margin-bottom: var(--sp-16); }
.notice.good { background: var(--good-soft); color: var(--good); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad, .form-errors { background: var(--bad-soft); color: var(--bad); }
.form-errors { margin: var(--sp-8) 0; padding-left: var(--sp-32); }

/* forms */
.field { margin-bottom: var(--sp-16); }
.field label { display: block; font-size: var(--text-sm); font-weight: var(--w-semibold); }
.field input, .field select { display: block; width: 100%; margin-top: var(--sp-4); padding: var(--sp-8) var(--sp-12);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--ground);
  color: var(--text); font-family: inherit; font-size: var(--text-base); }
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px;
  border-color: var(--accent); }
.field input.mono { font-family: var(--mono); }
.field .hint { font-size: var(--text-xs); color: var(--muted); font-weight: var(--w-regular); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-12); }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-12); }

/* modal: a native <dialog>; admin.js opens and closes it */
dialog.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay); width: 100%; max-width: 460px; padding: var(--sp-24); max-height: 88vh;
  overflow-y: auto; color: var(--text); }
dialog.modal::backdrop { background: var(--overlay); }
.modal h3 { font-size: var(--text-lg); margin-bottom: var(--sp-4); }
.modal .lead { color: var(--muted); font-size: var(--text-sm); margin-bottom: var(--sp-20);
  overflow-wrap: anywhere; }
#confirm-dialog { max-width: 400px; }
#confirm-dialog .modal-foot { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-8); margin-top: var(--sp-24); }

.placeholder { padding: var(--sp-12) var(--sp-16); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md); color: var(--muted); background: var(--surface); }

/* login page: centered card, see templates/authentication/login.html */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-24); }
.login-card { width: 100%; max-width: 380px; padding: var(--sp-32) var(--sp-32) var(--sp-24); text-align: center; }
.login-card .logo { display: block; width: 64px; height: 64px; margin: 0 auto var(--sp-16); }
.login-card h1 { font-size: var(--text-lg); }
.login-card .sub { color: var(--muted); font-size: var(--text-sm); margin: var(--sp-4) 0 var(--sp-20); }
.login-card form, .login-card .notice { text-align: left; }
.login-card .btn { width: 100%; justify-content: center; gap: var(--sp-8); padding: var(--sp-12) var(--sp-16);
  text-decoration: none; }
.login-card .or { display: flex; align-items: center; gap: var(--sp-8); margin: var(--sp-16) 0;
  color: var(--muted); font-size: var(--text-xs); }
.login-card .or::before, .login-card .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* subscriptions list */
.subs { max-width: 1240px; }
.subs .nowrap { white-space: nowrap; }
.subs-bar { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-12);
  margin-bottom: var(--sp-8); font-size: var(--text-sm); }
.subs-err { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-12); }
.subs-table table { min-width: 860px; font-size: var(--text-sm); }
.subs-table th, .subs-table td { padding: var(--sp-8) var(--sp-12); }
.subs-table th .sort { color: inherit; text-decoration: none; display: inline-flex; gap: var(--sp-4); }
.subs-table th .sort.on { color: var(--text); }
/* When the table scrolls sideways, Sub ID stays in view. */
.subs-table .pin { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
.subs-table th.pin { background: var(--surface-2); z-index: 2; }
.subs-table .pp { display: flex; align-items: center; }
.subs-table .pp > span { display: flex; flex-direction: column; }
.pill.created { background: var(--warn-soft); color: var(--warn); }
.pill.inactive { background: var(--surface-2); color: var(--muted); }
.cp { margin-left: var(--sp-2); padding: 0 var(--sp-4); border: none; border-radius: var(--radius-sm); background: none;
  color: var(--faint); opacity: 0; }
tr:hover .cp, .cp:focus-visible, .cp.copied { opacity: 1; }
.cp:hover { color: var(--accent); background: var(--accent-soft); }
.cp.copied { color: var(--good); }
.cp.on { opacity: 1; }
/* Expandable rows: one tbody per subscription, the row then its details row. Cells are shaded, not
   the tr: the sticky Sub ID cell paints its own background over the row's. */
.subs-table tbody.sub tr.expandable { cursor: pointer; }
.subs-table tbody.sub tr.expandable:hover > td, .subs-table tbody.sub tr.open > td { background: var(--surface-2); }
.subs-table tbody.sub tr.open td { border-bottom-color: transparent; }
.exp { width: 20px; height: 20px; margin-right: var(--sp-4); padding: 0; border: none; border-radius: var(--radius-sm);
  background: none; color: var(--muted); font-size: var(--text-lg); line-height: 1; vertical-align: middle;
  transition: transform var(--transition); }
.exp:hover { background: var(--surface); color: var(--text); }
tr.open .exp { transform: rotate(90deg); color: var(--accent); }
.subs-table tr.detail td { background: var(--surface-2); padding: var(--sp-4) var(--sp-16) var(--sp-16) 44px; cursor: default; }
.dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--sp-12); }
.dgrid section { min-width: 0; padding: var(--sp-12); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); }
.dgrid h4 { margin: 0 0 var(--sp-8); }
.dgrid dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-4) var(--sp-12); margin: 0; }
.dgrid dt { color: var(--muted); }
.dgrid dd { margin: 0; overflow-wrap: anywhere; }
.dgrid dd.mono { font-variant-numeric: tabular-nums; }
.dgrid dd .mono { font-size: var(--text-xs); }
.dgrid dd:has(> .cp) { display: flex; align-items: baseline; }
.dgrid dd:has(> .cp) > span { min-width: 0; }
.dlink { color: var(--accent); text-decoration: none; }
.dlink:hover { text-decoration: underline; }
/* On narrow screens the table scrolls sideways; keep the details pinned to the visible width. */
@media (max-width: 860px) {
  .dgrid { grid-template-columns: minmax(0, 1fr); }
  .subs-table tr.detail td { padding-left: var(--sp-12); }
  .subs-table tr.detail td > * { position: sticky; left: var(--sp-12); max-width: calc(100vw - 72px); }
}
.pager { position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-12); flex-wrap: wrap; margin-top: var(--sp-12); padding: var(--sp-12) 0;
  background: var(--ground); border-top: 1px solid var(--border); font-size: var(--text-sm); }
.pager .pages { display: flex; align-items: center; gap: var(--sp-8); }
.pager a { text-decoration: none; }
/* Instant tooltip for [data-tip], placed by admin.js. Fixed, so a scrolling table never clips it. */
.tip { position: fixed; z-index: 60; max-width: 420px; padding: var(--sp-4) var(--sp-8); border-radius: var(--radius-sm);
  background: var(--text); color: var(--surface); font-size: var(--text-xs); box-shadow: var(--shadow-overlay);
  pointer-events: none; white-space: nowrap; }
.tip.mono { font-family: var(--mono); }
/* Pinned header: title, filters and count stay in reach while the rows scroll. */
.subs-top { position: sticky; top: var(--envbar-h); z-index: 6; margin-top: calc(-1 * var(--sp-24));
  padding: var(--sp-24) 0 var(--sp-4); background: var(--ground); border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-12); }
/* Token box: applied filters are chips inside one input; .panel offers fields, then values. */
.tokens { position: relative; margin-bottom: var(--sp-12); }
.tokenbox { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-6); min-height: 40px;
  padding: var(--sp-4) var(--sp-8); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); cursor: text; }
.tokenbox:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.tokenbox .ico { width: 16px; height: 16px; color: var(--muted); flex: none; }
.tokenbox input { flex: 1; min-width: 200px; border: none; outline: none; padding: var(--sp-4) 0;
  background: transparent; color: var(--text); font: inherit; font-size: var(--text-sm); }
.tokenbox .pending { font-size: var(--text-sm); font-weight: var(--w-semibold); color: var(--accent); }
.fchip { display: inline-flex; align-items: center; gap: var(--sp-4); max-width: 100%;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-8); border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--accent-soft); font-size: var(--text-sm); }
.fchip .k { color: var(--muted); }
.fchip .v { font-weight: var(--w-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fchip .x { display: grid; place-items: center; width: 20px; height: 20px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-size: var(--text-lg); line-height: 1; }
.fchip .x:hover { background: var(--surface); color: var(--bad); }
.tokens .panel { position: absolute; z-index: 25; top: calc(100% + var(--sp-4)); left: 0; width: 360px; max-width: 100%;
  max-height: 60vh; overflow-y: auto; padding: var(--sp-8); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-overlay); }
.tokens .suggest { border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); padding-bottom: var(--sp-4); }
.tokens .suggest code { font-size: var(--text-xs); }
.tokens .val { display: flex; flex-direction: column; gap: var(--sp-2); }
.tokens .val[hidden], .tokens .opt[hidden] { display: none; }
.tokens .hint { padding: var(--sp-4) var(--sp-8); font-size: var(--text-xs); color: var(--muted); }
.tokens .hint.bad { color: var(--bad); font-weight: var(--w-semibold); }
.opt { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-8); width: 100%;
  padding: var(--sp-6) var(--sp-8); border: none; border-radius: var(--radius-sm); background: none;
  color: var(--text); text-align: left; font-size: var(--text-sm); }
.opt:hover, .opt:focus-visible, .opt.hot { background: var(--accent-soft); color: var(--accent); }
.opt .kind { font-size: var(--text-xs); }
/* Status and PSP toggles. */
.quick { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-6); margin-bottom: var(--sp-12); }
.quick .label { margin-left: var(--sp-8); }
.quick .label:first-child { margin-left: 0; }
.qchip { padding: var(--sp-2) var(--sp-8); border: 1px solid var(--border); border-radius: var(--radius-full);
  background: var(--surface); color: var(--text); font-size: var(--text-sm); text-decoration: none; }
.qchip:hover { border-color: var(--accent); }
.qchip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: var(--w-semibold); }
.empty-act { margin-top: var(--sp-16); }
/* UTC or Local times: a segmented toggle in the page header. */
.seg { display: inline-flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--surface); flex: none; }
.seg .label { padding: 0 var(--sp-8) 0 var(--sp-6); }
.seg a { padding: var(--sp-4) var(--sp-8); border-radius: var(--radius-sm); color: var(--muted); text-decoration: none;
  font-size: var(--text-sm); white-space: nowrap; }
.seg a:hover { color: var(--text); background: var(--surface-2); }
.seg a.on { background: var(--accent-soft); color: var(--accent); font-weight: var(--w-semibold); }
/* Range calendar in the token box: first click sets the start day, second the end. */
.cal-wrap { display: flex; flex-direction: column; gap: var(--sp-8); margin-top: var(--sp-4); padding-top: var(--sp-8);
  border-top: 1px solid var(--border); }
.cal-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); font-size: var(--text-sm); }
.cal-nav { width: 28px; height: 28px; border: none; border-radius: var(--radius-sm); background: none; color: var(--text);
  font-size: var(--text-lg); line-height: 1; }
.cal-nav:hover { background: var(--surface-2); }
.cal-g { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: var(--sp-2); }
.cal-wd { text-align: center; font-size: var(--text-label); font-weight: var(--w-bold); color: var(--muted); padding: var(--sp-4) 0; }
.cal-d { height: 32px; border: none; background: none; color: var(--text); font-size: var(--text-sm);
  font-variant-numeric: tabular-nums; border-radius: 0; }
.cal-d:hover:not(:disabled) { outline: 1px solid var(--accent); outline-offset: -1px; border-radius: var(--radius-sm); }
.cal-d:disabled { color: var(--border-strong); cursor: not-allowed; opacity: .5; }
.cal-d.today { font-weight: var(--w-bold); text-decoration: underline; text-underline-offset: 3px; }
.cal-d.in { background: var(--accent-soft); color: var(--accent); }
.cal-d.start, .cal-d.end { background: var(--accent); color: var(--accent-ink); font-weight: var(--w-bold); }
.cal-d.start { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.cal-d.end { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.cal-d.start.end { border-radius: var(--radius-sm); }
.cal-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-8); font-size: var(--text-sm); }

@media (max-width: 860px) {
  .subs-top { position: static; margin-top: 0; padding-top: 0; }
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: none;
    border-bottom: 1px solid var(--border); }
  .main { padding: var(--sp-20) var(--sp-16) var(--sp-48); }
  .toast { left: var(--sp-16); }
}

@media (max-width: 520px) {
  :root { --envbar-h: 40px; }
  .envbar { white-space: normal; text-align: center; line-height: 1.25; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
