:root {
  --surface: #fcfcfb;
  --panel: #ffffff;
  --ocean: #f3f6f9;
  --land: #e8e6df;
  --coast: #9a9890;
  --border: #dcdad3;
  --text-primary: #1f1e1c;
  --text-secondary: #5b5a55;
  --text-muted: #85837c;
  --accent: #2a78d6;
  --zero: #a9a7a0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { display: flex; flex-direction: column; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; line-height: 1.2; }
.byline { margin: 0; font-size: 12px; line-height: 1.3; white-space: nowrap; }
.byline a { color: var(--accent); text-decoration: none; }
.byline a:hover { text-decoration: underline; }
.subtitle { margin: 0; color: var(--text-secondary); font-size: 13px; white-space: nowrap; }
.dev-note {
  margin: 0 0 0 auto;
  padding: 2px 10px;
  white-space: nowrap;
  border: 1px solid #e6d9a8;
  border-radius: 999px;
  background: #fbf6e3;
  color: var(--text-secondary);
  font-size: 12px;
}
.dev-note a { color: var(--accent); }

.layout {
  flex: 1;
  min-height: 0;   /* fill whatever height the header leaves */
  display: grid;
  grid-template-columns: 320px 1fr;
}

.controls {
  overflow-y: auto;
  padding: 12px 16px 16px;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.control { margin-bottom: 16px; }
.control label, .control .label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.two-up { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two-up > div { min-width: 0; }
.two-up > p { grid-column: 1 / -1; margin-top: 0; }
.nocase { text-transform: none; }

input, select, button { font: inherit; color: inherit; }
input[type="search"], input[type="number"], select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}
input[type="range"] { width: 100%; margin: 8px 0 2px; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.hint { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); }
.period-label { margin: 2px 0 0; font-size: 13px; color: var(--text-primary); min-height: 2.9em; white-space: pre-line; }

.species-picker { position: relative; }
.species-list {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  margin: 2px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.species-list li { padding: 5px 10px; cursor: pointer; }
.species-list li[aria-selected="true"], .species-list li:hover { background: #eef4fc; }
.species-list .sci { font-style: italic; color: var(--text-secondary); }
.species-list .count { float: right; color: var(--text-muted); font-size: 12px; }
.species-select { margin-top: 6px; }

/* What the map shows right now, on the land side of the map. */
.map-label {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 56px;
  max-width: min(326px, calc(100% - 80px));   /* the colour bar (300 px) and the padding */
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary);
  pointer-events: none;
}
.map-label:empty { display: none; }
/* An empty season (no tows): a prominent message over the open ocean, top left (clear of the stations and the label). */
.map-message { position: absolute; z-index: 3; top: 16px; left: 16px; max-width: min(380px, calc(100% - 40px));
  padding: 14px 20px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15); text-align: center; pointer-events: none; }
.map-message[hidden] { display: none; }
/* First-visit note on the landing view (setupWelcome). */
.welcome { position: absolute; z-index: 6; top: 50%; left: 50%; transform: translate(-50%, -55%); width: min(520px, calc(100% - 32px));
  padding: 18px 22px 16px; border: 1px solid var(--border); border-radius: 12px; background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22); font-size: 14px; line-height: 1.5; color: var(--text-secondary); }
.welcome[hidden] { display: none; }
.welcome-logo { display: block; width: 96px; height: 96px; margin: 0 auto 10px; border-radius: 6px; }
.welcome h2 { margin: 0 0 8px; font-size: 18px; color: var(--text-primary); text-align: center; }
.welcome p { margin: 0 0 8px; }
.welcome ul { margin: 0 0 12px; padding-left: 18px; }
.welcome button { display: block; margin-left: auto; }
.map-message strong { display: block; font-size: 17px; color: var(--text-primary); }
.map-message span { display: block; margin-top: 4px; font-size: 13px; color: var(--text-secondary); }
/* CalCOFI logo: a brand label kept on land (see placeLogo in atlas.js). */
.brand-logo { position: absolute; z-index: 2; width: 108px; height: 108px; pointer-events: none; border-radius: 4px; }
.brand-logo[hidden] { display: none; }
.map-label .when { display: block; font-size: 20px; font-weight: 600; color: var(--text-primary); }
.map-label .species { display: block; font-weight: 600; color: var(--text-primary); }
.map-label .sci { font-style: italic; font-weight: 400; }
.map-label .members { font-size: 11px; font-weight: 400; }
.map-label .map-note { display: block; margin-top: 4px; font-size: 11px; color: var(--text-muted); }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button {
  flex: 1;
  padding: 6px 8px;
  border: 0;
  background: var(--panel);
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-checked="true"] { background: var(--accent); color: #fff; }

.stepper { display: flex; gap: 6px; }

.secondary-button {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.secondary-button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* Distribution of counts, over the open ocean (top left). */
/* Distribution + survey-month panels, stacked over the open ocean (top left).
   When the station chart is open the column stops above it and scrolls. */
.left-panels {
  position: absolute;
  z-index: 3;
  top: 12px;
  left: 12px;
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.left-panels[hidden] { display: none; }
.map-area.station-open .left-panels { max-height: calc(100% - 260px); }
/* Hydrographic section: at the bottom of the map; when the station chart is
   open too, the chart takes the left half and the section the right. */
.section-panel { position: absolute; left: 12px; right: 12px; bottom: 12px; height: 320px; display: flex; flex-direction: column;
  padding: 6px 10px 4px; border: 1px solid var(--border); border-radius: 8px; background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); z-index: 3; }
.section-panel[hidden] { display: none; }
.section-panel header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-panel h2 { margin: 0; font-size: 14px; font-weight: 600; }
.section-panel header button { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--text-secondary); }
#section-chart { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#section-chart svg { display: block; }
.section-note { margin: 0; font-size: 11px; line-height: 1.3; color: var(--text-muted); }
.section-controls { margin-top: 8px; }
.map-area.panels-split .section-panel { left: calc(50% + 6px); }
.map-area.panels-split .station-panel { right: calc(50% + 6px); }
.map-area.section-open .left-panels { max-height: calc(100% - 350px); }
.high-panel {
  flex: none;
  padding: 8px 12px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.high-panel header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.high-panel h2 { margin: 0; font-size: 13px; font-weight: 600; }
.high-panel header button { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--text-secondary); }
#high-chart { position: relative; height: 250px; }
#cruise-chart { position: relative; height: 168px; }
#cruise-chart svg { width: 100%; height: 100%; display: block; }
.swatch-sq { display: inline-block; width: 9px; height: 9px; margin: 0 2px 0 6px; vertical-align: -1px; border-radius: 2px; }
.cruise-legend { display: inline-block; margin-top: 2px; }
#high-chart svg { width: 100%; height: 100%; display: block; }
.high-panel .hint { margin: 2px 0 0; }

.download .segmented { margin-top: 6px; }
.download .hint { margin-top: 6px; }
.dl-row { margin-top: 6px; }
.download-button {
  width: 100%;
  margin-top: 8px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.download-button:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
.stepper button {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
.stepper #play-btn { flex: 1; }

.legend ul { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; margin: 3px 0; color: var(--text-secondary); font-size: 13px; }
.legend .swatch { flex: none; display: inline-block; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.9); }

.about { margin-top: 20px; font-size: 12px; color: var(--text-muted); }
.about a { color: var(--accent); }

.map-area { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--ocean); }

.status {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-secondary);
  font-size: 13px;
  pointer-events: none;
}
.status:empty { display: none; }

.station-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 8px 12px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 3;   /* above MapLibre's controls (scale bar, attribution) */
}
.station-panel header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.station-panel header .chart-toggle { margin-left: auto; flex: none; }
.station-panel header .chart-toggle[hidden] { display: none; }
.station-panel header .chart-toggle button { padding: 3px 10px; font-size: 12px; color: inherit; background: var(--panel); border: 0; }
.station-panel header .chart-toggle button + button { border-left: 1px solid var(--border); }
.station-panel header .chart-toggle button[aria-checked="true"] { background: var(--accent); color: #fff; }
.station-panel h2 { margin: 0; font-size: 14px; font-weight: 600; }
.station-panel header .ens-smooth { flex: none; display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-secondary); }
.station-panel header .ens-smooth select { font-size: 12px; padding: 2px 4px; }
.station-panel header .ens-key { flex: none; display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.station-panel header .ens-key i { display: inline-block; width: 16px; height: 2px; background: #d62728; }
.station-panel header .ens-key i.med { background: #2b2a27; margin-left: 6px; }
.station-panel header .chart-toggle[hidden] + .ens-key { margin-left: auto; }
@media (max-width: 700px) { .station-panel header .ens-key { display: none; } }
.station-panel header button {
  border: 0;
  background: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-secondary);
}
#station-chart { position: relative; height: 180px; }
#station-chart svg { width: 100%; height: 100%; display: block; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--text-primary);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.maplibregl-popup-content { padding: 8px 10px; font: 13px/1.4 var(--font); }

/* CalCOFI line numbers at the offshore (western) end of each line. */
.line-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 760px) {
  .layout { flex: none; grid-template-columns: 1fr; grid-template-rows: auto 60vh; height: auto; }
  .controls { border-right: 0; border-bottom: 1px solid var(--border); }
  .map-area { height: 60vh; }
  .topbar { flex-direction: column; gap: 2px; }
  .dev-note { margin: 4px 0 0; border-radius: 8px; white-space: normal; }
  .topbar h1, .subtitle { white-space: normal; }
}

/* Colour bar (side panel and map label). */
.legend .segmented { margin-bottom: 8px; }
.control[hidden] { display: none; }
.compare { margin: 0 0 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #f7f6f2; }
.compare[hidden] { display: none; }
.compare-q { display: block; margin-bottom: 4px; font-weight: 600; font-size: 13px; }
.contour-label { font: 600 10px/1 var(--font); white-space: nowrap; pointer-events: none; }
.bathy-label { font: 500 9.5px/1 var(--font); color: #4d5862; white-space: nowrap; pointer-events: none;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff; }
/* Four Map buttons in a 2 x 2 grid. */
.segmented.grid2 { display: grid; grid-template-columns: 1fr 1fr; }
.segmented.grid2 button:nth-child(odd) { border-left: 0; }
.segmented.grid2 button:nth-child(n+3) { border-top: 1px solid var(--border); }
#hydro-depth-box[hidden], #hydro-iso-box[hidden], .hint[hidden] { display: none; }
.segmented.grid2 button:last-child:nth-child(odd) { grid-column: span 2; border-left: 0; }
.ternary-panel { position: absolute; z-index: 4; inset: 12px 12px 12px 12px; display: flex; flex-direction: column;
  padding: 8px 12px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); box-shadow: 0 4px 18px rgba(0,0,0,0.15); }
.ternary-panel[hidden] { display: none; }
.ternary-panel header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.ternary-panel h2 { margin: 0; font-size: 14px; font-weight: 600; }
.ternary-panel header button { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--text-secondary); }
.ternary-panel iframe { flex: 1; width: 100%; border: 0; }
.segmented.three button { font-size: 12px; padding-left: 4px; padding-right: 4px; }
.checkbox { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-weight: 500; cursor: pointer; }
.legend-bar { margin-top: 2px; }
.colour-bar { display: block; max-width: 100%; height: auto; }
.map-label .bar-title { display: block; margin-top: 6px; font-size: 11px; font-weight: 600; color: var(--text-secondary); }
