:root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --panel-alt: #f8fafc;
    --border: #d8dee8;
    --text: #152033;
    --muted: #5f6b7a;
    --green: #169c52;
    --green-soft: #d8f4e3;
    --red: #d93b3b;
    --red-soft: #fde2e2;
    --blue: #2962ff;
    --blue-soft: #dce6ff;
    --shadow: 0 10px 30px rgba(21, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: linear-gradient(180deg, #f8faff 0%, var(--bg) 180px);
    color: var(--text);
}

.page {
    max-width: 1360px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

.hero {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.hero h1 {
    margin: 0 0 8px;
    font-size: clamp(24px, 3.5vw, 36px);
    line-height: 1.1;
}

.hero > div > p {
    margin: 0 0 8px;
    max-width: 760px;
    color: var(--muted);
    line-height: 1.5;
}

.hero-links {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

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

.hero-links a {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    background-size: 200% auto;
    animation: shimmer 3.5s linear infinite;
    transition: opacity 0.15s ease;
}

.hero-links a:hover {
    opacity: 0.88;
    text-decoration: none;
}

.hero-btn-dist {
    background-image: linear-gradient(110deg, #1d4ed8 0%, #2563eb 35%, #60a5fa 50%, #2563eb 65%, #1d4ed8 100%);
}

.hero-btn-map {
    background-image: linear-gradient(110deg, #0f766e 0%, #0d9488 35%, #2dd4bf 50%, #0d9488 65%, #0f766e 100%);
}

.hero-meta {
    min-width: 220px;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(216, 222, 232, 0.9);
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
}

.hero-meta-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 4px;
}

.hero-meta-value {
    font-size: 18px;
    font-weight: 700;
}

.threshold-note {
    margin-top: 10px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.45;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.summary-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.summary-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 10px;
}

.summary-value {
    font-size: clamp(24px, 2.7vw, 34px);
    font-weight: 750;
    line-height: 1;
    margin-bottom: 8px;
}

.summary-detail {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.4;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 18px;
}

.controls {
    display: grid;
    grid-template-columns: 1.1fr 1.1fr 0.8fr;
    gap: 16px;
    margin-bottom: 18px;
}

.control-group {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
}

.control-group h2 {
    margin: 0 0 10px;
    font-size: 14px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip,
.date-input,
.date-apply {
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
    font: inherit;
}

.chip {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip.active {
    background: var(--text);
    border-color: var(--text);
    color: #fff;
}

.chip:not(.active):hover,
.date-apply:hover {
    border-color: #9aa7bb;
}

/* Cluster: a bordered capsule that wraps a group of related chips */
/* Cluster: a bordered capsule that wraps a group of related chips.
   The border + background only show when the cluster contains multiple chips. */
.chip-cluster {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0;
    border-radius: 10px;
    border: 1.5px solid transparent;
}

.chip-cluster--multi {
    padding: 4px;
}

.chip-cluster--multi[data-group="volume"]   { border-color: rgba(37,  99,  235, 0.5); background: rgba(37,  99,  235, 0.04); }
.chip-cluster--multi[data-group="permits"]  { border-color: rgba(234, 88,  12,  0.5); background: rgba(234, 88,  12,  0.04); }
.chip-cluster--multi[data-group="approval"] { border-color: rgba(180, 83,  9,   0.5); background: rgba(180, 83,  9,   0.04); }
.chip-cluster--multi[data-group="brp"]      { border-color: rgba(219, 39,  119, 0.5); background: rgba(219, 39,  119, 0.04); }
.chip-cluster--multi[data-group="gup"]      { border-color: rgba(13,  148, 136, 0.5); background: rgba(13,  148, 136, 0.04); }

/* Mode chip groups — inactive background + border tint, group-colored active state.
   Colors chosen for maximum distinctness: blue, orange, gold, pink, teal */
.chip[data-group="volume"]   { background: rgba(37,  99,  235, 0.08); border-color: rgba(37,  99,  235, 0.45); }
.chip[data-group="permits"]  { background: rgba(234, 88,  12,  0.08); border-color: rgba(234, 88,  12,  0.45); }
.chip[data-group="approval"] { background: rgba(180, 83,  9,   0.08); border-color: rgba(180, 83,  9,   0.45); }
.chip[data-group="brp"]      { background: rgba(219, 39,  119, 0.08); border-color: rgba(219, 39,  119, 0.45); }
.chip[data-group="gup"]      { background: rgba(13,  148, 136, 0.08); border-color: rgba(13,  148, 136, 0.45); }

.chip[data-group="volume"].active   { background: #2563eb; border-color: #2563eb; color: #fff; }
.chip[data-group="permits"].active  { background: #ea580c; border-color: #ea580c; color: #fff; }
.chip[data-group="approval"].active { background: #b45309; border-color: #b45309; color: #fff; }
.chip[data-group="brp"].active      { background: #db2777; border-color: #db2777; color: #fff; }
.chip[data-group="gup"].active      { background: #0d9488; border-color: #0d9488; color: #fff; }

.custom-range {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.date-input {
    padding: 8px 12px;
    min-width: 150px;
    font-size: 13px;
}

.date-apply {
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
}

.chart-card {
    padding: 18px;
    margin-bottom: 18px;
}

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

.chart-title-wrap h2 {
    margin: 0 0 6px;
    font-size: 20px;
}

.chart-description {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    display: inline-block;
}

.swatch.green {
    background: var(--green);
}

.swatch.red {
    background: var(--red);
}

.swatch.blue {
    background: var(--blue);
}

.swatch-line {
    width: 18px;
    height: 3px;
    border-radius: 2px;
    background: #475569;
    display: inline-block;
}

.threshold-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    background: #eef2f7;
    padding: 6px 10px;
}

.threshold-line-mini {
    width: 18px;
    border-top: 2px dashed #475569;
}

.value-axis-row {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 0;
    height: 32px;
    position: relative;
}

.value-axis-spacer {
    width: 80px;
}

.chart-scroll {
    position: relative;
    overflow-y: auto;
    max-height: 70vh;
    padding-right: 6px;
}

.chart-layout {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 0;
    align-items: start;
    min-height: min-content;
}

.y-axis {
    position: relative;
    width: 80px;
}

.chart {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 0 16px 16px 0;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98)),
        repeating-linear-gradient(180deg, rgba(15, 23, 42, 0.015) 0, rgba(15, 23, 42, 0.015) 1px, transparent 1px, transparent 80px);
    overflow: hidden;
}

.x-axis {
    position: relative;
    height: 32px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    background: var(--panel-alt);
}

.gridline {
    position: absolute;
    top: 0;
    bottom: 0;
    border-left: 1px dashed #d4dae4;
}

.x-label {
    position: absolute;
    top: 8px;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--muted);
}

.monthline,
.threshold-line {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 1;
}

.monthline {
    border-top: 1px dashed #d3d9e5;
}

.threshold-line {
    border-top: 2px dashed #475569;
    opacity: 0.95;
}

.threshold-label {
    position: absolute;
    left: 8px;
    transform: translateY(-50%);
    background: #0f172a;
    color: #fff;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 3;
}

.bar-row,
.line-layer {
    position: absolute;
    inset: 0;
}

.bar {
    position: absolute;
    left: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    z-index: 2;
    cursor: pointer;
}

.bar-segment {
    height: 100%;
    position: relative;
}

.bar-segment.green {
    background: var(--green);
}

.bar-segment.red {
    background: var(--red);
}

.bar-segment .divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 1px;
    background: rgba(255, 255, 255, 0.92);
}

.line-svg {
    display: block;
    overflow: visible;
}

.line-path {
    fill: none;
    stroke: var(--blue);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.line-area {
    fill: rgba(41, 98, 255, 0.12);
}

.line-point {
    fill: var(--blue);
    stroke: white;
    stroke-width: 2;
    cursor: pointer;
}

.axis-label {
    position: absolute;
    right: 8px;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.tooltip {
    position: fixed;
    display: none;
    min-width: 210px;
    max-width: 300px;
    pointer-events: none;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.94);
    color: #fff;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.32);
    transform: translateY(calc(-100% - 12px));
}

.tooltip-title {
    font-weight: 700;
    margin-bottom: 8px;
    font-size: 13px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    margin-top: 4px;
}

.tooltip-row span:first-child {
    color: rgba(255, 255, 255, 0.72);
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.info-card h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.info-card p,
.info-card li {
    color: var(--muted);
    line-height: 1.55;
    font-size: 14px;
}

.info-card ul {
    margin: 0;
    padding-left: 18px;
}

.info-callout {
    margin-top: 10px;
    background: #f7f9fc;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 13px;
    color: var(--muted);
}

.footnote {
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted);
}

.loading-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--muted);
    font-size: 16px;
}

/* Horizontal chart mode: dates on X axis, fixed height, no scroll */
.chart-card.mode-horizontal {
    display: flex;
    flex-direction: column;
}

.chart-card.mode-horizontal > .chart-head { order: 1; }
.chart-card.mode-horizontal > .value-axis-row { order: 4; }
.chart-card.mode-horizontal > #chartScroll { order: 3; }
.chart-card.mode-horizontal > .footnote { order: 5; }

.chart-card.mode-horizontal .value-axis-row {
    border-radius: 0 0 16px 16px;
    border: 1px solid var(--border);
    border-top: none;
    background: var(--panel-alt);
}

.chart-card.mode-horizontal .x-axis {
    border: none;
    border-radius: 0;
    background: transparent;
}

.chart-card.mode-horizontal #chartScroll {
    overflow: hidden;
    max-height: none;
    padding-right: 0;
}

.chart-card.mode-horizontal .chart {
    border-radius: 0 16px 0 0;
    overflow: visible;
}

/* Horizontal gridlines (value scale) */
.gridline-h {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed #d4dae4;
    z-index: 0;
}

/* Vertical month boundary lines in horizontal chart */
.monthline-v {
    position: absolute;
    top: 0;
    bottom: 0;
    border-left: 1px dashed #d3d9e5;
    z-index: 0;
}

/* Vertical threshold line in horizontal chart */
.threshold-line-v {
    position: absolute;
    top: 0;
    bottom: 0;
    border-left: 2px dashed #475569;
    opacity: 0.95;
    z-index: 1;
}

/* Threshold label inside horizontal chart */
.threshold-label-h {
    position: absolute;
    top: 6px;
    transform: translateX(-50%);
    background: #0f172a;
    color: #fff;
    padding: 3px 7px;
    border-radius: 999px;
    font-size: 10px;
    white-space: nowrap;
    z-index: 3;
}

/* Vertical bar growing upward (horizontal chart mode) */
.bar-v {
    position: absolute;
    bottom: 0;
    display: flex;
    flex-direction: column-reverse;
    align-items: stretch;
    z-index: 2;
    cursor: pointer;
}

.bar-segment-v {
    width: 100%;
}

.bar-segment-v.green { background: var(--green); }
.bar-segment-v.red { background: var(--red); }

/* Scatter plot dots */
.scatter-dot {
    opacity: 0.45;
    cursor: pointer;
    transition: opacity 0.15s;
}

.scatter-dot:hover {
    opacity: 1;
    r: 6;
}

.scatter-dot.green { fill: var(--green); }
.scatter-dot.red { fill: var(--red); }

/* Smoothed trendline */
.trend-line {
    fill: none;
    stroke: #475569;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.8;
}

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

    .controls {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .hero,
    .chart-head,
    .info-grid {
        grid-template-columns: 1fr;
        display: grid;
    }

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

    .page {
        padding: 18px 12px 28px;
    }

    .chart-scroll {
        max-height: 60vh;
    }
}

@media (max-width: 560px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .chart-layout {
        grid-template-columns: 60px 1fr;
    }

    .value-axis-row {
        grid-template-columns: 60px 1fr;
    }

    .value-axis-spacer,
    .y-axis {
        width: 60px;
    }
}
