:root {
  /* Inspire brand palette — matched to the Portal project's tokens. */
  --ink: #00121c;              /* Inspire near-black */
  --ink-soft: #10222c;
  --muted: #53616a;            /* AA-body contrast on white */
  --paper: #f7f9f9;            /* cool page background */
  --surface: #ffffff;
  --surface-2: #eef2f2;        /* subtle inset for nested panels */
  --line: #d6d9d9;
  --field: #002942;            /* Inspire navy — primary brand color */
  --field-2: #1f6f69;          /* deep teal accent */
  --teal: #298f88;             /* Ecosystems group */
  --clay: #df572a;             /* People group (Inspire orange) */
  --navy: #002942;             /* Businesses group */
  --moss: #598027;             /* Inspire green */
  --plum: #4d214b;             /* Inspire plum */
  --warn: #b3261e;             /* Inspire red */
  --danger: #9b2c16;
  --shadow: 0 12px 28px rgba(0, 41, 66, 0.10);
  font-family: "Red Hat Text", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark theme: cool navy surfaces with a light teal accent for legibility. */
    --ink: #eef3f4;
    --ink-soft: #cdd8da;
    --muted: #9fb0b4;
    --paper: #08161d;
    --surface: #10242e;
    --surface-2: #17303a;
    --line: #26404a;
    --field: #7cc4bd;
    --field-2: #5fb0a8;
    --shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
button:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex="0"]:focus-visible {
  outline: 3px solid rgba(46, 111, 100, 0.42);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 0 14px 34px;
}

.hero {
  padding: 18px 0 12px;
  border-bottom: 1px solid rgba(24, 56, 50, 0.14);
}

.topbar, .section-heading, .location-panel, .export-panel, .item-row, .hero-metrics, .top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.top-actions { flex-wrap: wrap; justify-content: flex-end; }

h1, h2, h3, p { margin: 0; }
h1 {
  color: var(--field);
  font-family: "Sofia Sans Extra Condensed", "Red Hat Text", ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
}
h2 {
  color: var(--field);
  font-size: 1.18rem;
  line-height: 1.1;
}
h3 {
  color: var(--field);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.brand { min-width: 0; }

.eyebrow {
  color: var(--clay);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.legend-hint {
  display: inline;
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: 8px;
}

.hero-copy {
  max-width: 39rem;
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.45;
}

.hero-metrics {
  margin-top: 14px;
  justify-content: flex-start;
  flex-wrap: wrap;
  padding-bottom: 2px;
}

.hero-metrics span {
  border: 1px solid rgba(24, 56, 50, 0.18);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: nowrap;
}

.hero-metrics strong { color: var(--field); }

.privacy-badge {
  background: var(--field) !important;
  color: #fffdf7;
  border-color: var(--field) !important;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

main {
  display: grid;
  gap: 12px;
  padding-top: 14px;
}

/* The tabs + map/list/dashboard share one right-hand column so they stack
   together, instead of each being pinned to grid rows that align with the
   (much taller) composer in the left column. */
.views-col {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-heading { margin-bottom: 14px; align-items: flex-start; }
.section-heading.compact { align-items: center; }

.photo-drop {
  min-height: 236px;
  border: 2px dashed rgba(24, 56, 50, 0.32);
  border-radius: 10px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  overflow: hidden;
  position: relative;
}

.photo-drop img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.photo-drop span {
  z-index: 1;
  display: grid;
  gap: 6px;
  padding: 18px;
  justify-items: center;
}
.photo-drop .photo-icon {
  width: 56px;
  height: 42px;
  color: var(--field-2);
  opacity: 0.9;
}
.photo-drop strong { color: var(--ink); font-size: 1.04rem; }
.photo-drop.has-photo .photo-icon { display: none; }
.photo-drop.has-photo span {
  align-self: end;
  width: 100%;
  color: white;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.62));
  padding-top: 56px;
  padding-bottom: 14px;
}
.photo-drop.has-photo strong { color: white; }
.photo-drop.has-photo small { color: rgba(255, 255, 255, 0.92); }

.photo-actions, .camera-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer; /* it's a <label>, not a <button>, so set the hand cursor explicitly */
}
.camera-status {
  margin-top: 8px;
  line-height: 1.35;
}
.camera-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
}
.camera-panel video {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--field);
}
.camera-actions .primary { margin-top: 0; }

fieldset { border: 0; padding: 0; margin: 18px 0 0; }
legend, .field span { font-weight: 800; margin-bottom: 9px; display: block; color: var(--ink); }
.pill-grid, .chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.pill, .chip {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 700;
  font-size: 0.92rem;
}
.pill.active { color: white; border-color: transparent; }
.chip.active { background: var(--field); color: white; border-color: var(--field); }

.element-chip { min-width: 96px; text-align: center; }

.field { display: block; margin-top: 18px; }
.compact-field { margin-top: 0; }
.observer-field { margin-bottom: 4px; }
.observer-field span { font-size: 0.84rem; }

/* Workspace switcher + project-management popover, top-right in the header. */
.workspace-switcher select {
  width: auto;
  max-width: 46vw;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 700;
}
.project-manage { position: relative; }
.project-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
  width: min(300px, 84vw);
  padding: 14px;
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: left;
}
.project-menu.hidden { display: none; }
.project-menu-section { display: grid; gap: 8px; }
.project-menu-section .field span { font-size: 0.84rem; }
.project-menu-section small { color: var(--muted); font-size: 0.78rem; line-height: 1.3; }
.priority-chip { min-width: 92px; text-align: center; }
/* Traffic-light severity scale: green (low) -> amber (medium) -> red (high).
   Per-chip color comes from the inline --chip-color set in renderPriorityControls. */
.priority-chip::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  position: relative;
  top: -1px;
  background: var(--chip-color, var(--muted));
}
.priority-chip.active {
  background: var(--chip-color);
  border-color: var(--chip-color);
  color: #fff;
}
.priority-chip.active::before { background: rgba(255, 255, 255, 0.9); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 106px; }

.location-panel, .export-panel {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid rgba(24, 56, 50, 0.08);
  border-radius: 10px;
  align-items: center;
}
small { color: var(--muted); display: block; line-height: 1.35; }
.location-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.location-actions button { white-space: nowrap; }

.primary, .secondary, .ghost {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 800;
}
.primary {
  color: white;
  background: var(--field);
  box-shadow: 0 10px 20px rgba(24, 56, 50, 0.2);
  flex: 1;
}
.secondary { color: white; background: var(--field-2); }
.ghost {
  color: var(--field);
  background: var(--surface);
  border: 1px solid rgba(24, 56, 50, 0.18);
}
.ghost.danger { color: var(--danger); border-color: rgba(181, 57, 41, 0.4); }
.small { padding: 8px 10px; font-size: 0.8rem; }

.submit-row {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(24, 56, 50, 0.04);
}
.tab {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 9px 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.tab.active { background: var(--field); color: white; }
.hidden { display: none !important; }

/* Map */
.map-shell { position: relative; }
.map-canvas {
  height: 430px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.map-canvas .leaflet-container { font: inherit; }
/* Mute the OpenStreetMap basemap toward Inspire's calm neutral so the
   color-coded pins read as the primary layer, not the streets. */
.map-canvas .leaflet-tile {
  filter: grayscale(0.4) saturate(0.72) contrast(0.96) brightness(1.04) sepia(0.06);
}
.map-canvas .leaflet-control-attribution {
  font-size: 0.65rem;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
}
.map-canvas .leaflet-control-attribution a { color: var(--field-2); }
.map-pin-icon {
  background: transparent;
  border: 0;
}
.map-pin-icon svg {
  display: block;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.32));
}

.map-empty {
  position: absolute;
  inset: 50% 0 auto 0;
  transform: translateY(-50%);
  pointer-events: none;
  text-align: center;
  padding: 16px;
  margin: 0 auto;
  max-width: 80%;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 10px;
  border: 1px solid var(--line);
  display: grid;
  gap: 4px;
  width: max-content;
  box-shadow: 0 6px 18px rgba(24, 56, 50, 0.12);
}
.map-empty strong { color: var(--field); font-size: 1rem; }

.map-popup {
  display: grid;
  gap: 6px;
  max-width: 220px;
}
.map-popup img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--surface-2);
}
.map-popup strong { color: var(--field); }
.map-popup p { color: var(--ink-soft); margin: 0; }
.popup-meta { display: flex; flex-wrap: wrap; gap: 4px; }
.popup-element {
  font-size: 0.7rem;
  padding: 3px 7px;
  border-radius: 6px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--field);
}
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: 0 16px 34px rgba(31, 48, 42, 0.2); }
.leaflet-popup-content { margin: 12px; }
.leaflet-bar { border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.leaflet-control-zoom a {
  color: var(--field);
  background: var(--surface);
  border-bottom-color: var(--line);
}
.leaflet-control-zoom a:hover { background: var(--surface-2); color: var(--field-2); }

/* Dark theme: flip the light OSM tiles into a muted dark basemap that matches
   the app's dark surfaces instead of a glaring white map. */
@media (prefers-color-scheme: dark) {
  .map-canvas { background: #0d1f28; }
  .map-canvas .leaflet-tile {
    filter: grayscale(0.5) invert(0.94) hue-rotate(180deg) brightness(0.85) contrast(0.9);
  }
  .map-canvas .leaflet-control-attribution {
    background: rgba(20, 32, 30, 0.8);
    color: var(--muted);
  }
}

.map-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  width: 100%;
}

/* iOS "Add to Home Screen" hint — a dismissible bottom banner shown only on
   iOS Safari (which never fires an install prompt). See app.js. */
.ios-install-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 460px;
  margin: 0 auto;
  padding: 12px 14px;
  background: var(--field);
  color: #fffdf7;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.ios-install-text { flex: 1; line-height: 1.35; }
.ios-install-hint strong { color: #fffdf7; }
.ios-share-icon { width: 18px; height: 18px; vertical-align: -4px; margin: 0 1px; }
.ios-install-close {
  flex: none;
  background: transparent;
  border: 0;
  color: #fffdf7;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: 0.85;
}
.ios-install-close:hover { opacity: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.legend span, .item-meta span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  background: var(--surface);
  font-size: 0.76rem;
}
.swatch, .category-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

/* List items */
.observation-list { display: grid; gap: 10px; }
.observation-item {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.item-body { min-width: 0; display: grid; gap: 6px; }
.item-photo { width: 82px; height: 82px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.item-category { text-transform: capitalize; }
.item-date { margin-left: auto; white-space: nowrap; color: var(--muted); }
.item-comment { margin: 0; color: var(--ink-soft); line-height: 1.4; }
.item-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.item-actions { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

/* Dashboard hierarchy */
#dashboardStats { display: grid; gap: 14px; }
.dashboard-section-title {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 4px;
}
.dashboard-hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.dashboard-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.stat {
  min-height: 90px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface);
}
.stat strong { font-size: 1.6rem; line-height: 1.05; display: block; color: var(--field); margin-top: 4px; }
.stat.hero-stat { background: var(--field); border-color: var(--field); color: #fffdf7; }
.stat.hero-stat strong, .stat.hero-stat small { color: #fffdf7; }

.export-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* Minimize button for the "Add an observation" composer. It's an explicit
   button (not a tappable header) so mobile users don't collapse it by accident,
   and it only appears on mobile — on desktop the composer is a sticky sidebar. */
.composer-toggle {
  display: none;
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--field);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
@media (max-width: 779.98px) {
  .composer-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .composer.collapsed #observationForm { display: none; }
}

@media (max-width: 420px) {
  .topbar { align-items: flex-start; }
  .location-panel, .export-panel { align-items: stretch; flex-direction: column; }
  .location-actions { width: 100%; }
  .location-panel button, .export-actions button { width: 100%; }
  .section-heading { gap: 8px; }
  .submit-row { flex-direction: column; }
  .submit-row .primary { width: 100%; }
}

@media (min-width: 780px) {
  .app-shell { padding-inline: 24px; }
  .hero { padding-top: 24px; }
  main {
    grid-template-columns: minmax(330px, 0.82fr) minmax(0, 1.18fr);
    align-items: start;
    gap: 16px;
  }
  .composer { position: sticky; top: 14px; }
  .views-col { grid-column: 2; }
  .tabs { top: 14px; }
  .dashboard-hero { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
