/* Datasets + dashboards-list pages.
   Widget/grid styling lives in page-dashboard.css. */

/* ── Page chrome shared by both list pages ───────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin: 4px 0 20px;
}

.page-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary, #111827);
}

.page-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted, #6b7280);
}

.page-actions { display: flex; gap: 8px; align-items: center; }

.empty-state {
    border: 1px dashed var(--border-color, #d1d5db);
    border-radius: var(--radius-lg, 12px);
    padding: 40px 24px;
    text-align: center;
}

.empty-state h3 { margin: 0 0 6px; font-size: 16px; }
.empty-state-actions { margin-top: 16px; }

/* ── Dashboards list ─────────────────────────────────────────────────── */
.dash-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.dash-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    background: var(--bg-primary, #fff);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.05));
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.dash-card:hover {
    border-color: var(--color-primary, #0d9488);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .08);
}

.dash-card-main {
    display: block;
    padding: 16px;
    text-decoration: none;
    color: inherit;
    flex: 1;
}

.dash-card-name { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.dash-card-meta { margin: 0; font-size: 12px; color: var(--text-muted, #6b7280); }

.dash-card-actions {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-secondary, #f9fafb);
}

.dash-card-actions:empty { display: none; }
.dash-card-delete { margin-left: auto; color: #b91c1c; }

/* ── Import drop zone ────────────────────────────────────────────────── */
.import-dropzone {
    border: 2px dashed var(--border-color, #d1d5db);
    border-radius: var(--radius-lg, 12px);
    padding: 32px 24px;
    text-align: center;
    background: var(--bg-secondary, #f9fafb);
    transition: border-color .15s ease, background .15s ease;
    cursor: pointer;
}

.import-dropzone:hover,
.import-dropzone.is-dragover {
    border-color: var(--color-primary, #0d9488);
    background: rgba(13, 148, 136, .06);
}

.import-dropzone-title { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.import-dropzone-hint { font-size: 12px; color: var(--text-muted, #6b7280); margin: 0; }

/* Column table on the dataset detail page + import confirm dialog */
.column-type-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.column-type-table th,
.column-type-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.column-type-table th { font-weight: 600; color: var(--text-muted, #6b7280); }

/* A column whose type came from the Excel-serial heuristic rather than an
   explicit format — the user should glance at these before importing. */
.column-inferred { background: #fffbeb; }
.column-inferred-flag { font-size: 11px; color: #92400e; margin-left: 6px; }

.drift-banner {
    border: 1px solid #fcd34d;
    background: #fffbeb;
    color: #78350f;
    border-radius: var(--radius-md, 8px);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.drift-banner h4 {
    margin: 0 0 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.drift-banner ul { margin: 0; padding-left: 18px; }
.drift-banner li { margin-bottom: 3px; overflow-wrap: anywhere; }

.drift-added,
.drift-removed,
.drift-changed {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 4px;
    padding: 1px 5px;
    margin-right: 5px;
}

.drift-added   { background: #dcfce7; color: #166534; }
.drift-removed { background: #fee2e2; color: #991b1b; }
.drift-changed { background: #fef3c7; color: #92400e; }

/* ── Import queue detail lines ───────────────────────────────────────── */
/* The queue item is a block (name + status row, then an optional detail line)
   rather than a single flex row, so a long warning wraps under the name
   instead of squeezing the status out of view. */
.import-queue-item { display: block; }

.import-queue-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.import-queue-detail {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
    overflow-wrap: anywhere;
}

.import-queue-detail.is-warn-text { color: #92400e; }
.import-queue-detail.is-error-text { color: #991b1b; }

.import-queue-item.is-awaiting { border-color: #fcd34d; }
.import-queue-item.is-skipped { opacity: .6; }

/* ── Import confirm dialog ───────────────────────────────────────────── */

/* A 168-column audit workbook makes this dialog far taller than the viewport.
   Without an explicit max-height AND an internal scroll area, the footer — and
   the Import button with it — renders below the fold and cannot be reached. */
.import-dialog {
    width: min(46rem, calc(100vw - 32px));
    max-width: none;
    max-height: calc(100vh - 48px);
    padding: 0;
    border: none;
    background: transparent;
    overflow: visible;
}

.import-dialog > .card {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 48px);
}

.import-dialog-body {
    overflow-y: auto;
    min-height: 0;
}

.import-dialog::backdrop { background: rgba(15, 23, 42, .45); }

.import-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 0 0 16px;
}

.import-summary dt {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted, #6b7280);
}

.import-summary dd {
    margin: 2px 0 0;
    font-size: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.import-summary code,
.import-existing code {
    font-size: 13px;
    background: var(--bg-secondary, #f9fafb);
    border-radius: 4px;
    padding: 1px 5px;
}

.import-warnings {
    margin: 0 0 16px;
    padding: 10px 12px 10px 28px;
    border-radius: var(--radius-md, 8px);
    background: #fffbeb;
    color: #78350f;
    font-size: 13px;
    line-height: 1.45;
}

.import-warnings li + li { margin-top: 4px; }

/* Replace-in-place vs import-as-new. The default is REPLACE: re-importing next
   week's export is the whole point of the stable dataset id, and every
   dashboard built on it should follow the new data. */
.import-existing {
    margin: 0 0 16px;
    padding: 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-secondary, #f9fafb);
}

.import-existing-title { margin: 0 0 8px; font-size: 13px; }

.import-radio {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    font-size: 13px;
    line-height: 1.4;
    padding: 3px 0;
    cursor: pointer;
}

.import-radio input { margin-top: 3px; flex: none; }
.import-newid { margin: 8px 0 0; }

.import-columns-title {
    margin: 0 0 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted, #6b7280);
}

/* 168 columns scroll INSIDE their own box, so the dialog body stays navigable
   and a wide table never makes the page scroll sideways. */
.import-columns {
    max-height: 22rem;
    overflow: auto;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-md, 8px);
}

.import-columns .column-type-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-secondary, #f9fafb);
}

.import-col-name { font-weight: 600; overflow-wrap: anywhere; max-width: 18rem; }

.import-col-sample {
    color: var(--text-muted, #6b7280);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.import-col-type { white-space: nowrap; width: 1%; }

.import-type-select {
    width: auto;
    min-width: 104px;
    padding: 3px 6px;
    font-size: 12px;
}

/* The "guessed" badge marks a column typed from its NAME plus a plausible
   number range — nothing in the file declared it. That is the one inference a
   human should actually check before importing. */
.column-inferred-flag {
    display: inline-block;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-radius: 4px;
    padding: 1px 5px;
    background: #92400e;
    color: #fff;
    cursor: help;
}

@media (max-width: 640px) {
    .import-dialog { width: calc(100vw - 16px); }
    .import-columns { max-height: 16rem; }
    .import-col-sample,
    .import-columns .column-type-table thead th:nth-child(2) { display: none; }
}

/* ── Dataset list table ──────────────────────────────────────────────── */
.dataset-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 20px; }
.dataset-table th,
.dataset-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border-color, #e5e7eb); }
.dataset-table th { font-weight: 600; color: var(--text-muted, #6b7280); font-size: 12px; }
.dataset-table th.num, .dataset-table td.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.dataset-link { font-weight: 600; color: var(--link-color, #0d9488); text-decoration: none; }
.dataset-link:hover { text-decoration: underline; }
.dataset-row-id { font-size: 11px; color: var(--text-muted, #9ca3af); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ── Dataset detail ──────────────────────────────────────────────────── */
.back-link { font-size: 12px; color: var(--text-muted, #6b7280); text-decoration: none; }
.back-link:hover { text-decoration: underline; }

.detail-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .detail-columns { grid-template-columns: 1fr; } }

.detail-panel {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    background: var(--bg-primary, #fff);
    padding: 16px;
    margin-bottom: 16px;
    min-width: 0;
}

.detail-panel-title { margin: 0 0 10px; font-size: 14px; font-weight: 600; }

.type-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: #eef2ff;
    color: #3730a3;
}
.type-badge.type-number { background: #ecfdf5; color: #065f46; }
.type-badge.type-date, .type-badge.type-datetime { background: #eff6ff; color: #1e40af; }
.type-badge.type-string { background: #f3f4f6; color: #374151; }

/* Wide previews scroll inside their own box — the page never scrolls sideways. */
.preview-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
.dataset-preview-table { border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.dataset-preview-table th,
.dataset-preview-table td { padding: 4px 8px; border-bottom: 1px solid var(--border-color, #e5e7eb); text-align: left; }
.dataset-preview-table thead th { position: sticky; top: 0; background: var(--bg-secondary, #f9fafb); font-weight: 600; }
.preview-note { font-size: 12px; margin-top: 8px; }

/* ── Expected sources ────────────────────────────────────────────────────
   Which exports feed the boards, and which are stale. Status colour is the
   whole point: the eye should land on the overdue rows first. */
.source-panel {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    background: var(--bg-primary, #fff);
    padding: 16px;
    margin: 24px 0 20px;
}

.source-panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.source-panel-title { margin: 0; font-size: 15px; font-weight: 600; }
.dataset-list-title { margin: 28px 0 8px; }

.source-headline { font-size: 13px; font-weight: 600; }
.source-headline-ok { color: #15803d; }
.source-headline-action { color: #b45309; }

.source-due-list {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--text-primary, #111827);
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: var(--radius-md, 8px);
    padding: 8px 10px;
}

.source-unlisted { margin: 10px 0 0; font-size: 12px; color: var(--text-muted, #6b7280); }

/* Wide table scrolls in its own box — the page never scrolls sideways. */
.source-table-scroll { overflow-x: auto; }

.source-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.source-table th,
.source-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    vertical-align: top;
}
.source-table th { font-weight: 600; color: var(--text-muted, #6b7280); font-size: 12px; white-space: nowrap; }

.source-name { font-weight: 600; }
.source-file {
    font-size: 11px;
    color: var(--text-muted, #9ca3af);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.source-crit {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #b91c1c;
}
.source-feeds { color: var(--text-muted, #6b7280); font-size: 12px; max-width: 320px; }

.source-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.source-status-fresh   { background: #dcfce7; color: #14532d; }
.source-status-due     { background: #fef3c7; color: #78350f; }
.source-status-overdue { background: #fee2e2; color: #7f1d1d; }
.source-status-never   { background: #e5e7eb; color: #374151; }
.source-status-unknown { background: #e5e7eb; color: #374151; }

/* A left edge on the row itself, so a long list still reads at a glance. */
.source-row.source-overdue td:first-child { box-shadow: inset 3px 0 0 #dc2626; }
.source-row.source-due td:first-child     { box-shadow: inset 3px 0 0 #d97706; }
.source-row.source-never td:first-child   { box-shadow: inset 3px 0 0 #9ca3af; }

@media (max-width: 700px) {
    .source-feeds { display: none; }
    .source-table th:last-child, .source-table td:last-child { display: none; }
}

.source-blocked-note {
    margin: 0 0 12px;
    font-size: 13px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #3730a3;
    border-radius: var(--radius-md, 8px);
    padding: 8px 10px;
}
.source-status-blocked { background: #e0e7ff; color: #3730a3; }
.source-row.source-blocked td:first-child { box-shadow: inset 3px 0 0 #6366f1; }

/* ── Dashboard tab strip ─────────────────────────────────────────────────
   Flip between boards the way the old workbook's sheet tabs did. Hidden in
   present mode by the rules in page-dashboard.css, which switch off every
   piece of chrome outside the grid. */
.dash-tabs {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    margin: 0 0 16px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.dash-tab {
    flex: 0 0 auto;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted, #6b7280);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.dash-tab:hover { color: var(--text-primary, #111827); }

.dash-tab.is-active {
    color: var(--color-primary, #0d9488);
    border-bottom-color: var(--color-primary, #0d9488);
}

.dash-tab-all { margin-left: auto; font-weight: 500; }

/* ── Dataset cards ───────────────────────────────────────────────────────
   The LaunchPad card grid, applied to exports. Each card answers the three
   questions you actually have: what is it, is it current, and what period
   does it cover (top-right — the single most useful fact about an export). */
.ds-panel { margin: 24px 0 8px; }

.ds-section { margin-bottom: 1.75rem; }

.ds-section-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.75rem;
}

.ds-section-title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary, #111827);
}

.ds-section-count {
    font-size: 0.675rem;
    color: var(--text-muted, #6b7280);
    padding: 0.1rem 0.45rem;
    background: var(--bg-secondary, #f3f4f6);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 100px;
    font-variant-numeric: tabular-nums;
}

.ds-cards {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.ds-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.9rem 0.95rem;
    min-height: 118px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.ds-card:hover {
    transform: translateY(-3px);
    border-color: rgba(13, 148, 136, .35);
    box-shadow: 0 8px 22px rgba(0, 0, 0, .08);
}

.ds-card-top { display: flex; align-items: center; justify-content: space-between; }

.ds-card-chip {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: rgba(13, 148, 136, .10);
    color: var(--color-primary, #0d9488);
    display: inline-flex; align-items: center; justify-content: center;
}
.ds-card-chip svg { width: 16px; height: 16px; }

/* The coverage date. Deliberately prominent — a fresh import of a stale file
   is still a stale board, and this is the only thing on the card that says so. */
.ds-card-cover {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-primary, #111827);
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 100px;
    padding: 0.12rem 0.5rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.ds-card-cover-none { color: var(--text-muted, #9ca3af); font-weight: 500; }

.ds-card-name { margin: 0.15rem 0 0; font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; }
.ds-card-name a { color: inherit; text-decoration: none; }
.ds-card-name a::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.ds-card:hover .ds-card-name a { color: var(--color-primary, #0d9488); }

.ds-card-file {
    margin: 0;
    font-size: 0.7rem;
    color: var(--text-muted, #9ca3af);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ds-card-foot {
    margin-top: auto;
    display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
    padding-top: 0.4rem;
    /* Two narrow columns on a phone leave too little room for both; let the
       pair stack rather than breaking "86,136 rows" across lines. */
    flex-wrap: wrap;
}

.ds-card-rows { font-size: 0.7rem; white-space: nowrap; color: var(--text-muted, #6b7280); font-variant-numeric: tabular-nums; }

/* Status shows as a left edge as well as a chip, so a wall of cards still
   reads at a glance. */
.ds-card-overdue { border-left: 3px solid #dc2626; }
.ds-card-due     { border-left: 3px solid #d97706; }
.ds-card-never   { border-left: 3px solid #9ca3af; }
.ds-card-blocked { border-left: 3px solid #6366f1; }
.ds-card-fresh   { border-left: 3px solid #16a34a; }

.ds-card[data-critical="1"] .ds-card-name::after {
    content: '';
    display: inline-block;
    width: 5px; height: 5px;
    margin-left: 6px;
    border-radius: 50%;
    background: #dc2626;
    vertical-align: middle;
}

@media (prefers-reduced-motion: reduce) {
    .ds-card { transition: none; }
    .ds-card:hover { transform: none; }
}

/* Import age sits where the coverage date used to — small and muted, because
   it answers a lesser question than the chip below it does. */
.ds-card-imported {
    font-size: 0.675rem;
    color: var(--text-muted, #9ca3af);
    white-space: nowrap;
}
