/* =========================================================
   LDWA Marsh Map — styles
   Layout: a fixed side panel on desktop, a bottom sheet on phones.
   Palette: estuary at first light — slate water, marsh green,
   and a dawn amber used only for the boundary and key actions.
   ========================================================= */

:root {
  --ink:        #E9E6DC;   /* main text */
  --ink-soft:   #A9ADA4;   /* secondary text */
  --slate:      #151B1E;   /* panel background */
  --slate-2:    #1E2629;   /* raised surfaces */
  --line:       #2E383B;   /* hairlines */
  --marsh:      #7FA07A;   /* pool pins, positive states */
  --dawn:       #E8A54B;   /* boundary + primary actions */
  --dawn-ink:   #1A1206;   /* text on amber */

  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-ui:      "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, Menlo, monospace;

  --panel-w: 340px;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* The HTML 'hidden' attribute must always win over our display:flex rules (V1 bug fix) */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--slate);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
}

/* ---------- Overall layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100%;
}
.map { height: 100%; background: #0d1214; }

/* ---------- Panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 20px 0;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  z-index: 500;
  background: var(--slate);
}

.brand { display: flex; gap: 14px; align-items: center; }
.brand__logo {
  width: 58px; height: 58px; object-fit: contain;
  background: #fff; border-radius: 50%; padding: 4px; flex: none;
}
.eyebrow {
  margin: 0 0 2px;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--dawn);
}
h1 {
  margin: 0;
  font: 600 24px/1.15 var(--font-display);
  text-wrap: balance;
}
h2 {
  margin: 0;
  font: 600 13px/1 var(--font-ui);
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft);
}

.section { display: flex; flex-direction: column; gap: 12px; }
.section__head { display: flex; align-items: center; justify-content: space-between; }
.count {
  font: 500 12px var(--font-mono); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px;
}

/* ---------- Pool list ---------- */
.pool-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.pool-list button {
  width: 100%; text-align: left; background: none; border: 0; color: inherit; cursor: pointer;
  display: grid; grid-template-columns: 12px 1fr; gap: 12px; align-items: start;
  padding: 10px 6px; border-bottom: 1px solid var(--line); font: inherit;
}
.pool-list button:hover, .pool-list button:focus-visible { background: var(--slate-2); outline: none; }
.pool-list .dot { width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--marsh); box-shadow: 0 0 0 3px rgba(127,160,122,.2); }
.pool-list .name { font-weight: 600; }
.pool-list .notes { display: block; color: var(--ink-soft); font-size: 13px; }
.empty, .hint { margin: 0; color: var(--ink-soft); font-size: 13px; }

/* ---------- Editor ---------- */
.saved { font-size: 12px; color: var(--marsh); }
.saved.is-dirty { color: var(--dawn); }
.tools { display: grid; gap: 8px; }
.tool {
  text-align: left; cursor: pointer; font: inherit; color: inherit;
  background: var(--slate-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.tool:hover { border-color: var(--ink-soft); }
.tool.is-active { border-color: var(--dawn); box-shadow: inset 3px 0 0 var(--dawn); }
.tool__title { font-weight: 600; }
.tool__hint { color: var(--ink-soft); font-size: 13px; }

.pool-form {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px; border: 1px solid var(--marsh); border-radius: var(--radius); background: var(--slate-2);
}
.pool-form label { font-size: 13px; font-weight: 600; }
.pool-form input, .pool-form textarea {
  font: inherit; color: var(--ink); background: var(--slate);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; resize: vertical;
}
.pool-form input:focus, .pool-form textarea:focus { outline: 2px solid var(--marsh); outline-offset: 1px; }
.muted { color: var(--ink-soft); font-weight: 400; }

/* ---------- Buttons ---------- */
.row { display: flex; gap: 8px; }
.row--wrap { flex-wrap: wrap; }
.btn {
  font: 600 14px var(--font-ui); cursor: pointer;
  padding: 9px 14px; border-radius: 8px;
  color: var(--ink); background: var(--slate-2); border: 1px solid var(--line);
}
.btn:hover { border-color: var(--ink-soft); }
.btn:focus-visible, .tool:focus-visible { outline: 2px solid var(--dawn); outline-offset: 2px; }
.btn--primary { background: var(--marsh); border-color: var(--marsh); color: #0f170e; }
.btn--ghost { background: none; }
.btn--toggle[aria-pressed="true"] { background: var(--dawn); border-color: var(--dawn); color: var(--dawn-ink); }

.panel__foot {
  margin-top: auto;
  position: sticky; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0 calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--slate); border-top: 1px solid var(--line);
}
.coords { font: 400 12px var(--font-mono); color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------- V2: ground relief controls ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch__track {
  width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative;
  transition: background .2s;
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); transition: transform .2s;
}
.switch input:checked + .switch__track { background: var(--marsh); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--dawn); outline-offset: 2px; }

/* The legend bar uses the same colour stops as the relief tiles (see tools/step2_render_tiles.py) */
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend__bar {
  height: 10px; border-radius: 3px;
  background: linear-gradient(90deg,
    rgb(32,52,66) 0%, rgb(62,92,98) 14.3%, rgb(138,128,92) 28.6%, rgb(96,128,78) 42.9%,
    rgb(140,164,98) 57.1%, rgb(176,182,112) 71.4%, rgb(206,196,140) 85.7%, rgb(230,220,190) 100%);
}
.legend__ticks, .legend__words { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); }
.legend__ticks { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.legend__words { letter-spacing: .04em; }

.slider { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.slider input { accent-color: var(--marsh); width: 100%; }

.readout { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; min-width: 0; }
.readout__height { font: 500 13px var(--font-mono); color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Things drawn on the map ---------- */
.relief-pane { mix-blend-mode: normal; }
/* The boundary: amber line with a soft glow so it reads over busy imagery */
.marsh-boundary { filter: drop-shadow(0 0 4px rgba(232,165,75,.75)); }

.pool-pin {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--marsh); border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(127,160,122,.35), 0 2px 6px rgba(0,0,0,.5);
}
.pool-label {
  background: rgba(21,27,30,.85); color: var(--ink); border: 0; border-radius: 6px;
  font: 600 12px var(--font-ui); padding: 3px 8px; box-shadow: none;
}
.pool-label::before { display: none; }
/* Zoomed out, names crowd each other: hide them and rely on the list + tap */
.labels-off .pool-label { display: none; }

/* Leaflet's own controls, nudged into our palette */
.leaflet-bar a { background: var(--slate); color: var(--ink); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--slate-2); }
.leaflet-control-attribution { background: rgba(21,27,30,.75) !important; color: var(--ink-soft); }
.leaflet-control-attribution a { color: var(--ink); }
.leaflet-control-scale-line { background: rgba(21,27,30,.75); color: var(--ink); border-color: var(--ink-soft); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--slate); color: var(--ink); }
.leaflet-popup-content { font: 14px/1.45 var(--font-ui); margin: 12px 14px; }
.leaflet-popup-content strong { font-family: var(--font-display); font-size: 17px; }

/* ---------- Phones: panel becomes a bottom sheet ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .map { grid-row: 1; }
  .panel {
    grid-row: 2; max-height: 45vh;
    border-right: 0; border-top: 1px solid var(--line);
    padding: 14px 16px 0; gap: 14px;
  }
  .brand__logo { width: 44px; height: 44px; }
  h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
