/* ============================================================
   RFM Insight — data-dense dashboard
   Light + dark, pure CSS, no build step.
   ============================================================ */

:root {
    --font-sans: 'Fira Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Consolas, monospace;

    --bg: #f5f8fd;
    --bg-image: radial-gradient(1100px 600px at 100% -10%, rgba(30, 64, 175, .07), transparent 60%),
                radial-gradient(900px 500px at -10% 110%, rgba(217, 119, 6, .05), transparent 60%);
    --surface: #ffffff;
    --surface-2: #f1f5fb;
    --surface-3: #e2e9f4;
    --text: #0f1b2d;
    --muted: #5a6b84;
    --border: #dde6f2;

    --primary: #1e40af;
    --primary-strong: #17358f;
    --primary-soft: #e3ebff;
    --on-primary: #ffffff;

    --accent: #b45309;
    --accent-fill: #d97706;

    --good: #0f766e;
    --good-soft: #d9f5ef;
    --warn: #a16207;
    --warn-soft: #fdf0cf;
    --bad: #b91c1c;
    --bad-soft: #fde3e3;
    --info: #1d4ed8;
    --info-soft: #e2ebff;

    --chart-grid: rgba(15, 27, 45, .08);
    --chart-text: #5a6b84;

    --shadow-sm: 0 1px 2px rgba(15, 27, 45, .05), 0 2px 8px rgba(15, 27, 45, .04);
    --shadow-md: 0 18px 40px -28px rgba(15, 27, 45, .45);

    --radius: 16px;
    --radius-sm: 10px;
    --sidebar: 264px;
}

[data-theme="dark"] {
    --bg: #091120;
    --bg-image: radial-gradient(1100px 600px at 100% -10%, rgba(96, 165, 250, .10), transparent 60%),
                radial-gradient(900px 500px at -10% 110%, rgba(251, 191, 36, .05), transparent 60%);
    --surface: #101a2b;
    --surface-2: #16233a;
    --surface-3: #1d2d49;
    --text: #e7eef9;
    --muted: #9cb0ca;
    --border: #23324c;

    --primary: #8ab4ff;
    --primary-strong: #a9c8ff;
    --primary-soft: #17264a;
    --on-primary: #071226;

    --accent: #fbbf24;
    --accent-fill: #f59e0b;

    --good: #5eead4;
    --good-soft: #0b3b36;
    --warn: #fcd34d;
    --warn-soft: #3a2a0a;
    --bad: #fca5a5;
    --bad-soft: #3d1515;
    --info: #93b4ff;
    --info-soft: #14244b;

    --chart-grid: rgba(231, 238, 249, .09);
    --chart-text: #9cb0ca;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 10px rgba(0, 0, 0, .25);
    --shadow-md: 0 22px 48px -30px rgba(0, 0, 0, .8);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    color-scheme: light;
}

[data-theme="dark"] {
    color-scheme: dark;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    background-image: var(--bg-image);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p {
    margin-top: 0;
}

img {
    max-width: 100%;
}

::selection {
    background: var(--primary-soft);
    color: var(--text);
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.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;
}

.skip-link {
    position: fixed;
    left: 12px;
    top: -60px;
    z-index: 999;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--primary);
    color: var(--on-primary);
    text-decoration: none;
    font-weight: 600;
    transition: top .2s ease;
}

.skip-link:focus {
    top: 12px;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 12px;
}

code {
    font-family: var(--font-mono);
    font-size: .92em;
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--surface-3);
}

.icon {
    width: 18px;
    height: 18px;
    flex: none;
}

/* ---------- App shell ---------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    min-height: 100dvh;
}

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 14px;
    border-right: 1px solid var(--border);
    background: var(--surface);
    z-index: 40;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px 16px;
    border-bottom: 1px solid var(--border);
}

.brand__mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    box-shadow: 0 8px 18px -10px #1e40af;
}

.brand__mark .icon {
    width: 20px;
    height: 20px;
}

.brand strong {
    display: block;
    font-size: 15px;
    letter-spacing: -.01em;
}

.brand small {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-top: 1px;
}

.side-label {
    display: block;
    padding: 0 10px;
    margin-bottom: 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .13em;
    color: var(--muted);
}

.side-block {
    display: flex;
    flex-direction: column;
}

.dataset-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dataset {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    transition: background .15s ease, border-color .15s ease;
}

.dataset:hover {
    background: var(--surface-2);
}

.dataset.is-active {
    background: var(--surface-2);
    border-color: var(--border);
}

.dataset__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--dot, var(--primary));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot, var(--primary)) 18%, transparent);
    flex: none;
}

.dataset__text {
    min-width: 0;
}

.dataset strong {
    display: block;
    font-size: 12.5px;
    line-height: 1.3;
}

.dataset small {
    display: block;
    font-size: 10.5px;
    color: var(--muted);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    transition: background .15s ease, color .15s ease;
}

.nav__item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav__item.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--primary);
}

.side-foot {
    margin-top: auto;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.side-foot__icon {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--primary);
    flex: none;
}

.side-foot__icon .icon {
    width: 16px;
    height: 16px;
}

.side-foot strong {
    display: block;
    font-size: 11.5px;
}

.side-foot small {
    display: block;
    font-size: 10.5px;
    color: var(--muted);
    line-height: 1.4;
}

.main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 24px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.topbar__crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--muted);
    min-width: 0;
}

.topbar__crumb strong {
    color: var(--text);
    font-weight: 600;
    white-space: nowrap;
}

.topbar__sep {
    opacity: .5;
}

.topbar__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.content {
    width: 100%;
    max-width: 1520px;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
}

.site-foot {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 1520px;
    width: 100%;
    margin: 0 auto;
    padding: 18px 24px 26px;
    font-size: 11px;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

/* ---------- Buttons, pills, badges ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
    touch-action: manipulation;
}

.btn:hover {
    background: var(--surface-2);
    border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

.btn:active {
    transform: scale(.985);
}

.btn .icon {
    width: 16px;
    height: 16px;
}

.btn--primary {
    background: var(--primary);
    border-color: transparent;
    color: var(--on-primary);
    box-shadow: 0 10px 22px -14px var(--primary);
}

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

.btn--ghost {
    background: transparent;
}

.btn--sm {
    padding: 6px 10px;
    font-size: 11.5px;
    border-radius: 8px;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.icon-btn .icon {
    width: 18px;
    height: 18px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    white-space: nowrap;
}

.pill .icon {
    width: 13px;
    height: 13px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .01em;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--muted);
}

.badge--good { background: var(--good-soft); color: var(--good); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--bad { background: var(--bad-soft); color: var(--bad); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--neutral { background: var(--surface-2); color: var(--muted); }

.theme-icon {
    display: grid;
    place-items: center;
}

[data-theme="light"] .theme-icon--sun { display: none; }
[data-theme="dark"] .theme-icon--moon { display: none; }

/* ---------- Page head ---------- */

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin: 2px 0 20px;
}

.page-head__text {
    min-width: 0;
}

.eyebrow {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .13em;
    color: var(--primary);
}

.page-head h1 {
    margin: 5px 0 6px;
    font-size: clamp(24px, 2.6vw, 32px);
    line-height: 1.12;
    letter-spacing: -.025em;
    font-weight: 600;
}

.page-head p {
    margin: 0;
    max-width: 72ch;
    color: var(--muted);
    font-size: 13px;
}

.page-head__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---------- KPIs ---------- */

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(186px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kpi {
    position: relative;
    padding: 15px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    min-width: 0;
    overflow: hidden;
}

.kpi::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), transparent 75%);
    opacity: .5;
}

.kpi__top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.kpi__label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
}

.kpi__icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary);
    flex: none;
}

.kpi__icon .icon {
    width: 16px;
    height: 16px;
}

.tone-primary { background: var(--primary-soft); color: var(--primary); }
.tone-good { background: var(--good-soft); color: var(--good); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-bad { background: var(--bad-soft); color: var(--bad); }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-neutral { background: var(--surface-2); color: var(--muted); }

.tone-bg-good { background: var(--good); }
.tone-bg-warn { background: var(--warn); }
.tone-bg-bad { background: var(--bad); }

.kpi__value {
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: clamp(19px, 1.9vw, 26px);
    font-weight: 600;
    letter-spacing: -.03em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    word-break: break-word;
}

.kpi__hint {
    margin: 4px 0 0;
    font-size: 11.5px;
    color: var(--muted);
}

.kpi__foot {
    margin-top: 5px;
    font-size: 10px;
    color: var(--muted);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Insights ---------- */

.insights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.insight {
    display: flex;
    gap: 11px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.insight__icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--muted);
    flex: none;
}

.insight__icon .icon {
    width: 16px;
    height: 16px;
}

.insight--good .insight__icon { background: var(--good-soft); color: var(--good); }
.insight--warn .insight__icon { background: var(--warn-soft); color: var(--warn); }
.insight--bad .insight__icon { background: var(--bad-soft); color: var(--bad); }
.insight--info .insight__icon { background: var(--info-soft); color: var(--info); }

.insight h3 {
    margin: 0 0 2px;
    font-size: 12.5px;
    line-height: 1.35;
    letter-spacing: -.005em;
}

.insight p {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
}

.insight strong {
    color: var(--text);
    font-weight: 600;
}

/* ---------- Notice ---------- */

.notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    margin-bottom: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    font-size: 12.5px;
    color: var(--muted);
}

.notice .icon {
    width: 17px;
    height: 17px;
    margin-top: 1px;
    color: var(--primary);
}

.notice p {
    margin: 0;
}

.notice strong {
    color: var(--text);
}

.notice--warn {
    background: var(--warn-soft);
    border-color: color-mix(in srgb, var(--warn) 30%, var(--border));
    color: var(--text);
}

.notice--warn .icon {
    color: var(--warn);
}

/* ---------- Grids & cards ---------- */

.grid {
    display: grid;
    gap: 16px;
    margin-bottom: 16px;
}

.grid--main {
    grid-template-columns: minmax(0, 1.9fr) minmax(290px, .85fr);
}

.grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid--split {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
}

.card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 17px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 13px;
}

.card__head h2 {
    margin: 0;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -.01em;
}

.card__head p {
    margin: 3px 0 0;
    font-size: 11.5px;
    color: var(--muted);
    max-width: 72ch;
}

.card__actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 22px 0 12px;
}

.section-head h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: -.015em;
}

.section-head p {
    margin: 3px 0 0;
    font-size: 12px;
    color: var(--muted);
    max-width: 80ch;
}

/* ---------- Charts ---------- */

.chart {
    position: relative;
    width: 100%;
    height: 300px;
}

.chart--tall {
    height: 420px;
}

.chart canvas {
    display: block;
    max-width: 100%;
}

.chart-note {
    margin: 10px 0 0;
    font-size: 10.5px;
    color: var(--muted);
}

.chart-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.search {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1 1 210px;
    min-width: 190px;
    max-width: 300px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--muted);
}

.search:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search__icon .icon {
    width: 15px;
    height: 15px;
}

.search input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 12.5px;
}

.search input::placeholder {
    color: var(--muted);
}

.seg-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.seg-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}

.seg-chip:hover {
    background: var(--surface-2);
}

.seg-chip.is-active {
    background: color-mix(in srgb, var(--seg) 9%, var(--surface));
    border-color: color-mix(in srgb, var(--seg) 34%, var(--border));
    color: var(--text);
}

.seg-chip.is-off {
    opacity: .45;
    background: var(--surface-2);
}

.seg-chip.is-off .seg-chip__dot {
    background: var(--muted);
}

.seg-chip__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--seg);
    flex: none;
}

.seg-chip__meta {
    font-family: var(--font-mono);
    font-size: 9.5px;
    opacity: .7;
}

.mini-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 7px;
    margin-top: 12px;
}

.mini-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
    min-width: 0;
}

.mini-user strong {
    display: block;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mini-user small {
    display: block;
    font-size: 10px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.mini-user__value {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text);
    white-space: nowrap;
}

/* ---------- Segment mix / legend ---------- */

.donut-wrap {
    position: relative;
    width: 100%;
    max-width: 250px;
    height: 215px;
    margin: 0 auto 10px;
}

.donut-center {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
    pointer-events: none;
}

.donut-center span {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted);
}

.donut-center strong {
    font-family: var(--font-mono);
    font-size: 21px;
    letter-spacing: -.02em;
}

.legend-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.legend-row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    grid-template-areas:
        "dot name value"
        "bar bar bar";
    gap: 2px 8px;
    width: 100%;
    padding: 7px 8px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}

.legend-row:hover {
    background: var(--surface-2);
}

.legend-row.is-off {
    opacity: .45;
}

.legend-row__dot {
    grid-area: dot;
    width: 8px;
    height: 8px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--seg);
}

.legend-row__name {
    grid-area: name;
    min-width: 0;
}

.legend-row__name strong {
    display: block;
    font-size: 11.5px;
    line-height: 1.3;
}

.legend-row__name small {
    display: block;
    font-size: 9.5px;
    color: var(--muted);
}

.legend-row__value {
    grid-area: value;
    text-align: right;
}

.legend-row__value strong {
    display: block;
    font-size: 11.5px;
    font-family: var(--font-mono);
}

.legend-row__value small {
    display: block;
    font-size: 9px;
    color: var(--muted);
}

.legend-row__bar {
    grid-area: bar;
    position: relative;
    height: 4px;
    margin-top: 4px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}

.legend-row__bar span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--seg);
}

/* ---------- Top customers ---------- */

.top-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.top-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto;
    align-items: center;
    gap: 2px 9px;
    padding: 8px;
    border-radius: 9px;
}

.top-row:hover {
    background: var(--surface-2);
}

.top-row__rank {
    grid-row: 1 / 3;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
    text-align: center;
}

.top-row__main {
    min-width: 0;
}

.top-row__main strong {
    display: block;
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-row__main small {
    display: block;
    font-size: 9.5px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.top-row__side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.top-row__value {
    font-family: var(--font-mono);
    font-size: 11px;
    white-space: nowrap;
}

/* ---------- Cluster cards ---------- */

.cluster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(228px, 1fr));
    gap: 11px;
    margin-bottom: 16px;
}

.cluster-card {
    display: flex;
    flex-direction: column;
    gap: 9px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-top: 3px solid var(--seg);
    border-radius: 13px;
    background: var(--surface);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.cluster-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.cluster-card.is-off {
    opacity: .45;
}

.cluster-card__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cluster-id {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
}

.cluster-card__size {
    font-size: 11.5px;
    color: var(--muted);
}

.cluster-card__size strong {
    font-family: var(--font-mono);
    font-size: 20px;
    color: var(--text);
    margin-right: 2px;
}

.cluster-card__stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
}

.cluster-card__stats > span {
    display: flex;
    flex-direction: column;
    padding: 6px 7px;
    border-radius: 7px;
    background: var(--surface-2);
    min-width: 0;
}

.cluster-card__stats small {
    font-size: 8.5px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}

.cluster-card__stats strong {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cluster-card__bar {
    height: 5px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}

.cluster-card__bar > span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--seg);
}

.cluster-card__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 10px;
    color: var(--muted);
}

.cluster-card__foot strong {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text);
}

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

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th,
.data-table td {
    padding: 8px 9px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table thead th {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    white-space: nowrap;
}

.data-table tbody tr:last-child th,
.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table .num {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.metric {
    display: flex;
    align-items: center;
    gap: 7px;
}

.metric__bar {
    width: 74px;
    height: 5px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
    flex: none;
}

.metric__fill {
    display: block;
    height: 100%;
    border-radius: 999px;
}

.metric__value {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--muted);
}

/* ---------- Artifacts ---------- */

.artifacts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 7px;
}

.artifact {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: inherit;
    text-decoration: none;
    transition: border-color .15s ease, background .15s ease;
    min-width: 0;
}

.artifact:hover {
    border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
    background: var(--surface-2);
}

.artifact__icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary);
    flex: none;
}

.artifact__icon .icon {
    width: 15px;
    height: 15px;
}

.artifact__body {
    min-width: 0;
    flex: 1;
}

.artifact__name {
    display: block;
    font-family: var(--font-mono);
    font-size: 10.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artifact__desc {
    display: block;
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artifact__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    flex: none;
}

.artifact__type {
    font-size: 8.5px;
    font-weight: 700;
    letter-spacing: .08em;
    color: var(--primary);
}

.artifact__size {
    font-family: var(--font-mono);
    font-size: 9.5px;
    color: var(--muted);
}

/* ---------- Figures, details, empty ---------- */

.figure {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 11px;
    overflow: hidden;
    background: #ffffff;
}

.figure img {
    display: block;
    width: 100%;
    height: auto;
    background: #ffffff;
}

.figure figcaption {
    padding: 7px 10px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 9.5px;
}

.figure figcaption a {
    color: var(--primary);
}

.figure--compact {
    margin-bottom: 10px;
}

.plot-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.plot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
    padding: 0 0 14px;
}

.plot-grid figcaption {
    border-top: 1px solid var(--border);
}

.details {
    margin: 0 0 16px;
    padding: 2px 16px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface);
}

.details summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.details summary::-webkit-details-marker {
    display: none;
}

.details summary .icon {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

.details[open] summary {
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 30px 18px;
    text-align: center;
    color: var(--muted);
    min-height: 160px;
}

.empty__icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--muted);
}

.empty__icon .icon {
    width: 20px;
    height: 20px;
}

.empty h3 {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text);
}

.empty p {
    margin: 0;
    font-size: 11.5px;
    max-width: 48ch;
}

/* ---------- Mobile navigation ---------- */

.scrim {
    display: none;
}

[data-menu] {
    display: none;
}

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

    .grid--3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1024px) {
    .app {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(302px, 86vw);
        height: 100dvh;
        transform: translateX(-103%);
        transition: transform .25s cubic-bezier(.22, 1, .36, 1);
        box-shadow: 0 30px 60px -20px rgba(2, 6, 23, .55);
        border-right: 1px solid var(--border);
    }

    body.nav-open .sidebar {
        transform: translateX(0);
    }

    .scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 35;
        background: rgba(2, 6, 23, .55);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    body.nav-open .scrim {
        opacity: 1;
        pointer-events: auto;
    }

    [data-menu] {
        display: grid;
    }

    .topbar {
        padding: 10px 16px;
    }

    .content {
        padding: 18px 16px;
    }

    .grid--2,
    .grid--3 {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 720px) {
    .kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .page-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-head__actions {
        width: 100%;
    }

    .page-head__actions .btn {
        flex: 1;
    }

    .topbar__crumb > span:first-child,
    .topbar__sep,
    .pill--muted {
        display: none;
    }

    .chart--tall {
        height: 340px;
    }

    .chart-toolbar {
        align-items: stretch;
    }

    .search {
        max-width: none;
        flex-basis: 100%;
    }

    .site-foot {
        flex-direction: column;
    }
}

@media (max-width: 440px) {
    .kpis {
        grid-template-columns: minmax(0, 1fr);
    }

    .cluster-card__stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* ---------- Motion & print ---------- */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

@media print {
    .sidebar,
    .topbar,
    .scrim,
    .skip-link,
    .page-head__actions,
    .seg-chips,
    .search,
    [data-scale-toggle] {
        display: none !important;
    }

    .app {
        display: block;
    }

    .card,
    .kpi,
    .insight {
        box-shadow: none;
        break-inside: avoid;
    }

    .content {
        max-width: none;
        padding: 0;
    }
}