/* ==========================================================================
   Components: every reusable UI element. Pages compose these; they never restyle them.
   ========================================================================== */

/* ---------- Layout primitives ---------- */
.stack { display: grid; gap: var(--s-5); align-content: start; min-width: 0; }
.stack-sm { display: grid; gap: var(--s-3); align-content: start; min-width: 0; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); min-width: 0; }
.cluster-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); }
.split { display: grid; gap: var(--s-5); grid-template-columns: minmax(0, 1fr); align-items: start; }
.cols-2, .cols-3, .cols-4 { display: grid; gap: var(--s-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .cols-2, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .split { grid-template-columns: minmax(0, 1fr) 340px; } .split-wide { grid-template-columns: minmax(0, 1fr) 380px; } }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); }
.page-header > :first-child { min-width: 0; flex: 1 1 320px; }
.page-eyebrow { display: inline-flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.page-title { font-size: var(--fs-2xl); overflow-wrap: anywhere; }
.page-lede { margin: var(--s-2) 0 0; color: var(--text-2); max-width: 68ch; }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-top: var(--s-3); color: var(--text-3); font-size: var(--fs-sm); }
.page-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); margin: 0 0 var(--s-3); padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--text-3); }
.crumbs li { display: inline-flex; align-items: center; gap: var(--s-1); min-width: 0; }
.crumbs li + li::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-top: 1.5px solid currentColor; transform: rotate(45deg); margin: 0 6px 0 2px; opacity: .6; }
.crumbs a { color: var(--text-2); text-decoration: none; }
.crumbs a:hover { color: var(--brand); }
.crumbs [aria-current] { color: var(--text); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }

/* ---------- Panels (cards) ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding: var(--s-5) var(--s-5) 0; }
.panel-head + .panel-body { padding-top: var(--s-4); }
.panel-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.panel-sub { margin: var(--s-1) 0 0; font-size: var(--fs-sm); color: var(--text-3); }
.panel-body { padding: var(--s-5); }
.panel-foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.panel-flush > .panel-head { padding-bottom: var(--s-4); }
.panel-flush > .table-scroll, .panel-flush > .filters + .table-scroll { border-top: 1px solid var(--line); }
.panel-danger { border-color: var(--danger-line); }
.panel-danger .panel-title { color: var(--danger); }
.panel-feature { background: linear-gradient(135deg, var(--ink), var(--ink-2)); color: var(--ink-text); border-color: transparent; }
.panel-feature .panel-title, .panel-feature h2, .panel-feature h3 { color: var(--ink-text); }
.panel-feature .panel-sub, .panel-feature p { color: var(--ink-muted); }
a.panel { display: block; color: inherit; text-decoration: none; transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast); }
a.panel:hover { border-color: var(--line-strong); box-shadow: var(--shadow-2); }
a.panel[aria-current] { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.section-label { margin: 0 0 var(--s-3); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }

/* ---------- Metrics ---------- */
.metric { padding: var(--s-5); display: grid; gap: var(--s-1); align-content: start; }
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.metric-label { font-size: var(--fs-sm); color: var(--text-2); font-weight: var(--fw-medium); }
.metric-value { font-size: var(--fs-3xl); font-weight: var(--fw-bold); letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-value-sm { font-size: var(--fs-xl); letter-spacing: -.01em; }
.metric-note { font-size: var(--fs-sm); color: var(--text-3); }
.metric-icon { width: 36px; height: 36px; border-radius: var(--r-md); display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.trend { display: inline-flex; align-items: center; gap: 2px; font-weight: var(--fw-semibold); margin-right: var(--s-1); }
.trend-up { color: var(--success); } .trend-down { color: var(--danger); } .trend-flat { color: var(--text-3); }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-line: var(--line-strong); --btn-bg-hover: var(--surface-2);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--control-h); padding: 0 var(--s-4); border-radius: var(--r-md); border: 1px solid var(--btn-line);
  background: var(--btn-bg); color: var(--btn-fg); font: inherit; font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.2;
  text-decoration: none; white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { background: var(--btn-bg-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--brand); --btn-fg: var(--brand-contrast); --btn-line: var(--brand); --btn-bg-hover: var(--brand-hover); box-shadow: 0 1px 2px rgba(14, 26, 48, .12); }
.btn-primary:hover { border-color: var(--brand-hover); }
.btn-secondary { --btn-bg: var(--surface); }
.btn-ghost { --btn-bg: transparent; --btn-line: transparent; --btn-fg: var(--text-2); --btn-bg-hover: var(--surface-2); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #FFFFFF; --btn-line: var(--danger); --btn-bg-hover: color-mix(in srgb, var(--danger) 86%, #000); }
html[data-theme=dark] .btn-danger { --btn-fg: #2A0906; }
.btn-danger-soft { --btn-bg: transparent; --btn-fg: var(--danger); --btn-line: var(--danger-line); --btn-bg-hover: var(--danger-bg); }
.btn-ink { --btn-bg: var(--highlight); --btn-fg: #1A1405; --btn-line: var(--highlight); --btn-bg-hover: #FFE08E; }
.btn-sm { min-height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-sm); gap: 6px; }
.btn-lg { min-height: 50px; padding: 0 var(--s-6); font-size: var(--fs-lg); border-radius: var(--r-md); }
.btn-icon { padding: 0; width: var(--control-h); }
.btn-icon.btn-sm { width: var(--control-h-sm); }
.btn-block { width: 100%; }
.btn .icon { width: 17px; height: 17px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin .7s linear infinite; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.btn-row > form { display: contents; }
.form-inline { display: inline-flex; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-stack { display: grid; gap: var(--s-4); }
.form-grid { display: grid; gap: var(--s-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .form-grid .span-all { grid-column: 1 / -1; } }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field-label { display: flex; align-items: baseline; gap: var(--s-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); }
.field-label .req { color: var(--danger); margin-left: -4px; }
.field-label .opt { font-weight: var(--fw-regular); color: var(--text-3); font-size: var(--fs-xs); }
.field-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); }
.field-hint { margin: 0; font-size: var(--fs-sm); color: var(--text-3); }
.field-error { margin: 0; font-size: var(--fs-sm); color: var(--danger); font-weight: var(--fw-medium); display: flex; gap: 6px; align-items: flex-start; }
.field-error::before { content: "!"; flex: none; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 11px; font-weight: var(--fw-bold); }
.control {
  width: 100%; min-height: var(--control-h); padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-md); line-height: 1.4;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.control::placeholder { color: var(--text-3); opacity: .85; }
.control:hover { border-color: color-mix(in srgb, var(--line-strong) 60%, var(--text-3)); }
.control:focus-visible, .control:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); border-radius: var(--r-md); }
.control[aria-invalid=true] { border-color: var(--danger); }
.control[aria-invalid=true]:focus { box-shadow: 0 0 0 3px var(--danger-bg); }
.control:disabled, .control[readonly] { background: var(--surface-2); color: var(--text-2); }
.control-sm { min-height: var(--control-h-sm); padding: 5px 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
textarea.control { min-height: 104px; resize: vertical; }
select.control { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type=file].control { padding: 7px; }
input[type=file].control::file-selector-button { margin-right: var(--s-3); padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface-2); color: var(--text); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer; }
input[type=color] { width: var(--control-h); height: var(--control-h); padding: 3px; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface); cursor: pointer; flex: none; }
.control.mono { font-family: var(--mono); font-size: var(--fs-sm); }
.affix { display: flex; align-items: stretch; min-width: 0; }
.affix > .affix-text { display: inline-flex; align-items: center; padding: 0 12px; border: 1px solid var(--line-strong); border-right: 0; border-radius: var(--r-md) 0 0 var(--r-md); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.affix > .affix-text + .control { border-radius: 0 var(--r-md) var(--r-md) 0; }
.affix > .control:not(:last-child) { border-radius: var(--r-md) 0 0 var(--r-md); }
.affix > .btn { border-radius: 0 var(--r-md) var(--r-md) 0; margin-left: -1px; }
.color-pair { display: flex; gap: var(--s-2); align-items: center; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; padding-top: var(--s-2); }
.form-actions-end { justify-content: flex-end; }
.hp-field { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* Checkbox & radio choices */
.choice { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-2) 0; cursor: pointer; font-size: var(--fs-md); }
.choice input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); cursor: pointer; }
.choice-text { display: grid; gap: 2px; color: var(--text); }
.choice-text small { color: var(--text-3); font-size: var(--fs-sm); }
.choice-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3); background: var(--surface); transition: border-color var(--t-fast), background-color var(--t-fast); }
.choice-card:hover { border-color: var(--line-strong); }
.choice-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice-list { display: grid; gap: var(--s-2); }

/* Segmented control (radio group) */
.segment { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); max-width: 100%; }
.segment label { position: relative; flex: 1 1 auto; }
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment span { display: block; padding: 7px 14px; border-radius: 7px; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); text-align: center; white-space: nowrap; transition: background-color var(--t-fast), color var(--t-fast); }
.segment input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); }
.segment input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- Notices (inline alerts) ---------- */
.notice { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); border: 1px solid var(--neutral-line); background: var(--neutral-bg); color: var(--text); font-size: var(--fs-md); }
.notice > .icon { margin-top: 2px; }
.notice > div { min-width: 0; }
.notice ul { margin: var(--s-2) 0 0; }
.notice-success { background: var(--success-bg); border-color: var(--success-line); } .notice-success > .icon { color: var(--success); }
.notice-warning { background: var(--warning-bg); border-color: var(--warning-line); } .notice-warning > .icon { color: var(--warning); }
.notice-danger { background: var(--danger-bg); border-color: var(--danger-line); } .notice-danger > .icon { color: var(--danger); }
.notice-info { background: var(--info-bg); border-color: var(--info-line); } .notice-info > .icon { color: var(--info); }
.notice + .notice { margin-top: var(--s-3); }
.notice-title { display: block; font-weight: var(--fw-semibold); margin-bottom: 2px; }

/* ---------- Pills (status badges) & tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-pill); border: 1px solid var(--neutral-line); background: var(--neutral-bg); color: var(--neutral); font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; vertical-align: middle; line-height: 1; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.pill-plain::before { display: none; }
.pill .icon { width: 13px; height: 13px; margin: 0 -2px; }
.pill-success { color: var(--success); background: var(--success-bg); border-color: var(--success-line); }
.pill-warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-line); }
.pill-danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-line); }
.pill-info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.pill-brand { color: var(--brand); background: var(--brand-soft); border-color: transparent; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-medium); text-decoration: none; white-space: nowrap; }
a.tag:hover { border-color: var(--brand); color: var(--brand); }
.tag .icon { width: 12px; height: 12px; }
.tag-ok .icon { color: var(--success); } .tag-no .icon { color: var(--text-3); }
.avatar-tile { flex: none; width: 36px; height: 36px; border-radius: var(--r-md); display: inline-grid; place-items: center; font-weight: var(--fw-bold); font-size: var(--fs-sm); }
.tone-1 { background: #E6EEFF; color: #2347B8; } .tone-2 { background: #E2F6EE; color: #0F6A49; } .tone-3 { background: #FFF1D6; color: #8A5200; }
.tone-4 { background: #F3E8FF; color: #6B2BB8; } .tone-5 { background: #FFE6EA; color: #A6213A; } .tone-6 { background: #E1F4F8; color: #126274; }
html[data-theme=dark] .tone-1, html[data-theme=dark] .tone-2, html[data-theme=dark] .tone-3, html[data-theme=dark] .tone-4, html[data-theme=dark] .tone-5, html[data-theme=dark] .tone-6 { background: var(--surface-3); color: var(--text); }
@media (prefers-color-scheme: dark) { html:not([data-theme=light]) :is(.tone-1, .tone-2, .tone-3, .tone-4, .tone-5, .tone-6) { background: var(--surface-3); color: var(--text); } }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--highlight); color: #1A1405; font-weight: var(--fw-bold); font-size: var(--fs-sm); flex: none; }

/* ---------- Key/value list ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 34%) minmax(0, 1fr); margin: 0; }
.kv > dt, .kv > dd { padding: var(--s-3) 0; border-bottom: 1px solid var(--line); margin: 0; min-width: 0; }
.kv > dt { color: var(--text-3); font-size: var(--fs-sm); padding-right: var(--s-4); }
.kv > dd { overflow-wrap: anywhere; }
.kv > dt:last-of-type, .kv > dd:last-of-type { border-bottom: 0; }
.kv-tight > dt, .kv-tight > dd { padding: var(--s-2) 0; }
@media (max-width: 520px) { .kv { grid-template-columns: minmax(0, 1fr); } .kv > dt { border-bottom: 0; padding-bottom: 0; } }

/* ---------- Copy field ---------- */
.copy-field { display: flex; align-items: center; gap: var(--s-2); padding: 6px 6px 6px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface-2); min-width: 0; }
.copy-field code, .copy-field .copy-value { flex: 1; min-width: 0; background: none; border: 0; padding: 0; font-family: var(--mono); font-size: var(--fs-sm); overflow-wrap: anywhere; color: var(--text); }
.copy-field .btn { flex: none; }
.short-url { font-family: var(--mono); font-size: .92em; color: var(--brand); overflow-wrap: anywhere; font-weight: var(--fw-medium); }

/* ---------- Filters toolbar ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-5); }
.filters .field { flex: 1 1 150px; }
.filters .field-grow { flex: 3 1 240px; }
.filters .filters-actions { display: flex; gap: var(--s-2); align-items: center; }
.filters-more { flex-basis: 100%; }
.filters-more-body { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); padding-top: var(--s-3); align-items: end; }
.search-control { position: relative; display: block; }
.search-control .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-control .control { padding-left: 38px; }

/* ---------- Data tables ---------- */
.table-scroll { position: relative; container-type: inline-size; overflow-x: auto; min-width: 0; }
.data-table { width: 100%; font-size: var(--fs-md); }
.data-table th { text-align: left; font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); padding: var(--s-3) var(--s-4); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); vertical-align: middle; min-width: 0; }
.data-table tbody tr:last-child > td { border-bottom: 0; }
.data-table tbody tr { transition: background-color var(--t-fast); }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.data-table th:first-child, .data-table td:first-child { padding-left: var(--s-5); }
.data-table th:last-child, .data-table td:last-child { padding-right: var(--s-5); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .col-check { width: 44px; padding-right: 0; }
.data-table .col-check input { width: 17px; height: 17px; accent-color: var(--brand); vertical-align: middle; cursor: pointer; }
.data-table .col-actions { width: 1%; text-align: right; white-space: nowrap; }
.data-table tr.row-detail > td { padding-top: 0; background: transparent; }
.data-table tr.row-detail:hover { background: transparent; }
.data-table .row-has-detail > td { border-bottom: 0; }
.cell-main { min-width: 220px; }
.cell-row { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.cell-row > div { min-width: 0; }
.cell-title { font-weight: var(--fw-semibold); color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
a.cell-title:hover { color: var(--brand); }
.cell-sub { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 48ch; }
.sort-link { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.sort-link::after { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; opacity: .25; }
.sort-link[data-sorted=asc]::after { transform: rotate(180deg); opacity: 1; }
.sort-link[data-sorted=desc]::after { opacity: 1; }
.sort-link:hover { color: var(--text); }
/* Narrow containers: rows become labelled cards */
@container (max-width: 680px) {
  .data-table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .data-table-stack, .data-table-stack tbody, .data-table-stack tr, .data-table-stack td { display: block; width: 100%; }
  .data-table-stack tbody tr { position: relative; padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
  .data-table-stack tbody tr:last-child { border-bottom: 0; }
  .data-table-stack td { padding: 3px 0 !important; border: 0; text-align: left !important; }
  .data-table-stack td[data-label]:not(.cell-main)::before { content: attr(data-label); display: inline-block; min-width: 110px; margin-right: var(--s-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
  .data-table-stack td.cell-main { padding-bottom: var(--s-2) !important; min-width: 0; }
  .data-table-stack td.col-check { position: absolute; top: var(--s-4); right: var(--s-5); width: auto; }
  .data-table-stack .col-check + .cell-main { padding-right: 36px !important; }
  .data-table-stack td.col-actions { width: auto; padding-top: var(--s-2) !important; }
  .data-table-stack td.col-actions:empty { display: none; }
  .data-table-stack tr.row-detail { padding-top: 0; }
  .data-table-stack .row-has-detail { border-bottom: 0; padding-bottom: 0; }
  .data-table-stack .cell-sub { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
}

/* ---------- Bulk selection bar ---------- */
.selection-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-5); background: var(--ink); color: var(--ink-text); position: sticky; top: var(--topbar-h); z-index: 5; }
.selection-bar strong { margin-right: auto; font-size: var(--fs-sm); }
.selection-bar .btn { --btn-bg: rgba(255, 255, 255, .08); --btn-fg: #fff; --btn-line: var(--ink-line); --btn-bg-hover: rgba(255, 255, 255, .16); }
.selection-bar .btn-danger-soft { --btn-fg: #FFB4AB; --btn-line: rgba(255, 180, 171, .35); }

/* ---------- Pagination ---------- */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); font-size: var(--fs-sm); color: var(--text-3); }
.pager nav { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-link { min-width: 34px; height: 34px; padding: 0 8px; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text-2); text-decoration: none; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.pager-link:hover { border-color: var(--line-strong); color: var(--text); }
.pager-link[aria-current] { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.pager-link.is-disabled { pointer-events: none; opacity: .45; }
.pager-link .icon { width: 15px; height: 15px; }

/* ---------- Tabs & chips ---------- */
.tabbar { display: flex; gap: var(--s-1); overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: var(--s-6); scrollbar-width: thin; }
.tabbar a { flex: none; display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-3); margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--text-2); font-weight: var(--fw-semibold); font-size: var(--fs-sm); text-decoration: none; white-space: nowrap; }
.tabbar a:hover { color: var(--text); }
.tabbar a[aria-current] { color: var(--brand); border-bottom-color: var(--brand); }
.tabbar-count { display: inline-flex; min-width: 1.5rem; justify-content: center; padding: 0 var(--s-2); border-radius: 999px; background: var(--surface-2); color: var(--text-3); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.tabbar a[aria-current] .tabbar-count { background: var(--brand-soft, var(--surface-2)); color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips a { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface); color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); text-decoration: none; white-space: nowrap; }
.chips a:hover { border-color: var(--line-strong); color: var(--text); }
.chips a[aria-current] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chips .count { font-weight: var(--fw-medium); opacity: .7; font-variant-numeric: tabular-nums; }

/* ---------- Disclosure (details/summary) ---------- */
.disclosure > summary { display: flex; align-items: center; gap: var(--s-2); cursor: pointer; list-style: none; font-weight: var(--fw-semibold); color: var(--text); }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(45deg) translateY(-2px); transition: transform var(--t-fast); flex: none; }
.disclosure[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.disclosure > summary .disclosure-hint { font-weight: var(--fw-regular); color: var(--text-3); font-size: var(--fs-sm); }
.panel.disclosure > summary { padding: var(--s-4) var(--s-5); border-radius: var(--r-lg); }
.panel.disclosure[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--r-lg) var(--r-lg) 0 0; }
.disclosure-body { padding: var(--s-5); }
.disclosure-inline > summary { display: inline-flex; font-size: var(--fs-sm); color: var(--brand); gap: 6px; }
.disclosure-inline > summary::after { width: 6px; height: 6px; border-width: 0 1.5px 1.5px 0; border-color: currentColor; margin-left: 2px; }
.disclosure-inline > .disclosure-body { padding: var(--s-3) 0 0; }
.disclosure-pop { position: relative; display: inline-block; text-align: left; }
.disclosure-pop > summary { font-size: var(--fs-sm); color: var(--text); padding: 0 var(--s-3); height: var(--control-h-sm); border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); }
.disclosure-pop > summary::after { width: 6px; height: 6px; border-width: 0 1.5px 1.5px 0; }
.disclosure-pop[open] > .disclosure-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 290px; padding: var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-3); }

/* ---------- Popover menus ---------- */
.dropdown { position: relative; display: inline-block; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 220px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-3); text-align: left; animation: pop-in var(--t-fast) var(--ease); }
.menu.menu-up { top: auto; bottom: calc(100% + 6px); }
.menu form { margin: 0; }
.menu-item { display: flex; width: 100%; align-items: center; gap: var(--s-3); padding: 9px 10px; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; font-size: var(--fs-md); text-align: left; text-decoration: none; cursor: pointer; white-space: nowrap; }
.menu-item .icon { color: var(--text-3); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); text-decoration: none; box-shadow: none; outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--brand); }
.menu-item.is-danger, .menu-item.is-danger .icon { color: var(--danger); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.menu-head { padding: 8px 10px 6px; font-size: var(--fs-sm); color: var(--text-3); line-height: 1.4; }
.menu-head strong { display: block; color: var(--text); font-size: var(--fs-md); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Empty state ---------- */
.empty-state { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-12) var(--s-6); text-align: center; }
.empty-state-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); margin-bottom: var(--s-2); }
.empty-state-icon .icon { width: 26px; height: 26px; }
.empty-state h3 { font-size: var(--fs-lg); }
.empty-state p { margin: 0; max-width: 44ch; color: var(--text-3); }
.empty-state .btn-row { margin-top: var(--s-3); justify-content: center; }
.empty-inline { display: flex; align-items: center; gap: var(--s-2); color: var(--text-3); font-size: var(--fs-sm); margin: 0; }
.empty-inline .icon { color: var(--success); }

/* ---------- Checklist (status lines) ---------- */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; }
.checklist > li { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) 0; border-bottom: 1px solid var(--line); }
.checklist > li:last-child { border-bottom: 0; }
.checklist > li > div { flex: 1; min-width: 0; }
.checklist .check-mark { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--neutral-bg); color: var(--neutral); }
.checklist .check-mark .icon { width: 16px; height: 16px; }
.checklist .is-ok .check-mark, .checklist > li.is-ok > .check-mark { background: var(--success-bg); color: var(--success); }
.checklist .is-warn .check-mark, .checklist > li.is-warn > .check-mark { background: var(--warning-bg); color: var(--warning); }
.checklist .is-fail .check-mark, .checklist > li.is-fail > .check-mark { background: var(--danger-bg); color: var(--danger); }
.checklist-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); font-weight: var(--fw-semibold); }
.checklist-detail { display: block; margin-top: 2px; font-size: var(--fs-sm); color: var(--text-3); overflow-wrap: anywhere; }
.checklist .btn, .checklist form { flex: none; }
a.checklist-title { color: var(--text); text-decoration: none; }
a.checklist-title:hover { color: var(--brand); }

/* ---------- Ranked bars (breakdowns) ---------- */
.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.ranking li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: var(--s-3); row-gap: 6px; align-items: baseline; font-size: var(--fs-sm); }
.ranking-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: var(--fw-medium); text-decoration: none; }
a.ranking-label:hover { color: var(--brand); }
.ranking-value { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.ranking-share { color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }
.meter { grid-column: 1 / -1; height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.meter-ink > span { background: var(--ink); }
.fill-0 { width: 0; } .fill-5 { width: 5%; } .fill-10 { width: 10%; } .fill-15 { width: 15%; } .fill-20 { width: 20%; } .fill-25 { width: 25%; } .fill-30 { width: 30%; } .fill-35 { width: 35%; } .fill-40 { width: 40%; } .fill-45 { width: 45%; } .fill-50 { width: 50%; } .fill-55 { width: 55%; } .fill-60 { width: 60%; } .fill-65 { width: 65%; } .fill-70 { width: 70%; } .fill-75 { width: 75%; } .fill-80 { width: 80%; } .fill-85 { width: 85%; } .fill-90 { width: 90%; } .fill-95 { width: 95%; } .fill-100 { width: 100%; }

/* ---------- Charts (rendered by charts.js) ---------- */
.chart { position: relative; min-height: 240px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .series-area { fill: var(--brand-soft); }
.chart .series-line { fill: none; stroke: var(--brand); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-line-2 { fill: none; stroke: var(--text-3); stroke-width: 1.75; stroke-dasharray: 4 4; }
.chart .bar { fill: var(--brand); opacity: .9; }
.chart .bar:hover { opacity: 1; }
.chart-tip { position: absolute; transform: translate(-50%, calc(-100% - 10px)); pointer-events: none; padding: 6px 10px; border-radius: var(--r-sm); background: var(--ink); color: #fff; font-size: var(--fs-xs); font-weight: var(--fw-medium); white-space: nowrap; box-shadow: var(--shadow-2); z-index: 2; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-4); margin-top: var(--s-3); font-size: var(--fs-sm); color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: var(--s-2); }
.legend i { width: 18px; height: 3px; border-radius: 2px; background: var(--brand); }
.legend i.is-alt { background: repeating-linear-gradient(90deg, var(--text-3) 0 4px, transparent 4px 7px); }

/* ---------- QR frame ---------- */
.qr-frame { display: grid; place-items: center; padding: var(--s-4); border-radius: var(--r-md); background: #FFFFFF; border: 1px solid var(--line); }
.qr-frame img { width: 100%; max-width: 220px; height: auto; display: block; }

/* ---------- Code snippet with copy ---------- */
.snippet { position: relative; }
.snippet pre { margin: 0; padding-right: 96px; }
.snippet .btn { position: absolute; top: 8px; right: 8px; --btn-bg: rgba(255, 255, 255, .08); --btn-fg: #fff; --btn-line: rgba(255, 255, 255, .2); --btn-bg-hover: rgba(255, 255, 255, .16); }

/* ---------- Steps ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-4); counter-reset: step; }
.steps > li { position: relative; padding-left: 44px; counter-increment: step; min-width: 0; }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: -2px; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: var(--fw-bold); font-size: var(--fs-sm); }
.steps > li strong { display: block; margin-bottom: 2px; }
.steps > li p { color: var(--text-2); font-size: var(--fs-sm); }

/* ---------- Dialogs ---------- */
.dialog { width: min(480px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-3); }
.dialog::backdrop { background: rgba(8, 18, 40, .55); backdrop-filter: blur(2px); }
.dialog[open] { animation: dialog-in var(--t) var(--ease); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-5) var(--s-5) 0; }
.dialog-head h2 { font-size: var(--fs-xl); }
.dialog-body { padding: var(--s-4) var(--s-5); color: var(--text-2); }
.dialog-body .field { margin-top: var(--s-4); }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-5) var(--s-5); }
.dialog-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; margin-bottom: var(--s-3); background: var(--danger-bg); color: var(--danger); }
.dialog-icon.is-primary { background: var(--brand-soft); color: var(--brand); }
.dialog-icon.is-warning { background: var(--warning-bg); color: var(--warning); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (max-width: 520px) {
  .dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .dialog-foot .btn { flex: 1 1 auto; }
}

/* ---------- Toasts (one global system) ---------- */
.toast-region { position: fixed; z-index: 300; right: var(--s-5); bottom: var(--s-5); display: grid; gap: var(--s-2); width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--info); box-shadow: var(--shadow-3); font-size: var(--fs-md); animation: toast-in var(--t) var(--ease); }
.toast > .icon { margin-top: 2px; color: var(--info); }
.toast-msg { flex: 1; min-width: 0; padding-top: 1px; overflow-wrap: anywhere; }
.toast-title { display: block; font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.toast-close { flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin: -2px -2px 0 0; border: 0; border-radius: 7px; background: none; color: var(--text-3); cursor: pointer; }
.toast-close:hover { background: var(--surface-2); color: var(--text); }
.toast-close .icon { width: 15px; height: 15px; }
.toast-success { border-left-color: var(--success); } .toast-success > .icon { color: var(--success); }
.toast-warning { border-left-color: var(--warning); } .toast-warning > .icon { color: var(--warning); }
.toast-error { border-left-color: var(--danger); } .toast-error > .icon { color: var(--danger); }
.toast.is-leaving { animation: toast-out var(--t) var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@media (max-width: 640px) { .toast-region { left: 50%; right: auto; bottom: auto; top: calc(var(--s-3) + env(safe-area-inset-top, 0px)); transform: translateX(-50%); } @keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } } }

/* ---------- Highlight result banner ---------- */
.spotlight { position: relative; overflow: hidden; border-radius: var(--r-lg); padding: var(--s-6); background: linear-gradient(135deg, var(--ink), var(--ink-2)); color: var(--ink-text); margin-bottom: var(--s-6); }
.spotlight::after { content: ""; position: absolute; right: -60px; top: -80px; width: 260px; height: 260px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 214, 110, .28), transparent 70%); pointer-events: none; }
.spotlight > * { position: relative; }
.spotlight h2 { color: #fff; font-size: var(--fs-lg); display: flex; align-items: center; gap: var(--s-2); }
.spotlight h2 .icon { color: var(--highlight); }
.spotlight p { color: var(--ink-muted); }
.spotlight-value { margin: var(--s-3) 0 var(--s-4); font-family: var(--mono); font-size: clamp(1.1rem, .9rem + 1vw, 1.5rem); font-weight: var(--fw-semibold); color: #fff; overflow-wrap: anywhere; }
.spotlight .btn { --btn-bg: rgba(255, 255, 255, .08); --btn-fg: #fff; --btn-line: var(--ink-line); --btn-bg-hover: rgba(255, 255, 255, .16); }
.spotlight .btn-ink { --btn-bg: var(--highlight); --btn-fg: #1A1405; --btn-line: var(--highlight); --btn-bg-hover: #FFE08E; }
.spotlight .copy-field { background: rgba(255, 255, 255, .08); border-color: var(--ink-line); }
.spotlight .copy-field code, .spotlight .copy-field .copy-value { color: #fff; }

/* ---------- Brand mark ---------- */
.brand { display: inline-flex; align-items: center; gap: var(--s-3); color: inherit; text-decoration: none; min-width: 0; }
.brand-mark { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--highlight); color: #1A1405; font-weight: 800; font-size: 1rem; letter-spacing: -.02em; }
.brand-name { font-weight: var(--fw-bold); font-size: var(--fs-lg); letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-logo { display: block; max-height: 36px; width: auto; max-width: 180px; }
.is-copied { color: var(--success); }
.cols-2 > .span-all, .cols-3 > .span-all, .cols-4 > .span-all { grid-column: 1 / -1; }
.sub-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); margin: 0 0 var(--s-3); display: flex; align-items: center; gap: var(--s-2); }
.user-avatar-lg { width: 52px; height: 52px; font-size: var(--fs-xl); }
.notice p { margin: 0; }
.checklist-padded > li { padding-left: var(--s-5); padding-right: var(--s-5); }
.panel-body + .panel-body { border-top: 1px solid var(--line); }
.data-table .col-actions .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
@container (max-width: 680px) { .data-table-stack .col-actions .btn-row { justify-content: flex-start; flex-wrap: wrap; } }
.cols-start { align-items: start; }
@media (min-width: 360px) and (max-width: 719px) { .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-4 .metric-value { font-size: var(--fs-2xl); } }
