:root {
    --bg: #0b1014;
    --panel: #111820;
    --panel-2: #17212b;
    --panel-3: #1d2934;
    --line: rgba(227, 236, 230, 0.12);
    --line-strong: rgba(227, 236, 230, 0.22);
    --text: #edf3ee;
    --muted: #a9b7b3;
    --quiet: #74847f;
    --cyan: #51d1c2;
    --lime: #a9d65c;
    --gold: #f2c14e;
    --coral: #ef7d60;
    --violet: #b799ff;
    --danger: #ff6b73;
    --body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --serif: "Source Serif 4", Georgia, serif;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
  }

  * { box-sizing: border-box; }
  html, body { width: 100%; height: 100%; margin: 0; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--body);
    letter-spacing: 0;
    overflow: hidden;
  }

  button, input {
    font: inherit;
  }

  button {
    color: inherit;
  }

  .app {
    display: grid;
    grid-template-columns: 420px minmax(0, 1fr);
    height: 100vh;
    min-height: 640px;
  }

  .map-stage {
    position: relative;
    min-width: 0;
    background: #07121b;
    grid-column: 2;
    grid-row: 1;
  }

  #map {
    width: 100%;
    height: 100%;
  }

  .maplibregl-ctrl-group {
    background: rgba(17, 24, 32, 0.92) !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 8px !important;
    box-shadow: var(--shadow) !important;
    overflow: hidden;
  }

  .maplibregl-ctrl-group button {
    background: transparent !important;
    border-bottom: 1px solid var(--line) !important;
  }

  .maplibregl-ctrl-group button:hover {
    background: var(--panel-3) !important;
  }

  .maplibregl-ctrl-group button span {
    filter: invert(1) opacity(0.8);
  }

  .maplibregl-ctrl-attrib {
    background: rgba(11, 16, 20, 0.72) !important;
    color: var(--muted) !important;
    font-size: 10px !important;
  }

  .maplibregl-popup-content {
    background: var(--panel) !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 8px !important;
    color: var(--text) !important;
    padding: 0 !important;
    box-shadow: var(--shadow) !important;
    min-width: 220px;
  }

  .maplibregl-popup-tip {
    border-top-color: var(--panel) !important;
    border-bottom-color: var(--panel) !important;
  }

  .maplibregl-popup-close-button {
    color: var(--muted) !important;
    font-size: 18px !important;
    padding: 6px 8px !important;
  }

  .hover-popup {
    pointer-events: none;
  }

  .hover-popup .maplibregl-popup-content {
    border-color: rgba(242, 193, 78, 0.82) !important;
  }

  .fixed-detail-card {
    position: absolute;
    z-index: 7;
    top: 70px;
    left: 20px;
    width: min(330px, calc(100% - 40px));
    max-height: calc(100% - 128px);
    overflow: auto;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    box-shadow: var(--shadow);
    display: none;
  }

  .fixed-detail-card.visible {
    display: block;
  }

  .fixed-detail-card .popup {
    padding-right: 38px;
  }

  .fixed-detail-close {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
  }

  .fixed-detail-close:hover {
    background: var(--panel-3);
    color: var(--text);
  }

  .heat-legend {
    position: absolute;
    z-index: 6;
    right: 20px;
    bottom: 46px;
    width: min(320px, calc(100% - 40px));
    padding: 13px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: rgba(17, 24, 32, 0.88);
    color: var(--text);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    pointer-events: auto;
    display: none;
  }

  .heat-legend.visible {
    display: block;
  }

  .legend-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 10px;
  }

  .legend-head span {
    color: var(--quiet);
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .legend-head strong {
    color: var(--text);
    font-size: 12px;
    font-weight: 900;
    text-align: right;
  }

  .legend-scale {
    height: 12px;
    border-radius: 999px;
    border: 1px solid rgba(237, 243, 238, 0.22);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
  }

  .legend-labels {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
  }

  .legend-labels span:nth-child(2) {
    text-align: center;
  }

  .legend-labels span:last-child {
    text-align: right;
  }

  .map-hud {
    position: absolute;
    z-index: 5;
    left: 20px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    pointer-events: none;
  }

  .hud-top {
    top: 18px;
  }

  .hud-bottom {
    bottom: 18px;
  }

  .chip {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(11, 16, 20, 0.72);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    backdrop-filter: blur(10px);
    white-space: nowrap;
  }

  .chip strong {
    color: var(--text);
    font-weight: 700;
  }

  .chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--cyan);
    box-shadow: 0 0 12px rgba(81, 209, 194, 0.7);
  }

  .status {
    position: absolute;
    z-index: 20;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, calc(100% - 36px));
    background: rgba(17, 24, 32, 0.94);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
    display: none;
  }

  .status.visible {
    display: block;
  }

  .status-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 8px;
    font-weight: 800;
  }

  .spinner {
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 2px solid rgba(81, 209, 194, 0.28);
    border-top-color: var(--cyan);
    animation: spin 0.75s linear infinite;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  .status p {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
    font-size: 14px;
  }

  .panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    border-right: 1px solid var(--line-strong);
    background: var(--panel);
    grid-column: 1;
    grid-row: 1;
  }

  .panel-scroll {
    overflow-y: auto;
    padding-bottom: 18px;
  }

  .panel-scroll::-webkit-scrollbar { width: 10px; }
  .panel-scroll::-webkit-scrollbar-track { background: var(--panel); }
  .panel-scroll::-webkit-scrollbar-thumb {
    background: var(--panel-3);
    border: 3px solid var(--panel);
    border-radius: 999px;
  }

  .brand {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
  }

  .kicker {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--cyan);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
  }

  .live-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 8px;
    border: 1px solid rgba(169, 214, 92, 0.35);
    border-radius: 999px;
    color: var(--lime);
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
  }

  .live-pill span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: currentColor;
  }

  h1 {
    margin: 0;
    font-family: var(--serif);
    font-size: 38px;
    line-height: 1;
    letter-spacing: 0;
  }

  .subtitle {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
  }

  .section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
  }

  .section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 14px;
  }

  .section-title h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .section-title .tiny {
    color: var(--quiet);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }

  .metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .metric {
    min-height: 84px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
  }

  .metric span {
    display: block;
    color: var(--quiet);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 8px;
  }

  .metric strong {
    display: block;
    font-size: 22px;
    line-height: 1.05;
    color: var(--text);
  }

  .metric small {
    display: block;
    color: var(--muted);
    margin-top: 6px;
    font-size: 12px;
  }

  .toolbar {
    display: grid;
    gap: 8px;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
  }

  .segmented button {
    min-height: 42px;
    border: 0;
    background: var(--panel-2);
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
  }

  .segmented button:hover {
    background: var(--panel-3);
    color: var(--text);
  }

  .segmented button.active {
    background: var(--cyan);
    color: #06201d;
  }

  .segmented svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.4;
  }

  .search-box {
    position: relative;
  }

  .search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 17px;
    height: 17px;
    color: var(--quiet);
    pointer-events: none;
  }

  .search-box input {
    width: 100%;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
    outline: 0;
    padding: 0 12px 0 38px;
  }

  .search-box input:focus {
    border-color: rgba(81, 209, 194, 0.75);
    box-shadow: 0 0 0 3px rgba(81, 209, 194, 0.12);
  }

  .results {
    margin-top: 8px;
    display: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
  }

  .results.visible {
    display: block;
  }

  .result-btn {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    padding: 9px 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    text-align: left;
  }

  .result-btn:last-child {
    border-bottom: 0;
  }

  .result-btn:hover {
    background: var(--panel-3);
  }

  .result-name {
    font-weight: 800;
    min-width: 0;
  }

  .result-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
  }

  .result-pop {
    color: var(--gold);
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
  }

  .selected {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
  }

  .selected-type {
    color: var(--cyan);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 9px;
  }

  .selected h3 {
    margin: 0;
    font-family: var(--serif);
    font-size: 30px;
    line-height: 1.05;
    letter-spacing: 0;
  }

  .selected-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
  }

  .selected-grid div {
    min-height: 58px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(11, 16, 20, 0.38);
  }

  .selected-grid span {
    display: block;
    color: var(--quiet);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 5px;
  }

  .selected-grid strong {
    display: block;
    font-size: 17px;
  }

  .chart {
    display: grid;
    gap: 7px;
  }

  .bar-row {
    display: grid;
    grid-template-columns: minmax(92px, 1fr) 74px;
    align-items: center;
    gap: 10px;
    min-height: 30px;
    color: var(--muted);
    font-size: 12px;
  }

  .bar-track {
    position: relative;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(11, 16, 20, 0.36);
    overflow: hidden;
  }

  .bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    min-width: 3px;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(81, 209, 194, 0.38), rgba(169, 214, 92, 0.78));
  }

  .bar-name {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: 0 10px;
    color: var(--text);
    font-weight: 800;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .bar-value {
    text-align: right;
    color: var(--gold);
    font-weight: 900;
    white-space: nowrap;
  }

  .ranking {
    display: grid;
    gap: 6px;
  }

  .rank-btn {
    width: 100%;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    padding: 10px;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    gap: 9px;
    align-items: center;
    text-align: left;
  }

  .rank-btn:hover,
  .rank-btn.active {
    border-color: rgba(81, 209, 194, 0.62);
    background: var(--panel-3);
  }

  .rank-no {
    color: var(--cyan);
    font-size: 12px;
    font-weight: 900;
  }

  .rank-main {
    min-width: 0;
  }

  .rank-name {
    display: block;
    font-size: 14px;
    font-weight: 900;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .rank-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
  }

  .rank-pop {
    color: var(--gold);
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
  }

  .empty {
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    color: var(--muted);
    padding: 14px;
    font-size: 13px;
    line-height: 1.5;
  }

  .footer {
    margin-top: auto;
    padding: 14px 24px;
    border-top: 1px solid var(--line);
    color: var(--quiet);
    font-size: 11px;
    line-height: 1.45;
    background: var(--panel);
  }

  .footer a {
    color: var(--cyan);
    text-decoration: none;
  }

  .footer a:hover {
    text-decoration: underline;
  }

  .popup {
    padding: 13px 14px 14px;
  }

  .popup-kind {
    color: var(--cyan);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 7px;
  }

  .popup-title {
    font-family: var(--serif);
    font-size: 24px;
    font-weight: 700;
    line-height: 1.05;
    margin: 0 22px 9px 0;
  }

  .popup-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    color: var(--muted);
    border-top: 1px solid var(--line);
    padding-top: 8px;
    font-size: 12px;
  }

  .legend-head select {
    background: rgba(255, 255, 255, 0.05);
    color: var(--gold);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    font-size: 11px;
    padding: 2px 4px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    outline: none;
  }
  .legend-head select:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--gold);
  }
  .legend-head select option {
    background: #1a242d;
    color: #fff;
  }

  .year-stepper {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
  }
  .year-stepper button {
    background: none;
    border: none;
    color: var(--gold);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background 0.2s;
  }
  .year-stepper button:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  .year-stepper button:disabled {
    opacity: 0.3;
    cursor: default;
  }
  .year-stepper select {
    appearance: none;
    -webkit-appearance: none;
    border: none !important;
    background: none !important;
    padding: 0 6px !important;
    height: 22px;
    font-size: 10px !important;
    text-align: center;
    width: auto;
  }

  .popup-row strong {
    color: var(--gold);
  }

  @media (max-width: 1040px) {
    body {
      overflow: auto;
    }

    .app {
      grid-template-columns: 1fr;
      grid-template-rows: 58vh auto;
      height: auto;
      min-height: 100vh;
    }

    .map-stage {
      grid-column: 1;
      grid-row: 1;
    }

    .panel {
      grid-column: 1;
      grid-row: 2;
      border-right: 0;
      border-top: 1px solid var(--line-strong);
      overflow: visible;
    }

    .panel-scroll {
      overflow: visible;
    }
  }

  @media (max-width: 620px) {
    .app {
      grid-template-rows: 54vh auto;
    }

    .brand,
    .section,
    .footer {
      padding-left: 16px;
      padding-right: 16px;
    }

    h1 {
      font-size: 31px;
    }

    .metrics,
    .selected-grid {
      grid-template-columns: 1fr;
    }

    .segmented {
      grid-template-columns: 1fr 1fr;
    }

    .hud-bottom {
      display: none;
    }

    .heat-legend {
      right: 12px;
      bottom: 42px;
      width: min(280px, calc(100% - 24px));
    }
  }
}

/* Utility Classes for CSP Compliance */
.flex-gap-4 { display: flex; gap: 4px; }
.mt-6 { margin-top: 6px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mb-4 { margin-bottom: 4px; }
.mb-6 { margin-bottom: 6px; }
.mb-8 { margin-bottom: 8px; }
.w-full { width: 100%; }
.pt-10 { padding-top: 10px; }
.border-top-line { border-top: 1px solid var(--line); }
.pib-history-header { font-size: 10px; color: var(--quiet); margin-bottom: 8px; text-transform: uppercase; font-weight: 800; }
.pib-history-container { height: 80px; display: flex; align-items: flex-end; gap: 4px; width: 100%; }
.pib-history-footer { display: flex; justify-content: space-between; font-size: 9px; color: var(--quiet); margin-top: 6px; }
.stat-card-plain { display: block !important; padding: 0 !important; border: 0 !important; background: transparent !important; }
.grid-full-span { grid-column: 1 / -1; min-height: 100px; padding: 10px 0; border: 0; background: transparent; width: 100%; }
.video-thumb { width: 100%; border-radius: 6px; margin-bottom: 8px; aspect-ratio: 16/9; object-fit: cover; display: block; border: 1px solid rgba(255,255,255,0.1); }
.video-title { font-size: 10px; color: #aaa; margin-bottom: 4px; text-transform: uppercase; line-height: 1.2; }
.video-link { color: #f2c14e; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 13px; padding: 4px 0; }
.icon-small { width: 12px; height: 12px; }
.bar-fill { height: 100%; background: var(--gold); border-radius: 2px; }

.cols-1 { grid-template-columns: repeat(1, 1fr) !important; }
.cols-2 { grid-template-columns: repeat(2, 1fr) !important; }
.cols-3 { grid-template-columns: repeat(3, 1fr) !important; }
.cols-4 { grid-template-columns: repeat(4, 1fr) !important; }
.cols-5 { grid-template-columns: repeat(5, 1fr) !important; }
