/* =====================================================================
   FILE: style.css
   PURPOSE: Base layout + theming for Rockdoggin
   STRUCTURE:
     1) Theme Variables (light default + dark override)
     2) Global Resets & Base
     3) Layout: App grid (header, main, footer)
     4) Components: topbar, buttons, fields, panels, footer
     5) Visualization area (Leaflet-first)
     6) Responsive tweaks
     7) Location details (right panel)
===================================================================== */


/* =====================================================================
   1) THEME (Two modes): light (default) and dark
===================================================================== */

/* ----- LIGHT (default) ----- */
:root {
  --bg:       #e9eef6;   /* page background (soft gray/blue) */
  --bg-elev:  #f6f8fc;   /* elevated surfaces (header/footer) */
  --panel:    #ffffff;   /* cards/panels */
  --text:     #0f1420;   /* primary text */
  --muted:    #5c6675;   /* secondary text */
  --accent:   #3b6cff;   /* links & accents */
  --border:   #d9e1ec;   /* soft borders */
  --focus:    #7a9cff;   /* focus outline */
  --shadow:   0 2px 12px rgba(0, 0, 0, .07);
  color-scheme: light;
}

/* ----- DARK ----- */
:root[data-theme="dark"] {
  --bg:       #505769;   /* updated dark background */
  --bg-elev:  #505769;
  --panel:    #333a47;   /* panel surface */
  --text:     #e9edf1;
  --muted:    #a3adbd;
  --accent:   #79a6ff;
  --border:   #252a33;
  --focus:    #ffd166;
  --shadow:   0 2px 10px rgba(0,0,0,.25);
  color-scheme: dark;
}

/* Smooth transitions; respect reduced motion */
@media (prefers-reduced-motion: no-preference) {
  body, .topbar, .panel, .footer, .btn, select {
    transition: background-color .2s ease, color .2s ease, border-color .2s ease;
  }
}

/* Panels use themed surface */
.panel { background: var(--panel); }


/* =====================================================================
   2) GLOBAL RESET & BASE
===================================================================== */

/* Box-model sanity: width/height include padding + border */
* { box-sizing: border-box; }

/* Let the app stretch full height */
html, body { height: 100%; }

/* Smooth anchor scrolling */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Base text + background (theme-driven) */
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
}

/* Accessibility: skip to #main */
.skip-link {
  position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden;
}
.skip-link:focus {
  position: fixed; left: 16px; top: 16px; padding: 8px 12px;
  background: var(--panel); color: var(--text); border: 2px solid var(--focus);
  border-radius: 8px; z-index: 1000;
}


/* =====================================================================
   3) LAYOUT: APP GRID
===================================================================== */

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto; /* header, main, footer */
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.3px; }
.brand .subtitle { color: var(--muted); font-size: 14px; }

.tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Basemap select placed inline with panel title (right-aligned) */
.basemap-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.basemap-select select {
  margin-left: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

@media (max-width: 720px) {
  .panel h2 { flex-direction: column; align-items: flex-start; gap: 6px; }
  .basemap-select { width: 100%; justify-content: flex-start; }
}


/* =====================================================================
   4) COMPONENTS
===================================================================== */

/* Buttons & fields */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:focus { outline: 2px solid var(--focus); outline-offset: 2px; }

.field { display: inline-flex; align-items: center; gap: 6px; }
.field .label { color: var(--muted); font-size: 12px; }

select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

/* Main: 3 panels with sashes between columns */
.main {
  display: grid;
  /* left | sash | center | sash | right */
  grid-template-columns: 0.9fr 12px 1.6fr 12px 0.9fr;  /* sash hit area = 12px */
  grid-template-rows: minmax(300px, 1fr);

  /* IMPORTANT: remove column gap so the sash isn't inflated by 14px on each side */
  column-gap: 0;
  row-gap: 14px;

  padding: 8px 8px 6px;
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex; flex-direction: column;
  min-height: 300px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0;
  padding: 12px 14px;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-body {
  padding: 12px 14px;
  overflow: auto;
  flex: 1;
}

/* Full-width panel below the 3-column main row */
.panel.full {
  margin: 0 16px 12px; /* align with .main padding */
}


/* Map panel header layout: title on left, controls (link + basemap) on right */
.panel-title {
  white-space: nowrap;
}

/* Wrap link toggle + basemap select nicely */
.panel-head-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Small, icon-style link toggle */
.btn-link-toggle {
  padding: 4px 8px;
  min-width: 0;
  font-size: 16px;
  line-height: 1;
}

/* Visually indicate "unlinked" state */
.btn-link-toggle.is-off {
  opacity: 0.6;
}


/* Footer */
.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 10px 16px;
}
.footer-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
}
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.sep { color: var(--muted); }


/* =====================================================================
   5) VISUALIZATION AREA
   Leaflet-first: the map fills .map-base; SVG overlay not used for now.
===================================================================== */

/* --- 5·A) BASE LAYERS & STACKING ----------------------------------- */

/* The map wrapper defines the stacking context and size the map can fill */
.map-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background: transparent;
  min-height: 68vh;        /* responsive height so a full Utah view fits */
}

/* Leaflet renders into this element (which later also gets .leaflet-container) */
.map-base {
  position: absolute;
  inset: 0;                /* top/right/bottom/left: 0 */
  z-index: 0;
  width: 100%;
  height: 100%;
  transition: opacity 500ms ease-in-out;
}

.map-base.is-sync-fading {
  opacity: 0.35;
}

/* Ensure Leaflet's container always fills the parent */
.leaflet-container {
  width: 100%;
  height: 100%;
  font: inherit;           /* keep typography consistent with your app */
}

/* TEMP: If an SVG overlay sneaks back in, keep it hidden until needed */
.map-canvas { display: none !important; }

/* Ensure the panel body containing a map can actually grow (Flexbox fix) */
.panel-body:has(.map-wrap) {
  /* For map panels, prefer letting content fill without inner scrollbars. */
  overflow: hidden;
  min-height: 0;           /* critical in flex layouts so children can expand */
}

/* --- 5·B) Leaflet control polish ----------------------------------- */
.leaflet-control-layers-expanded {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.leaflet-top.leaflet-right .leaflet-control-layers { margin-bottom: 10px; }

.leaflet-control-layers-overlays label,
.leaflet-control-layers-base label {
  display: grid;
  grid-template-columns: 1.2rem auto;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 0.95rem;
}
.leaflet-control-layers input[type="checkbox"],
.leaflet-control-layers input[type="radio"] {
  width: 1.2rem;
  height: 1.2rem;
}

/* Search control (top-left) */
.leaflet-top.leaflet-left .rockdog-search {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: var(--shadow);
}
.rockdog-search input {
  width: 220px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  outline: none;
}

/* Hide markers on filter (JS toggles this) */
.pin-hidden { visibility: hidden; }


/* --- 5·C) Custom Rockdog panel (Leaflet control) -------------------- */
/* Custom consolidated Leaflet panel */
.leaflet-control.rockdog-panel .rd-card {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  min-width: 240px;
}
.rockdog-panel .rd-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 6px;
}
.rockdog-panel .rd-body { display: block; }
.rockdog-panel .rd-sec { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.rockdog-panel .rd-sec:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.rockdog-panel .rd-sec-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .3px; }
.rockdog-panel .rd-row { display: grid; grid-template-columns: 1.8rem auto; align-items: center; gap: 10px; margin: 6px 0; }

/* Pretty switches */
.rockdog-panel input[type="checkbox"], .rockdog-panel input[type="radio"] {
  appearance: none; width: 36px; height: 22px; border-radius: 999px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elev), var(--panel));
  position: relative; cursor: pointer; transition: border-color .15s, background-color .15s;
}
.rockdog-panel input[type="checkbox"]::after, .rockdog-panel input[type="radio"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--muted); transition: transform .18s, background-color .18s;
}
.rockdog-panel input[type="checkbox"]:checked, .rockdog-panel input[type="radio"]:checked {
  border-color: var(--accent); background: var(--accent);
}
.rockdog-panel input[type="checkbox"]:checked::after, .rockdog-panel input[type="radio"]:checked::after {
  transform: translateX(14px); background: #fff;
}

/* Opacity sliders */
.rockdog-panel .rd-slider { display: flex; align-items: center; gap: 8px; margin: 2px 0 8px 0; }
.rockdog-panel .rd-slider input[type="range"] { width: 140px; }
.rockdog-panel .rd-slider .rd-val { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }

/* Compact collapsed state */
.rockdog-panel.is-collapsed .rd-card {
  padding: 6px 8px;
  min-width: auto;              /* let it shrink */
  border-radius: 12px;
}

.rockdog-panel.is-collapsed .rd-head span { /* hide the "Layers" title */
  display: none;
}

.rockdog-panel.is-collapsed .rd-toggle.btn {
  padding: 24x 24px;
  min-width: 0;
  font-size: 14px;              /* icon-sized */
  line-height: 0;
}

/* Hide the body (JS also sets display:none for instant toggle) */
.rockdog-panel.is-collapsed .rd-body {
  display: none !important;
}

/* Optional: reduce shadow/visual weight when collapsed */
.rockdog-panel.is-collapsed .rd-card {
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
}

.rockdog-panel .rd-head { cursor: grab; user-select: none; }
.rockdog-panel.is-dragging .rd-head { cursor: grabbing; }


/* --- 5·D) Resizable panel sashes (5-track grid) -------------------- */
.main {
  display: grid;
  /* left | sash | center | sash | right */
  grid-template-columns: 0.9fr 8px 1.6fr 8px 0.9fr; /* JS will override with px values */
  position: relative;
}

/* Place each item in the correct column */
.panel.left   { grid-column: 1; }
.sash-lc      { grid-column: 2; }
.panel.center { grid-column: 3; }
.sash-cr      { grid-column: 4; }
.panel.right  { grid-column: 5; }

/* Keep the hit area wide (easy to grab) */
.sash {
  width: 12px;                  /* hit area */
  cursor: col-resize;
  position: relative;
  align-self: stretch;
  background: transparent;      /* no visible bar here */
  z-index: 20;
}

/* Draw a thin centered line inside the wide hit area */
.sash::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 2px;                   /* <-- visible line thickness */
  transform: translateX(-50%);  /* center it */
  border-radius: 2px;
  background: transparent;      /* default: invisible */
  transition: background-color .12s ease, width .12s ease;
}

/* On hover/focus/drag: show the line (still thin) */
.sash:hover::before,
.sash:focus-visible::before,
.sash.is-dragging::before {
  background: var(--border);
}

/* Optional: make the line thicken slightly on hover for affordance */
.sash:hover::before { width: 3px; }

/* Accessibility outline remains on the whole hit area */
.sash:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

@media (max-width: 720px) {
  .sash { display: none; }
  /* fall back to 3-column layout on phones if you want: */
  .main { grid-template-columns: 1fr; }
}

/* =====================================================================
   6) RESPONSIVE TWEAKS
===================================================================== */

@media (max-width: 1100px) {
  .main {
    grid-template-columns: 1fr 1fr; /* left + center first row, right second row */
    grid-auto-rows: minmax(300px, 1fr);
  }
  .right { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; } /* stack all three */
  .tools { gap: 8px; }
  .brand h1 { font-size: 18px; }
}


/* =====================================================================
   7) LOCATION DETAILS (right panel)
===================================================================== */

.loc-header { display: grid; gap: 4px; margin-bottom: 8px; }
.loc-name { font-weight: 600; }
.loc-coords { font-size: 13px; color: var(--muted); }
.loc-section { margin-top: 12px; }
.loc-subtitle { margin: 0 0 6px 0; font-size: 14px; color: var(--muted); }
.loc-minerals { margin: 0; padding-left: 18px; }


.collapsible-section {
  margin-bottom: 0.75rem;
}

.collapsible-header {
  cursor: pointer;
  padding: 6px 8px;
  background: #444;
  color: #fff;
  border-radius: 4px;
  font-weight: 600;
  user-select: none;
}

.collapsible-body {
  display: none;
  padding: 6px 8px;
  border-left: 3px solid #888;
  margin-top: 4px;
  color: var(--text-color, #eee);
}

.collapsible-body.open {
  display: block;
}

.macro-color-swatch {
  width: 16px; height: 16px;
  border-radius: 4px;
  display: inline-block;
  margin-right: 6px;
  border: 1px solid #444;
}



/* =====================================================================
   Legends (bottom panel)
===================================================================== */


#bottom-content {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--panel-bg);
  font-size: 13px;
  color: var(--fg-muted);

  /* NEW: prevent bottom panel from pushing the whole page up */
  max-height: 180px;       /* tweak this number to taste (160–220px works well) */
  overflow-y: auto;        /* scroll *inside* the bottom strip if it gets too tall */
}


#bottom-content.is-empty {
  display: none;
}

.legend-block.is-hidden {
  display: none;
}

/* Each legend section */
.legend-block {
  min-width: 180px;
  max-width: 260px;
}

.legend-block h3 {
  margin: 0 0 6px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-strong);
}

/* List of legend entries */
.legend-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Scrollable list for long legends (e.g., AGE categories) */
.legend-list.legend-scroll {
  max-height: 110px;   /* was 150px; shorter so the whole panel can stay compact */
  overflow-y: auto;
  padding-right: 4px;
}

/* The actual color swatch */
.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  vertical-align: middle;
}

/* Label next to the swatch */
.legend-label {
  vertical-align: middle;
}


/* Wider block for ownership legend so lines don't wrap */
.legend-block--ownership {
  min-width: 360px;
  max-width: 520px;
  flex: 1 1 360px;
}

/* Single-line layout for ownership items */
.legend-list--ownership .legend-item {
  display: flex;
  align-items: center;
  white-space: nowrap;   /* keep each legend line on one row */
}

.legend-list--ownership .legend-swatch {
  margin-right: 8px;
  flex: 0 0 auto;
}

.legend-list--ownership .legend-line {
  flex: 1 1 auto;
}

/* Make acronyms feel interactive (tooltips) */
.legend-acronym {
  cursor: help;
}


/* ===============================
   Rockdog Panel — Smaller Text
   =============================== */

.rockdog-panel .rd-card {
  font-size: 13px;        /* smaller overall */
}

.rockdog-panel .rd-card .rd-head span,
.rockdog-panel .rd-card .rd-row span,
.rockdog-panel .rd-card .rd-sec-title,
.rockdog-panel .rd-card label {
  font-size: 13px;        /* even tighter for labels */
}

.rockdog-panel input[type="checkbox"],
.rockdog-panel input[type="radio"] {
  transform: scale(0.90);  /* optional — reduces switch size a little */
}

.rockdog-panel .rd-slider input[type="range"] {
  height: 5px;            /* optional — visually lighter slider */
}

.rockdog-panel .rd-val {
  font-size: 10px;
}

.rockdog-panel .rd-row {
  grid-template-columns: 2.4rem auto; 
  gap: 12px;
}

.rockdog-panel .rd-row span {
  padding-left: 2px;
}


/* ============================================
   MINI TOGGLE SWITCHES for Rockdog Panel
   ============================================ */

.rockdog-panel input[type="checkbox"],
.rockdog-panel input[type="radio"] {
  appearance: none;
  width: 28px;           /* compact */
  height: 16px;
  border-radius: 12px;
  background: #c8cdd8;   /* neutral (light mode friendly) */
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  border: none;
}

.rockdog-panel input[type="checkbox"]::after,
.rockdog-panel input[type="radio"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;              /* compact knob */
  height: 12px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

/* When toggled on */
.rockdog-panel input[type="checkbox"]:checked,
.rockdog-panel input[type="radio"]:checked {
  background: var(--accent);   /* uses your theme's accent color */
}

.rockdog-panel input[type="checkbox"]:checked::after,
.rockdog-panel input[type="radio"]:checked::after {
  transform: translateX(12px);
}

/* OPTIONAL: dark-theme tuning */
:root[data-theme="dark"] .rockdog-panel input[type="checkbox"],
:root[data-theme="dark"] .rockdog-panel input[type="radio"] {
  background: #606676;
}

:root[data-theme="dark"] .rockdog-panel input[type="checkbox"]:checked,
:root[data-theme="dark"] .rockdog-panel input[type="radio"]:checked {
  background: var(--accent);
}
