/* Phone-first. No browser chrome is assumed: the app draws its own top bar and
   bottom tabs, and everything is reachable with a thumb. */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --line: #e0ded4;
  --line-strong: #cfccbe;
  --text: #22251f;
  --muted: #6b6f66;
  --accent: #2f6d4f;
  --accent-soft: #e4efe7;
  --over: #8a5a12;
  --over-soft: #f7ecd8;
  --radius: 12px;
  --tap: 44px;
  --pad: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f24;
    --surface-2: #23272d;
    --line: #2e333a;
    --line-strong: #3d434b;
    --text: #e8eae6;
    --muted: #9aa196;
    --accent: #7cc39a;
    --accent-soft: #1f2f27;
    --over: #e0b169;
    --over-soft: #322a1c;
  }
}

* { box-sizing: border-box; }

/* A class that sets display must not defeat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 19px; }
h2 { font-size: 15px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: inherit; }

.muted { color: var(--muted); font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }

/* ---------- frame ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title p { margin-top: 1px; }

.view {
  padding: var(--pad) var(--pad) 96px;
  max-width: 780px;
  margin: 0 auto;
  outline: none;
}

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tap); font-size: 13px; text-decoration: none;
  color: var(--muted); font-weight: 500;
}
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }

.connection {
  padding: 8px var(--pad);
  background: var(--over-soft); color: var(--over);
  font-size: 13px; text-align: center;
  border-bottom: 1px solid var(--line);
}

/* ---------- building blocks ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.card + .card { margin-top: 8px; }

.section { margin-bottom: 22px; }
.section-head {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 8px;
}
.section-head h2 { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500;
  text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #10231a; } }
.btn-small { min-height: 30px; padding: 0 9px; font-size: 13px; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 32px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 12.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
  font-weight: 600;
}

.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  white-space: nowrap;
}
.tag-over { background: var(--over-soft); color: var(--over); }
.tag-due { background: var(--accent-soft); color: var(--accent); }
.tag-prov { background: var(--over-soft); color: var(--over); }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.field .muted { font-weight: 400; margin-bottom: 6px; }

input[type="text"], input[type="search"], input[type="number"], input[type="date"],
input[type="time"], input[type="password"], textarea, select {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px;
}
textarea { min-height: 74px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.switch { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

details.why { margin-top: 8px; }
details.why > summary {
  cursor: pointer; font-size: 13px; color: var(--accent); font-weight: 600;
  list-style: none; min-height: 28px; display: flex; align-items: center;
}
details.why > summary::-webkit-details-marker { display: none; }
details.why > summary::after { content: "\00a0▾"; }
details.why[open] > summary::after { content: "\00a0▴"; }
.why-body {
  margin-top: 8px; padding: 10px;
  background: var(--surface-2); border-radius: 9px; font-size: 13px;
}
.why-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.why-row + .why-row { border-top: 1px solid var(--line); }

/* ---------- plant rows ---------- */

.plant-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.plant-row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.plant-row:last-child { border-bottom: 0; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list.compact .plant-row { padding: 7px 12px; }
.list.compact .thumb { width: 30px; height: 30px; }
.list.compact .row-fields { font-size: 12px; }

.thumb {
  width: 42px; height: 42px; border-radius: 8px; flex: none;
  object-fit: cover; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 16px;
}
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-title a { text-decoration: none; font-weight: 600; }
.row-fields {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  color: var(--muted); font-size: 12.5px; margin-top: 2px;
}
.row-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.row-check { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin-top: 11px; }

/* ---------- layer (side/bottom panel) ---------- */

.layer {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.42);
  display: flex; align-items: flex-end; justify-content: center;
}
.layer-panel {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 16px var(--pad) calc(20px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  animation: rise 0.16s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0.6; } }
.layer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.layer-head h2 { flex: 1; font-size: 17px; }
@media (min-width: 720px) {
  .layer { align-items: center; }
  .layer-panel { border-radius: 16px; max-height: 82vh; }
}

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

.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom));
  z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; padding: 0 var(--pad);
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 9px 13px; border-radius: 10px; font-size: 13.5px;
  max-width: 520px; box-shadow: 0 6px 20px rgba(0,0,0,0.22);
  pointer-events: auto; display: flex; gap: 10px; align-items: center;
}
.toast button { background: none; border: 0; color: var(--bg); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.toast-warn { background: var(--over); color: #fff; }

/* ---------- misc ---------- */

.summary-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; background: var(--over-soft);
  border: 1px solid color-mix(in srgb, var(--over) 30%, transparent);
  border-radius: var(--radius);
}
.summary-row .strong { color: var(--over); }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.toolbar .grow { flex: 1; min-width: 150px; }

.photostrip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.photostrip img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; flex: none; background: var(--surface-2); }

.timeline { position: relative; }
.tl-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.tl-item:last-child { border-bottom: 0; }
.tl-when { flex: none; width: 96px; color: var(--muted); font-size: 12px; padding-top: 1px; }
.tl-what { flex: 1; min-width: 0; font-size: 14px; }
.tl-month { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 14px 0 2px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.intro { border-left: 3px solid var(--accent); }
.intro li { margin-bottom: 6px; }
.intro ul { margin: 8px 0; padding-left: 18px; }

.group-head {
  display: flex; align-items: baseline; gap: 8px;
  margin: 16px 0 6px; font-size: 13px; font-weight: 700; color: var(--muted);
}

.spinner { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }
