/* ── Design tokens ──────────────────────────────────────────────────
   Light theme by default; dark when the system prefers it (unless the user
   forced light), or when the user forces dark via the theme button. */
:root {
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-2: #eef3ec;
  --text: #1c2a21;
  --muted: #5d6f63;
  --border: #dbe5d8;
  --accent: #2f7a4f;
  --accent-text: #ffffff;
  --accent-soft: #dcefe2;
  --late: #b93a32;
  --late-soft: #fbe3e0;
  --today: #a35c00;
  --today-soft: #fdecd0;
  --soon: #2b6cb0;
  --soon-soft: #dde9f7;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 14px rgb(0 0 0 / .06);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101814;
    --surface: #18231d;
    --surface-2: #213028;
    --text: #e4ede6;
    --muted: #93a79a;
    --border: #2b3b32;
    --accent: #5cc48a;
    --accent-text: #0c1a12;
    --accent-soft: #1f3a2b;
    --late: #ff8a80;
    --late-soft: #3d1f1d;
    --today: #ffb85c;
    --today-soft: #3a2c16;
    --soon: #8ab8f0;
    --soon-soft: #1c2b3d;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #101814;
  --surface: #18231d;
  --surface-2: #213028;
  --text: #e4ede6;
  --muted: #93a79a;
  --border: #2b3b32;
  --accent: #5cc48a;
  --accent-text: #0c1a12;
  --accent-soft: #1f3a2b;
  --late: #ff8a80;
  --late-soft: #3d1f1d;
  --today: #ffb85c;
  --today-soft: #3a2c16;
  --soon: #8ab8f0;
  --soon-soft: #1c2b3d;
  --shadow: 0 1px 2px rgb(0 0 0 / .3);
  color-scheme: dark;
}

/* ── Base ───────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: .4em 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ── Top bar ────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 640px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg); /* fallback for browsers without color-mix */
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.35rem; letter-spacing: -.01em; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn, .icon-btn {
  font: inherit; cursor: pointer; border: 1px solid transparent;
  border-radius: 999px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s ease, background .15s ease;
}
.btn { padding: 8px 16px; font-weight: 600; white-space: nowrap; }
.btn:active, .icon-btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--accent-soft); color: var(--text); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--late); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: progress; }
.icon-btn {
  width: 44px; background: var(--surface-2); color: var(--text); font-size: 1.1rem;
}
.link {
  background: none; border: 0; padding: 0; font: inherit; font-size: .875rem;
  color: var(--accent); text-decoration: underline; cursor: pointer;
}

.fab {
  position: fixed; z-index: 10;
  right: max(16px, calc(50% - 304px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 14px 22px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font: 600 1rem system-ui, sans-serif; box-shadow: 0 6px 20px rgb(0 0 0 / .2);
  cursor: pointer;
}

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.tip { padding: 12px 16px; margin: 4px 0 16px; }
.tip summary { cursor: pointer; font-weight: 600; }
.tip ul { padding-left: 1.2em; margin: .5em 0; }

/* ── Plant list ─────────────────────────────────────────────────── */
.plant-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.plant { padding: 12px; }
.plant-main { display: flex; gap: 12px; }
.thumb {
  flex: none; width: 72px; height: 72px; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-fallback { font-size: 2rem; }
.plant-info { min-width: 0; flex: 1; }
.plant-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.plant-title { font-size: 1.05rem; overflow-wrap: anywhere; }
.plant-sub { margin: 2px 0 0; font-style: italic; }
.plant-meta { margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.chip { white-space: nowrap; }
.chip.toxic { color: var(--late); font-weight: 600; }

.badge {
  flex: none; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.late { background: var(--late-soft); color: var(--late); }
.badge.today { background: var(--today-soft); color: var(--today); }
.badge.soon { background: var(--soon-soft); color: var(--soon); }

.plant-tip { margin: 8px 0 0; }
.plant-tip summary { cursor: pointer; color: var(--muted); }
.plant-tip p { margin: 4px 0 0; }

.actions, .confirm { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.actions .btn { flex: 1; padding-inline: 8px; font-size: .95rem; }
.confirm { background: var(--late-soft); border-radius: 12px; padding: 8px; flex-wrap: wrap; }
.confirm-text { flex: 1 1 100%; font-weight: 600; padding: 0 4px; }
.confirm .btn { flex: 1; }

.empty { text-align: center; padding: 48px 16px; }
.empty-art { font-size: 3.5rem; }

.backup { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 28px; }
.footnote { text-align: center; font-size: .8rem; }

/* ── Add-plant sheet ────────────────────────────────────────────── */
dialog {
  width: 100%; max-width: 560px;
  height: 100vh; max-height: 100vh; /* fallback for older iOS */
  height: 100dvh; max-height: 100dvh;
  margin: 0 auto; padding: 0; border: 0;
  background: var(--surface); color: var(--text);
}
@media (min-width: 600px) {
  dialog { height: auto; max-height: 92dvh; margin: auto; border-radius: 20px; }
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { display: flex; flex-direction: column; height: 100%; max-height: inherit; }
.sheet-head, .sheet-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-color: var(--border);
}
.sheet-head { border-bottom: 1px solid var(--border); padding-top: calc(12px + env(safe-area-inset-top)); }
.sheet-foot { border-top: 1px solid var(--border); padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.sheet-foot .btn { flex: 1; }
.sheet-body { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; flex: 1; }
.sheet-body > * { flex-shrink: 0; }

.photo-picker {
  display: grid; place-items: center; aspect-ratio: 4 / 3; max-height: 260px; width: 100%;
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface-2); overflow: hidden; cursor: pointer;
}
.photo-picker img { width: 100%; height: 100%; object-fit: cover; }
.photo-buttons { display: flex; gap: 8px; margin-top: -8px; }
.photo-buttons .btn { flex: 1; }
.photo-buttons:has(+ input:focus-visible) label:first-child,
.photo-buttons:has(~ #library-input:focus-visible) label:last-child { outline: 3px solid var(--accent); }
.photo-placeholder { display: grid; justify-items: center; gap: 4px; color: var(--muted); font-weight: 600; }
.photo-placeholder .big { font-size: 2.5rem; }

.status { margin: 0; font-size: .9rem; color: var(--muted); }
.status:empty { display: none; }
.status.error { color: var(--late); }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .field > span { font-weight: 600; font-size: .9rem; margin-bottom: 6px; padding: 0; }
.field { display: grid; gap: 4px; }
input[type="text"], input[type="date"], input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%;
}

.matches #match-list { display: grid; gap: 8px; }
.match {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer; background: var(--surface-2);
}
.match:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.match input { accent-color: var(--accent); width: 20px; height: 20px; }
.match .name { flex: 1; min-width: 0; }
.match .name em { display: block; font-size: .85rem; color: var(--muted); }
.match .pct { font-weight: 700; font-variant-numeric: tabular-nums; }

.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; text-align: center; padding: 8px 4px; border-radius: 9px; cursor: pointer;
  font-weight: 600; font-size: .92rem; color: var(--muted);
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); }

.schedule-box { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; }
.care-match { margin: 0; font-weight: 600; }
.interval-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-weight: 600; }
.interval-row input { width: 5em; text-align: center; font-weight: 700; }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(88px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow);
}
