/* Phone first: iPhones 375–440 CSS px wide, also fine on a PC. Same look as Lokobot's web\. */
:root {
  color-scheme: dark;              /* always dark; form controls match */
  --bg: #14180f;
  --panel: #1e2418;
  --panel-2: #262e1f;
  --text: #e9eee2;
  --muted: #a3ae98;
  --line: #333c2a;
  --header: #1d3517;
  --header-text: #f3f7ee;
  --good: #2e7d32;
  --good-text: #86efac;
  --warn-text: #fbbf24;
  --bad: #b3261e;
  --bad-text: #fca5a5;
  --water: #60a5fa;                /* top depth */
  --water-deep: #a78bfa;           /* deep depth */
  --tap: 44px;
}

* { box-sizing: border-box; touch-action: manipulation; }
[hidden] { display: none !important; }
* { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input:not([type="range"]), textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;                /* each tab scrolls by itself, between the two bars */
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  --side: max(12px, env(safe-area-inset-left), env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
}

/* ---------- Top bar */

#topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 4px) var(--side) 4px;
  background: var(--header);
  color: var(--header-text);
}
#loc-picker {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 60%;
  text-overflow: ellipsis;
  min-height: var(--tap);
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--header-text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
}
#top-status { flex: 1 1 auto; min-width: 0; overflow: hidden; text-align: right; font-size: 14px; line-height: 18px; font-variant-numeric: tabular-nums; }
#top-line { display: flex; align-items: center; justify-content: flex-end; gap: 6px; white-space: nowrap; }
#top-line > span, #top-detail { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top-detail { color: #c5d4b8; font-size: 13px; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #7d8a74; }
.dot.good { background: #4ade80; }
.dot.warn { background: #f59e0b; }
.dot.bad { background: #f87171; }

.banner {
  flex: none;
  margin: 8px var(--side) 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 15px;
}
.banner.alert { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.banner.demo { padding: 4px 10px; background: #5a4310; border-color: #7a5c18; color: #ffdf9e; font-size: 13px; }

/* ---------- Tabs */

#panels { flex: 1 1 0; min-height: 0; position: relative; }
.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  padding: 10px var(--side) 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.panel[hidden] { display: none; }

#tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px var(--side) max(4px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
#tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 52px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#tabs button[aria-current="page"] { background: var(--good); color: #fff; }
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Building blocks (ui.js) */

.card {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0; font-size: 16px; font-weight: 600; }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.hint a { color: var(--good-text); }
.empty { margin: 24px 8px; color: var(--muted); text-align: center; line-height: 1.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #2a3322;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { filter: brightness(1.3); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { border-color: var(--good); background: var(--good); color: #fff; }
.btn.danger { border-color: #5c1f1b; background: #3a1714; color: var(--bad-text); }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 14px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button-row .btn { flex: 1 1 0; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-top { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 14px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.input, select.input, textarea.input {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;                 /* below 16 px, iOS zooms the page on focus */
}
textarea.input { padding: 10px; min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--good); outline-offset: -1px; }
.input.invalid { border-color: var(--bad); }

.segments { display: flex; gap: 2px; padding: 2px; border-radius: 10px; background: var(--bg); }
.segment {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 0 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.segment[aria-pressed="true"] { background: var(--good); color: #fff; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: #e9eee2;
  color: #14180f;
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 10;
}
.toast.error { background: var(--bad); color: #fff; }

/* ---------- Status colours */

.st-ok { color: var(--good-text); }
.st-soon { color: var(--warn-text); }
.st-due, .st-late { color: var(--bad-text); }
.st-nodata, .st-quiet { color: var(--muted); }

/* ---------- Plants tab: one card per plant */

.plant-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.plant-card:active { filter: brightness(1.2); }
.plant-card.late { border-color: #7a2a24; }
.thumb {
  width: 76px;
  height: 76px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--panel-2);
}
.thumb.placeholder, .hero.placeholder { display: flex; align-items: center; justify-content: center; color: #4d5e40; }
.thumb.placeholder svg { width: 40px; height: 40px; }
.plant-card-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.plant-name { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plant-status { font-size: 15px; font-weight: 600; }
.plant-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-bars { display: grid; grid-template-columns: auto minmax(0, 1fr) 3.2em; gap: 3px 6px; align-items: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-bars .val { text-align: right; color: var(--text); }

/* A moisture bar: fill to the reading, a tick at "water at" and "full". */
.bar { position: relative; height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.bar.big { height: 14px; border-radius: 7px; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--water); }
.bar-fill.deep { background: var(--water-deep); }
.bar-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: #f87171; }
.bar-mark.full { background: #e9eee2; opacity: 0.6; }

/* ---------- Plant tab */

.hero {
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 46vh;
  border-radius: 12px;
  object-fit: cover;
  background: var(--panel-2);
}
.hero.placeholder { aspect-ratio: auto; height: 120px; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; }
.hero.placeholder svg { width: 48px; height: 48px; color: #4d5e40; }
.plant-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 2px 2px 0; }
.plant-title h1 { margin: 0; font-size: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plant-title span { color: var(--muted); font-size: 14px; white-space: nowrap; }
.big-status { font-size: 22px; font-weight: 700; }
.big-sub { margin-top: -6px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.depth-row { display: grid; grid-template-columns: 4.6em minmax(0, 1fr) 3.4em; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.depth-row .label { font-size: 15px; }
.depth-row .label small { display: block; color: var(--muted); font-size: 11px; }
.depth-row .val { text-align: right; font-size: 18px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 12px; height: 3px; margin-right: 5px; vertical-align: middle; border-radius: 2px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin: 0; font-size: 15px; }
.stat-grid div { min-width: 0; }
.stat-grid dt { color: var(--muted); font-size: 12px; }
.stat-grid dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Charts (chart.js) */

.chart { display: block; width: 100%; height: 170px; touch-action: pan-y; }
.chart.small { height: 110px; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .threshold { stroke: #f87171; stroke-width: 1.2; stroke-dasharray: 4 4; }
.chart .marker { stroke: #4ade80; stroke-width: 1.5; }
.chart .cursor { stroke: #e9eee2; stroke-width: 1; opacity: 0.6; }
.chart-readout { min-height: 18px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- Settings and Admin */

.photo-edit { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: center; }
.photo-edit .thumb { width: 96px; height: 96px; }
.photo-edit .button-row { flex-direction: column; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.sensor { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.sensor:first-of-type { border-top: 0; padding-top: 0; }
.sensor-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.fw-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.fw-row .hint { margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--good); }
.sensor-head b { color: var(--text); font-weight: 600; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.cal-grid { display: grid; grid-template-columns: 3.6em minmax(0, 1fr) minmax(0, 1fr); gap: 6px 8px; align-items: center; font-size: 14px; }
.cal-grid .head { color: var(--muted); font-size: 12px; }
details > summary { min-height: var(--tap); display: flex; align-items: center; color: var(--good-text); font-size: 15px; cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; margin-right: 6px; }
details[open] > summary::before { content: "▾"; }
.location { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.location:first-of-type { border-top: 0; padding-top: 0; }
.badge { padding: 2px 8px; border-radius: 999px; background: #5a4310; color: #ffdf9e; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.good { background: #204d2a; color: #b7f0c4; }
