/* PetMapper — map-first layout, dark chrome, light map. */

:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --bg-softer: #334155;
  --line: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #6366f1;
  --accent-hot: #818cf8;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --band-high: #ef4444;
  --band-medium: #f59e0b;
  --band-low: #64748b;
  --band-unknown: #94a3b8;
  --act-searched: #22c55e;
  --act-leafletted: #38bdf8;
  --act-both: #f59e0b;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
  --sidebar-w: 340px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

/* Author `display` rules beat the UA stylesheet's [hidden] rule, so elements
   like .tool (display: inline-flex) would stay visible when hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--text-dim); }
.small { font-size: 0.8rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.req { color: var(--accent-hot); }

/* --- shell ---------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "side map";
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.9rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 1200;
}

.brand { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub {
  color: var(--text-dim);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }
.user-chip { white-space: nowrap; }
.inline-form { margin: 0; }
.sidebar-toggle { display: none; }

.sidebar {
  grid-area: side;
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 1100;
}

.map-wrap { grid-area: map; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0b1220; }
#map.is-picking { cursor: crosshair; }
#map.is-picking .leaflet-interactive { cursor: crosshair; }

/* --- summary + lists ------------------------------------------------- */

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.stat { background: var(--bg); padding: 0.6rem 0.9rem; }
.stat-wide { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; }
.stat-num { display: block; font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.stat-when { font-size: 0.9rem; font-weight: 600; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 0.65rem 0.5rem;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.tab-pane { display: none; overflow-y: auto; flex: 1; min-height: 0; }
.tab-pane.is-active { display: block; }

.record-list { list-style: none; margin: 0; padding: 0; }
.record {
  padding: 0.65rem 0.9rem 0.7rem 1.1rem;
  border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--band-unknown);
  cursor: pointer;
}
.record:hover { background: var(--bg-soft); }
.record.band-high { border-left-color: var(--band-high); }
.record.band-medium { border-left-color: var(--band-medium); }
.record.band-low { border-left-color: var(--band-low); }
.record.act-searched { border-left-color: var(--act-searched); }
.record.act-leafletted { border-left-color: var(--act-leafletted); }
.record.act-both { border-left-color: var(--act-both); }

.record-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.record-title { font-weight: 600; font-size: 0.9rem; }
.record-sub { margin: 0.2rem 0 0; font-size: 0.8rem; color: var(--text-dim); }
.record-notes { margin: 0.3rem 0 0; font-size: 0.82rem; color: var(--text-dim); }
.tag { display: inline-block; margin-top: 0.35rem; font-size: 0.72rem; color: var(--text-dim); }

.empty { padding: 1.6rem 1rem; text-align: center; color: var(--text-dim); font-size: 0.88rem; line-height: 1.6; }

.pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
  color: #0b1220;
}
.pill.band-high { background: var(--band-high); color: #fff; }
.pill.band-medium { background: var(--band-medium); }
.pill.band-low { background: var(--band-low); color: #fff; }
.pill.band-unknown { background: var(--bg-softer); color: var(--text-dim); }
.pill.act-searched { background: var(--act-searched); }
.pill.act-leafletted { background: var(--act-leafletted); }
.pill.act-both { background: var(--act-both); }

/* --- map furniture --------------------------------------------------- */

.toolbar {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.35rem;
  padding: 0.3rem;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 900;
  max-width: calc(100% - 1.5rem);
  flex-wrap: wrap;
  justify-content: center;
}
.tool {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tool:hover { background: var(--bg-soft); }
.tool.is-active { background: var(--accent); border-color: var(--accent-hot); }
.tool:disabled { opacity: 0.4; cursor: not-allowed; }
.tool-cancel { color: var(--text-dim); }
.tool-finish { background: var(--ok); color: #052e16; }
.tool-finish:hover:not(:disabled) { background: #16a34a; }

.tool-dot { width: 9px; height: 9px; border-radius: 50%; }
.dot-sighting { background: var(--band-high); }
.dot-street { background: var(--act-searched); }
.dot-area { background: var(--act-leafletted); }

.mode-hint {
  position: absolute;
  bottom: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.45rem 0.9rem;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 900;
  max-width: calc(100% - 2rem);
  text-align: center;
}

.legend {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  display: grid;
  gap: 0.15rem;
  padding: 0.55rem 0.7rem;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.72rem;
  color: var(--text-dim);
  z-index: 800;
}
.legend-title { font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.64rem; margin-top: 0.25rem; }
.legend-title:first-child { margin-top: 0; }
.legend-row { display: flex; align-items: center; gap: 0.4rem; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.swatch.band-high { background: var(--band-high); }
.swatch.band-medium { background: var(--band-medium); }
.swatch.band-low { background: var(--band-low); }
.swatch.band-unknown { background: var(--band-unknown); }
.swatch.line-searched { background: var(--act-searched); height: 5px; }
.swatch.line-leafletted { background: var(--act-leafletted); height: 5px; }
.swatch.line-both { background: var(--act-both); height: 5px; }

/* Markers are div icons so confidence can be coloured with plain CSS. */
.pin {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 8px rgba(2, 6, 23, 0.5);
  background: var(--band-unknown);
}
.pin-label {
  transform: rotate(45deg);
  font-size: 0.62rem;
  font-weight: 800;
  color: #0b1220;
  letter-spacing: -0.02em;
}
.pin.band-high { background: var(--band-high); }
.pin.band-high .pin-label { color: #fff; }
.pin.band-medium { background: var(--band-medium); }
.pin.band-low { background: var(--band-low); }
.pin.band-low .pin-label { color: #fff; }
.pin.band-unknown { background: var(--band-unknown); }

.pin-wrap.is-flashing .pin { animation: flash 0.5s ease-in-out 3; }
@keyframes flash {
  50% { transform: rotate(-45deg) scale(1.35); filter: brightness(1.4); }
}

/* --- side panel ------------------------------------------------------ */

.panel {
  position: fixed;
  top: 56px;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100%;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.18s ease-out;
  z-index: 1300;
}
.panel.is-open { transform: none; }
.panel-inner { padding: 1rem 1.1rem 1.6rem; }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.panel-head h2 { margin: 0; font-size: 1.05rem; }

.panel-actions { display: flex; gap: 0.5rem; margin-top: 1.2rem; }

.detail { margin: 0; display: grid; grid-template-columns: 100px 1fr; gap: 0.45rem 0.8rem; font-size: 0.88rem; }
.detail dt { color: var(--text-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 0.1rem; }
.detail dd { margin: 0; }
.prose { line-height: 1.55; }

.photo { display: block; width: 100%; border-radius: var(--radius); margin-top: 1rem; }
.photo-thumb { max-width: 140px; margin: 0.4rem 0; }
.photo-link { display: block; }

/* --- forms ----------------------------------------------------------- */

.form { display: grid; gap: 0.9rem; }
.field { display: grid; gap: 0.3rem; border: 0; padding: 0; margin: 0; }
.field label, .field legend { font-size: 0.82rem; font-weight: 600; color: var(--text-dim); padding: 0; }

.input, .select, textarea, input[type="text"], input[type="password"],
input[type="datetime-local"], input[type="number"]:not([type="range"]) {
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}
.select { width: auto; padding: 0.35rem 0.5rem; font-size: 0.82rem; }
textarea { resize: vertical; line-height: 1.5; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent-hot);
  outline-offset: 1px;
}
.file { font-size: 0.82rem; color: var(--text-dim); }

.prob-slider { width: 100%; accent-color: var(--accent); }
.prob-slider:disabled { opacity: 0.35; }
.prob-out { font-weight: 700; color: var(--text); float: right; }
.prob-out.is-muted { color: var(--text-dim); font-weight: 500; }

.check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; color: var(--text-dim); font-weight: 500; }
.check input { accent-color: var(--accent); }

.radio-row { display: grid; gap: 0.35rem; }
.radio-chip {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--bg-softer);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
  font-size: 0.85rem;
}
.radio-chip:hover { background: var(--bg-soft); }
.radio-chip:has(input:checked) { background: var(--bg-soft); border-color: var(--accent); }
.radio-chip.act-searched { border-left-color: var(--act-searched); }
.radio-chip.act-leafletted { border-left-color: var(--act-leafletted); }
.radio-chip.act-both { border-left-color: var(--act-both); }
.radio-chip input { accent-color: var(--accent); }

.geo-note {
  margin: 0;
  padding: 0.5rem 0.65rem;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 8px;
  font-size: 0.8rem;
  color: #86efac;
}
.geo-note.is-warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

/* --- segment trimming controls --------------------------------------- */

.segment-controls {
  display: grid;
  gap: 0.5rem;
  padding: 0.6rem 0.7rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.segment-head { display: flex; justify-content: space-between; align-items: baseline; }
.segment-label { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }
.segment-count { font-size: 0.86rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.segment-buttons { display: flex; gap: 0.35rem; }
.segment-buttons .btn { flex: 1; }

/* --- draggable shape handles ------------------------------------------ */

/* Handles sit inside Leaflet divIcons, which are transparent by default. */
.handle {
  display: block;
  width: 14px;
  height: 14px;
  margin: 2px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #4c1d95;
  box-shadow: 0 1px 4px rgba(2, 6, 23, 0.6);
  cursor: grab;
  transition: transform 0.1s ease-out;
}
.handle:hover { transform: scale(1.25); }
.handle:active { cursor: grabbing; }

/* Midpoint handles read as "not a corner yet": smaller and hollow. */
.handle-mid {
  width: 10px;
  height: 10px;
  margin: 2px;
  background: rgba(255, 255, 255, 0.45);
  border-style: dashed;
  border-color: #6d28d9;
}
.handle-mid:hover { background: #fff; border-style: solid; }

.leaflet-marker-icon.leaflet-drag-target { cursor: grabbing; }

.error { margin: 0; color: #fca5a5; font-size: 0.8rem; }
.alert {
  padding: 0.55rem 0.7rem;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 0.84rem;
}

/* --- buttons --------------------------------------------------------- */

.btn {
  padding: 0.5rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-softer);
  color: var(--text);
}
.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: transparent; border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.15); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: progress; }

.icon-btn {
  background: none; border: 0; color: var(--text-dim);
  font-size: 1.05rem; cursor: pointer; padding: 0.25rem 0.4rem; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

/* --- toasts ---------------------------------------------------------- */

.toasts {
  position: fixed; bottom: 1rem; right: 1rem;
  display: grid; gap: 0.5rem; z-index: 2000; max-width: min(360px, calc(100% - 2rem));
}
.toast {
  padding: 0.6rem 0.85rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease-out;
}
.toast-error { border-left-color: var(--danger); }
.toast-warn { border-left-color: var(--warn); }
.toast.is-leaving { opacity: 0; transform: translateX(12px); transition: all 0.4s ease-in; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- login ----------------------------------------------------------- */

.login-shell { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.login-card {
  width: min(360px, 100%);
  display: grid; gap: 0.55rem;
  padding: 1.75rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 0.6rem; }
.login-mark { font-size: 2rem; }
.login-card h1 { margin: 0.2rem 0 0.3rem; font-size: 1.3rem; }
.login-card label { font-size: 0.82rem; font-weight: 600; color: var(--text-dim); }
.login-card .btn { margin-top: 0.7rem; }
.login-card code { font-size: 0.78rem; background: var(--bg); padding: 0.1rem 0.3rem; border-radius: 4px; }

/* --- narrow screens --------------------------------------------------- */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "map"; }
  .sidebar-toggle { display: block; }
  .brand-sub { display: none; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; width: min(var(--sidebar-w), 88%);
    transform: translateX(-100%);
    transition: transform 0.18s ease-out;
  }
  .sidebar.is-open { transform: none; }
  .panel { width: 100%; }
  .legend { display: none; }
  .user-chip { display: none; }
}
