:root {
  --paper: #ffffff;
  --paper-2: #f7f8fc;
  --ink: #181818;
  --ink-soft: #2e2e2e;
  --muted: #655f58;
  --blue: #3f78ef;
  --blue-deep: #244db8;
  --blue-soft: rgba(63,120,239,0.10);
  --hairline: rgba(24,24,24,0.14);
  --hairline-soft: rgba(24,24,24,0.06);
  --shadow: 0 16px 34px rgba(63,120,239,0.18);
  --danger: #b53929;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { 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(63,120,239,0.42);
  outline-offset: 2px;
}

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

/* Hero band — full blue gradient */
.hero {
  background: radial-gradient(circle at 78% 47%, rgba(255,255,255,.16), transparent 15rem),
              linear-gradient(135deg, #3f78ef, #244db8);
  padding: clamp(20px, 4vw, 40px) 0 clamp(16px, 3vw, 28px);
  margin: 0 -14px;
  padding-left: 14px;
  padding-right: 14px;
}

.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, .view-actions { flex-wrap: wrap; justify-content: flex-end; }
.view-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  font-size: clamp(2.4rem, 8vw, 4rem);
  line-height: 0.88;
  color: #fffaf1;
  letter-spacing: 0;
}
h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1.1;
}
h3 {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.brand { min-width: 0; }

.eyebrow {
  color: #e8f1ff;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  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: 8px;
  color: rgba(255,255,255,0.82);
  font-size: 1rem;
  line-height: 1.55;
}

.hero-metrics {
  margin-top: 14px;
  justify-content: flex-start;
  flex-wrap: wrap;
  padding-bottom: 2px;
}
.hero-metrics span {
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.12);
  padding: 7px 11px;
  white-space: nowrap;
  color: #fffaf1;
  font-size: 0.88rem;
}
.hero-metrics strong { color: #ffffff; }
.privacy-badge {
  background: rgba(255,255,255,0.18) !important;
  color: #fffaf1;
  border-color: rgba(255,255,255,0.36) !important;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

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

.card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  padding: 16px;
}

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

/* Photo area */
.photo-drop {
  min-height: 236px;
  border: 2px dashed var(--hairline);
  background: var(--paper-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(--blue); opacity: 0.7; }
.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); }
.compact-composer .photo-drop { min-height: 118px; }
.compact-composer .photo-drop .photo-icon { width: 38px; height: 28px; }
.compact-composer .photo-drop small { display: none; }

.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;
}
.camera-status { margin-top: 8px; line-height: 1.35; }
.camera-panel {
  margin-top: 12px;
  border: 1px solid var(--hairline);
  padding: 10px;
  background: var(--paper-2);
}
.camera-panel video {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: cover;
  background: var(--ink);
}
.camera-actions .primary { margin-top: 0; }

fieldset { border: 0; padding: 0; margin: 18px 0 0; }
legend, .field span { font-weight: 700; 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(--hairline);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0;
  padding: 9px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}
.pill.active { color: white; border-color: var(--blue); background: var(--blue); }
.chip.active { background: var(--blue); color: white; border-color: var(--blue); }

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

.field { display: block; margin-top: 18px; }
textarea, select {
  width: 100%;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--paper);
  padding: 12px;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 106px; }

.location-panel, .export-panel {
  margin-top: 16px;
  padding: 14px;
  background: var(--paper-2);
  border: 1px solid var(--hairline-soft);
  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; }

/* Buttons — sharp corners, uppercase Inter */
.primary, .secondary, .ghost {
  border: 0;
  border-radius: 0;
  padding: 12px 18px;
  font-weight: 900;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 44px;
}
.primary {
  color: #fffaf1;
  background: var(--blue);
  box-shadow: var(--shadow);
  flex: 1;
}
.secondary { color: white; background: var(--blue-deep); }
.ghost {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--hairline);
}
.ghost.danger { color: var(--danger); border-color: rgba(181,57,41,0.4); }
.small { padding: 7px 10px; font-size: 0.72rem; }

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

/* Tabs */
.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  background: var(--paper);
  border: 1px solid var(--hairline);
}
.tab {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--hairline);
  padding: 9px 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 0;
}
.tab:last-child { border-right: 0; }
.tab.active { background: var(--blue); color: white; border-color: var(--blue); }
.hidden { display: none !important; }

/* Map */
.map-shell { position: relative; }
.map-canvas {
  height: 430px;
  overflow: hidden;
  background: #e8eef8;
  border: 1px solid var(--hairline);
}
.map-canvas.leaflet-container { font: inherit; }

/*
  Leaflet's tile positioning depends on its library stylesheet. Keep the
  essential layout rules local so CDN/CSP/cache misses cannot turn tiles into
  normal inline images.
*/
.leaflet-container {
  overflow: hidden;
  touch-action: pan-x pan-y;
}
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}
.leaflet-tile {
  width: 256px;
  height: 256px;
}
.leaflet-pane { z-index: 400; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}
.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}
.leaflet-top { top: 0; }
.leaflet-right { right: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-top .leaflet-control { margin-top: 10px; }
.leaflet-bottom .leaflet-control { margin-bottom: 10px; }
.leaflet-left .leaflet-control { margin-left: 10px; float: left; clear: both; }
.leaflet-right .leaflet-control { margin-right: 10px; float: right; clear: both; }
.leaflet-control-attribution { font-size: 0.65rem; }
.map-pin-icon { background: transparent; border: 0; }
.map-pin-icon svg { display: block; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.28)); }

.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.96);
  border: 1px solid var(--hairline);
  display: grid;
  gap: 4px;
  width: max-content;
  box-shadow: 0 6px 18px rgba(63,120,239,0.12);
}
.map-empty strong { color: var(--blue); font-size: 1rem; }

.map-popup { display: grid; gap: 6px; max-width: 220px; }
.map-popup img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  background: var(--paper-2);
}
.map-popup strong { color: var(--blue); }
.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;
  font-weight: 700;
  background: var(--blue-soft);
  color: var(--blue-deep);
}
.leaflet-popup-content-wrapper { border-radius: 0; box-shadow: 0 16px 34px rgba(63,120,239,0.18); }
.leaflet-popup-content { margin: 12px; }
.leaflet-control-zoom a { color: var(--blue); }

.map-note { margin-top: 8px; color: var(--muted); font-size: 0.76rem; width: 100%; }
.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(--hairline);
  padding: 5px 8px;
  background: var(--paper);
  font-size: 0.75rem;
}
.swatch, .category-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

/* List */
.observation-list { display: grid; gap: 10px; }
.observation-item {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  padding: 11px;
  border: 1px solid var(--hairline);
  background: var(--paper);
}
.item-body { min-width: 0; display: grid; gap: 6px; }
.item-photo { width: 82px; height: 82px; object-fit: cover; background: var(--paper-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 */
#dashboardStats { display: grid; gap: 14px; }
.dashboard-section-title {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-weight: 600;
  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(--hairline);
  padding: 12px;
  background: var(--paper);
}
.stat strong { font-size: 1.6rem; line-height: 1.05; display: block; color: var(--blue); margin-top: 4px; }
.stat.hero-stat { background: var(--blue); border-color: var(--blue); color: #fffaf1; }
.stat.hero-stat strong, .stat.hero-stat small { color: #fffaf1; }
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(12px);
  z-index: 10000;
  max-width: min(92vw, 420px);
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  background: var(--ink);
  color: #fffaf1;
  box-shadow: 0 12px 28px rgba(0,0,0,0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { color: var(--muted); padding: 20px; text-align: center; }

@media (max-width: 420px) {
  .topbar { align-items: flex-start; }
  .location-panel, .export-panel { align-items: stretch; flex-direction: column; }
  .location-actions, .view-actions { width: 100%; }
  .view-actions { align-items: stretch; flex-direction: column; }
  .location-panel button, .export-actions button, .view-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 { margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
  main {
    grid-template-columns: minmax(330px, 0.82fr) minmax(0, 1.18fr);
    align-items: start;
    gap: 16px;
  }
  /* Span all rows so row heights are set by the column-2 items, not the form */
  .composer { position: sticky; top: 14px; grid-row: 1 / span 4; }
  .tabs, .view { grid-column: 2; }
  .tabs { top: 14px; }
  .dashboard-hero { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
