/* Shared components for BOTH the customer portal and the admin console.
   Everything here is expressed in tokens (tokens.css); the theme layers
   (portal.css / style.css) only add layout chrome (topnav vs sidebar) and
   density overrides. Class names are the vocabulary the templates already
   use -- card, badge, flash, form-grid, table/data-table, mention,
   action-row, row-actions, walkthrough, evidence-strip, plan-list... */

/* ---------- reset + typography ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: var(--lh);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: var(--lh-tight); margin: 0 0 var(--space-3); font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }
p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.4em; border-radius: var(--r-sm); }
pre { margin: 0; }
img { max-width: 100%; }
ul, ol { margin: 0 0 var(--space-3); padding-left: 1.25rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }
table { font-variant-numeric: tabular-nums; }

/* focus is visible everywhere, on every interactive element, in both themes */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.skip-link { position: absolute; left: -999px; top: var(--space-2); background: var(--panel); color: var(--accent); padding: var(--space-2) var(--space-3); border-radius: var(--r-sm); z-index: 100; }
.skip-link:focus { left: var(--space-2); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- icons ---------- */
.icon { width: 1em; height: 1em; flex: 0 0 auto; vertical-align: -0.15em; }
.icon-spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout primitives ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-4); }
.page-header h1 { margin: 0; }
.page-header a { font-size: var(--text-sm); text-decoration: none; }
.page-header a:hover { text-decoration: underline; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: calc(var(--space-6) * var(--density));
    margin: var(--space-5) 0;
    box-shadow: var(--shadow-1);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-subtle { background: var(--surface-2); box-shadow: none; }
.card-link { display: block; text-decoration: none; color: inherit; transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease; }
.card-link:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: var(--shadow-2); color: inherit; }
.cta-card { text-align: center; padding: calc(var(--space-7) * var(--density)) var(--space-5); }
details.card > summary, .summary-title { cursor: pointer; font-weight: 600; }
details.card > summary { list-style: none; display: flex; align-items: center; gap: var(--space-2); }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: ""; width: 0.55em; height: 0.55em; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform 0.15s; margin-right: var(--space-1); }
details.card[open] > summary::before { transform: rotate(45deg); }
.summary-title { display: inline; font-size: var(--text-xl); margin: 0; }
details summary { cursor: pointer; color: var(--accent-dark); font-weight: 600; }

/* ---------- buttons ---------- */
button, .button {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: 36px; padding: 0.45rem 1rem;
    background: var(--accent); color: var(--on-accent);
    border: 1px solid transparent; border-radius: var(--r-md);
    font: inherit; font-size: var(--text-sm); font-weight: 600; line-height: 1.2;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
button:hover, .button:hover { background: var(--accent-dark); color: var(--on-accent); }
button:disabled, .button[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
button.secondary, .button.secondary { background: var(--panel); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); color: var(--text); }
button.ghost, .button.ghost { background: transparent; color: var(--accent); border-color: transparent; }
button.ghost:hover, .button.ghost:hover { background: var(--accent-soft); color: var(--accent-dark); }
button.danger, .button.danger { background: var(--danger); color: #fff; }
button.danger:hover, .button.danger:hover { background: var(--danger); filter: brightness(0.9); }
.btn-sm { min-height: 30px; padding: 0.25rem 0.7rem; font-size: var(--text-xs); }
.btn-lg { min-height: 44px; padding: 0.7rem 1.75rem; font-size: var(--text-base); }
a > button { pointer-events: none; }
a:has(> button) { text-decoration: none; display: inline-block; }
button[aria-busy="true"]::before, .is-busy::before { content: ""; width: 0.9em; height: 0.9em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-1) var(--space-3); }
.form-grid label { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--muted); font-weight: 500; }
.form-grid label:first-child { margin-top: 0; }
.form-grid button { margin-top: var(--space-4); justify-self: start; }
.form-grid input, .form-grid textarea, .form-grid select, .url-input, .eligibility-form input, .eligibility-form select, input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], input[type="month"], textarea, select {
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--r-md);
    padding: 0.55rem 0.75rem; font: inherit; font-size: var(--text-sm); min-height: 40px;
}
textarea { min-height: 5rem; resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[type="checkbox"], input[type="radio"] { width: 1rem; height: 1rem; min-height: 0; accent-color: var(--accent); margin: 0; }
.url-input { display: block; width: 100%; margin-bottom: var(--space-2); }
.field-hint { color: var(--muted); font-size: var(--text-xs); margin: var(--space-1) 0 0; }
.check-row { display: flex; align-items: flex-start; gap: var(--space-2); font-size: var(--text-sm); color: var(--text); font-weight: 400; margin-top: var(--space-2) !important; }
.check-row input { margin-top: 0.2rem; width: auto; }
.checkbox-grid { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); margin: var(--space-2) 0; }
.checkbox-grid label { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: 400; color: var(--text); margin-top: 0; }
.eligibility-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: end; margin: var(--space-2) 0; }
.eligibility-form label { display: flex; flex-direction: column; font-size: var(--text-xs); color: var(--muted); gap: var(--space-1); }
.inline-form { display: inline-flex; gap: var(--space-2); align-items: center; margin: var(--space-1) var(--space-1) var(--space-1) 0; flex-wrap: wrap; }
.row-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.action-bar { display: flex; gap: var(--space-3); margin: var(--space-4) 0; flex-wrap: wrap; }

.auth-divider { display: flex; align-items: center; gap: var(--space-3); color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; margin: var(--space-3) 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ---------- badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 0.3em;
    padding: 0.15rem 0.55rem; border-radius: var(--r-pill);
    background: var(--neutral-soft); color: var(--neutral);
    font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; line-height: 1.4;
    white-space: nowrap; vertical-align: middle;
}
.badge-success, .badge-resolved, .badge-positive, .badge-done { background: var(--success-soft); color: var(--success); }
.badge-warning, .badge-actioned, .badge-processing, .badge-ready_for_review, .badge-mixed { background: var(--warning-soft); color: var(--warning); }
.badge-danger, .badge-unwanted, .badge-negative, .badge-rejected, .badge-failed { background: var(--danger-soft); color: var(--danger); }
.badge-info, .badge-new, .badge-monitoring, .badge-submitted, .badge-pending_response, .badge-running { background: var(--info-soft); color: var(--info); }
.badge-neutral, .badge-reviewed, .badge-ignored, .badge-draft, .badge-queued { background: var(--neutral-soft); color: var(--neutral); }

/* ---------- flash / hints ---------- */
.flash { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-radius: var(--r-md); margin-bottom: var(--space-4); font-weight: 500; font-size: var(--text-sm); border: 1px solid; border-left-width: 4px; }
.flash-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.flash-error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.flash-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.flash-info { background: var(--info-soft); border-color: var(--info); color: var(--info); }
.hint { display: block; max-width: 22rem; padding: var(--space-2) var(--space-3); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--text-sm); }
.hint-warning { background: var(--warning-soft); color: var(--warning); }
.hint-info { background: var(--info-soft); color: var(--info); }
.text-warning { color: var(--warning); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* ---------- text helpers ---------- */
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.hidden { display: none !important; }
.empty-state { color: var(--muted); }
.truncate-url { overflow-wrap: anywhere; cursor: help; }
.meta { color: var(--muted); font-size: var(--text-xs); display: inline-flex; align-items: center; gap: 0.3em; }
.pre-wrap { white-space: pre-wrap; }
.maxw-sm { max-width: 26rem; }
.maxw-md { max-width: 32rem; }
.text-center { text-align: center; }
.quote { border-left: 3px solid var(--border-strong); padding-left: var(--space-3); color: var(--muted); font-size: var(--text-sm); margin: var(--space-3) 0; }

/* ---------- empty + loading states ---------- */
.empty-block { text-align: center; padding: calc(var(--space-6) * var(--density)) var(--space-4); color: var(--muted); }
.empty-block .icon { width: 2.25rem; height: 2.25rem; color: var(--border-strong); margin-bottom: var(--space-3); }
.empty-block h3 { color: var(--text); margin-bottom: var(--space-1); }
.empty-block p { max-width: 34rem; margin: 0 auto var(--space-4); font-size: var(--text-sm); }
.spinner-sm { width: 12px; height: 12px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex: 0 0 auto; }
.loading-block { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--r-md); background: var(--surface-2); color: var(--muted); font-size: var(--text-sm); }
.skeleton { display: block; background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-sm); }
.skeleton-line { height: 0.9em; margin: 0.35em 0; }
.skeleton-card { height: 4.5rem; margin: var(--space-3) 0; border-radius: var(--r-md); }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .spinner, .skeleton, .icon-spin, button[aria-busy="true"]::before { animation: none; } .card-link { transition: none; } }

/* ---------- progress ---------- */
.progress-meta { display: flex; align-items: center; gap: var(--space-3); color: var(--muted); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-pill); transition: width 0.3s; }

/* ---------- stat tiles ---------- */
.status-card-grid, .stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); margin: var(--space-4) 0; }
.status-card, .stat { display: block; border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--space-4); background: var(--panel); text-decoration: none; color: inherit; }
a.status-card:hover { border-color: var(--accent); color: inherit; }
.status-card .value, .stat .v { font-size: var(--text-2xl); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.status-card .label, .stat .l { color: var(--muted); font-size: var(--text-xs); margin-top: var(--space-1); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: var(--space-3) 0; }
.table, .data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td, .data-table th, .data-table td { text-align: left; padding: calc(var(--space-3) * var(--density)) var(--space-2); border-bottom: 1px solid var(--border); vertical-align: top; }
.table th, .data-table th { color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.table tbody tr:hover td, .data-table tbody tr:hover td { background: var(--surface-2); }
.table tr:last-child td, .data-table tr:last-child td { border-bottom: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- mentions / actions ---------- */
.mention { border-top: 1px solid var(--border); padding: var(--space-4) 0; }
.mention:first-of-type { border-top: 0; }
.mention-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.mention-head a { color: var(--accent-dark); font-weight: 600; text-decoration: none; }
.mention-head a:hover { text-decoration: underline; }
.snippet { color: var(--muted); font-size: var(--text-sm); }
.classification, .action-row { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--space-4); margin-top: var(--space-3); }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--space-3) var(--space-4); white-space: pre-wrap; word-break: break-word; font-size: var(--text-sm); font-family: var(--font-mono); color: var(--text); }
.divider-top { border-top: 1px solid var(--border); padding-top: var(--space-3); margin-top: var(--space-3); }

/* ---------- lists: walkthrough, steps, stepper, plan ---------- */
.walkthrough { padding-left: 1.25rem; display: flex; flex-direction: column; gap: var(--space-2); color: var(--text); }
.walkthrough li { padding-left: var(--space-1); }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: flex; flex-direction: column; gap: var(--space-4); }
.steps li { position: relative; padding-left: 2.4rem; counter-increment: step; min-height: 1.6rem; }
.steps li::before, .plan-item::before {
    content: counter(step); position: absolute; left: 0; top: 0; width: 1.6rem; height: 1.6rem; border-radius: 50%;
    background: var(--accent); color: var(--on-accent); font-size: var(--text-xs); font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.stepper { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: flex; gap: var(--space-2); flex-wrap: wrap; counter-reset: stepper; }
.stepper li { counter-increment: stepper; flex: 1 1 12rem; }
.stepper a { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel); color: var(--text); text-decoration: none; font-size: var(--text-sm); font-weight: 600; }
.stepper a::before { content: counter(stepper); width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: var(--text-xs); flex: 0 0 auto; }
.stepper li.is-active a { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.stepper li.is-active a::before { background: var(--accent); color: var(--on-accent); }
.stepper li.is-done a::before { content: "\2713"; background: var(--success-soft); color: var(--success); }
.stepper li.is-skipped a { color: var(--muted); }
.plan-list { list-style: none; padding: 0; margin: var(--space-2) 0 0; counter-reset: step; display: flex; flex-direction: column; gap: var(--space-2); }
.plan-item { counter-increment: step; display: flex; flex-direction: column; padding: var(--space-3) var(--space-4) var(--space-3) 2.6rem; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); position: relative; }
.plan-item::before { position: absolute; left: var(--space-3); top: var(--space-3); margin-top: 0; }
.plan-item.plan-published { opacity: 0.75; }
.plan-item.plan-published::before { background: var(--success); content: "\2713"; }
.plan-item-head { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* ---------- evidence thumbnails ---------- */
.evidence-strip { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
.evidence-strip a { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; text-decoration: none; }
.evidence-strip img { width: 96px; height: 64px; object-fit: cover; object-position: top; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--panel); transition: transform 0.15s, box-shadow 0.15s; }
.evidence-strip a:hover img { transform: scale(1.03); box-shadow: var(--shadow-2); }
.evidence-strip span { font-size: var(--text-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }

/* ---------- spacing utilities (replace inline margin styles) ---------- */
.m-0 { margin: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--space-1) !important; }
.mt-2 { margin-top: var(--space-2) !important; }
.mt-3 { margin-top: var(--space-3) !important; }
.mt-4 { margin-top: var(--space-4) !important; }
.mt-5 { margin-top: var(--space-5) !important; }
.mt-6 { margin-top: var(--space-6) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--space-2) !important; }
.mb-4 { margin-bottom: var(--space-4) !important; }
.flex { display: flex; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.w-8 { width: 8rem; }
.w-10 { width: 10rem; }
.w-full { width: 100%; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
    h1 { font-size: var(--text-xl); }
    .card { padding: var(--space-4); margin: var(--space-4) 0; border-radius: var(--r-md); }
    .page-header { flex-direction: column; align-items: flex-start; }
    button, .button { min-height: 44px; }
    .btn-sm { min-height: 36px; }
    .table-wrap { margin-left: calc(-1 * var(--space-4)); margin-right: calc(-1 * var(--space-4)); padding: 0 var(--space-4); }
    .data-table, .table { min-width: 560px; }
    .stepper li { flex-basis: 100%; }
}

/* ---------- print ---------- */
@media print {
    .topnav, .sidebar, .skip-link, .trust-strip button, .row-actions, .inline-form, button, .button { display: none !important; }
    body { background: #fff; color: #000; }
    .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
    a { color: inherit; text-decoration: none; }
}
