/* ============================================================
   components.css — the primitives.
   Load after layout.css. Nothing here is dark-aware; the
   tokens in theme.css handle both modes.
   ============================================================ */

/* ---------- Raised surfaces ---------- */

.card,
.stat-card,
.chart-card,
.filter-bar,
.scope-bar,
.table-wrap,
.modal {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.card,
.chart-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.card h3,
.chart-card h3,
.widget-head h3,
.modal-head h3 {
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: var(--font-weight-medium);
}

.chart-card h3 { margin-bottom: 14px; }

.widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: 14px;
}

.widget-head h3 { margin-bottom: 0; }

canvas { max-width: 100%; }

/* ---------- Form controls ---------- */

.select,
.input,
.btn,
.widget-range,
.filters input,
.filters select {
    min-height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-base);
}

.select,
.input,
.widget-range,
.filters input,
.filters select { padding: 6px var(--space-3); }

.select,
.filters select { cursor: pointer; padding-right: 32px; }

.nav-select {
    flex: 0 1 200px;
    min-width: 120px;
    max-width: 200px;
}

.input::placeholder,
.filters input::placeholder { color: var(--quiet); }

.widget-range {
    min-height: 30px;
    color: var(--muted);
    font-size: var(--text-label);
    cursor: pointer;
}

.widget-range.overridden {
    border-color: var(--accent);
    color: var(--accent-strong);
    font-weight: var(--font-weight-medium);
    background: var(--accent-tint-soft);
}

/* ---------- Buttons ----------
   .btn is the secondary/default; add .btn-primary for the
   accent fill or .btn-quiet for the borderless variant. */

.btn {
    padding: 7px 14px;
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background var(--motion), border-color var(--motion), color var(--motion);
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--on-accent);
}

.btn-sm {
    min-height: 32px;
    padding: 6px 11px;
    font-size: var(--text-label);
}

.btn-quiet {
    padding: 5px var(--space-3);
    background: transparent;
    color: var(--muted);
    font-size: var(--text-label);
}

.btn-quiet:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ---------- Filter bars ---------- */

.filter-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: 18px;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
}

.filter-bar label {
    color: var(--muted);
    font-size: var(--text-label);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
}

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 1.6fr) repeat(auto-fit, minmax(130px, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

/* ---------- Stat card ---------- */

.stat-card {
    position: relative;
    min-height: 118px;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--space-4);
    overflow: hidden;
}

/* The 4px spine down the left edge. */
.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--accent);
}

/* The small tick in the bottom-right corner. */
.stat-card::after {
    content: "";
    position: absolute;
    inset: auto var(--space-4) var(--space-4) auto;
    width: 44px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--accent-tint-strong);
}

.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.success::before { background: var(--success); }
.stat-card.info::before { background: var(--info); }

.stat-label {
    position: relative;
    z-index: 1;
    color: var(--muted);
    font-size: var(--text-label);
    font-weight: var(--font-weight-medium);
}

.stat-value,
.status-item .status-value {
    position: relative;
    z-index: 1;
    font-size: var(--text-stat);
    font-weight: var(--font-weight-medium);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.info .stat-value { color: var(--info); }

/* ---------- Clickable lift ---------- */

.clickable {
    cursor: pointer;
    transition: transform var(--motion), box-shadow var(--motion), border-color var(--motion);
}

.clickable:hover {
    transform: translateY(-1px);
    border-color: var(--accent);
    box-shadow: var(--accent-lift);
}

/* ---------- Status strip ---------- */

.strip-card { margin: 6px 0 var(--space-6); }

.status-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
    gap: var(--space-2);
}

.status-item {
    min-width: 0;
    padding: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--subtle);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
}

.status-item .status-value { font-size: 24px; }

.status-item .status-name {
    color: var(--muted);
    font-size: var(--text-label);
    line-height: 1.3;
}

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    box-shadow: none;
}

.scroll-table {
    max-height: 500px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th,
td {
    padding: 11px var(--space-4);
    border-bottom: 1px solid var(--border);
    text-align: left;
    color: var(--muted);
    font-size: var(--text-base);
    vertical-align: middle;
}

th {
    position: relative;
    color: var(--ink);
    background: var(--subtle);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-bold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
}

.scroll-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

td:first-child,
td.numeric,
.link { font-variant-numeric: tabular-nums; }

tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--motion); }
tbody tr:hover { background: var(--accent-tint-soft); }

.truncate {
    max-width: 360px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
}

.link {
    color: var(--accent-strong);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

td.clickable-cell {
    cursor: pointer;
    color: var(--ink);
    font-weight: var(--font-weight-medium);
}

td.clickable-cell:hover {
    background: var(--accent-tint);
    color: var(--accent-strong);
}

.result-count {
    margin-bottom: var(--space-3);
    color: var(--muted);
    font-size: var(--text-base);
}

/* ---------- Badges ----------
   One recipe, five semantic variants: a 10%-tint background
   with the solid hue as foreground. */

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-bold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--neutral-tint);
    color: var(--muted);
}

.badge-accent { background: var(--accent-tint); color: var(--accent-strong); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-warning { background: var(--warning-tint); color: var(--accent-strong); }
.badge-success { background: var(--success-tint); color: var(--success); }
.badge-info { background: var(--info-tint); color: var(--info); }
.badge-neutral { background: var(--neutral-tint); color: var(--muted); }

/* ---------- Alerts ----------
   Inline message block. Same tint recipe as .badge, but sized
   for a sentence rather than a label. */

.alert {
    padding: var(--space-3) 14px;
    border-radius: var(--radius-md);
    background: var(--neutral-tint);
    color: var(--muted);
    font-size: var(--text-base);
    line-height: 1.45;
    text-align: left;
}

.alert[hidden] { display: none; }

.alert-danger { background: var(--danger-tint); color: var(--danger); }
.alert-warning { background: var(--warning-tint); color: var(--accent-strong); }
.alert-success { background: var(--success-tint); color: var(--success); }
.alert-info { background: var(--info-tint); color: var(--info); }

/* ---------- List items ---------- */

.list { display: grid; gap: var(--space-2); }

.list-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--subtle);
    color: var(--muted);
}

.list-item strong {
    color: var(--ink);
    font-weight: var(--font-weight-medium);
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-2);
    margin-top: 14px;
}

.pagination button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

/* ---------- Scope bar ---------- */

.scope-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
    padding: var(--space-3) var(--space-4);
    border-color: var(--accent-tint-strong);
    border-radius: var(--radius-lg);
    color: var(--accent-strong);
    font-size: var(--text-base);
}

.scope-bar[hidden] { display: none; }

.scope-bar strong {
    color: var(--ink);
    font-weight: var(--font-weight-medium);
}

.scope-bar button {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--accent-tint);
    color: var(--accent-strong);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.scope-bar button:hover { background: var(--accent-tint-strong); }

/* ---------- Modal ----------
   The only backdrop-filter in the system. Behaviour (Esc,
   focus trap, focus restore) lives in js/ui.js. */

.modal-overlay[hidden] { display: none; }

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    background: var(--scrim);
    backdrop-filter: blur(4px);
}

.modal {
    width: min(1120px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    padding: 18px;
    border-radius: var(--radius-lg);
}

.modal-head {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: 14px;
}

.modal-head .result-count { margin: 0; }

.modal-search {
    min-height: 32px;
    min-width: min(280px, 100%);
    margin-left: auto;
    padding: 6px var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-base);
}

.modal-search::placeholder { color: var(--quiet); }
.modal-search ~ .modal-close { margin-left: 0; }
.modal-table { max-height: 60vh; }

.modal-close {
    margin-left: auto;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--subtle);
    color: var(--muted);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* ---------- Loading & empty ---------- */

.loading {
    color: transparent !important;
    min-width: 70px;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--subtle) 25%, var(--neutral-tint) 50%, var(--subtle) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.empty-note {
    padding: 40px 0;
    color: var(--quiet);
    font-size: var(--text-base);
    text-align: center;
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
    .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
    .stat-card { min-height: 112px; }
}

@media (max-width: 720px) {
    .filters { grid-template-columns: 1fr; }
    .filter-bar { flex-wrap: wrap; }
    .modal-overlay { padding: var(--space-4); align-items: flex-start; }
    th, td { padding: var(--space-3) 11px; }
}
