/* North Sea Oil & Gas Production Mapper */

:root {
  --surface: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --accent: #2a78d6;
  --danger: #e34948;
  --header-h: 52px;
  --panel-w: 460px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
  --radius: 6px;
  --hc-oil: #2a78d6;
  --hc-gas: #e34948;
  --hc-oilgas: #eda100;
  --hc-gascond: #e87ba4;
  --hc-unknown: #898781;
}

[data-theme="dark"] {
  --surface: #1a1a19;
  --page: #0d0d0d;
  --ink: #ffffff;
  --secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --accent: #3987e5;
  --danger: #e66767;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --hc-oil: #3987e5;
  --hc-gas: #e66767;
  --hc-oilgas: #c98500;
  --hc-gascond: #d55181;
}

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

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

a {
  color: var(--accent);
}

/* —— Header —— */
.app-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1000;
  background: var(--surface);
  border-bottom: 1px solid var(--gridline);
  box-shadow: var(--shadow);
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-h);
  padding: 0 14px;
}

.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand .sub {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 280px;
  min-width: 140px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.filters-toggle {
  display: none;
}

.search-wrap input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  background: var(--page);
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: none;
  z-index: 1100;
}

.search-results.open {
  display: block;
}

.search-results button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--gridline);
}

.search-results button:last-child {
  border-bottom: none;
}

.search-results button:hover,
.search-results button[aria-selected="true"] {
  background: var(--page);
}

.search-results .name {
  font-weight: 500;
}

.search-results .meta {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.hc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 0;
  margin-left: auto;
}

.filter-select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  background: var(--page);
}

.basemap-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  white-space: nowrap;
}

.basemap-caption {
  font-size: 12px;
  color: var(--secondary);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  background: var(--page);
  font-size: 12px;
  color: var(--secondary);
  white-space: nowrap;
  user-select: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toggle input {
  accent-color: var(--accent);
}

.toggle.active {
  border-color: var(--accent);
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 10%, var(--page));
}

.hc-legend {
  display: flex;
  gap: 4px;
}

.hc-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--gridline);
  font-size: 11px;
  color: var(--secondary);
  background: var(--page);
}

.hc-chip .swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.hc-chip[data-type="OIL"] .swatch {
  background: var(--hc-oil);
}
.hc-chip[data-type="GAS"] .swatch {
  background: var(--hc-gas);
}
.hc-chip[data-type="OIL/GAS"] .swatch {
  background: var(--hc-oilgas);
}
.hc-chip[data-type="GAS/CONDENSATE"] .swatch {
  background: var(--hc-gascond);
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--secondary);
}

.icon-btn:hover {
  color: var(--ink);
  border-color: var(--muted);
}

.link-btn {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  background: var(--page);
  font-size: 12px;
  color: var(--secondary);
}

.link-btn:hover {
  color: var(--ink);
}

/* —— Layout —— */
.app-main {
  display: flex;
  height: 100%;
  padding-top: var(--header-h);
}

#map {
  flex: 1;
  min-width: 0;
  height: calc(100vh - var(--header-h));
  background: var(--page);
}

.panel {
  width: var(--panel-w);
  flex-shrink: 0;
  height: calc(100vh - var(--header-h));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--gridline);
  overflow: hidden;
}

.panel-header {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--gridline);
  flex-shrink: 0;
}

.panel-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-subtitle {
  margin: -4px 0 8px;
  font-size: 12px;
  color: var(--secondary);
}

.selection-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 0;
}

.selection-chips:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 6px 0 8px;
  border-radius: 999px;
  background: var(--page);
  border: 1px solid var(--gridline);
  font-size: 12px;
}

.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chip .x {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

.chip .x:hover {
  background: var(--gridline);
  color: var(--ink);
}

.clear-btn {
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
  color: var(--muted);
  border: 1px dashed var(--baseline);
  border-radius: 999px;
}

.clear-btn:hover {
  color: var(--ink);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--page);
}

.seg button {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--secondary);
  border-right: 1px solid var(--baseline);
}

.seg button:last-child {
  border-right: none;
}

.seg button.active {
  background: var(--ink);
  color: var(--surface);
}

.hc-chip.size-hint {
  border-style: dashed;
  color: var(--muted);
}

.hc-chip.size-hint .swatch {
  display: none;
}

.mode-wrap {
  display: none;
}

.mode-wrap.visible {
  display: inline-flex;
}

.download-menu {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
  padding: 4px 6px 5px;
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  background: var(--page);
}

.download-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--secondary);
}

.download-options {
  display: flex;
  gap: 2px;
}

.download-options button {
  height: 20px;
  padding: 0 6px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--secondary);
  border-radius: 3px;
}

.download-options button:hover {
  color: var(--ink);
  background: var(--gridline);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px 14px 0;
  flex-shrink: 0;
}

.stats:empty,
.stats.hidden {
  display: none;
}

.stat-tile {
  padding: 8px 10px;
  background: var(--page);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
}

.stat-tile .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat-tile .value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-tile .unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 3px;
}

.chart-wrap {
  flex: 1;
  min-height: 0;
  padding: 4px 6px 0;
  position: relative;
}

#chart {
  width: 100%;
  height: 100%;
  min-height: 280px;
}

.chart-note {
  padding: 4px 14px 8px;
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.chart-note:empty {
  display: none;
}

.info-card {
  padding: 10px 14px 16px;
  border-top: 1px solid var(--gridline);
  overflow-y: auto;
  max-height: 38%;
  flex-shrink: 0;
}

.info-card.hidden {
  display: none;
}

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

.info-item .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.info-item .value {
  font-size: 13px;
  color: var(--ink);
  word-break: break-word;
}

.empty-note {
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--secondary);
  background: var(--page);
  border-radius: var(--radius);
  border-left: 3px solid var(--baseline);
}

.footer-attr {
  padding: 8px 14px 12px;
  font-size: 10px;
  line-height: 1.45;
  color: var(--muted);
  border-top: 1px solid var(--gridline);
  flex-shrink: 0;
}

/* —— Modal —— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  color: var(--ink);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 8px;
  padding: 20px 22px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}

.modal h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.modal h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.modal p,
.modal li {
  font-size: 13px;
  line-height: 1.55;
  color: var(--secondary);
}

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

.modal-close {
  float: right;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  color: var(--muted);
}

.modal-close:hover {
  background: var(--page);
  color: var(--ink);
}

/* —— Toast —— */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Leaflet tweaks */
.leaflet-container {
  font: inherit;
  background: var(--page);
}

.leaflet-tooltip.field-tip {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--gridline);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
}

.leaflet-tooltip.field-tip::before {
  border-top-color: var(--gridline);
}

.field-tip strong {
  display: block;
  font-weight: 600;
}

.field-tip .tip-meta {
  color: var(--secondary);
  font-size: 11px;
}

/* Medium desktop: keep controls usable without overflow */
@media (max-width: 1200px) and (min-width: 901px) {
  .hc-legend {
    display: none;
  }

  .basemap-caption {
    display: none;
  }

  .search-wrap {
    max-width: 200px;
  }
}

/* Narrow screens */
@media (max-width: 900px) {
  .header-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  .brand h1 {
    font-size: 13px;
  }

  .search-wrap {
    max-width: none;
    flex: 1 1 calc(100% - 180px);
    min-width: 120px;
  }

  .header-actions {
    margin-left: auto;
  }

  .filters-toggle {
    display: inline-flex;
    align-items: center;
  }

  .filters-toggle[aria-expanded="true"] {
    border-color: var(--accent);
    color: var(--ink);
    background: color-mix(in srgb, var(--accent) 10%, var(--page));
  }

  .filters {
    display: none;
    flex: 1 1 100%;
    order: 4;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 4px;
    margin-left: 0;
  }

  .filters.open {
    display: flex;
  }

  .filters .filter-select,
  .filters .toggle,
  .filters .basemap-label {
    width: 100%;
    min-height: 40px;
    height: auto;
  }

  .basemap-label {
    justify-content: space-between;
    padding: 0 10px;
    border: 1px solid var(--baseline);
    border-radius: var(--radius);
    background: var(--page);
  }

  .basemap-label .filter-select {
    width: auto;
    border: none;
    background: transparent;
    min-height: 40px;
  }

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

  .app-main {
    flex-direction: column;
    height: calc(100vh - var(--header-h));
    overflow: hidden;
  }

  #map {
    height: 45vh;
    width: 100%;
    flex: 0 0 45vh;
    position: sticky;
    top: 0;
    z-index: 1;
  }

  .panel {
    width: 100%;
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    border-left: none;
    border-top: 1px solid var(--gridline);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chart-wrap {
    min-height: 280px;
  }

  .info-card {
    max-height: none;
  }

  .seg button {
    min-height: 36px;
    padding: 0 12px;
  }

  .toggle {
    min-height: 40px;
  }
}

@media (max-width: 600px) {
  .brand .sub {
    display: none;
  }

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

  .chart-wrap {
    min-height: 240px;
  }

  .controls {
    gap: 8px;
  }

  .search-wrap {
    flex: 1 1 100%;
    order: 3;
  }
}
