/* ---------------------------------------------------------------
   Canopy — design tokens
   A field-guide / herbarium-label aesthetic: moss greens, a warm
   paper panel tone (kept off the generic cream/terracotta pairing),
   an ochre accent used only for the specimen-tag markers, serif
   display type for plant names, mono for data (dates, yields).
------------------------------------------------------------------ */
:root {
  --moss-900: #1c2a1f;
  --moss-800: #223528;
  --moss-700: #35533b;
  --moss-600: #46704d;
  --moss-500: #5c8a63;

  --paper-100: #efe9d8;
  --paper-200: #e6e0cc;
  --paper-300: #d9d2b8;

  --ink-900: #1d2118;
  --ink-600: #4c5245;
  --ink-400: #7c8271;

  --ochre-600: #a9761f;
  --ochre-500: #c08b2c;

  --danger-600: #8f3a24;
  --danger-700: #7a2f1c;

  --line: #cdc5a6;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 18px;

  --shadow-1: 0 1px 3px rgba(28, 42, 31, 0.18), 0 1px 2px rgba(28, 42, 31, 0.1);
  --shadow-2: 0 8px 24px rgba(28, 42, 31, 0.28);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--ink-900);
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------------- Top bar ---------------- */
.topbar {
  position: relative;
  z-index: 1030;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 10px 10px;
  background: var(--moss-900);
  color: var(--paper-100);
  box-shadow: var(--shadow-1);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand-mark { font-size: 18px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.01em;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(239, 233, 216, 0.12); }
.icon-btn.small { width: 32px; height: 32px; }

/* ---------------- Map ---------------- */
#map {
  flex: 1;
  min-height: 0;
  background: var(--paper-200);
}

/* Leaflet marker: specimen tag */
.plant-tag {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px 999px 999px 3px;
  transform: rotate(-45deg);
  background: var(--moss-600);
  border: 2px solid var(--paper-100);
  box-shadow: var(--shadow-1);
}
.plant-tag .plant-tag-glyph {
  transform: rotate(45deg);
  font-size: 14px;
  line-height: 1;
}
.plant-tag.is-selected { background: var(--ochre-500); }

.corner-handle {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--ochre-500);
  border: 3px solid var(--paper-100);
  box-shadow: var(--shadow-1);
}

/* Popup styled like a herbarium index card */
.leaflet-popup-content-wrapper {
  background: var(--paper-100);
  color: var(--ink-900);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}
.leaflet-popup-tip { background: var(--paper-100); }
.plant-card { font-family: var(--font-body); min-width: 200px; }
.plant-card .eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-400);
}
.plant-card h3 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
}
.plant-card .sci {
  font-style: italic;
  color: var(--ink-600);
  font-size: 13px;
  margin: 2px 0 8px;
}
.plant-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  margin: 0 0 8px;
  font-size: 12.5px;
}
.plant-card dt {
  font-family: var(--font-mono);
  color: var(--ink-400);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.04em;
}
.plant-card dd { margin: 0; }
.plant-card .notes {
  font-size: 12.5px;
  color: var(--ink-600);
  margin: 0 0 8px;
  white-space: pre-wrap;
}
.plant-card .links {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
}
.plant-card .links a { color: var(--moss-700); }
.plant-card .card-actions {
  display: flex;
  gap: 8px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

/* ---------------- FAB ---------------- */
.fab {
  position: absolute;
  right: 16px;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 1025;
  width: 58px;
  height: 58px;
  border-radius: 999px;
  border: none;
  background: var(--moss-700);
  color: var(--paper-100);
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fab:active { background: var(--moss-800); }
.fab.is-active { background: var(--ochre-500); color: var(--moss-900); }

/* ---------------- Add-mode hint ---------------- */
.add-hint {
  position: absolute;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1026;
  background: var(--moss-900);
  color: var(--paper-100);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  max-width: calc(100vw - 32px);
}

/* ---------------- Panels (layers) ---------------- */
.panel {
  position: absolute;
  z-index: 1028;
  background: var(--paper-100);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  width: min(320px, calc(100vw - 24px));
}
.panel-top-right { top: calc(64px + var(--safe-top)); right: 12px; }
.panel-header, .drawer-header, .sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-header h2, .drawer-header h2, .sheet-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0;
}
.panel-body { padding: 12px 16px 16px; }

.layer-row { padding: 6px 0; }
.layer-sub { padding: 4px 0 10px 0; }
.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-400);
  margin-bottom: 4px;
}
.divider { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.hint-text { font-size: 12px; color: var(--ink-400); margin: 6px 0 0; min-height: 14px; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}
.switch input { width: 20px; height: 20px; accent-color: var(--moss-700); }

/* ---------------- Alignment toolbar ---------------- */
.align-toolbar {
  position: absolute;
  z-index: 1027;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--moss-900);
  color: var(--paper-100);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  width: min(360px, calc(100vw - 24px));
}
.align-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------------- Buttons ---------------- */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary { background: var(--moss-700); color: var(--paper-100); }
.btn-primary:active { background: var(--moss-800); }
.btn-secondary { background: var(--paper-200); color: var(--ink-900); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--ink-900); }
.btn-danger-ghost { background: transparent; color: var(--danger-600); }
.btn-block { width: 100%; }
.btn-small { padding: 7px 12px; font-size: 13px; }
.link-btn {
  background: none;
  border: none;
  color: var(--paper-100);
  text-decoration: underline;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

/* ---------------- Drawer (catalog, slides from left) ---------------- */
.drawer {
  position: absolute;
  z-index: 1040;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(360px, 88vw);
  background: var(--paper-100);
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  padding-top: var(--safe-top);
}
.drawer:not(.hidden) { transform: translateX(0); }
.drawer.hidden { display: flex; visibility: hidden; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
.drawer-footer { padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); }

.search-row { padding: 4px 0 12px; }
.search-row input[type="search"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 14px;
}

.catalog-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.catalog-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.catalog-item .swatch {
  width: 30px; height: 30px; border-radius: 999px 999px 999px 3px;
  background: var(--moss-600); flex-shrink: 0; transform: rotate(-45deg);
}
.catalog-item .meta { min-width: 0; flex: 1; }
.catalog-item .name { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.catalog-item .sub {
  font-size: 12px; color: var(--ink-600); font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.catalog-item .chev { color: var(--ink-400); flex-shrink: 0; }
.catalog-item.editable { cursor: default; }
.catalog-item .edit-btn {
  border: none; background: var(--paper-200); border-radius: 999px;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
}

.empty-state { color: var(--ink-400); font-size: 13.5px; text-align: center; padding: 24px 8px; }
.empty-state.hidden { display: none; }

/* ---------------- Bottom sheets ---------------- */
.sheet {
  position: absolute;
  z-index: 1045;
  left: 0; right: 0; bottom: 0;
  max-height: 82vh;
  background: var(--paper-100);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-2);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.22s ease;
  padding-bottom: var(--safe-bottom);
}
.sheet:not(.hidden) { transform: translateY(0); }
.sheet.hidden { display: flex; visibility: hidden; }
.sheet-grabber {
  width: 36px; height: 4px; border-radius: 999px;
  background: var(--line); margin: 10px auto 0;
}
.sheet .search-row { padding: 12px 16px 8px; }
.sheet .catalog-list { padding: 0 16px 16px; overflow-y: auto; }
.sheet .empty-state { padding: 8px 16px 20px; }

.link-btn.dark { color: var(--moss-700); }

.planting-species-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--paper-200);
  border-bottom: 1px solid var(--line);
}
.planting-species-banner .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}
.planting-species-banner .sci {
  font-style: italic;
  font-size: 12.5px;
  color: var(--ink-600);
}
#planting-reuse-hint {
  padding: 0;
  margin: 0 0 12px;
}
#planting-reuse-hint:empty { display: none; }

/* ---------------- Form ---------------- */
.form { padding: 14px 16px calc(16px + var(--safe-bottom)); overflow-y: auto; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; }
.field span { font-weight: 600; color: var(--ink-600); font-size: 12.5px; }
.field input, .field textarea {
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 15px;
  width: 100%;
}
.field textarea { resize: vertical; font-family: var(--font-body); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.form-actions-right { display: flex; gap: 8px; }

/* ---------------- Scrim ---------------- */
.scrim {
  position: absolute;
  inset: 0;
  z-index: 1035;
  background: rgba(28, 42, 31, 0.4);
  opacity: 1;
  transition: opacity 0.2s ease;
}
.scrim.hidden { display: none; }

/* ---------------- Toast ---------------- */
.toast {
  position: absolute;
  z-index: 1060;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink-900);
  color: var(--paper-100);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  box-shadow: var(--shadow-2);
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.hidden { display: none; }

.hidden { display: none !important; }

/* ---------------- Small screens polish ---------------- */
@media (max-width: 380px) {
  .brand-name { font-size: 18px; }
  .fab { width: 52px; height: 52px; right: 12px; }
}

/* ---------------- Larger screens: keep it mobile-first but not cramped ---------------- */
@media (min-width: 720px) {
  .drawer { width: 380px; }
  .sheet { left: auto; right: 16px; bottom: 16px; width: 380px; border-radius: var(--radius-lg); max-height: 70vh; }
}
