/* MergeSafe app shell and base components.
 *
 * Colours come only from tokens.css. Layout: a fixed sidebar with the
 * sections, a top bar with the org switcher and account menu, and a
 * scrolling content column. Below 860px the sidebar becomes a drawer.
 */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--text-base) / 1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-text); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
img, svg { max-width: 100%; }
.skip-link {
  position: absolute; left: var(--space-4); top: var(--space-2); z-index: 50;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--primary-text); font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }
/* Motion is decoration here: with reduced motion asked for, none of it runs. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition: none !important; scroll-behavior: auto !important;
  }
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- Shell ---- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  grid-template-areas: "side top" "side main";
  min-height: 100svh;
}
.sidebar {
  grid-area: side;
  position: sticky; top: 0; height: 100svh;
  display: flex; flex-direction: column; gap: var(--space-5);
  padding: var(--space-4) var(--space-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar .brand { display: flex; padding: var(--space-1) var(--space-2); }
.sidebar .brand img { height: 34px; width: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--fg-muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-sunken); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--surface-sunken); color: var(--fg); }
.nav a[aria-current="page"]::before {
  content: ""; width: 3px; height: 16px; margin-left: calc(-1 * var(--space-3));
  margin-right: calc(var(--space-3) - 3px); border-radius: 2px; background: var(--primary);
}
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; font-size: var(--text-sm); color: var(--fg-muted); padding: 0 var(--space-3); }

.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-5);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
/* Scoped so the later .btn rule's display cannot bring it back on wide screens. */
.topbar .menu-button { display: none; }

.org-switcher, .account {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg);
  font: inherit; font-size: var(--text-sm); font-weight: 500; cursor: pointer;
}
.avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--primary); color: var(--primary-fg);
  font-size: var(--text-xs); font-weight: 700;
}
.org-switcher .avatar { border-radius: 5px; }
.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + var(--space-1));
  min-width: 200px; padding: var(--space-1);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}
.menu-panel[hidden] { display: none; }
.menu-panel.left { left: 0; right: auto; }
.menu-panel a, .menu-panel button {
  display: flex; width: 100%; gap: var(--space-2); align-items: center;
  padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--fg); font: inherit; font-size: var(--text-sm);
  text-align: left; text-decoration: none; cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-sunken); }
.menu-panel hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-1) 0; }
.menu-label { padding: var(--space-2) var(--space-3) var(--space-1); font-size: var(--text-xs); color: var(--fg-muted); }

.content { grid-area: main; min-width: 0; padding: var(--space-6) var(--space-5) var(--space-7); }
.page { max-width: 1120px; margin: 0 auto; }
.page-header { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-3); margin-bottom: var(--space-5); }
.page-header .spacer { flex: 1; }
h1 { font-size: var(--text-2xl); line-height: 1.2; letter-spacing: -0.02em; font-weight: 650; margin: 0; }
h2 { font-size: var(--text-lg); font-weight: 620; margin: 0 0 var(--space-3); }
.subtitle { color: var(--fg-muted); margin: var(--space-1) 0 0; }
.stack { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); }
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
/* Phone overflow (owner test feedback): a grid or flex child defaults to
 * min-width:auto, so one wide table or long value widened the whole page.
 * Children may shrink; long values wrap; tables scroll inside .table-wrap. */
.page, .stack > *, .grid > *, .row > *, .card { min-width: 0; }
.stat-value, .stat-note, .card p { overflow-wrap: anywhere; }

/* ---- Button ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 34px; padding: 0 var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg);
  font: inherit; font-size: var(--text-sm); font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-sunken); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, var(--fg)); }
.btn-ghost { border-color: transparent; background: none; }
.btn-sort { padding: 0; min-height: 0; font: inherit; font-weight: 600; }
.btn-danger { color: var(--danger-fg); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-icon { padding: 0; width: 34px; }
.btn-icon svg { width: 18px; height: 18px; }

/* ---- Card ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--space-5);
}
.card-flush { padding: 0; overflow: hidden; }
.card-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: var(--text-base); }
.card-header .spacer { flex: 1; }
.stat-label { font-size: var(--text-sm); color: var(--fg-muted); }
.stat-value { font-size: var(--text-2xl); font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: var(--space-1); }
.stat-note { font-size: var(--text-sm); color: var(--fg-muted); margin-top: var(--space-1); }

/* ---- Table ---- */
/* A wide table scrolls inside its own box, never the page. Positioned, so
 * absolutely placed children (visually-hidden labels) are clipped with it. */
.table-wrap { position: relative; overflow-x: auto; max-width: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  text-align: left; font-weight: 600; color: var(--fg-muted);
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-5); background: var(--surface-sunken);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table > tbody:last-child > tr:last-child > td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-sunken) 55%, transparent); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .title { font-weight: 550; color: var(--fg); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.muted { color: var(--fg-muted); }

/* ---- Badge ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px var(--space-2); border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
  background: var(--neutral-bg); color: var(--neutral-fg);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-bg); color: var(--success-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-severity { border-radius: var(--radius-sm); font-family: var(--font-mono); }
.badge-severity::before { display: none; }

/* ---- Empty state ---- */
.empty {
  display: grid; justify-items: center; gap: var(--space-2); text-align: center;
  padding: var(--space-7) var(--space-5);
}
.empty svg { width: 40px; height: 40px; color: var(--fg-muted); }
.empty h2 { margin: var(--space-2) 0 0; }
.empty p { margin: 0 0 var(--space-3); color: var(--fg-muted); max-width: 42ch; }

/* ---- Error banner ---- */
.banner {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius);
  background: var(--danger-bg); color: var(--danger-fg); font-size: var(--text-sm);
}
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.banner strong { display: block; }
.banner-info { background: var(--info-bg); color: var(--info-fg); }
.banner-warning { background: var(--warning-bg); color: var(--warning-fg); }
.banner-danger { background: var(--danger-bg); color: var(--danger-fg); }
.banner .spacer { flex: 1; }

/* ---- Loading skeleton ---- */
.skeleton {
  display: block; height: 12px; border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-sunken) 25%,
    color-mix(in srgb, var(--surface-sunken) 50%, var(--surface)) 50%, var(--surface-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton + .skeleton { margin-top: var(--space-3); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---- Narrow screens: sidebar becomes a drawer ---- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(280px, 84vw);
    transform: translateX(-100%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  /* Hidden, not just off-screen, so a closed drawer's links are out of the tab order. */
  .shell[data-nav-open] .sidebar {
    transform: none; visibility: visible; transition: transform 0.2s ease;
    box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.35);
  }
  .topbar .menu-button { display: inline-flex; }
  .topbar { padding: 0 var(--space-4); }
  .content { padding: var(--space-5) var(--space-4) var(--space-6); }
  .account .name { display: none; }
}

/* ---- Top bar: page title and the always-visible credit balance ---- */
.topbar-title { font-weight: 600; }
.credits-pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 34px; padding: 0 var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg-muted);
  font-size: var(--text-sm); text-decoration: none; white-space: nowrap;
}
.credits-pill:hover { background: var(--surface-sunken); }
.credits-pill strong { color: var(--fg); font-variant-numeric: tabular-nums; }
.credits-pill .balance { color: var(--primary-text); }
.credits-pill .ring {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--primary);
}
.credits-pill .divider { width: 1px; height: 16px; background: var(--border); }
/* A low balance turns the pill to the warning colours so it is noticed before reviews stop. */
.credits-pill[data-low] { background: var(--warning-bg); border-color: transparent; color: var(--warning-fg); }
.credits-pill[data-low] .balance, .credits-pill[data-low] strong { color: var(--warning-fg); }
.credits-pill[data-low] .ring { border-color: var(--warning-fg); }
@media (max-width: 860px) {
  .credits-pill .spend, .credits-pill .divider { display: none; }
  .topbar-title { display: none; }
  .org-switcher > span:not(.avatar) { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; }
}

/* ---- Diffstat, as GitHub shows it: +added −removed and five blocks ---- */
.diffstat { display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.diffstat .add { color: var(--success-fg); font-weight: 600; }
.diffstat .del { color: var(--danger-fg); font-weight: 600; }
.diffstat .blocks { display: inline-flex; gap: 1px; }
.diffstat .blocks i { width: 8px; height: 8px; border-radius: 1px; background: var(--neutral-bg); }
.diffstat .blocks i.add { background: var(--success-fg); }
.diffstat .blocks i.del { background: var(--danger-fg); }

/* ---- Review rows: effort tier and expandable per-commit passes ---- */
.tier { font-size: var(--text-xs); font-weight: 600; color: var(--fg-muted); white-space: nowrap; }
.tier::before { content: ""; display: inline-block; width: 18px; height: 6px; margin-right: 6px; border-radius: 3px; vertical-align: 1px;
  background: linear-gradient(90deg, var(--primary) var(--fill), var(--neutral-bg) var(--fill)); }
.tier-budget { --fill: 33%; }
.tier-strong { --fill: 66%; }
.tier-mad-max { --fill: 100%; }
.table .expander-cell { width: 40px; padding-right: 0; }
.expander {
  display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--fg-muted); cursor: pointer;
}
.expander:hover { background: var(--surface-sunken); color: var(--fg); }
.expander svg { width: 16px; height: 16px; transition: transform 0.15s ease; }
.expander[aria-expanded="true"] svg { transform: rotate(90deg); }
.table tr.pass td { background: var(--surface-sunken); padding-top: var(--space-2); padding-bottom: var(--space-2); border-bottom-color: var(--border); }

/* ---- Segmented control (filters) ---- */
.segmented { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius-sm); background: var(--surface-sunken); }
.segmented button {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--space-3);
  border: 0; border-radius: 5px; background: none; color: var(--fg-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 550; cursor: pointer;
}
.segmented button:hover { color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.segmented .count { font-size: var(--text-xs); color: var(--fg-muted); font-variant-numeric: tabular-nums; }

/* ---- PR icon: shape is the PR state, colour is the review status ---- */
.pr-state { display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 5px; }
.pr-state svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tone-success { background: var(--success-bg); color: var(--success-fg); }
.tone-warning { background: var(--warning-bg); color: var(--warning-fg); }
.tone-danger { background: var(--danger-bg); color: var(--danger-fg); }
.tone-info { background: var(--info-bg); color: var(--info-fg); }
.tone-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

/* ---- Severity legend ---- */
.info { display: inline-block; vertical-align: middle; }
.info-button {
  width: 16px; height: 16px; margin-left: 4px; padding: 0; border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--fg-muted); font: 700 10px/1 var(--font-sans); cursor: pointer;
}
.info-button:hover { color: var(--fg); }
.legend-panel { left: 0; right: auto; width: min(360px, 86vw); padding: var(--space-3); text-transform: none; letter-spacing: 0; font-weight: 400; white-space: normal; }
.legend { margin: 0; display: grid; gap: var(--space-3); font-size: var(--text-sm); color: var(--fg); }
.legend dt { font-weight: 600; }
.legend dd { margin: 2px 0 0; }
.legend-link { display: block; margin-top: var(--space-3); font-size: var(--text-sm); font-weight: 600; }

/* ---- Radio choice list (settings) ---- */
.choice-list { border: 0; padding: 0; margin: var(--space-4) 0 0; display: grid; gap: var(--space-2); }
.choice { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, var(--surface)); }
.choice input { margin-top: 3px; accent-color: var(--primary); }
.choice strong { display: block; font-weight: 600; }
.choice .muted { font-size: var(--text-sm); }

/* ---- Detailed view: people and trigger ---- */
.person { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.avatar-sm { width: 18px; height: 18px; font-size: 10px; }
.trigger { font-size: var(--text-xs); font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--neutral-bg); color: var(--neutral-fg); }
.trigger-manual { background: var(--info-bg); color: var(--info-fg); }
.trigger-api { background: var(--warning-bg); color: var(--warning-fg); }
.table td:has(.trigger) { white-space: nowrap; }

/* Severity reasons: one bullet each, the score effect last and set apart. */
.reasons { margin: var(--space-1) 0 0; padding-left: 1.1em; font-size: var(--text-sm); color: var(--fg); }
.reasons li + li { margin-top: 2px; }
.reasons .effect { list-style: none; margin-left: -1.1em; margin-top: var(--space-1); color: var(--fg-muted); font-weight: 550; }

/* Severity reasons: one bullet each, the score effect last and set apart. */
.reasons { margin: var(--space-1) 0 0; padding-left: 1.1em; font-size: var(--text-sm); color: var(--fg); }
.reasons li + li { margin-top: 2px; }
.reasons .effect { list-style: none; margin-left: -1.1em; margin-top: var(--space-1); color: var(--fg-muted); font-weight: 550; }

/* ---- Collapsible sidebar (wide screens only; narrow screens use the drawer) ---- */
.sidebar { transition: width 0.18s ease; }
.sidebar .brand { align-items: center; }
.sidebar .mark { display: none; height: 28px; width: auto; }
.collapse-button { position: absolute; top: var(--space-4); right: var(--space-3); }
.collapse-button svg { transition: transform 0.18s ease; }
@media (min-width: 861px) {
  .shell { transition: grid-template-columns 0.18s ease; }
  .shell[data-collapsed] { grid-template-columns: 64px minmax(0, 1fr); }
  .shell[data-collapsed] .sidebar { padding-inline: var(--space-2); align-items: center; }
  .shell[data-collapsed] .sidebar .logo { display: none; }
  .shell[data-collapsed] .sidebar .mark { display: block; }
  .shell[data-collapsed] .nav a { justify-content: center; padding: var(--space-2); }
  .shell[data-collapsed] .nav .label, .shell[data-collapsed] .sidebar-foot { display: none; }
  .shell[data-collapsed] .nav a[aria-current="page"]::before { display: none; }
  .shell[data-collapsed] .nav a[aria-current="page"] { box-shadow: inset 0 0 0 1px var(--border); }
  .shell[data-collapsed] .collapse-button { position: static; order: 1; }
  .shell[data-collapsed] .collapse-button svg { transform: scaleX(-1); }
}
@media (max-width: 860px) { .collapse-button { display: none; } }
.inline-number {
  width: 4.5em; height: 26px; padding: 0 var(--space-2); margin: 0 2px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg); font: inherit; font-variant-numeric: tabular-nums;
}

/* ---- API keys ---- */
.card-header .subtitle { font-size: var(--text-sm); }
.banner-success { background: var(--success-bg); color: var(--success-fg); margin: var(--space-4) var(--space-5) 0; }
.key-reveal { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.key-reveal code { padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg); word-break: break-all; user-select: all; }
.key-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.key-form label { font-size: var(--text-sm); font-weight: 600; }
.key-form input {
  flex: 1 1 220px; height: 34px; padding: 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg); font: inherit;
}
.price-note { font-size: var(--text-xs); font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--success-bg); color: var(--success-fg); }

/* ---- Toggle switch and toggle list (notification preferences) ---- */
.switch {
  appearance: none; flex: none; position: relative; width: 36px; height: 20px; margin: 2px 0 0; border-radius: 999px;
  background: var(--neutral-bg); border: 1px solid var(--border); cursor: pointer; transition: background 0.15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--fg-muted); transition: transform 0.15s ease, background 0.15s ease;
}
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::after { transform: translateX(16px); background: var(--primary-fg); }
.toggle-list { list-style: none; margin: 0; padding: 0; }
.toggle-list li { display: flex; gap: var(--space-4); align-items: flex-start; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.toggle-list li:last-child { border-bottom: 0; }
.toggle-list label { display: block; cursor: pointer; }
.toggle-list p { margin: 2px 0 0; font-size: var(--text-sm); }
.profile-row { display: flex; align-items: center; gap: var(--space-3); }
.avatar-lg { width: 44px; height: 44px; font-size: var(--text-lg); }

/* ---- Collapsible settings sections ---- */
.section summary {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5);
  cursor: pointer; list-style: none;
}
.section summary::-webkit-details-marker { display: none; }
.section summary:hover { background: color-mix(in srgb, var(--surface-sunken) 50%, transparent); }
.section-title { font-weight: 620; }
.section-value { margin-left: auto; font-size: var(--text-sm); color: var(--fg-muted); text-align: right; }
.section .chevron { width: 18px; height: 18px; flex: none; color: var(--fg-muted); transition: transform 0.15s ease; }
.section[open] .chevron { transform: rotate(180deg); }
.section[open] summary { border-bottom: 1px solid var(--border); }
.section-body { padding: var(--space-4) var(--space-5) var(--space-5); }
.section-body > .subtitle { margin: 0; font-size: var(--text-sm); }
.section-body.flush { padding: 0; }
.section-body.flush > .subtitle { padding: var(--space-4) var(--space-5) 0; }
.section-actions { padding: var(--space-3) var(--space-5) var(--space-4); border-bottom: 1px solid var(--border); }

/* ---- Spending limits ---- */
.limit-list { display: grid; margin-top: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.limit-row { display: grid; grid-template-columns: 90px 150px minmax(0, 1fr); gap: var(--space-4); align-items: center; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.limit-row:last-child { border-bottom: 0; }
.limit-usage { font-size: var(--text-sm); display: grid; gap: var(--space-1); }
.money-input { display: flex; align-items: center; height: 34px; padding-left: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg-muted); }
.money-input:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.money-input input { width: 100%; height: 100%; padding: 0 var(--space-2) 0 var(--space-1); border: 0; outline: 0; background: none; color: var(--fg); font: inherit; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--neutral-bg); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--primary); }
.meter.near span { background: var(--warning-fg); }
.meter.over span { background: var(--danger-fg); }
.choice-legend { padding: 0; margin-bottom: var(--space-1); font-weight: 600; font-size: var(--text-sm); }
.choice-list .choice .muted { display: block; }
@media (max-width: 860px) {
  .limit-row { grid-template-columns: 80px minmax(0, 1fr); }
  .limit-usage { grid-column: 1 / -1; }
}

/* ---- Detailed reviews: full width. PR cell: title line, then repo · #number · time ---- */
.page-wide { max-width: none; }
.pr-cell { min-width: 280px; }
.pr-name { display: flex; align-items: flex-start; gap: var(--space-2); }
.pr-name .title { font-size: var(--text-base); line-height: 22px; }
.pr-meta { margin: 2px 0 0 30px; font-size: var(--text-sm); color: var(--fg-muted); }
.pr-number { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--fg); }
.page-wide .table td, .page-wide .table th { padding-left: var(--space-3); padding-right: var(--space-3); }

/* ---- Filter bar: free-text search, then dropdown filters ---- */
.card-header-stack { flex-direction: column; align-items: stretch; gap: var(--space-3); }
.filter-bar { display: grid; gap: var(--space-3); }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--fg-muted); pointer-events: none; }
.search input {
  width: 100%; height: 36px; padding: 0 var(--space-3) 0 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); font: inherit;
}
.search input::placeholder { color: var(--fg-muted); }
.select select {
  height: 32px; padding: 0 28px 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 14px;
  color: var(--fg); font: inherit; font-size: var(--text-sm); appearance: none; cursor: pointer;
}
.select select.is-set { border-color: var(--primary); background-color: color-mix(in srgb, var(--primary) 8%, var(--surface)); font-weight: 600; }

/* ---- Billing: stacked rows inside a card, usage bar, transactions ---- */
.rows > .row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.rows > .row:last-child { border-bottom: 0; }
.row-main { flex: 1 1 320px; min-width: 0; }
.row-main p { margin: 2px 0 0; font-size: var(--text-sm); }
.row-block { display: block !important; padding-inline: 0 !important; }
.row-block > .title { padding: 0 var(--space-5) var(--space-2); }
.title { font-weight: 600; }
.usage-figures { display: flex; justify-content: space-between; align-items: baseline; margin: var(--space-2) 0; max-width: 560px; font-variant-numeric: tabular-nums; }
.usage-spent, .usage-charged { font-size: var(--text-xl); font-weight: 650; color: var(--primary-text); }
.meter-lg { height: 8px; border-radius: 4px; max-width: 560px; }
.amounts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.table-plain th { background: none; }
.amount { font-weight: 600; }
.amount-in { color: var(--success-fg); }
.amount-failed { color: var(--fg-muted); text-decoration: line-through; }

/* ---- Integrations ---- */
.integrations { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.integration { padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); }
.integration-head { display: flex; align-items: center; gap: var(--space-3); }
.integration-head .soon { margin-left: auto; }
.integration-head .soon::before { display: none; }
.integration-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 8px; background: var(--logo-bg); border: 1px solid var(--border); color: var(--ink); }
.integration-icon svg { width: 22px; height: 22px; }
.integration p { margin: var(--space-2) 0 0; font-size: var(--text-sm); }

/* ---- Usage history chart: one series, recessive grid, hover tooltip ---- */
.usage-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); padding: 0 var(--space-5) var(--space-3); }
.usage-head .stat-value { margin-top: 0; }
.chart { position: relative; padding: 0 var(--space-5); }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--fg-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--primary); }
.chart .hit { fill: transparent; }
.chart .bar-slot.active .hit { fill: color-mix(in srgb, var(--fg) 6%, transparent); }
.chart-tip {
  position: absolute; top: -8px; padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm);
  background: var(--fg); color: var(--bg); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; pointer-events: none;
}
.share { display: flex; align-items: center; gap: var(--space-2); min-width: 140px; }
.share .meter { flex: 1; }
/* Help links sit at the bottom of the sidebar, above the build note. */
.nav-foot { margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--border); }
.nav-foot + .sidebar-foot { margin-top: 0; }

/* ---- Forms ---- */
.form { display: grid; gap: var(--space-4); max-width: 640px; }
.field { display: grid; gap: var(--space-1); }
.field label { font-size: var(--text-sm); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); font: inherit;
}
.field input, .field select { height: 36px; }
.field textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
.form-note { margin: 0; font-size: var(--text-sm); }
.form-error { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--danger-bg); color: var(--danger-fg); font-size: var(--text-sm); }
.form-error[hidden] { display: none; }
.form-actions { display: flex; justify-content: flex-end; }

/* ---- Clusters ---- */
.chips { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px var(--space-2); border-radius: var(--radius-sm); background: var(--surface-sunken); font-size: var(--text-xs); font-family: var(--font-mono); }
.chip-note { font-family: var(--font-sans); color: var(--warning-fg); font-weight: 600; }
.link-row a.title { color: var(--fg); text-decoration: none; }
.link-row a.title:hover { text-decoration: underline; }
.back { display: inline-block; margin-bottom: var(--space-3); font-size: var(--text-sm); text-decoration: none; }
.stat-badge .badge { font-size: var(--text-sm); }
.summary { margin: 0; max-width: 72ch; }
.edge { display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.edge .arrow { color: var(--fg-muted); }

/* ---- Sign-in and first run (auth.js) ---- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: var(--space-5) var(--space-4); background: var(--bg); }
.gate[hidden], .shell[hidden] { display: none; }
.gate-card { width: 100%; max-width: 520px; display: grid; gap: var(--space-3); }
.gate-logo { height: 28px; width: auto; justify-self: start; margin-bottom: var(--space-3); }
.gate-body { display: grid; gap: var(--space-3); }
.gate-body h1:focus { outline: none; }
.gate-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.gate-steps { margin: 0; padding-left: var(--space-5); display: grid; gap: var(--space-2); }
.gate-fine, .gate-status { color: var(--fg-muted); font-size: var(--text-sm); margin: 0; }
.btn-lg { min-height: 42px; padding: 0 var(--space-5); font-size: var(--text-base); }
.org-list { list-style: none; margin: 0; padding: 0; outline: none; }
.org-list li { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); font-size: var(--text-sm); cursor: pointer; }
.org-list li:hover, .org-list li.active { background: var(--surface-sunken); }
.org-list li[aria-selected="true"] { font-weight: 600; }
.org-list .org-label { flex: 1; }
.org-list .org-balance { color: var(--fg-muted); font-weight: 400; }
.org-list .org-check { width: 1em; text-align: center; }
.org-single { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: 500; }
.org-single[hidden], .org-switcher[hidden] { display: none; }
.org-single .avatar { border-radius: 5px; }
.org-notice { margin-bottom: var(--space-4); }
.credits-pill[hidden] { display: none; }

/* ---- Admin (issue 794): all-orgs switcher, view-as form, "viewing as" banner ---- */
.org-admin { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; padding: 0 var(--space-1) var(--space-2); }
.org-admin input, .view-as-form input {
  flex: 1; min-width: 0; font: inherit; font-size: var(--text-sm); padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg);
}
.org-admin-status:empty, .view-as-error:empty, .view-as-exit-error:empty { display: none; }
.org-admin-status, .view-as-error { font-size: var(--text-sm); color: var(--danger-fg); width: 100%; }
.view-as-form { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-2) var(--space-3); }
.view-as-form label { width: 100%; font-size: var(--text-sm); color: var(--fg-muted); }
.menu-panel .view-as-form button { width: auto; }
/* Inverse colours for the highest contrast either theme has; fixed so it is on
 * every page, the gate screens and the narrow-screen drawer alike. */
.view-as-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); background: var(--fg); color: var(--bg); font-weight: 600;
}
.view-as-banner[hidden], [data-admin-only][hidden] { display: none; }
.view-as-banner .view-as-text { flex: 1; min-width: 12ch; }
.view-as-banner .btn { background: var(--bg); color: var(--fg); }
body.read-only { padding-bottom: 4.5rem; }
body.read-only [data-write] { display: none !important; }

/* ---- Reviews filters: "Showing X of Y loaded" ---- */
.filter-count { font-size: var(--text-sm); margin-left: auto; }
.section-note { margin: calc(-1 * var(--space-2)) 0 var(--space-3); font-size: var(--text-sm); }

/* ---- Preview pages (Settings, Integrations, Clusters, Profile, Contact) ---- */
.preview-banner { margin-bottom: var(--space-5); }
.preview-note { display: inline-block; margin-left: var(--space-2); font-size: var(--text-sm); font-weight: 600; color: var(--warning-fg); background: var(--warning-bg); padding: 1px var(--space-2); border-radius: var(--radius-sm); }

/* ---- Buy credits dialog and auto-refill (preview until Stripe is live) ---- */
.dialog-backdrop { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: var(--space-4); background: color-mix(in srgb, var(--bg) 40%, transparent); box-shadow: inset 0 0 0 100vmax rgb(0 0 0 / 0.35); }
.dialog { width: min(460px, 100%); max-height: calc(100vh - 2 * var(--space-4)); overflow-y: auto; display: grid; gap: var(--space-3); box-shadow: 0 16px 48px rgb(0 0 0 / 0.25); }
.dialog p { margin: 0; }
.dialog-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }
.dialog-head h2 { margin: 0; }
.dialog-head .spacer { flex: 1; }
.amount-choices { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.amount-choices legend { font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--space-2); }
.amount-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.amount-choice span { display: inline-flex; align-items: center; min-height: 34px; padding: 0 var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; }
.amount-choice input:checked + span { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); color: var(--primary-text); }
.amount-choice input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.topup-buys { font-weight: 600; }
.refill-toggle { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; cursor: pointer; }
.refill-rule { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ---- Billing: spending over time (issue 818) ---- */
.usage-card { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); }
.usage-card > * { min-width: 0; }
.usage-custom { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-sm); }
.usage-custom input { height: 32px; padding: 0 var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--fg); font: inherit; }
.usage-totals { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-5); }
.usage-total { font-size: var(--text-lg); font-variant-numeric: tabular-nums; }
.usage-view { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }
.usage-chart { padding: 0; }
.usage-chart svg { max-width: 100%; }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--primary); }
.chart .dot-active { stroke: var(--surface); stroke-width: 2; }
.chart .cursor { stroke: var(--fg-muted); stroke-dasharray: 3 3; }
.usage-table tbody th, .usage-table tfoot th { background: none; color: var(--fg); font-size: inherit; text-transform: none; letter-spacing: 0; font-weight: 500; }
.usage-table tfoot th, .usage-table tfoot td { font-weight: 650; border-top: 1px solid var(--border); }
.usage-empty { margin: 0; padding: var(--space-4) 0; }

/* ---- Settings on the API (issue 762) ---- */
fieldset.plain { min-width: 0; margin: 0; padding: 0; border: 0; }
.save-row { align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
.save-status { margin: 0; padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.save-status:empty { display: none; }
.key-status { margin: var(--space-3) var(--space-5) 0; }
.commit-limit { margin-top: var(--space-3); }
.commit-limit[hidden] { display: none; }
.key-confirm { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2); }
.code-snippet { margin: var(--space-2) 0 0; padding: var(--space-3); overflow-x: auto; border-radius: var(--radius-sm); background: var(--surface); font-size: var(--text-sm); white-space: pre; }
