:root {
    --blue-darkest: #0b3072;
    --blue-dark: #366ac7;
    --blue-medium: #1d7aec;
    --grey-light-1: #d2dfef;
    --grey-light-2: #e1e2e8;
    --grey-light-3: #edeef4;
    --grey-light-4: #f4f6f9;
    --grey-medium: #747f91;
    --black: #0d1726;
    --white: #fff;
    --font-family: "Barlow", sans-serif;
    --sidebar-width: 248px;
    --header-height: 70px;
    --transition-speed: 0.24s;
    --chart-blue: #1d7aec;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { font-size: 100%; }

body {
    margin: 0;
    min-width: 320px;
    background: var(--theme-page-bg);
    color: var(--theme-text);
    font-family: var(--font-family);
    line-height: 1.5;
    padding-top: var(--header-height);
}

button, input { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.metrics-locked #page-header,
.metrics-locked #content-wrapper { visibility: hidden; }

.access-gate {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(circle at 20% 10%, rgba(89, 155, 255, 0.2), transparent 34rem),
        linear-gradient(145deg, #071a3b, #0b3072 55%, #174d9f);
}

.access-gate[hidden] { display: none; }

.access-gate-card {
    width: min(410px, 100%);
    padding: 2.4rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 26px 70px rgba(1, 10, 28, 0.35);
    color: #fff;
    text-align: center;
    backdrop-filter: blur(18px);
}

.gate-mark {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin: 0 auto 1rem;
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.16);
    font-size: 1.4rem;
}

.access-gate h1 { margin: 0; font-size: 1.55rem; }
.access-gate p { margin: 0.45rem 0 0; color: rgba(255, 255, 255, 0.76); }

.gate-link {
    display: inline-flex;
    margin-top: 1.3rem;
    padding: 0.65rem 1rem;
    border-radius: 10px;
    background: #fff;
    color: #0b3072;
    font-weight: 600;
    text-decoration: none;
}

#page-header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1100;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 1.1rem;
    background: var(--theme-header-bg);
    box-shadow: 0 2px 10px rgba(2, 17, 45, 0.22);
    color: #fff;
}

.header-actions { display: flex; align-items: center; gap: 0.55rem; margin-left: auto; }

.icon-button,
.logout-button {
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    transition: background var(--transition-speed), transform var(--transition-speed);
}

.icon-button { width: 38px; height: 38px; border-radius: 50%; }
.logout-button { padding: 0.45rem 0.9rem; border-radius: 20px; font-size: 0.86rem; font-weight: 500; }
.icon-button:hover, .logout-button:hover { background: rgba(255, 255, 255, 0.24); }
.icon-button:active, .logout-button:active { transform: translateY(1px); }
.icon-button.refreshing i { animation: rotate 0.8s linear infinite; }

#content-wrapper { display: flex; min-height: calc(100vh - var(--header-height)); }

.sidebar {
    position: sticky;
    top: var(--header-height);
    align-self: flex-start;
    z-index: 1000;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    flex: 0 0 var(--sidebar-width);
    margin-left: 0;
    padding: 1rem 0 1rem 1rem;
    background: var(--theme-sidebar-bg);
    color: #fff;
    transition: margin-left var(--transition-speed) ease;
}

.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-width)); }

.sidebar-content {
    display: flex;
    height: 100%;
    flex-direction: column;
    overflow-y: auto;
    padding-right: 1rem;
    scrollbar-width: none;
}

.sidebar-content::-webkit-scrollbar { display: none; }

.sidebar-header { padding: 1.15rem 0 0.8rem; text-align: center; }

.user-name {
    display: block;
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.4rem;
    padding: 0.18rem 0.52rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar-separator { width: 88%; height: 1px; margin: 1rem auto 0.65rem; border: 0; background: rgba(255, 255, 255, 0.22); }
.sidebar-nav { flex: 1; }
.sidebar-nav ul { margin: 0; padding: 0; list-style: none; }
.sidebar-nav li { margin-bottom: 0.45rem; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.78rem 0.9rem;
    border-radius: 9px;
    color: var(--theme-sidebar-link);
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition-speed), color var(--transition-speed);
}

.nav-link i { width: 22px; text-align: center; }
.nav-link:hover, .nav-link.active { background: var(--theme-sidebar-link-active-bg); color: #fff; }
.sidebar-footer { margin-top: auto; padding: 1rem 0 0.4rem; color: var(--theme-sidebar-muted); font-size: 0.78rem; text-align: center; }

#sidebar-drag-handle {
    position: fixed;
    top: 50%;
    left: calc(var(--sidebar-width) - 2px);
    z-index: 1001;
    display: flex;
    align-items: center;
    width: 48px;
    height: 142px;
    padding: 0;
    border: 0;
    border-radius: 0 100% 100% 0 / 0 50% 50% 0;
    background: transparent;
    cursor: pointer;
    transform: translateY(-50%);
    transition: left var(--transition-speed), background var(--transition-speed);
}

#sidebar-drag-handle:hover { background: var(--theme-focus-shadow); }

.handle-knob {
    display: grid;
    place-items: center;
    width: 20px;
    height: 76px;
    border-radius: 0 8px 8px 0;
    background: var(--theme-drag-handle-bg);
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    color: rgba(255, 255, 255, 0.92);
    font-size: 0.76rem;
    opacity: 0.64;
}

.sidebar.collapsed #sidebar-drag-handle { left: -2px; }
.sidebar.collapsed .handle-knob i { transform: rotate(180deg); }

.main-content {
    width: calc(100% - var(--sidebar-width));
    min-width: 0;
    flex: 1;
    padding: clamp(1rem, 2.2vw, 2.2rem);
    background:
        radial-gradient(circle at 90% 2%, color-mix(in srgb, var(--blue-medium) 7%, transparent), transparent 24rem),
        var(--theme-page-bg);
}

.page-intro,
.section-heading,
.chart-card-header,
.finder-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.page-intro { align-items: center; margin-bottom: 2rem; }
.eyebrow, .section-kicker { margin: 0 0 0.24rem; color: var(--theme-link); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.page-intro h1 { margin: 0; color: var(--theme-heading); font-size: clamp(1.8rem, 3vw, 2.45rem); line-height: 1.1; }
.page-subtitle, .section-heading p, .chart-card-header p { margin: 0.35rem 0 0; color: var(--theme-muted-text); }

.freshness {
    display: inline-flex;
    align-items: center;
    gap: 0.48rem;
    padding: 0.46rem 0.72rem;
    border: 1px solid var(--theme-border);
    border-radius: 999px;
    background: var(--theme-surface);
    color: var(--theme-muted-text);
    box-shadow: var(--theme-card-shadow);
    font-size: 0.78rem;
    white-space: nowrap;
}

.freshness span { width: 7px; height: 7px; border-radius: 50%; background: #f4a41d; }
.freshness.ready span { background: #17a768; box-shadow: 0 0 0 4px rgba(23, 167, 104, 0.12); }

.metric-section { margin-bottom: 2.7rem; }
.section-heading { margin-bottom: 1.1rem; }
.section-heading h2 { margin: 0; color: var(--theme-heading); font-size: clamp(1.35rem, 2vw, 1.72rem); }
.section-heading code { color: var(--theme-link); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82em; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; margin-bottom: 0.9rem; }

.summary-card,
.chart-card,
.finder-summary,
.finder-card {
    border: 1px solid var(--theme-border);
    background: var(--theme-surface);
    box-shadow: var(--theme-card-shadow);
}

.summary-card { min-width: 0; padding: 1rem 1.1rem; border-radius: 14px; }
.summary-label { display: block; color: var(--theme-muted-text); font-size: 0.77rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.summary-card strong { display: block; overflow: hidden; margin: 0.12rem 0; color: var(--theme-heading); font-size: clamp(1.45rem, 2.2vw, 2rem); line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.summary-card small { color: var(--theme-muted-text); }

.chart-card { padding: clamp(1rem, 2vw, 1.35rem); border-radius: 18px; }
.chart-card-header { align-items: center; margin-bottom: 0.8rem; }
.chart-card-header h3 { margin: 0; color: var(--theme-heading); font-size: 1.08rem; }

.site-filters { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.45rem; max-width: 62%; }

.site-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    padding: 0.38rem 0.62rem;
    border: 1px solid var(--theme-border);
    border-radius: 999px;
    background: var(--theme-surface);
    color: var(--theme-text);
    cursor: pointer;
    font-size: 0.77rem;
    font-weight: 600;
    transition: opacity var(--transition-speed), transform var(--transition-speed), border-color var(--transition-speed);
}

.site-chip::before { width: 8px; height: 8px; border-radius: 50%; background: var(--chip-color); content: ""; }
.site-chip:hover { transform: translateY(-1px); border-color: var(--chip-color); }
.site-chip[aria-pressed="false"] { opacity: 0.42; }
.site-chip[aria-pressed="false"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--chip-color); }

.lead-chart-wrap { position: relative; height: min(430px, 52vh); min-height: 315px; }

.chart-status {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 315px;
    gap: 0.65rem;
    color: var(--theme-muted-text);
    text-align: center;
}

.chart-status.error { color: #bd3545; }
.spinner { width: 17px; height: 17px; border: 2px solid var(--theme-border); border-top-color: var(--theme-link); border-radius: 50%; animation: rotate 0.72s linear infinite; }

.finder-heading { align-items: flex-start; flex-direction: column; }
.finder-controls { display: flex; width: 100%; flex-wrap: wrap; justify-content: flex-start; gap: 0.8rem; }
.control-group { min-width: 0; }
.control-label { display: block; margin-bottom: 0.3rem; color: var(--theme-muted-text); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.control-label strong { color: var(--theme-heading); }

.segmented-control {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--theme-border);
    border-radius: 10px;
    background: var(--theme-surface-muted);
}

.segmented-control button {
    min-height: 34px;
    padding: 0.38rem 0.72rem;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--theme-muted-text);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

.segmented-control button.active { background: var(--theme-surface); color: var(--theme-heading); box-shadow: 0 1px 6px rgba(15, 42, 77, 0.13); }

.timeline-control { width: min(430px, 42vw); }
.timeline-range {
    --range-start: 0%;
    --range-end: 100%;
    position: relative;
    height: 28px;
}
.timeline-range::before {
    position: absolute;
    top: 12px;
    right: 0;
    left: 0;
    height: 5px;
    border-radius: 999px;
    background: linear-gradient(
        to right,
        var(--theme-surface-muted) 0 var(--range-start),
        var(--theme-button-bg) var(--range-start) var(--range-end),
        var(--theme-surface-muted) var(--range-end) 100%
    );
    content: "";
}
.timeline-range input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 28px;
    margin: 0;
    appearance: none;
    background: transparent;
    pointer-events: none;
}
.timeline-range input::-webkit-slider-runnable-track { height: 5px; background: transparent; }
.timeline-range input::-moz-range-track { height: 5px; background: transparent; }
.timeline-range input::-webkit-slider-thumb {
    width: 17px;
    height: 17px;
    margin-top: -6px;
    appearance: none;
    border: 3px solid var(--theme-button-bg);
    border-radius: 50%;
    background: var(--theme-surface);
    box-shadow: 0 1px 5px rgba(15, 42, 77, 0.28);
    cursor: grab;
    pointer-events: auto;
}
.timeline-range input::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: 3px solid var(--theme-button-bg);
    border-radius: 50%;
    background: var(--theme-surface);
    box-shadow: 0 1px 5px rgba(15, 42, 77, 0.28);
    cursor: grab;
    pointer-events: auto;
}
.timeline-range input:focus-visible::-webkit-slider-thumb { outline: 3px solid var(--theme-focus-shadow); outline-offset: 2px; }
.timeline-range input:focus-visible::-moz-range-thumb { outline: 3px solid var(--theme-focus-shadow); outline-offset: 2px; }
.timeline-labels { gap: 1rem; }
.timeline-labels span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-labels span:last-child { text-align: right; }

.bin-control { width: 190px; }
.bin-control input { width: 100%; accent-color: var(--theme-button-bg); cursor: pointer; }
.range-labels { display: flex; justify-content: space-between; color: var(--theme-muted-text); font-size: 0.64rem; font-weight: 600; }

.finder-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 1.1rem 0 0.9rem;
    border-radius: 14px;
}

.finder-summary div { min-width: 0; padding: 0.8rem 1rem; }
.finder-summary div + div { border-left: 1px solid var(--theme-border); }
.finder-summary span { display: block; color: var(--theme-muted-text); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.finder-summary strong { display: block; overflow: hidden; margin-top: 0.08rem; color: var(--theme-heading); font-size: 1.25rem; text-overflow: ellipsis; white-space: nowrap; }

.finder-status { min-height: 220px; border: 1px solid var(--theme-border); border-radius: 18px; background: var(--theme-surface); }
.finder-overall-card { margin-bottom: 0.9rem; }
.finder-overall-chart-wrap { position: relative; height: min(360px, 46vh); min-height: 290px; }
.finder-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 0.9rem; }
.finder-card { min-width: 0; padding: 1rem; border-radius: 16px; }
.finder-card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.55rem; }
.finder-identity { display: flex; align-items: center; min-width: 0; gap: 0.68rem; }
.finder-avatar { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px; background: color-mix(in srgb, var(--finder-color) 15%, var(--theme-surface)); color: var(--finder-color); font-weight: 700; }
.finder-card h3 { overflow: hidden; margin: 0; color: var(--theme-heading); font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.finder-total { color: var(--finder-color); font-size: 1.35rem; font-weight: 700; }
.finder-chart-wrap { position: relative; height: 190px; }
.empty-state { grid-column: 1 / -1; padding: 2.2rem; border: 1px dashed var(--theme-border); border-radius: 16px; color: var(--theme-muted-text); text-align: center; }
.data-note { margin: 0.75rem 0 0; color: var(--theme-muted-text); font-size: 0.72rem; text-align: right; }

@keyframes rotate { to { transform: rotate(360deg); } }

@media (max-width: 1080px) {
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .finder-heading { align-items: flex-start; flex-direction: column; }
    .finder-controls { width: 100%; justify-content: flex-start; }
    .site-filters { max-width: 100%; justify-content: flex-start; }
    .chart-card-header { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 760px) {
    :root { --sidebar-width: 224px; }

    .sidebar {
        position: fixed;
        left: 0;
        margin-left: calc(-1 * var(--sidebar-width));
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.18);
    }

    .sidebar:not(.collapsed) { margin-left: 0; }
    .main-content { width: 100%; padding: 1rem; }
    .page-intro { align-items: flex-start; flex-direction: column; gap: 0.7rem; }
    .summary-grid { grid-template-columns: 1fr; }
    .summary-card { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 0.8rem; }
    .summary-card strong { grid-row: 1 / span 2; grid-column: 2; }
    .finder-controls { display: grid; grid-template-columns: 1fr; }
    .segmented-control { display: flex; }
    .segmented-control button { flex: 1; }
    .timeline-control { width: 100%; }
    .bin-control { width: 100%; }
    .finder-grid { grid-template-columns: 1fr; }
    .lead-chart-wrap { height: 340px; min-height: 280px; }
}

@media (max-width: 480px) {
    .freshness { max-width: 100%; white-space: normal; }
    .finder-summary { grid-template-columns: 1fr; }
    .finder-summary div + div { border-top: 1px solid var(--theme-border); border-left: 0; }
    .finder-chart-wrap { height: 175px; }
    .chart-card { border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
