/* ============================================================
   VONDL — Admin analytics design system (VON-44)
   Palette: dataviz reference instance (validated light + dark).
   Tokens live here on `.vw-analytics`; scoped component CSS
   references them (custom properties inherit through the DOM).
   INTEGRATION: the shared admin shell (VON-43) is dark; this
   token block supports both modes and follows prefers-color-scheme.
   ============================================================ */

.vw-analytics {
    color-scheme: light;

    /* Surfaces & ink */
    --vw-surface: #fcfcfb;
    --vw-plane: #f9f9f7;
    --vw-elevated: #ffffff;
    --vw-ink: #0b0b0b;
    --vw-ink-2: #52514e;
    --vw-muted: #898781;
    --vw-grid: #e1e0d9;
    --vw-baseline: #c3c2b7;
    --vw-border: rgba(11, 11, 11, 0.10);
    --vw-hover: rgba(11, 11, 11, 0.04);

    /* Categorical series (fixed order, never cycled) */
    --vw-s1: #2a78d6;
    --vw-s2: #eb6834;
    --vw-s3: #1baf7a;
    --vw-s4: #eda100;
    --vw-s5: #e87ba4;
    --vw-s6: #008300;
    --vw-s7: #4a3aa7;
    --vw-s8: #e34948;

    /* Sequential (magnitude) — single blue hue */
    --vw-seq-fill: #2a78d6;
    --vw-seq-track: #cde2fb;

    /* Status (fixed, never themed) + delta text */
    --vw-good: #0ca30c;
    --vw-good-text: #006300;
    --vw-warning: #fab219;
    --vw-serious: #ec835a;
    --vw-critical: #d03b3b;
    --vw-down-text: #b0332f;

    color: var(--vw-ink);
    font-family: system-ui, -apple-system, "Segoe UI", "Inter", sans-serif;
    padding: clamp(16px, 3vw, 30px);

    /* The analytics area is a themed surface inside the (always-dark) admin shell.
       Filling the main content region keeps the dataviz palette cohesive rather than
       floating cards over the shell's navy background. */
    background: var(--vw-plane);
    flex: 1 1 auto;
    min-height: 100%;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .vw-analytics {
        color-scheme: dark;
        --vw-surface: #1a1a19;
        --vw-plane: #0d0d0d;
        --vw-elevated: #232322;
        --vw-ink: #ffffff;
        --vw-ink-2: #c3c2b7;
        --vw-muted: #898781;
        --vw-grid: #2c2c2a;
        --vw-baseline: #383835;
        --vw-border: rgba(255, 255, 255, 0.10);
        --vw-hover: rgba(255, 255, 255, 0.05);
        --vw-s1: #3987e5;
        --vw-s2: #d95926;
        --vw-s3: #199e70;
        --vw-s4: #c98500;
        --vw-s5: #d55181;
        --vw-s6: #008300;
        --vw-s7: #9085e9;
        --vw-s8: #e66767;
        --vw-seq-fill: #3987e5;
        --vw-seq-track: #184f95;
        --vw-good-text: #0ca30c;
        --vw-down-text: #e66767;
    }
}

:root[data-theme="dark"] .vw-analytics {
    color-scheme: dark;
    --vw-surface: #1a1a19;
    --vw-plane: #0d0d0d;
    --vw-elevated: #232322;
    --vw-ink: #ffffff;
    --vw-ink-2: #c3c2b7;
    --vw-muted: #898781;
    --vw-grid: #2c2c2a;
    --vw-baseline: #383835;
    --vw-border: rgba(255, 255, 255, 0.10);
    --vw-hover: rgba(255, 255, 255, 0.05);
    --vw-s1: #3987e5;
    --vw-s2: #d95926;
    --vw-s3: #199e70;
    --vw-s4: #c98500;
    --vw-s5: #d55181;
    --vw-s6: #008300;
    --vw-s7: #9085e9;
    --vw-s8: #e66767;
    --vw-seq-fill: #3987e5;
    --vw-seq-track: #184f95;
    --vw-good-text: #0ca30c;
    --vw-down-text: #e66767;
}

/* ---------- Layout ---------- */
.vw-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.vw-page-head h1 {
    font-size: clamp(1.4rem, 2.4vw, 1.85rem);
    font-weight: 650;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--vw-ink);
}

.vw-page-sub {
    color: var(--vw-ink-2);
    font-size: 0.9rem;
    margin-top: 4px;
}

.vw-grid {
    display: grid;
    gap: 16px;
}

.vw-kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
}

.vw-two-col {
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

.vw-three-col {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.vw-section-gap {
    margin-top: 16px;
}

/* ---------- Card ---------- */
.vw-card {
    background: var(--vw-surface);
    border: 1px solid var(--vw-border);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.vw-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.vw-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--vw-ink);
    margin: 0;
}

.vw-card-note {
    font-size: 0.78rem;
    color: var(--vw-muted);
}

/* ---------- Chart chrome ---------- */
.vw-axis-label,
.vw-tick {
    fill: var(--vw-muted);
    font-size: 11px;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}

.vw-gridline {
    stroke: var(--vw-grid);
    stroke-width: 1;
}

.vw-baseline {
    stroke: var(--vw-baseline);
    stroke-width: 1;
}

/* ---------- Ranked bars (top-N breakdowns; reused directly in pages) ---------- */
.vw-rb {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.vw-rb-row {
    display: grid;
    grid-template-columns: minmax(90px, 42%) 1fr auto;
    align-items: center;
    gap: 12px;
}

.vw-rb-label {
    font-size: 0.83rem;
    color: var(--vw-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vw-rb-label a {
    color: var(--vw-ink);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.vw-rb-label a:hover {
    border-bottom-color: var(--vw-baseline);
}

.vw-rb-track {
    height: 16px;
    display: flex;
    align-items: center;
}

.vw-rb-fill {
    height: 16px;
    min-width: 2px;
    border-radius: 0 4px 4px 0;
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
    .vw-rb-fill { transition: none; }
}

.vw-rb-value {
    font-size: 0.82rem;
    font-weight: 550;
    color: var(--vw-ink-2);
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 44px;
}

.vw-rb-empty {
    font-size: 0.85rem;
    color: var(--vw-muted);
    padding: 8px 0;
    margin: 0;
}

/* Image-based flags (flagcdn) — emoji flags don't render on Windows. */
.vw-flag {
    display: inline-block;
    width: 20px;
    height: 15px;
    flex: 0 0 auto;
    border-radius: 2px;
    object-fit: cover;
    vertical-align: middle;
    box-shadow: 0 0 0 1px rgba(11, 11, 11, 0.10);
    background: var(--vw-hover);
}

/* Neutral placeholder when the country is unknown. */
.vw-flag--empty {
    box-shadow: 0 0 0 1px rgba(11, 11, 11, 0.06);
}

/* onerror fallback: a small 2-letter ISO chip when the image can't load. */
.vw-flag--code {
    width: auto;
    height: 15px;
    padding: 0 3px;
    font-family: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
    font-size: 0.66rem;
    font-weight: 600;
    line-height: 15px;
    letter-spacing: 0.02em;
    color: var(--vw-ink-2);
    background: var(--vw-hover);
    box-shadow: none;
    text-align: center;
}

.vw-footnote {
    margin-top: 20px;
    font-size: 0.76rem;
    color: var(--vw-muted);
}

/* ---------- Charts (shared across widgets) ---------- */
.vw-chart {
    margin: 0;
}

.vw-chart-svg {
    display: block;
    width: 100%;
    height: auto;
}

.vw-chart-empty {
    font-size: 0.85rem;
    color: var(--vw-muted);
    padding: 24px 0;
    margin: 0;
    text-align: center;
}

.vw-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 10px;
}

.vw-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.8rem;
    color: var(--vw-ink-2);
}

.vw-legend-key {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex: 0 0 auto;
}

.vw-hoverband {
    cursor: crosshair;
}

.vw-hoverband:hover {
    fill: var(--vw-hover);
}

/* ---------- Filters ---------- */
.vw-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.vw-search {
    display: inline-flex;
    gap: 8px;
    flex: 1 1 260px;
    min-width: 220px;
}

.vw-search input {
    flex: 1;
    font: inherit;
    font-size: 0.87rem;
    color: var(--vw-ink);
    background: var(--vw-surface);
    border: 1px solid var(--vw-border);
    border-radius: 9px;
    padding: 8px 12px;
}

.vw-search input:focus-visible {
    outline: 2px solid var(--vw-s1);
    outline-offset: 1px;
}

.vw-facet {
    font: inherit;
    font-size: 0.84rem;
    color: var(--vw-ink);
    background: var(--vw-surface);
    border: 1px solid var(--vw-border);
    border-radius: 9px;
    padding: 8px 10px;
    max-width: 200px;
    color-scheme: inherit;
}

.vw-filters-clear {
    color: var(--vw-down-text);
}

.vw-filters-export {
    margin-left: auto;
}

/* ---------- Table ---------- */
.vw-table-card {
    padding: 0;
    overflow: hidden;
}

.vw-table-scroll {
    overflow-x: auto;
}

.vw-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.vw-table thead th {
    text-align: left;
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--vw-muted);
    padding: 12px 16px;
    border-bottom: 1px solid var(--vw-border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--vw-surface);
}

.vw-table th.vw-num,
.vw-table td.vw-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.vw-th-btn {
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    color: inherit;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.vw-th-btn:hover { color: var(--vw-ink); }
.vw-th-sort.is-active { color: var(--vw-ink); }
.vw-th-ind { font-size: 0.7em; }

.vw-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--vw-border);
    color: var(--vw-ink);
    vertical-align: middle;
}

.vw-table tbody tr:last-child td { border-bottom: none; }

.vw-row {
    cursor: pointer;
    transition: background 0.12s ease;
}

.vw-row:hover { background: var(--vw-hover); }

.vw-row:focus-visible {
    outline: 2px solid var(--vw-s1);
    outline-offset: -2px;
}

/* The org cell stays a normal table-cell so its bottom border sits on the shared
   row baseline (a `display:flex` <td> drops out of the row-height model and its
   separator line renders offset — that was the "asymmetric lines" bug). The flex
   layout lives on an inner wrapper instead. */
.vw-cell-org {
    max-width: 320px;
}

.vw-org-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.vw-org-name {
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}

.vw-org-isp {
    font-size: 0.76rem;
    color: var(--vw-muted);
    flex-basis: 100%;
}

.vw-when { color: var(--vw-ink-2); white-space: nowrap; }
.vw-row-skel td { padding: 14px 16px; }

/* ---------- Pager ---------- */
.vw-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--vw-border);
}

.vw-pager-info {
    font-size: 0.82rem;
    color: var(--vw-ink-2);
    font-variant-numeric: tabular-nums;
}

.vw-pager-controls {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.vw-pager-page {
    font-size: 0.82rem;
    color: var(--vw-ink-2);
    font-variant-numeric: tabular-nums;
}

.vw-pager-size select {
    font: inherit;
    font-size: 0.82rem;
    color: var(--vw-ink);
    background: var(--vw-surface);
    border: 1px solid var(--vw-border);
    border-radius: 8px;
    padding: 6px 8px;
    color-scheme: inherit;
}

/* ---------- States ---------- */
.vw-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--vw-ink-2);
}

.vw-state svg {
    width: 34px;
    height: 34px;
    opacity: 0.55;
}

.vw-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--vw-ink);
    margin: 0;
}

.vw-state p {
    font-size: 0.85rem;
    max-width: 42ch;
    margin: 0;
}

.vw-state--error h3 {
    color: var(--vw-critical);
}

.vw-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 550;
    color: var(--vw-ink);
    background: var(--vw-surface);
    border: 1px solid var(--vw-border);
    border-radius: 9px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    text-decoration: none;
}

.vw-btn:hover {
    background: var(--vw-hover);
}

.vw-btn:focus-visible {
    outline: 2px solid var(--vw-s1);
    outline-offset: 2px;
}

.vw-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.vw-btn--primary {
    color: #fff;
    background: var(--vw-s1);
    border-color: transparent;
}

.vw-btn--primary:hover {
    background: #256abf;
}

/* Skeleton tile — mirrors StatTile's box so the loading grid keeps its shape.
   (StatTile's own .vw-tile styles are component-scoped and don't reach the
   plain skeleton markup, so the box is restated here in the global sheet.) */
.vw-skel-tile {
    background: var(--vw-surface);
    border: 1px solid var(--vw-border);
    border-radius: 14px;
    padding: 16px 18px 14px;
    min-height: 118px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

/* Skeleton shimmer for loading state */
.vw-skel {
    background: linear-gradient(90deg, var(--vw-hover) 25%, rgba(137, 135, 129, 0.12) 37%, var(--vw-hover) 63%);
    background-size: 400% 100%;
    border-radius: 8px;
    animation: vw-shimmer 1.4s ease-in-out infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .vw-skel { animation: none; }
}

/* ---------- Badges ---------- */
.vw-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 550;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--vw-border);
    color: var(--vw-ink-2);
    background: var(--vw-plane);
    white-space: nowrap;
}

.vw-badge--dns {
    color: #fff;
    background: var(--vw-s7);
    border-color: transparent;
}

/* ---------- Screen-reader helper ---------- */
.vw-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
