:root {
  --bg: #eef4f0;
  --surface: #ffffff;
  --ink: #1c3326;
  --muted: #5b6f63;
  --line: #d3dfd8;
  --water: #1b7f8c;
  --water-soft: #d7ecef;
  --water-ink: #0f5a63;
  --alarm: #c4491e;
  --alarm-soft: #f9e2d9;
  --ok: #2e8b57;
  --ok-soft: #dcefe3;
  --warn: #b7791f;
  --warn-soft: #f7ecd6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 51, 38, .06), 0 6px 20px rgba(28, 51, 38, .06);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  padding-left: var(--sal);
  padding-right: var(--sar);
  min-height: 100dvh;
}

:focus-visible { outline: 3px solid var(--water); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--sat)) 16px 10px;
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.brand { font-size: 22px; font-weight: 600; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.brand b { color: var(--water); font-weight: 700; }
.topbar-actions { display: flex; gap: 4px; }

/* buttons */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 14px; background: var(--surface); color: var(--ink);
  cursor: pointer; min-height: 44px; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--water); color: #fff; font-weight: 600; }
.btn-primary:not(:disabled):hover { background: var(--water-ink); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: rgba(28, 51, 38, .06); }
.btn-ghost[aria-pressed="true"] { color: var(--water-ink); background: var(--water-soft); }
.btn-danger { color: var(--alarm); background: transparent; border-color: var(--alarm-soft); }
.btn-danger:hover { background: var(--alarm-soft); }
.btn-water { background: var(--water-soft); color: var(--water-ink); font-weight: 600; align-self: center; flex-shrink: 0; }
.btn-water:hover { background: var(--water); color: #fff; }
.btn-block { width: 100%; }

/* views */
.view { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(96px + var(--sab)); }

.login { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 15vh auto 0; }
.login h1 { font-size: 22px; margin: 0 0 8px; font-weight: 600; }
.login input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }

.ios-hint, .empty {
  margin: 8px 0 16px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-size: 14px;
}
.empty { text-align: center; }

/* plant list */
.plants { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.plant {
  display: flex; gap: 8px; padding: 10px 10px 10px 10px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.plant.is-overdue { box-shadow: var(--shadow), inset 3px 0 0 var(--alarm); }
.plant-main {
  flex: 1; display: flex; gap: 12px; align-items: center; min-width: 0;
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer; border-radius: 10px;
}
.thumb {
  flex-shrink: 0; width: 64px; height: 64px; border-radius: 12px; overflow: hidden;
  background: var(--water-soft);
  display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb:not(.has-photo) img { display: none; }
.thumb:not(.has-photo)::after { content: "🌿"; font-size: 26px; }
.plant-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.plant-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plant-species { font-style: italic; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plant-species:empty { display: none; }
.plant-meta { font-size: 14px; color: var(--muted); }
.is-overdue .plant-meta, .is-today .plant-meta { color: var(--alarm); font-weight: 600; }

/* moisture bar — the signature element */
.bar {
  display: block; height: 8px; border-radius: 999px; background: var(--water-soft); overflow: hidden; margin-top: 3px;
}
.bar-fill {
  display: block; height: 100%; width: 0; border-radius: 999px; background: var(--water);
  transition: width .6s cubic-bezier(.2, .7, .2, 1), background-color .3s;
}
.bar-fill.low { background: var(--alarm); }
.bar.unknown { background: repeating-linear-gradient(90deg, var(--line) 0 6px, transparent 6px 12px); }

/* floating add button */
.fab-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; justify-content: center;
  padding: 12px 16px calc(12px + var(--sab));
  pointer-events: none;
}
.fab { pointer-events: auto; box-shadow: 0 8px 24px rgba(15, 90, 99, .35); padding: 12px 22px; border-radius: 999px; }

/* bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(28, 51, 38, .35); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: calc(100dvh - 24px - var(--sat));
  margin: 0 auto; max-width: 640px;
  background: var(--surface); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 32px rgba(28, 51, 38, .18);
  padding-bottom: var(--sab);
  transform: translateY(0);
  transition: transform .25s ease-out;
}
.sheet[hidden] { transform: translateY(100%); }
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 4px 20px; }
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 4px 20px 20px; -webkit-overflow-scrolling: touch; }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .label { font-size: 14px; color: var(--muted); }
.field input[type="text"], .field input[type="date"], .field select, .field textarea {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); width: 100%; min-height: 44px;
}
.field textarea { resize: vertical; min-height: 72px; }
.field input[type="range"] { width: 100%; accent-color: var(--water); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--water); }
.range-value { font-weight: 600; }
.hint { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }

.preview {
  padding: 14px 16px; border-radius: var(--radius); background: var(--water-soft); color: var(--water-ink); margin-bottom: 16px;
}
.preview strong { font-size: 24px; font-weight: 600; display: block; line-height: 1.1; }
.preview .note { color: var(--ink); font-size: 14px; margin-top: 8px; }
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: rgba(255, 255, 255, .7); color: var(--water-ink); margin-top: 6px;
}
.chip.level-universal { background: var(--alarm-soft); color: var(--alarm); }

.species-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.species-head .thumb { width: 56px; height: 56px; }
.species-head .sci { font-style: italic; }
.species-head .com { color: var(--muted); font-size: 14px; }

.identify { display: flex; flex-direction: column; gap: 12px; }
.photo-pick { position: relative; }
.photo-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.photo-pick .btn { width: 100%; }
.photo-preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius); }
.status { color: var(--muted); font-size: 14px; }

.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result {
  width: 100%; text-align: left; display: flex; gap: 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer;
}
.result:hover { border-color: var(--water); }
.result .score { font-weight: 600; min-width: 48px; color: var(--water-ink); }
.result .sci { font-style: italic; }
.result .com { color: var(--muted); font-size: 13px; }
.result .lvl { font-size: 12px; color: var(--muted); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.manual { display: flex; gap: 8px; }
.manual input { flex: 1; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }

.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn-primary { flex: 1; }

/* toasts */
.toasts {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + var(--sab)); z-index: 20;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 480px; font-size: 14px;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--alarm); }

@media (min-width: 640px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill, .sheet { transition: none; }
}

/* plant profile view */
.plant-view { padding-bottom: calc(40px + var(--sab)); }
.back { display: inline-flex; align-items: center; gap: 6px; padding: 8px 4px; margin-bottom: 4px; }
.pv-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.pv-head .thumb { width: 88px; height: 88px; border-radius: 18px; }
.pv-head h1 { margin: 0; font-size: 22px; font-weight: 600; line-height: 1.2; }
.pv-head .sci { font-style: italic; color: var(--muted); }
.pv-head .chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip.soft { background: var(--water-soft); }
.pv-status { display: flex; gap: 12px; align-items: center; background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.pv-status .bar { flex: 1; height: 10px; margin: 0; }
.pv-status .plant-meta { white-space: nowrap; }
.pv-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.pv-actions .btn { text-align: center; padding: 10px 6px; }
.btn-soft { background: var(--water-soft); color: var(--water-ink); font-weight: 600; }
.btn-soft:hover { background: var(--water); color: #fff; }
.section { margin-bottom: 20px; }
.section h2 { font-size: 15px; font-weight: 600; margin: 0 0 8px; color: var(--muted); }
.card { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.care p { margin: 0 0 8px; font-size: 15px; }
.care p:last-child { margin-bottom: 0; }
.care b { font-weight: 600; }
.care ul { margin: 4px 0 0; padding-left: 18px; }
.muted { color: var(--muted); font-size: 14px; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.check { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.check-head { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: none; border: 0; text-align: left; cursor: pointer; }
.check-head .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.check-head .title { flex: 1; font-weight: 600; min-width: 0; }
.check-head .mode { font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--line); }
.dot.healthy { background: var(--ok); }
.dot.watch { background: var(--warn); }
.dot.sick { background: var(--alarm); }
.check-body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.check-body .photo { width: 100%; max-height: 240px; object-fit: cover; border-radius: 10px; margin: 12px 0 8px; }
.verdict { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; margin: 10px 0 6px; }
.verdict.healthy { background: var(--ok-soft); color: var(--ok); }
.verdict.watch { background: var(--warn-soft); color: var(--warn); }
.verdict.sick { background: var(--alarm-soft); color: var(--alarm); }
.findings { margin: 8px 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.findings li { padding: 8px 10px; background: var(--bg); border-radius: 10px; font-size: 14px; }
.findings .conf { font-size: 12px; color: var(--muted); }
.actions-list { margin: 6px 0 0; padding-left: 20px; }
.actions-list li { margin-bottom: 4px; }
.questions { margin: 10px 0 0; padding: 10px 12px; background: var(--warn-soft); border-radius: 10px; }
.questions ol { margin: 4px 0 8px; padding-left: 20px; }
.questions textarea { width: 100%; min-height: 64px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
.user-text { font-style: italic; color: var(--muted); font-size: 14px; margin: 6px 0; }
.usage { font-size: 12px; color: var(--muted); margin-top: 8px; }

.water-list { margin: 0; padding: 0; list-style: none; columns: 2; font-size: 14px; }
.water-list li { break-inside: avoid; padding: 3px 0; }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--water-soft); border-top-color: var(--water); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
