/* ============================================================================
   components.css — one rule block per component. The class vocabulary here
   is the one every section uses; components.js emits exactly these names.
   Colours and sizes come from tokens.css only.
   ========================================================================== */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--control-h); padding: 0 14px; border-radius: var(--r-1);
  font-weight: 500; line-height: 1; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }

/* a name that opens a record: reads as a link, behaves as a button */
.link { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 500; text-align: left; }
.link:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---------- controls and fields ---------- */
.control {
  display: block; width: 100%; height: var(--control-h); padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-1);
  background: var(--surface); color: var(--ink);
}
.control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.control:disabled { background: var(--surface-2); color: var(--ink-3); }
.control.is-error, .control[aria-invalid="true"] { border-color: var(--bad); }
textarea.control { height: auto; min-height: 72px; padding: var(--s-2) 10px; resize: vertical; line-height: 1.5; }
select.control { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% - 2px), calc(100% - 10px) calc(50% - 2px);
  background-size: 5px 5px; background-repeat: no-repeat; }
input.control[type="checkbox"] { width: 20px; height: 20px; padding: 0; accent-color: var(--accent); display: inline-block; }
.field { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.field > label { font-size: var(--text-sm); color: var(--ink-2); }
.field:has(> input[type="checkbox"]) { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: var(--s-2); }
.field:has(> input[type="checkbox"]) > label { font-size: var(--text-base); color: var(--ink); }
.inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); }
.inline > .field { flex: 0 1 220px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3) var(--s-4); }

/* ---------- panel and prose ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.note { color: var(--ink-2); }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }
.details { display: grid; grid-template-columns: minmax(120px, 160px) minmax(0, 1fr); gap: var(--s-2) var(--s-3); }
.details dt { font-size: var(--text-sm); color: var(--ink-3); padding-top: 2px; }
.details dd { min-width: 0; overflow-wrap: anywhere; }
.code {
  font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-1);
  padding: 10px 12px; white-space: pre-wrap; overflow-x: auto;
}

/* ---------- status word: a dot and a word, never uppercase ---------- */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px var(--s-2) 2px 6px; border-radius: var(--r-1);
  font-weight: 500; white-space: nowrap; color: var(--ink);
}
.status-dot { width: 8px; height: 8px; border-radius: var(--r-round); background: currentColor; flex: none; }
.status-ok { background: var(--ok-soft); } .status-ok .status-dot { color: var(--ok); }
.status-info { background: var(--info-soft); } .status-info .status-dot { color: var(--info); }
.status-warn { background: var(--warn-soft); } .status-warn .status-dot { color: var(--warn); }
.status-bad { background: var(--bad-soft); } .status-bad .status-dot { color: var(--bad); }
.status-muted { background: var(--muted-soft); } .status-muted .status-dot { color: var(--muted); }

/* ---------- stat card ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-3); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-3) var(--s-4); min-width: 0; container-type: inline-size; }
.stat-label { display: block; font-size: var(--text-sm); color: var(--ink-3); }
.stat-value { display: block; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: clamp(14px, 10.5cqi, 28px); font-weight: 500; line-height: 1.25; margin-top: var(--s-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { display: block; font-size: var(--text-sm); color: var(--ink-2); margin-top: 2px; }

/* ---------- banner ---------- */
.banner { padding: var(--s-3) var(--s-4); border-radius: var(--r-2); border: 1px solid var(--line); border-left-width: 4px; background: var(--surface); }
.banner-error { border-color: var(--bad); }
.banner-ok { border-color: var(--ok); }
.banner-info { border-color: var(--info); }
.banner-warn { border-color: var(--warn); }

/* ---------- list: tools, table, row cards, pager ---------- */
.list { padding: 0; overflow: hidden; }
.list-heading { padding: var(--s-4) var(--s-4) 0; }
.list-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4) 0; }
.list-tools .search { flex: 1 1 220px; max-width: 360px; }
.list-status { padding: var(--s-2) var(--s-4) 0; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.table-wrap { overflow-x: auto; margin-top: var(--s-3); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: var(--text-sm); font-weight: 500; color: var(--ink-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table th.u-num, .table td.u-num { text-align: right; }
.table th.u-num { font-family: var(--font-sans); }
.table td.u-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table td.empty { text-align: center; color: var(--ink-3); padding: var(--s-5) var(--s-4); }
.row-cards { list-style: none; margin: var(--s-3) 0 0; padding: 0 var(--s-4) var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.row-card { display: flex; align-items: flex-start; gap: var(--s-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-3) var(--s-4); }
.row-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s-1); }
.row-card-title { font-weight: 500; }
.row-card-facts { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); font-size: var(--text-sm); color: var(--ink-2); }
.row-card-fact { display: inline-flex; align-items: baseline; gap: var(--s-1); min-width: 0; }
.row-card-label { color: var(--ink-3); }
.row-card-fact .u-num { text-align: left; }
.row-card-menu { flex: none; }
.row-card.empty { color: var(--ink-3); justify-content: center; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); color: var(--ink-2); font-size: var(--text-sm); }
.pager .btn { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.skeleton { display: inline-block; height: 14px; border-radius: var(--r-1); background: var(--skeleton); animation: cp-shimmer 1.2s ease-in-out infinite; }
@keyframes cp-shimmer { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- tabs ---------- */
.tabset { display: flex; flex-direction: column; gap: var(--s-4); }
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  padding: 10px 12px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: transparent; color: var(--ink-2); white-space: nowrap; border-radius: 0;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 500; border-bottom-color: var(--accent); }
.tab-content { display: flex; flex-direction: column; gap: var(--s-4); }

/* ---------- access editor: one row per permission, view/manage pairs ---------- */
.perm-grid { display: flex; flex-direction: column; }
.perm-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--s-3); align-items: center; padding: var(--s-2) 0; border-bottom: 1px solid var(--line); }
.perm-row:last-child { border-bottom: 0; }
.perm-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.perm-label small { display: block; font-size: var(--text-sm); color: var(--ink-3); }

/* ---------- menu ---------- */
.more { width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: var(--r-1); background: transparent; color: var(--ink-3); font-size: var(--text-md); line-height: 1; }
.more:hover, .more[aria-expanded="true"] { background: var(--surface-2); color: var(--ink); }
.menu {
  position: fixed; z-index: 40; min-width: 180px; padding: var(--s-1);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-1); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.menu-item { display: block; width: 100%; text-align: left; min-height: 36px; padding: var(--s-2) 10px; border: 0; border-radius: var(--r-1); background: transparent; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline-offset: -2px; }

/* ---------- dialog (native <dialog>) ---------- */
.dialog {
  width: min(560px, calc(100vw - var(--s-6))); max-height: calc(100vh - var(--s-6));
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-2);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
.dialog-wide { width: min(760px, calc(100vw - var(--s-6))); }
.dialog::backdrop { background: var(--scrim); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - var(--s-6)); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding: 14px var(--s-4); border-bottom: 1px solid var(--line); }
.dialog-heading { min-width: 0; }
.dialog-heading h2 { outline: none; }
.dialog-heading p { color: var(--ink-2); margin-top: 2px; }
.dialog-close { flex: none; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: var(--r-1); background: transparent; color: var(--ink-3); font-size: var(--text-lg); line-height: 1; }
.dialog-close:hover { background: var(--surface-2); color: var(--ink); }
.dialog-body { padding: var(--s-4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-3); }
.dialog-body .panel { padding: 0; border: 0; background: transparent; }
.dialog-body .list-heading, .dialog-body .row-cards { padding-left: 0; padding-right: 0; }
.dialog-body .row-cards { padding-bottom: 0; }
.dialog-body .table-wrap { margin-top: var(--s-2); }
.dialog-feedback { padding: 0 var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); }
.dialog-feedback > :not([hidden]) { margin-bottom: var(--s-2); }
.discard { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); border: 1px solid var(--warn); border-left-width: 4px; border-radius: var(--r-2); }
.discard p { flex: 1 1 100%; }
.dialog-footer { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); }

/* ---------- drawer (non-modal, right-anchored) ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(480px, 100vw);
  display: flex; flex-direction: column; margin: 0; padding: 0;
  background: var(--surface); color: var(--ink); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform 160ms ease-out;
}
.drawer-open { transform: none; }
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 14px var(--s-4); border-bottom: 1px solid var(--line); }
.drawer-body { padding: var(--s-4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s-3); }
/* the grab pill and the scrim exist at every width; they only paint as a bottom sheet (narrow block) */
.drawer-grab { display: none; }
.scrim-sheet { display: none; }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

/* ---------- operations: the state card, phase strip, exception cards ---------- */
.ops-state { display: flex; flex-direction: row; align-items: center; gap: var(--s-5); }
.ops-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ops-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.ops-copy p { color: var(--ink); }
.ops-actions { flex: none; display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: flex-end; align-items: center; }
.status-big { font-size: var(--text-lg); font-weight: 600; gap: 10px; padding: 4px 12px 4px 10px; }
.status-big .status-dot { width: 10px; height: 10px; }
.stat-value .status { font-family: var(--font-sans); font-size: clamp(14px, 11cqi, 20px); font-weight: 600; }
.phases { display: flex; flex-wrap: wrap; gap: var(--s-1) 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-2); }
.phase { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-right: 1px solid var(--line); flex: 1 1 auto; white-space: nowrap; min-width: 0; }
.phase:last-child { border-right: 0; }
.phase-mark { width: 8px; height: 8px; border-radius: var(--r-round); background: currentColor; flex: none; }
.phase-name { font-size: var(--text-sm); color: var(--ink-2); }
.phase-time { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-3); margin-left: auto; padding-left: var(--s-2); }
.phase-ok .phase-mark { color: var(--ok); }
.phase-on .phase-mark { color: var(--info); }
.phase-on .phase-name { color: var(--ink); font-weight: 500; }
.phase-bad .phase-mark { color: var(--bad); }
.phase-bad .phase-time { color: var(--bad); }
.phase-wait .phase-mark { background: transparent; border: 1px solid var(--line-strong); }
.slot { min-width: 0; }
.kind-head { display: flex; align-items: baseline; gap: var(--s-2); margin-top: var(--s-2); }
.kind-head .spacer { flex: 1 1 auto; }
.kind-head h2 { font-size: var(--text-md); }
.kind-count { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-3); }
.xcard { display: flex; align-items: flex-start; gap: var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-3) var(--s-4); }
.xcard-select { flex: none; padding-top: 2px; }
.xcard-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.xcard-head { display: flex; align-items: flex-start; gap: var(--s-3); }
.xcard-head .status { width: 88px; flex: none; margin-top: 2px; }
.xcard-title { font-weight: 500; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.xcard-sub { font-weight: 400; font-size: var(--text-sm); color: var(--ink-3); }
.xcard-facts { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px var(--s-3); margin: 0; }
.xcard-facts dt { font-size: var(--text-sm); color: var(--ink-3); padding-top: 2px; }
.xcard-facts dd { min-width: 0; overflow-wrap: anywhere; }
.xcard-actions { flex: none; display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: flex-end; align-items: center; }
.xcard-actions .btn { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.selbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding: 10px var(--s-4); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-2); box-shadow: var(--shadow); }
.selbar-count { font-weight: 500; flex: 1; }
.selbar .btn { height: 32px; padding: 0 12px; font-size: var(--text-sm); }
.hist-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: 10px 0; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: 0; }
.hist-day { font-family: var(--font-mono); width: 56px; flex: none; }
.hist-meta { margin-left: auto; font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-3); }
.hist-when { flex: none; font-family: var(--font-mono); font-size: var(--text-sm); color: var(--ink-3); }
/* exact source text: one line per record, the only horizontal scroll on the page */
.code-line { white-space: pre; overflow-wrap: normal; word-break: normal; }

/* ---------- readiness: the payment-readiness panel, per-Vaulter rows, finding rows ---------- */
.readiness-head { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.readiness-head h3 { font-size: var(--text-md); }
.readiness .meta { font-size: var(--text-sm); color: var(--ink-3); }
.readiness-summary { display: flex; flex-direction: column; gap: var(--s-3); }
.readiness-sub { font-size: var(--text-sm); color: var(--ink-3); }
.readiness-detail { padding: var(--s-2) 0 0; }
.ready-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ready-rows { display: flex; flex-direction: column; gap: var(--s-2); }
.ready-row { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-3) var(--s-4); border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); container-type: inline-size; }
.ready-row.is-selected { box-shadow: inset 2px 0 0 var(--accent); }
.ready-name { flex: 0 0 180px; font-weight: 500; min-width: 0; }
.ready-name .link { color: var(--ink); }
.ready-row .status { flex: none; }
.ready-facts { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); font-size: var(--text-sm); color: var(--ink-2); min-width: 0; }
.ready-fact { display: inline-flex; align-items: baseline; gap: var(--s-1); }
.ready-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: clamp(13px, 2.6cqi, 18px); font-weight: 500; color: var(--ink); }
.findings { display: flex; flex-direction: column; gap: var(--s-2); }
.finding { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.finding .status { flex: none; }
.finding a, .finding span.finding-text { min-width: 0; overflow-wrap: anywhere; }
.readiness-helper { font-size: var(--text-sm); color: var(--ink-3); }

/* ---------- toasts: confirmation only ---------- */
.toast-host { position: fixed; left: 50%; bottom: var(--s-5); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: var(--s-2); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: var(--r-1); background: var(--ink); color: var(--paper); box-shadow: var(--shadow-lg); font-size: var(--text-sm); }
.toast-bad { background: var(--bad); color: #FFFFFF; }

/* ---------- narrow ---------- */
@media (max-width: 600px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .inline > .field { flex: 1 1 100%; }
  .inline > .btn { width: 100%; }
  .details { grid-template-columns: minmax(0, 1fr); gap: var(--s-1); }
  .details dd { margin-bottom: var(--s-2); }
  .dialog, .dialog-wide { width: 100vw; height: 100vh; max-height: none; max-width: none; inset: 0; margin: 0; border-radius: 0; border: 0; }
  .dialog-form { max-height: none; height: 100%; }
  .dialog-body { flex: 1; }
  /* the drawer is a bottom sheet: grab pill, scrim, slides up */
  .drawer { top: auto; left: 0; right: 0; bottom: 0; width: 100vw; max-height: 88vh; border-left: 0; border-top: 1px solid var(--line); border-radius: var(--r-2) var(--r-2) 0 0; transform: translateY(100%); }
  .drawer-open { transform: none; }
  .drawer-header { flex-wrap: wrap; padding-top: var(--s-2); }
  .drawer-grab { display: block; flex: 1 1 100%; width: 36px; height: 4px; margin: 0 auto var(--s-2); border-radius: var(--r-round); background: var(--line-strong); }
  .scrim-sheet { display: block; position: fixed; inset: 0; z-index: 29; background: var(--scrim); }
  .dialog-footer { flex-direction: column-reverse; }
  .dialog-footer .btn { width: 100%; }
  .ops-state { flex-direction: column; align-items: stretch; }
  .ops-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ops-actions { flex-direction: column; align-items: stretch; }
  .ops-actions .btn { width: 100%; }
  .phase { flex: 0 0 50%; }
  .phase:nth-child(2n) { border-right: 0; }
  .xcard { flex-wrap: wrap; }
  .xcard-head { flex-direction: column; gap: var(--s-2); }
  .xcard-head .status { width: auto; }
  .xcard-facts { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .xcard-facts dd { margin-bottom: var(--s-1); }
  .xcard-actions { flex: 1 1 100%; flex-direction: column; align-items: stretch; }
  .xcard-actions .btn { width: 100%; height: var(--control-h); }
  .selbar { position: sticky; bottom: var(--s-2); z-index: 10; }
  .ready-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ready-row { flex-direction: column; align-items: stretch; gap: var(--s-2); }
  .ready-name { flex: none; }
  .ready-row .status { align-self: flex-start; }
  .readiness-head .btn { width: 100%; }
  .perm-row { grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
}
