/* Self-hosted Playfair Display (variable, weights 400-900). No CDN. */
@font-face {
  font-family: "Playfair Display";
  src: url("vendor/fonts/PlayfairDisplay-VariableFont_wght.ttf") format("truetype");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Playfair Display";
  src: url("vendor/fonts/PlayfairDisplay-Italic-VariableFont_wght.ttf") format("truetype");
  font-weight: 400 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #1a2318;
  --panel: #f7f2e8;
  --panel-border: #d4c9a8;
  --accent: #4a8c47;
  --accent-dark: #2e5c34;
  --gold: #b07d2e;
  --text: #2a1f0d;
  --muted: #7a6e52;
  --danger: #b3392f;

  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over the id/class display rules below, which
   otherwise have higher specificity than the UA [hidden] { display:none }. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background-color: #efe7d4;
  background-image: url("/images/botanical/page-backdrop.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: 0.2px;
}

#map {
  position: absolute;
  inset: 0;
  top: 48px;
}

/* Top bar */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--bg);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  z-index: 1000;
  overflow-x: auto;
  overflow-y: hidden;
}
#topbar .brand { font-weight: 700; letter-spacing: 0.5px; flex: 0 0 auto; }
/* One row only: overflowing controls scroll horizontally rather than wrapping
   onto a hidden second line behind the map. */
.topbar-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: nowrap; }
.topbar-actions button,
.topbar-actions a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}
.topbar-icon { font-size: 15px; line-height: 1; }
.topbar-label { line-height: 1; }
.topbar-actions button:hover,
.topbar-actions a:hover { background: var(--accent-dark); }

/* Drawer */
#drawer {
  position: absolute;
  top: 48px; right: 0; bottom: 0;
  width: 360px;
  max-width: 90vw;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  box-shadow: -2px 0 12px rgba(0,0,0,0.25);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer-head {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
}
.drawer-head h2 { margin: 0; font-size: 20px; font-family: var(--serif); }
.drawer-head button {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
}
#drawer-body, #modal-body { padding: 16px; overflow-y: auto; }

/* Forms */
form.feature-form label,
.field-row {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
form.feature-form input,
form.feature-form select,
form.feature-form textarea {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
}
form.feature-form textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn {
  border: none; border-radius: 6px; padding: 10px 14px;
  font-size: 15px; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--panel-border); color: var(--text); }
.section-title { font-weight: 600; color: var(--text); margin: 16px 0 8px; }
.hint { font-size: 12px; color: var(--muted); }

/* Photos */
.photo-upload { display: inline-block; margin-top: 8px; }
.photo-upload.is-busy { opacity: 0.6; pointer-events: none; }
.topbar-actions button.is-active { background: var(--accent-dark); box-shadow: inset 0 0 0 2px #fff; }
.photo-gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-gallery figure { margin: 0; width: 100px; }
.photo-gallery img { width: 100px; height: 100px; object-fit: cover; border-radius: 6px; }
.photo-gallery button { font-size: 11px; margin-top: 2px; }

/* Modal */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 10, 0.75);
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  width: 860px;
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
/* Custom field list */
.cf-list { list-style: none; padding: 0; margin: 0 0 16px; }
.cf-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border: 1px solid var(--panel-border); border-radius: 6px; margin-bottom: 6px;
}
.cf-list .cf-key { color: var(--muted); font-size: 12px; }

/* Login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  height: 100%; background: var(--bg);
}
.login-card {
  background: var(--panel); padding: 32px; border-radius: 12px; width: 320px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.login-card h1 { margin: 0; color: var(--accent-dark); }
.login-sub { margin: 4px 0 20px; color: var(--muted); }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; padding: 10px; margin-top: 4px;
  border: 1px solid var(--panel-border); border-radius: 6px; font-size: 15px;
}
.login-card button {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border: none; border-radius: 6px; font-size: 16px; cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 14px; margin-top: 12px; }

/* Locate marker */
.locate-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: #2a7de1; border: 2px solid #fff; box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

@media (max-width: 600px) {
  #drawer { width: 100%; max-width: 100%; top: auto; bottom: 0; height: 60vh; }
  .topbar-actions button, .topbar-actions a { padding: 8px; font-size: 13px; }
  /* Icons only on phones: the text labels are dropped to keep the bar to one row. */
  .topbar-actions .topbar-label { display: none; }
  .topbar-actions button, .topbar-actions a { gap: 0; }
  #topbar .brand { display: none; }
}

/* Shell nav (feature links in the shared top bar) */
#topbar a.brand { color: #fff; text-decoration: none; }
.shell-nav { display: flex; gap: 4px; flex-wrap: nowrap; flex: 0 0 auto; }
.shell-nav .nav-link { white-space: nowrap; }
.shell-nav .nav-link {
  color: #d9c9a0; text-decoration: none; padding: 6px 8px;
  border-radius: 6px; font-size: 14px; line-height: 1;
}
.shell-nav .nav-link:hover { background: rgba(255,255,255,0.12); color: #fff; }
.shell-nav .nav-link.is-active { background: var(--accent); color: #fff; }
.shell-nav .nav-link.is-soon { color: var(--muted); cursor: default; pointer-events: none; }
.shell-nav .nav-sep {
  width: 1px; align-self: stretch; margin: 4px 6px;
  background: rgba(255,255,255,0.18);
}

/* Nav brand — gold Playfair */
#topbar .brand {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: var(--gold);
  flex: 0 0 auto;
}
#topbar a.brand { color: var(--gold); text-decoration: none; }
.shell-nav .nav-link.is-active {
  background: var(--accent);
  color: #fff;
  position: relative;
}
.shell-nav .nav-link.is-active::before {
  content: "🌱";
  margin-right: 5px;
  font-size: 11px;
  vertical-align: -1px;
}

/* Home hub */
#home {
  position: absolute;
  top: 48px; left: 0; right: 0; bottom: 0;
  overflow-y: auto;
  padding: 24px;
  background: transparent;
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  max-width: 900px;
  margin: 0 auto;
}
.feature-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 20px; min-height: 120px;
  text-decoration: none; color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.feature-card:hover { border-color: var(--accent); box-shadow: 0 3px 10px rgba(0,0,0,0.12); }
.feature-card.is-soon { opacity: 0.55; cursor: default; box-shadow: none; }
.feature-card.is-soon:hover { border-color: var(--panel-border); box-shadow: none; }
.card-icon { font-size: 32px; line-height: 1; }
.card-label { font-size: 18px; font-weight: 600; }
.card-snippet { font-size: 13px; color: var(--muted); }
.hub-upcoming {
  display: block; max-width: 900px; margin: 20px auto 0; padding: 16px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  text-decoration: none; color: inherit;
}
.hub-upcoming:hover { border-color: var(--accent); box-shadow: 0 3px 10px rgba(0,0,0,0.12); }
.hub-upcoming-title { margin: 0 0 8px; font-size: 16px; }
.hub-upcoming-list { list-style: none; margin: 0; padding: 0; }
.hub-upcoming-list li { display: flex; gap: 12px; padding: 4px 0; }
.hub-when { min-width: 84px; }
.card-soon { font-size: 12px; color: var(--muted); font-style: italic; }

@media (max-width: 600px) {
  .shell-nav .nav-link { padding: 6px; font-size: 13px; }
  #home { padding: 16px; }
}

.measure-tooltip {
  background: var(--danger);
  color: #fff;
  border: none;
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.measure-tooltip::before { display: none; }

.colour-row { display: flex; align-items: center; gap: 0.75rem; }
.colour-default { display: inline-flex; align-items: center; gap: 0.25rem; font-weight: 400; }
.zone-area { margin: 0.25rem 0; font-size: 0.9rem; color: var(--muted); }
.annotation-label {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #8844aa;
  color: #4a2b66;
  font-weight: 600;
}

/* Species list page */
/* Offset for the 48px absolutely-positioned topbar so controls clear it. */
#specieslist { padding: calc(48px + 1rem) 1rem 1rem; max-width: 1000px; margin: 0 auto; }
.list-controls { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.list-controls input[type="search"] { flex: 1 1 220px; padding: 0.4rem 0.5rem; }
.species-table-wrap {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 0.5rem 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.species-table { width: 100%; border-collapse: collapse; }
.species-table th, .species-table td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--panel-border); }
.species-table thead th {
  font-family: var(--serif);
  font-size: 0.9rem;
  color: var(--accent-dark);
  border-bottom: 2px solid var(--panel-border);
}
.species-table tbody tr:last-child td { border-bottom: none; }
.species-row { cursor: pointer; }
.species-row:hover { background: #efe7d4; }

/* Species pick-or-create picker */
.species-picker { position: relative; }
.species-picker input { width: 100%; box-sizing: border-box; }
.species-suggestions { position: absolute; z-index: 20; left: 0; right: 0; background: var(--panel);
  border: 1px solid var(--panel-border); border-top: none; max-height: 220px; overflow-y: auto; }
.species-suggestion { display: block; width: 100%; text-align: left; padding: 0.4rem 0.6rem;
  border: none; background: none; cursor: pointer; }
.species-suggestion:hover { background: #efe7d4; }
.species-add { font-style: italic; color: var(--accent-dark); }
.species-readonly.hint { margin: 0.25rem 0 0.5rem; color: var(--muted); font-size: 0.85em; }

/* Icons for the typed Geoman toolbar controls. Each control in draw.js is a
   copy of a built-in draw tool and carries only .control-icon (sizing, no
   image), so each needs its own background here. Grey %235B5B5B matches the
   built-ins; the button name is the CSS hook (pm-icon-<name>). */
.leaflet-pm-toolbar .pm-icon-draw-zone {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linejoin="round"><path d="M5 4l14 3-2 13-13-2z"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-draw-path {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 18C8 4 16 20 20 6" stroke-dasharray="3 2.5"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-draw-infrastructure {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="6" x2="4" y2="19"/><line x1="12" y1="6" x2="12" y2="19"/><line x1="20" y1="6" x2="20" y2="19"/><line x1="4" y1="9" x2="20" y2="9"/><line x1="4" y1="15" x2="20" y2="15"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-draw-planting {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="21" x2="12" y2="10"/><path d="M12 12c0-3 2-5 5-5 0 3-2 5-5 5z" fill="%235B5B5B" stroke="none"/><path d="M12 14c0-3-2-5-5-5 0 3 2 5 5 5z" fill="%235B5B5B" stroke="none"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-draw-planting-area {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linejoin="round"><path d="M4 8l7-4 9 3-2 11-10 2z"/><path d="M12 9c2.5 0 4 2 4 4.5-2.5 0-4-2-4-4.5z" fill="%235B5B5B" stroke="none"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-draw-sighting-point {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s4-6 10-6 10 6 10 6-4 6-10 6S2 12 2 12z"/><circle cx="12" cy="12" r="2.5" fill="%235B5B5B" stroke="none"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-draw-sighting-area {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1" stroke-dasharray="3 2.5"/><path d="M6 12s2.5-3.5 6-3.5 6 3.5 6 3.5-2.5 3.5-6 3.5S6 12 6 12z"/><circle cx="12" cy="12" r="1.5" fill="%235B5B5B" stroke="none"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-annotate-label {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h13l4 6-4 6H3z"/><line x1="7" y1="12" x2="13" y2="12"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-annotate-shape {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 20l4-1L19 8l-3-3L5 16z"/><line x1="14" y1="6" x2="18" y2="10"/></svg>');
}

/* Visual grouping in the draw toolbar: a gap + hairline before the first button
   of each object-type cluster (land | plantings | life | notes). Buttons are
   div.button-container in draw.js CONTROLS order. */
.leaflet-pm-draw .button-container:has(.pm-icon-draw-planting),
.leaflet-pm-draw .button-container:has(.pm-icon-draw-sighting-point),
.leaflet-pm-draw .button-container:has(.pm-icon-annotate-label) {
  margin-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.15);
  padding-top: 8px;
}
.leaflet-pm-toolbar .pm-icon-measure-distance {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linejoin="round"><rect x="2" y="8" width="20" height="8" rx="1"/><line x1="6" y1="8" x2="6" y2="12"/><line x1="10" y1="8" x2="10" y2="11"/><line x1="14" y1="8" x2="14" y2="12"/><line x1="18" y1="8" x2="18" y2="11"/></svg>');
}
.leaflet-pm-toolbar .pm-icon-measure-area {
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%235B5B5B" stroke-width="2" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="1"/><line x1="3" y1="8" x2="6" y2="8"/><line x1="3" y1="13" x2="6" y2="13"/><line x1="8" y1="3" x2="8" y2="6"/><line x1="13" y1="3" x2="13" y2="6"/></svg>');
}

/* Documents page */
#documents { padding: calc(48px + 1rem) 1rem 1rem; max-width: 1100px; margin: 0 auto; min-height: calc(100vh - 48px - 2rem); }
.documents-layout { display: flex; gap: 1rem; align-items: flex-start; min-height: inherit; }
.documents-list { flex: 0 0 260px; }
.documents-items { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.documents-item { padding: 0.5rem 0.6rem; border: 1px solid var(--panel-border); border-radius: 8px; margin-bottom: 6px; cursor: pointer; background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.documents-item:hover { background: #efe7d4; }
.documents-item.is-active { border-color: var(--accent); background: #e7e0cc; }
.documents-item-title { font-weight: 600; }
.documents-item-snippet {
  font-size: 0.85em;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 2px 0;
}
.documents-editor { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.documents-title-input { width: 100%; padding: 8px; font-size: 18px; margin-bottom: 0.5rem;
  border: 1px solid var(--panel-border); border-radius: 6px; }
.documents-editor-surface {
  flex: 1 1 auto;
  min-height: 420px;
  background: var(--panel);
}
@media (max-width: 600px) { .documents-layout { flex-direction: column; } .documents-list { flex-basis: auto; width: 100%; } }

/* Journal page */
#journal { padding: calc(48px + 1rem) 1rem 1rem; max-width: 1100px; margin: 0 auto; }
.journal-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 1rem; }
.journal-type-filter, .journal-from, .journal-to {
  padding: 8px; border: 1px solid var(--panel-border); border-radius: 6px; font-size: 14px; }
.journal-feed { display: flex; flex-direction: column; gap: 12px; }
.journal-card { border: 1px solid var(--panel-border); border-radius: 8px; padding: 12px 14px; background: var(--panel); }
.journal-card-head { display: flex; gap: 8px; align-items: center; }
.journal-card-date { font-size: 13px; color: var(--muted); }
.journal-card-type { font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: #e7e0cc; color: var(--accent-dark); text-transform: capitalize; }
.journal-card-title { margin: 6px 0 4px; font-size: 17px; }
.journal-card-snippet { margin: 0 0 8px; color: var(--text); }
.journal-card-subjects { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.journal-subject-chip { display: inline-block; padding: 0 6px; border-radius: 4px;
  background: #e7e0cc; color: var(--accent-dark); text-decoration: none; font-size: 13px; white-space: nowrap; }
.journal-subject-chip:hover { background: #d9c9a0; }
.journal-editor-surface { min-height: 200px; background: var(--panel); margin: 8px 0; }
.journal-form .journal-observed, .journal-form .journal-entry-type, .journal-form .journal-title {
  padding: 6px; border: 1px solid var(--panel-border); border-radius: 6px; }

/* Linked documents in the drawer */
.linked-doc { display: flex; align-items: center; gap: 8px; border: 1px solid var(--panel-border);
  border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; }
.linked-doc-title { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.linked-doc-open { flex: 0 0 auto; color: var(--accent-dark); text-decoration: none; font-size: 13px; }
.linked-doc-open:hover { text-decoration: underline; }

/* Embedded map-object chips */
.obj-chip { display: inline-block; padding: 0 4px; border-radius: 4px;
  background: #e7e0cc; color: var(--accent-dark); text-decoration: none; white-space: nowrap; }
.obj-chip:hover { background: #d9c9a0; text-decoration: none; }

/* Chip picker popover */
.obj-picker { position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  width: min(420px, 90vw); max-height: 60vh; overflow: auto; z-index: 2000;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18); padding: 12px; }
.obj-picker-search { width: 100%; padding: 8px; border: 1px solid var(--panel-border); border-radius: 6px; }
.obj-picker-results { margin-top: 8px; }
.obj-picker-row { display: block; width: 100%; text-align: left; padding: 6px 8px;
  border: none; background: none; cursor: pointer; border-radius: 6px; }
.obj-picker-row:hover { background: #efe7d4; }
.obj-picker-box {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  padding: 20px;
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow: auto;
}
.obj-picker-box h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 22px; }
.obj-picker-field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.obj-picker-field span { display: block; margin-bottom: 4px; }
.obj-picker-field input, .obj-picker-field select {
  width: 100%; padding: 8px; border: 1px solid var(--panel-border);
  border-radius: 6px; font-size: 15px; color: var(--text);
}
.obj-picker-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Read-only object card on the Documents page */
#obj-card-body { padding: 16px; overflow-y: auto; }
#obj-card .obj-card-name { font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.obj-card-fields dt { font-size: 12px; color: var(--muted); margin-top: 6px; }
.obj-card-fields dd { margin: 0 0 4px; }
.obj-card-open { display: inline-block; margin-top: 12px; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: min(360px, 92vw);
  background: var(--panel); border-left: 1px solid var(--panel-border);
  box-shadow: -2px 0 12px rgba(0,0,0,0.15); overflow: auto; z-index: 1500; }
#modal-title, #obj-card-title { font-family: var(--serif); }

/* Search page */
#search { padding: calc(48px + 1rem) 1rem 1rem; max-width: 800px; margin: 0 auto; }
.search-label { display: block; font-size: 13px; color: var(--muted); }
.search-input { width: 100%; padding: 10px; margin-top: 4px; font-size: 16px;
  border: 1px solid var(--panel-border); border-radius: 6px; }
.search-hint { color: var(--muted); margin-top: 1rem; }
.search-results { margin-top: 1rem; }
.search-group-head { font-size: 14px; color: var(--text); margin: 1rem 0 0.4rem;
  border-bottom: 1px solid var(--panel-border); padding-bottom: 2px; }
.search-result { display: block; padding: 8px 10px; border: 1px solid var(--panel-border);
  border-radius: 6px; margin-bottom: 6px; text-decoration: none; color: var(--text); }
.search-result:hover { background: #efe7d4; border-color: var(--accent); }
.search-result-label { font-weight: 600; }
.search-result-snippet { font-size: 13px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Costs page */
#costs { padding: calc(48px + 1rem) 1rem 1rem; max-width: 900px; margin: 0 auto; }
.costs-summary { border: 1px solid var(--panel-border); border-radius: 8px; padding: 16px; margin: 1rem 0; background: var(--panel); }
.costs-grand { font-size: 28px; font-weight: 700; color: var(--accent-dark); }
.costs-split { color: var(--text); margin: 4px 0; }
.costs-subhead { font-weight: 600; margin-top: 10px; }
.costs-cat-row, .costs-month-row { font-size: 14px; color: var(--text); padding: 1px 0; }
.costs-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 1rem; }
.costs-filter select, .costs-filter input { padding: 8px; border: 1px solid var(--panel-border); border-radius: 6px; font-size: 14px; }
.costs-ledger { display: flex; flex-direction: column; gap: 6px; }
.costs-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid var(--panel-border); border-radius: 6px; padding: 8px 10px; background: var(--panel); }
.costs-row-date { color: var(--muted); font-size: 13px; min-width: 90px; }
.costs-tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #e7e0cc; color: var(--accent-dark); }
.costs-row-desc { flex: 1 1 auto; min-width: 120px; }
.costs-row-amount { font-weight: 600; }

/* Calendar page */
#calendar { padding: calc(48px + 1rem) 1rem 2rem; max-width: 720px; margin: 0 auto; }
.cal-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 1.25rem;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.cal-toolbar .btn-primary { margin-right: auto; }
.cal-owner-filter, .cal-window {
  padding: 8px 10px; border: 1px solid var(--panel-border);
  border-radius: 6px; font-size: 14px; background: #fff;
}
.cal-agenda { display: flex; flex-direction: column; gap: 4px; }
.cal-day-heading {
  margin: 1.25rem 0 0.5rem;
  font-family: var(--serif);
  font-size: 18px;
  color: var(--accent-dark);
  border-bottom: 2px solid var(--panel-border);
  padding-bottom: 4px;
}
.cal-agenda .cal-day-heading:first-child { margin-top: 0; }
.cal-day { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cal-row-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.cal-row-item.is-done { opacity: 0.6; border-left-color: var(--muted); }
.cal-row-item.is-done .cal-row-title { text-decoration: line-through; }
.cal-row-icon { font-size: 18px; line-height: 1; }
.cal-row-title { flex: 1 1 auto; min-width: 120px; font-weight: 600; font-size: 15px; }
.cal-row-owner {
  flex: 0 0 auto; font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: #e7e0cc; color: var(--accent-dark);
}
.cal-row-link { flex: 0 0 auto; color: var(--accent-dark); text-decoration: none; font-size: 13px; }
.cal-row-link:hover { text-decoration: underline; }
.cal-row-edit, .cal-row-del { flex: 0 0 auto; padding: 4px 10px; font-size: 13px; }

/* Calendar entry form popover */
.cal-form .cal-row { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.cal-form .cal-row input[type="text"],
.cal-form .cal-row input[type="date"],
.cal-form .cal-row input[type="number"],
.cal-form .cal-row select {
  padding: 8px; border: 1px solid var(--panel-border); border-radius: 6px;
  font-size: 15px; color: var(--text); margin-top: 4px;
}
.cal-form .cal-row input[type="text"], .cal-form .cal-row > select { width: 100%; box-sizing: border-box; }
.cal-form .cal-repeat { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-form .cal-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Drawings page */
#drawings { padding: calc(48px + 1rem) 1rem 1rem; max-width: 900px; margin: 0 auto; }
.draw-gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.draw-empty { color: var(--muted); }
.draw-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1rem; }
.draw-card { border: 1px solid var(--panel-border); border-radius: 8px; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.draw-card-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  margin-bottom: 8px;
  background: #efe7d4;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  overflow: hidden;
}
.draw-card-thumb svg { display: block; max-width: 100%; max-height: 100%; }
.draw-card-thumb-empty { font-size: 0.85em; }
.draw-card-name { font-weight: 600; }
.draw-card-meta { font-size: 0.85rem; color: var(--muted); }
.draw-chip { align-self: flex-start; font-size: 0.8rem; border: 1px solid var(--panel-border); border-radius: 999px; padding: 0.1rem 0.6rem; background: #efe7d4; cursor: pointer; }
.draw-card-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.draw-del { color: var(--danger); }

.draw-editor-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
.draw-editor-title { font-weight: 600; }
.draw-editor-host { position: relative; }
.draw-toolbar { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 0.5rem; }
.draw-tool { padding: 0.3rem 0.6rem; border: 1px solid var(--panel-border); background: var(--panel); border-radius: 6px; cursor: pointer; }
.draw-tool.active { background: var(--accent-dark); color: #fff; border-color: var(--accent-dark); }
.draw-surface { border: 1px solid var(--panel-border); background: var(--panel); touch-action: none; max-width: 100%; height: auto; }
.draw-grid-minor { stroke: #efe7d4; stroke-width: 1; }
.draw-grid-major { stroke: var(--panel-border); stroke-width: 1; }
.draw-selected { outline: none; stroke-dasharray: 4 3; }
.draw-overlay { pointer-events: none; }
.draw-handle { fill: #fff; stroke: var(--accent-dark); stroke-width: 1.5; pointer-events: all; cursor: pointer; }
.draw-handle-rotate { fill: var(--accent-dark); stroke: #fff; stroke-width: 1.5; cursor: crosshair; }
.draw-handle-stem { stroke: var(--accent-dark); stroke-width: 1; pointer-events: none; }
.draw-preview { opacity: 0.6; }
.draw-readout { position: absolute; right: 0.5rem; bottom: 0.5rem; background: rgba(0,0,0,0.7); color: #fff; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.85rem; pointer-events: none; }

/* Home hero band */
#home::before {
  content: "🌳  Welcome to your food forest";
  display: block;
  max-width: 900px;
  margin: 0 auto 20px;
  padding: 28px 24px;
  font-family: var(--serif);
  font-size: 28px;
  color: var(--accent-dark);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
}

/* Section-page header bands. The ::before is a flow child of the padded
   container, so it survives the JS `mount.innerHTML = ''` re-renders. */
.page-fauna #specieslist::before,
.page-flora #specieslist::before,
.page-journal #journal::before,
.page-documents #documents::before,
.page-drawings #drawings::before,
.page-calendar #calendar::before,
.page-costs #costs::before,
.page-search #search::before {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 96px;
  margin-bottom: 16px;
  padding: 0 20px;
  font-family: var(--serif);
  font-size: 26px;
  color: var(--accent-dark);
  background-color: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
}
.page-fauna #specieslist::before    { content: "🦔  Fauna"; }
.page-flora #specieslist::before     { content: "🌿  Flora"; }
.page-journal #journal::before       { content: "📔  Journal"; }
.page-documents #documents::before   { content: "📝  Documents"; }
.page-drawings #drawings::before      { content: "📐  Drawings"; }
.page-calendar #calendar::before      { content: "📅  Calendar"; }
.page-costs #costs::before            { content: "💷  Costs"; }
.page-search #search::before          { content: "🔍  Search"; }

/* Empty-state seedling art */
.empty-state, .draw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  padding: 32px 16px;
  text-align: center;
  font-size: 15px;
}
.empty-state::before, .draw-empty::before {
  content: "🌱";
  font-size: 48px;
  line-height: 1;
  opacity: 0.7;
}

/* Fauna sightings in the species drawer */
.sighting-list { list-style: none; padding: 0; margin: 0 0 12px; }
.sighting-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--panel-border); }
.sighting-date { font-size: 13px; color: var(--muted); min-width: 84px; }
.sighting-notes { flex: 1 1 auto; min-width: 0; font-size: 14px; }
.sighting-map { flex: 0 0 auto; color: var(--accent-dark); text-decoration: none; font-size: 13px; }
.sighting-map:hover { text-decoration: underline; }
.sighting-del { flex: 0 0 auto; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; }
.sighting-add label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.sighting-add input, .sighting-add textarea { width: 100%; padding: 8px; margin-top: 4px;
  border: 1px solid var(--panel-border); border-radius: 6px; font-size: 15px; }
.sighting-add textarea { resize: vertical; min-height: 48px; }

@media (max-width: 640px) {
  .modal-card {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .obj-picker { top: 0; left: 0; transform: none; width: 100vw; height: 100vh; }
  .obj-picker-box { width: 100vw; max-height: 100vh; border-radius: 0; border: none; }
  /* Shrink header bands so the SVG + title stay legible */
  .page-fauna #specieslist::before,
  .page-flora #specieslist::before,
  .page-journal #journal::before,
  .page-documents #documents::before,
  .page-drawings #drawings::before,
  .page-calendar #calendar::before,
  .page-costs #costs::before,
  .page-search #search::before {
    height: 68px;
    font-size: 20px;
  }
  #home::before { font-size: 22px; padding: 20px 16px; }
}
