  :root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --border-color: #e1e4e9;
    --text: #1a1d24;
    --text-dim: #667085;
    --text-faint: #98a1b0;
    --accent: #2f6fb0;
    --tag-text: #1a1d24;
    --radius: 6px;
  }
  * { box-sizing: border-box; }
  html { -webkit-font-smoothing: antialiased; }
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    padding: 0 0 48px 0;
    line-height: 1.45;
  }
  header {
    padding: 30px 32px 20px 32px;
    border-bottom: 1px solid var(--border-color);
  }
  .eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin: 0 0 8px 0;
  }
  header h1 {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
  }
  header p {
    margin: 0;
    color: var(--text-dim);
    font-size: 13px;
    max-width: 900px;
    line-height: 1.6;
  }
  .stats-row {
    display: flex;
    gap: 1px;
    padding: 0 32px;
    margin-top: 20px;
    flex-wrap: wrap;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-left: 32px;
    margin-right: 32px;
    width: calc(100% - 64px);
    overflow: hidden;
  }
  .stat-card {
    background: var(--panel);
    padding: 16px 20px;
    min-width: 140px;
    flex: 1;
  }
  .stat-card .num {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
  }
  .stat-card .label {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 3px;
    letter-spacing: 0.01em;
  }
  .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 0 32px;
  }
  @media (max-width: 980px) {
    .grid { grid-template-columns: 1fr; }
    .stats-row { flex-direction: column; }
  }
  .panel {
    background: var(--panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 16px;
    /* Grid items default to min-width: auto, which lets a wide unbreakable
       child (e.g. a bar chart with many fixed-width bars) force the whole
       grid track wider than the viewport — that's what was making cards
       different widths / breaking the layout on small screens. This makes
       each card shrink with its column instead, and any content it can't
       shrink further scrolls internally via .chart-wrap's own overflow-x. */
    min-width: 0;
  }
  .panel.full { grid-column: 1 / -1; }
  .panel h2 {
    margin: 0 0 4px 0;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
  }
  .panel .sub {
    font-size: 12px;
    color: var(--text-dim);
    margin: 0 0 16px 0;
    line-height: 1.55;
  }
  .chart-wrap { position: relative; overflow-x: auto; }
  #mapRegion, #mapInst {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg);
    border: 1px solid var(--border-color);
  }
  /* On big screens the map's own equirectangular aspect ratio (width/2 for
     height) made it enormous once stretched across the full panel width.
     Cap it and center it there; below the 980px grid-collapse breakpoint
     (where every panel — including these — already goes full-width) leave
     it exactly as before. */
  @media (min-width: 981px) {
    #mapRegion, #mapInst {
      max-width: 760px;
      margin: 0 auto;
    }
  }
  .filter-bar {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    padding: 16px 32px 0 32px;
    margin-top: 20px;
  }
  .filter-bar select, .filter-bar input {
    background: var(--panel-2);
    border: 1px solid var(--border-color);
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 12.5px;
    font-family: inherit;
  }
  .filter-bar select:focus, .filter-bar input:focus {
    outline: none;
    border-color: var(--accent);
  }
  .filter-bar input[type="text"] { min-width: 230px; }
  .reset-link {
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    margin-left: auto;
  }
  .reset-link:hover { color: var(--text); text-decoration: underline; }
  table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
  thead th {
    text-align: left;
    color: var(--text-faint);
    font-weight: 600;
    font-size: 10.5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
    position: sticky; top: 0; background: var(--panel);
  }
  tbody td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    color: var(--text);
  }
  tbody tr:hover { background: var(--panel-2); }
  .table-scroll { max-height: 520px; overflow-y: auto; overflow-x: auto; border: 1px solid var(--border-color); border-radius: 4px; }
  .tag {
    display: inline-block;
    font-size: 10.5px;
    padding: 2px 8px;
    border-radius: 4px;
    margin: 1px 4px 1px 0;
    color: var(--tag-text);
    font-weight: 600;
    white-space: nowrap;
  }
  .doi-link { color: var(--accent); text-decoration: none; font-size: 11.5px; }
  .doi-link:hover { text-decoration: underline; }
  .edit-btn {
    background: none; border: 1px solid var(--border-color); color: var(--text-dim);
    cursor: pointer; font-size: 11px; padding: 2px 7px; border-radius: 4px;
    margin-top: 4px; display: inline-block;
  }
  .edit-btn:hover { color: var(--text); border-color: var(--text-dim); }
  .edit-btn.edited { color: var(--accent); border-color: var(--accent); }
  .new-badge {
    display: inline-block; font-size: 9.5px; font-weight: 700; letter-spacing: 0.03em;
    color: #fff; background: #fb8c00; padding: 1px 6px; border-radius: 3px;
    margin: 1px 4px 1px 0; vertical-align: middle;
  }
  .edit-toolbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 0 0 12px 0; font-size: 12px; color: var(--text-dim);
  }
  .edit-toolbar button, .edit-toolbar .file-btn {
    background: var(--panel-2); border: 1px solid var(--border-color); color: var(--text);
    cursor: pointer; font-size: 12px; padding: 6px 12px; border-radius: var(--radius);
    font-family: inherit;
  }
  .edit-toolbar button:hover, .edit-toolbar .file-btn:hover { border-color: var(--accent); }
  .edit-toolbar .edit-count { color: var(--text-faint); }
  .edit-toolbar label.check {
    display: flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text-dim);
  }
  .count-pill {
    background: var(--panel-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-dim);
    margin-left: 8px;
  }
  footer {
    padding: 20px 32px;
    color: var(--text-faint);
    font-size: 11px;
    line-height: 1.6;
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
  }
  a { color: var(--accent); }

  /* --- custom chart / map elements --- */
  .bar-row { display: flex; align-items: center; gap: 10px; margin: 7px 0; cursor: pointer; }
  .bar-row .bar-label { width: 150px; font-size: 12px; color: var(--text-dim); flex-shrink: 0; text-align: right; }
  .bar-row .bar-track { flex: 1; background: var(--panel-2); border-radius: 3px; height: 16px; position: relative; overflow: hidden; }
  .bar-row .bar-fill { height: 100%; border-radius: 3px; transition: opacity 0.15s; }
  .bar-row:hover .bar-fill { opacity: 0.82; }
  .bar-row .bar-value { width: 38px; font-size: 12px; color: var(--text-dim); flex-shrink: 0; font-variant-numeric: tabular-nums; }
  .bar-row.active .bar-label { color: var(--text); font-weight: 600; }
  .bar-row.dimmed { opacity: 0.4; }

  .year-bars { display: flex; align-items: flex-end; gap: 24px; height: 190px; padding: 0 20px; }
  .year-bar-col { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; flex: 1; height: 100%; justify-content: flex-end; min-width: 0; }
  /* width:100% + max-width caps it at the old fixed size on screens with
     room to spare, but lets it shrink below that on narrow screens/many
     bars instead of forcing the whole chart (and grid column) wider than
     the viewport. */
  .year-bar-col .bar { width: 100%; max-width: 56px; border-radius: 2px 2px 0 0; transition: opacity 0.15s; }
  .year-bar-col:hover .bar { opacity: 0.82; }
  .year-bar-col .bar-num { font-size: 14px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
  .year-bar-col .bar-lbl { font-size: 11.5px; color: var(--text-dim); }
  .year-bar-col.dimmed { opacity: 0.4; }

  .donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; justify-content: center; }
  .legend { display: flex; flex-direction: column; gap: 9px; }
  .legend .item { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; cursor: pointer; }
  .legend .item.dimmed { opacity: 0.4; }
  .legend .dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex-shrink: 0; }
  .legend .item b { color: var(--text); font-weight: 600; }

  /* --- percentage-stacked bar chart (Study Area distribution by year) --- */
  .stack-bars { align-items: flex-end; }
  .stack-col { padding: 0; }
  .stack-bar {
    width: 100%;
    height: 170px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--panel-2);
  }
  .stack-col:first-child .stack-bar { border-radius: 2px 0 0 2px; }
  .stack-col:last-child .stack-bar { border-radius: 0 2px 2px 0; }
  .stack-seg {
    width: 100%;
    flex-shrink: 0;
    cursor: pointer;
    transition: opacity 0.15s;
  }
  .stack-seg:hover { opacity: 0.82 !important; }
  .stack-legend {
    display: flex; flex-wrap: wrap; gap: 6px 16px;
    padding: 14px 20px 0 20px; margin-top: 6px;
    border-top: 1px solid var(--border-color);
  }
  .stack-legend .legend-chip {
    font-size: 11.5px; color: var(--text-dim); display: flex; align-items: center;
    gap: 6px; cursor: pointer;
  }
  .stack-legend .legend-chip:hover { color: var(--text); }
  .stack-legend .legend-chip.dimmed { opacity: 0.4; }
  .stack-legend .dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex-shrink: 0; }

  .chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--panel-2);
    border: 1px solid var(--border-color);
    color: var(--text-dim);
    padding: 3px 6px 3px 10px;
    border-radius: 4px;
    font-size: 11.5px;
  }
  .chip button {
    background: none; border: none; color: var(--text-faint); cursor: pointer;
    font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 3px;
  }
  .chip button:hover { color: var(--text); background: var(--border-color); }

  .map-tooltip, .chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--panel);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--text);
    max-width: 220px;
    display: none;
    z-index: 10;
    box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  }
  .chart-tooltip { white-space: nowrap; }
  .map-svg circle { cursor: pointer; transition: fill-opacity 0.1s; }
  .map-svg circle:hover { fill-opacity: 0.95 !important; stroke-width: 1.5; }
  .map-svg { cursor: grab; touch-action: none; }
  .map-svg.dragging { cursor: grabbing; }
  .map-empty {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.92); border: 1px solid var(--border-color);
    color: var(--text-dim); font-size: 12px; padding: 6px 14px; border-radius: var(--radius);
    white-space: nowrap;
    pointer-events: none;
  }

  .map-zoom-controls {
    position: absolute; top: 10px; right: 10px; z-index: 5;
    display: flex; flex-direction: column; align-items: stretch;
    background: var(--panel); border: 1px solid var(--border-color); border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1); overflow: hidden;
  }
  .map-zoom-controls button {
    width: 30px; height: 28px; border: none; background: var(--panel);
    color: var(--text); font-size: 15px; line-height: 1; cursor: pointer;
    border-bottom: 1px solid var(--border-color); font-family: inherit;
  }
  .map-zoom-controls button:last-of-type { border-bottom: none; }
  .map-zoom-controls button:hover:not(:disabled) { background: var(--panel-2); }
  .map-zoom-controls button:disabled { opacity: 0.35; cursor: default; }
  .map-zoom-pct {
    font-size: 10px; color: var(--text-dim); text-align: center; padding: 3px 0;
    border-top: 1px solid var(--border-color); user-select: none;
  }
  .map-zoom-hint {
    position: absolute; bottom: 8px; left: 10px; z-index: 5;
    font-size: 11px; color: var(--text-faint);
    background: rgba(255,255,255,0.75); padding: 2px 8px; border-radius: 10px;
    pointer-events: none;
  }

  /* --- timeline / dual-range slider --- */
  .timeline { margin-bottom: 12px; }
  .timeline-labels {
    display: flex; align-items: baseline; justify-content: space-between;
    font-size: 12px; color: var(--text-dim); margin-bottom: 8px;
  }
  .timeline-labels b { color: var(--text); font-weight: 600; }
  /* Extra top/bottom margin makes room for the floating year bubbles
     (rendered above the thumbs) and the tick-mark year scale (rendered
     below the track) that setupTimeline() injects into each slider. */
  .range-slider { position: relative; height: 20px; margin: 24px 0 20px; }
  .range-track {
    position: absolute; top: 9px; left: 6px; right: 6px; height: 3px;
    background: var(--border-color); border-radius: 2px;
  }
  .range-fill {
    position: absolute; top: 9px; height: 3px; background: var(--accent); border-radius: 2px;
  }
  .range-slider input[type="range"] {
    position: absolute; left: 0; right: 0; top: 0; width: 100%; margin: 0;
    height: 20px; background: transparent; -webkit-appearance: none; appearance: none;
    pointer-events: none;
  }
  .range-slider input[type="range"]::-webkit-slider-runnable-track { background: transparent; }
  .range-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; pointer-events: all; width: 15px; height: 15px;
    border-radius: 50%; background: var(--accent); border: 2px solid var(--panel);
    box-shadow: 0 0 0 1px var(--border-color); cursor: pointer; margin-top: -6px;
    transition: transform .1s;
  }
  .range-slider input[type="range"]:hover::-webkit-slider-thumb,
  .range-slider input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); }
  .range-slider input[type="range"]::-moz-range-track { background: transparent; border: none; }
  .range-slider input[type="range"]::-moz-range-thumb {
    pointer-events: all; width: 15px; height: 15px; border-radius: 50%;
    background: var(--accent); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--border-color); cursor: pointer;
    transition: transform .1s;
  }
  .range-slider input[type="range"]:hover::-moz-range-thumb,
  .range-slider input[type="range"]:active::-moz-range-thumb { transform: scale(1.2); }

  /* Year-value bubbles that float above each thumb, always visible — makes
     it obvious at a glance which handle sits at which year, which the two
     bare native-slider thumbs otherwise don't convey on their own. */
  .range-bubble {
    position: absolute; top: -22px; transform: translateX(-50%);
    font-size: 10.5px; font-weight: 600; color: #fff; padding: 1px 6px;
    border-radius: 3px; white-space: nowrap; pointer-events: none;
  }
  .range-bubble::after {
    content: ''; position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
    border: 4px solid transparent;
  }
  .range-bubble-min { background: #6d7686; }
  .range-bubble-min::after { border-top-color: #6d7686; }
  .range-bubble-max { background: var(--accent); }
  .range-bubble-max::after { border-top-color: var(--accent); }

  /* Tick-mark year scale below the track, so the slider's own range (not
     just the currently-selected span) is visible at a glance. */
  .range-ticks { position: absolute; top: 16px; left: 0; right: 0; height: 14px; }
  .range-tick {
    position: absolute; top: 6px; transform: translateX(-50%);
    font-size: 9.5px; color: var(--text-faint); white-space: nowrap;
  }
  .range-tick::before {
    content: ''; position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
    width: 1px; height: 4px; background: var(--border-color); margin-bottom: 1px;
  }

  /* --- modal --- */
  .modal-overlay {
    position: fixed; inset: 0; background: rgba(20,24,30,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 24px;
  }
  .modal {
    background: var(--panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 100%; max-width: 780px; max-height: 82vh;
    display: flex; flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  }
  .modal-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-color);
  }
  .modal-header h3 { margin: 0; font-size: 14.5px; font-weight: 600; color: var(--text); }
  .modal-close {
    background: none; border: none; color: var(--text-faint); cursor: pointer;
    font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 4px; flex-shrink: 0;
  }
  .modal-close:hover { color: var(--text); background: var(--panel-2); }
  .modal-sub { padding: 12px 20px 0 20px; font-size: 12px; color: var(--text-dim); line-height: 1.55; }

  /* --- selection + export toolbar (map-popup modal AND the main
     Publication List table — same look in both places) --- */
  .select-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
  .select-toolbar-spacer { flex: 1 1 auto; }
  .select-all-label {
    display: flex; align-items: center; gap: 6px; font-size: 12.5px;
    color: var(--text-dim); cursor: pointer; white-space: nowrap;
  }
  .select-count-label { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
  .export-dropdown { position: relative; }
  .export-btn { padding: 6px 12px; font-size: 12px; white-space: nowrap; }
  .export-btn:disabled { opacity: 0.45; cursor: not-allowed; }
  .export-menu {
    position: absolute; top: calc(100% + 4px); right: 0; z-index: 20;
    background: var(--panel); border: 1px solid var(--border-color); border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15); padding: 4px; min-width: 175px;
    display: flex; flex-direction: column;
  }
  .export-menu button {
    display: block; width: 100%; text-align: left; padding: 7px 10px;
    font-size: 12.5px; font-family: inherit; color: var(--text);
    background: none; border: none; border-radius: 4px; cursor: pointer;
  }
  .export-menu button:hover { background: var(--panel-2); }
  .modal-body { padding: 12px 20px 20px 20px; overflow-y: auto; }
  td.select-td, th.select-th { width: 30px; text-align: center; }

  /* --- classification edit form --- */
  .edit-field { margin-bottom: 16px; }
  .edit-field > label.field-label {
    display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-faint); margin-bottom: 8px;
  }
  .checkbox-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px;
  }
  .checkbox-grid label, .radio-row label {
    display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text);
    cursor: pointer; font-weight: 400;
  }
  .radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
  .edit-field input[type="text"] {
    width: 100%; margin-top: 8px; padding: 7px 10px; border-radius: var(--radius);
    border: 1px solid var(--border-color); background: var(--panel-2); color: var(--text);
    font-family: inherit; font-size: 12.5px; box-sizing: border-box;
  }
  .auto-detected {
    font-size: 11.5px; color: var(--text-faint); margin-top: 6px; font-style: italic;
  }
  .modal-actions {
    display: flex; gap: 10px; justify-content: flex-end; padding-top: 6px;
    border-top: 1px solid var(--border-color); margin-top: 4px;
  }
  .btn-primary, .btn-secondary {
    padding: 7px 16px; border-radius: var(--radius); font-size: 12.5px; cursor: pointer;
    font-family: inherit; border: 1px solid transparent;
  }
  .btn-primary { background: var(--accent); color: #fff; }
  .btn-primary:hover { opacity: 0.9; }
  .btn-secondary { background: none; border-color: var(--border-color); color: var(--text-dim); }
  .btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }
