/* Plants — dark only. */
:root {
  color-scheme: dark;
  --bg: #0b140f;
  --surface: #131f18;
  --surface-2: #1b2a21;
  --line: #26372d;
  --text: #e3ebe4;
  --muted: #8c9f92;
  --sage: #9cb68f;
  --sage-strong: #b4cca7;
  --on-sage: #0f1f17;
  --water: #7cc0e0;
  --danger: #e58a7c;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* The page never scrolls sideways (e.g. when a dragged tile goes past the screen edge).
   Also stops Sortable's auto-scroll from scrolling horizontally. `clip`, unlike `hidden`,
   doesn't make html a scroll container; `hidden` is the fallback for older Safari. */
html { overflow-x: hidden; overflow-x: clip; }
body {
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  font-size: 16px;
  line-height: 1.4;
}
body.no-scroll { overflow: hidden; }
a { color: var(--sage); text-decoration: none; }
h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 17px; }
p { margin: 0 0 8px; }
code { font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.italic { font-style: italic; }
.ico { width: 22px; height: 22px; flex: none; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  background: rgba(11, 20, 15, 0.92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.topbar-title { font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; justify-content: flex-end; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  border: 0; background: none; color: var(--text); border-radius: 12px; padding: 0; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small .ico { width: 16px; height: 16px; }

.page { padding: 12px 16px calc(var(--safe-bottom) + 32px); }

/* ---- buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer;
}
.btn:active { filter: brightness(1.2); }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--sage); border-color: var(--sage); color: var(--on-sage); }
.btn-danger { color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-small .ico { width: 16px; height: 16px; }
.btn-water { background: transparent; border-color: var(--water); color: var(--water); }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn-row .btn { flex: 1; }
.link { background: none; border: 0; padding: 8px 0; color: var(--sage); font: inherit; cursor: pointer; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.form .req { font-size: 12px; opacity: 0.7; }
input, textarea, select {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--sage); outline-offset: -1px; }
textarea { resize: vertical; }
input[type="date"], input[type="datetime-local"] { min-height: 46px; -webkit-appearance: none; appearance: none; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 16px; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--sage); flex: none; margin: 0; }
.form-error { color: var(--danger); min-height: 1.4em; }
fieldset.card { border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
legend { padding: 0 6px; font-weight: 600; }

.card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; }
.section { margin: 22px 0; }
.section h2 { margin-bottom: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.empty { text-align: center; padding: 64px 24px; color: var(--text); }
.empty .ico { width: 40px; height: 40px; color: var(--sage); margin-bottom: 8px; }

/* ---- hub ---- */
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px;
  padding: 8px 16px calc(var(--safe-bottom) + 96px);
}
.tile, .tile *, .cover, .photo-cell, .water-btn {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.tile-photo {
  aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--surface-2);
  cursor: pointer; touch-action: manipulation;
}
.tile-photo img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--sage); background: var(--surface-2); }
.placeholder .ico { width: 36px; height: 36px; opacity: 0.6; }
.tile-name { margin-top: 6px; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-row { display: flex; align-items: center; justify-content: space-between; margin-top: -2px; }
.tile-days { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.water-btn {
  width: 44px; height: 40px; margin-right: -8px; border: 0; background: none; color: var(--water);
  display: grid; place-items: center; border-radius: 12px; cursor: pointer; touch-action: manipulation;
  transition: transform 0.12s;
}
.water-btn.pressing { transform: scale(0.88); background: var(--surface-2); }
.water-btn.splash .ico { animation: splash 0.5s ease-out; }
@keyframes splash { 0% { transform: scale(1); } 40% { transform: scale(1.35); fill: var(--water); } 100% { transform: scale(1); } }
.btn-water.water-btn { display: inline-flex; width: auto; height: auto; min-height: 46px; margin: 0; border: 1px solid var(--water); white-space: nowrap; }

.tile-chosen .tile-photo { transform: scale(1.04); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); transition: transform 0.15s; }
.tile-ghost { opacity: 0.35; }
.tile-drag { opacity: 0.95; }

.fab {
  position: fixed; right: 20px; bottom: calc(var(--safe-bottom) + 20px); z-index: 20;
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: var(--sage); color: var(--on-sage); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.fab .ico { width: 28px; height: 28px; }

/* ---- sheets ---- */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); opacity: 0; transition: opacity 0.2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(var(--safe-bottom) + 16px);
  transform: translateY(100%); transition: transform 0.22s ease-out;
  display: flex; flex-direction: column; gap: 10px;
}
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet h2 { font-size: 18px; }
.sheet-msg { font-size: 16px; line-height: 1.5; }
.sheet-list { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 12px; overflow: hidden; }
.sheet-item {
  display: flex; align-items: center; gap: 12px; padding: 14px; border: 0; background: none;
  color: var(--text); font: inherit; text-align: left; border-bottom: 1px solid var(--line); cursor: pointer;
}
.sheet-item:last-child { border-bottom: 0; }
.sheet-item:active { background: var(--line); }
.sheet-img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; }
.upload-row { display: flex; gap: 12px; align-items: center; }
.upload-row img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; flex: none; }
.upload-row label { flex: 1; }
.slot-preview { display: flex; align-items: center; gap: 12px; }
.slot-preview img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 90px); z-index: 200;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 8px 12px 16px; border-radius: 12px; background: #e3ebe4; color: #0f1f17;
  font-weight: 550; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: none; pointer-events: auto; }
#toast button { border: 0; background: none; color: #2f6b3a; font: inherit; font-weight: 700; padding: 6px 10px; cursor: pointer; }

/* ---- profile ---- */
.cover { position: relative; aspect-ratio: 1; background: var(--surface-2); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.cover .placeholder { cursor: pointer; }
.cover .placeholder .ico { width: 64px; height: 64px; }
.cam-btn {
  position: absolute; right: 14px; bottom: 14px; width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: rgba(11, 20, 15, 0.75); color: var(--text); display: grid; place-items: center; cursor: pointer;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.plant-title { font-size: 26px; margin-top: 4px; }
.species { font-size: 17px; margin-top: 2px; }
.latin { font-style: italic; color: var(--muted); margin-top: 2px; }
.notes { white-space: pre-wrap; margin: 16px 0; padding: 12px 14px; background: var(--surface); border-radius: var(--radius); cursor: text; min-height: 46px; }
.notes textarea { margin-bottom: 4px; }
.banner { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted); margin-bottom: 12px; }
.banner .ico { width: 18px; height: 18px; }

.water-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.water-days { font-size: 20px; font-weight: 650; }
.water-log summary { cursor: pointer; color: var(--muted); padding: 8px 0 4px; }
.water-log ul { list-style: none; margin: 0; padding: 0; }
.water-log li { display: flex; justify-content: space-between; align-items: center; padding: 2px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }

.chart { margin: 14px 0 4px; }
.chart svg { width: 100%; height: auto; display: block; margin-top: 6px; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .dot { fill: var(--sage); stroke: var(--surface); stroke-width: 2; }
.chart .dot.active { fill: var(--sage-strong); r: 6; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart-readout { min-height: 1.4em; margin-top: 4px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.event { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.event.inherited { opacity: 0.55; cursor: default; }
.ev-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); color: var(--sage); display: grid; place-items: center; flex: none; }
.ev-icon .ico { width: 17px; height: 17px; }
.ev-body { flex: 1; min-width: 0; }
.ev-head { display: flex; justify-content: space-between; gap: 8px; }
.ev-desc { white-space: pre-wrap; margin-top: 2px; }
.ev-from { font-size: 12px; color: var(--muted); font-style: italic; }
.ev-photo { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }

.lineage { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.chip-muted { color: var(--muted); }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 28px; }

/* ---- photo timeline & viewer ---- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-cell { border: 0; padding: 0; background: none; color: var(--text); text-align: left; cursor: pointer; font: inherit; }
.photo-cell img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; pointer-events: none; }
.photo-cell.inherited { opacity: 0.5; }
.photo-date { display: block; font-size: 12px; color: var(--muted); padding: 3px 2px 6px; }

.viewer { position: fixed; inset: 0; z-index: 150; background: #000; }
.viewer-track { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.viewer-track::-webkit-scrollbar { display: none; }
.viewer-slide { flex: 0 0 100%; height: 100%; margin: 0; scroll-snap-align: center; display: flex; flex-direction: column; justify-content: center; }
.viewer-slide img { width: 100%; max-height: calc(100% - 140px); object-fit: contain; }
.viewer-slide figcaption { padding: 12px 16px calc(var(--safe-bottom) + 12px); display: flex; flex-direction: column; gap: 4px; }
.viewer-actions { display: flex; gap: 4px; margin-left: -10px; }
.viewer-close { position: absolute; top: calc(var(--safe-top) + 8px); right: 8px; background: rgba(0, 0, 0, 0.5); border-radius: 50%; }

/* ---- lists ---- */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); }
.row img, .pick img, .pick-ph { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; }
.pick-ph { display: grid; place-items: center; background: var(--surface-2); color: var(--sage); }
.row-main { display: flex; flex-direction: column; }
.pick-list { display: flex; flex-direction: column; gap: 2px; }
.form label.pick { flex-direction: row; align-items: center; gap: 12px; color: var(--text); font-size: 16px; padding: 6px 0; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 28px; margin: 18px 0 26px; font-size: 30px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stepper .btn { width: 56px; font-size: 24px; }

/* ---- login ---- */
.login { max-width: 380px; margin: 0 auto; padding: calc(var(--safe-top) + 72px) 24px 24px; text-align: center; }
.login-logo { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 18px; background: #0f1f17; color: var(--sage); display: grid; place-items: center; border: 1px solid var(--line); }
.login-logo .ico { width: 40px; height: 40px; }
.login h1 { margin-bottom: 28px; }
.login .form { text-align: left; }
