/* Harvestly – responsive styles.
   Phone first. Breakpoints:
     < 380px   small phones: single-column forms
     ≥ 640px   tablets: wider content, card grids
     ≥ 960px   computers: sidebar instead of the bottom tab bar, dialogs instead of bottom sheets
     ≥ 1200px  wide screens: two-column Today and plant pages */

:root {
  --bg: #f4f6f1;
  --card: #ffffff;
  --text: #1f2a1f;
  --muted: #667063;
  --line: #e2e7dc;
  --green: #2f6b3a;
  --green-strong: #24552d;
  --green-soft: #e3efe0;
  --amber: #a15f00;
  --amber-soft: #fff1d6;
  --red: #b3261e;
  --red-soft: #fde4e1;
  --blue: #1d5f8c;
  --blue-soft: #e0eef8;
  --on-green: #fff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .18);

  /* layout */
  --gutter: 16px;
  --sidebar: 0px;           /* width taken by the sidebar (0 on phones) */
  --tabbar: 58px;           /* height of the bottom tab bar (0 on computers) */
  --page-wide: 1120px;
  --page-narrow: 720px;
  --shift: calc(var(--sidebar) / 2); /* moves centred floating things to the middle of the content area */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121612;
    --card: #1c221c;
    --text: #e6ece3;
    --muted: #9aa596;
    --line: #2c352b;
    --green: #7cc28a;
    --green-strong: #95d4a2;
    --green-soft: #1f3323;
    --amber: #f0b44c;
    --amber-soft: #3a2c12;
    --red: #f2958d;
    --red-soft: #3d1d1a;
    --blue: #8cc4ec;
    --blue-soft: #16293a;
    --on-green: #102010;
    --shadow: none;
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
html[dir="rtl"] { --shift: calc(var(--sidebar) / -2); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.sheet-open { overflow: hidden; }
a { color: var(--green); text-decoration: none; }
img { max-width: 100%; }
h2 { font-size: 1.05rem; margin: 22px 4px 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h3 { font-size: 1rem; margin: 0 0 6px; overflow-wrap: anywhere; }
p { margin: 6px 0; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- Sign in ---------- */
body.signed-out { padding: 0; }
body.signed-out .sidebar, body.signed-out .tabbar, body.signed-out .topbar, body.signed-out .fab { display: none !important; }
.login { max-width: 400px; margin: 0 auto; padding: max(40px, 8vh) var(--gutter) 40px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.login-brand h1 { margin: 0; font-size: 1.5rem; color: var(--green); }
.login-brand .tagline { margin: 0; color: var(--muted, #667); text-align: center; }
.login-lang { justify-content: center; margin: 14px 0 4px; }
.login form h2 { margin: 0 0 8px; }
.login form label { display: block; margin: 12px 0 4px; font-weight: 600; }
.login form input { width: 100%; }
.login form .btn { margin-top: 16px; }
.login-error { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 8px 10px; margin: 12px 0 0; }

.side-user { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px 6px 0; border-top: 1px solid var(--line); min-width: 0; }
.side-user .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: var(--green); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #1a2a1c; } }
.topbar h1 { flex: 1; min-width: 0; font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 1.5rem; width: 40px; height: 40px; line-height: 1; cursor: pointer; display: grid; place-items: center; border-radius: 10px; flex: none; }
.icon-btn:hover { background: rgba(255, 255, 255, .14); }
.icon-btn.back { font-size: 2rem; margin-inline-start: -6px; }
html[dir="rtl"] .icon-btn.back { transform: scaleX(-1); }
.head-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.head-actions:empty { display: none; }
.head-btn { background: rgba(255, 255, 255, .16); border: 0; color: inherit; border-radius: 999px; height: 34px; padding: 0 12px; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.head-btn.round { width: 34px; padding: 0; justify-content: center; font-size: 1rem; }
@media (max-width: 420px) { .head-btn.labelled { width: 34px; padding: 0; justify-content: center; font-size: 1rem; } .head-btn.labelled span { display: none; } }
.head-btn:hover, .head-btn:focus-visible { background: rgba(255, 255, 255, .28); }
.lang-btn {
  flex: none; background: rgba(255, 255, 255, .15); color: inherit; border: 1px solid rgba(255, 255, 255, .35); border-radius: 99px;
  font: inherit; font-size: .85rem; padding: 2px 10px; min-height: 32px; cursor: pointer;
}

/* Urdu: right-to-left with an Urdu typeface (Nastaliq needs extra line height) */
html[lang="ur"] body { font-family: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Noto Naskh Arabic", "Segoe UI", system-ui, sans-serif; line-height: 1.95; }
html[lang="ur"] input, html[lang="ur"] select, html[lang="ur"] textarea, html[lang="ur"] button { font-family: inherit; }
html[lang="ur"] .lang-btn, html[lang="ur"] code, html[lang="ur"] .icon-btn { font-family: system-ui, sans-serif; }
html[lang="ur"] h2 { font-size: 1rem; }
html[lang="ur"] .tabbar a { font-size: .68rem; line-height: 1.6; }
html[dir="rtl"] .search-list button { text-align: right; }

/* ---------- Page ---------- */
main {
  max-width: var(--page-wide); margin: 0 auto;
  padding: 8px max(var(--gutter), env(safe-area-inset-right)) 88px max(var(--gutter), env(safe-area-inset-left)); /* bottom room so the floating mic never covers buttons */
}
main[data-width="narrow"] { max-width: var(--page-narrow); }
main > :first-child { margin-top: 8px; }

/* Bottom tab bar (phones and portrait tablets) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tabbar a { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; padding: 8px 2px 6px; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabbar a span { font-size: 1.3rem; line-height: 1.2; }
.tabbar a.active { color: var(--green); font-weight: 600; }

/* Sidebar (computers) */
.sidebar { display: none; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--text); font-weight: 700; font-size: 1.1rem; }
.sidebar .brand img { border-radius: 8px; flex: none; }
.sidebar .brand .brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar .brand .tagline { font-size: 0.72rem; font-weight: 400; color: var(--muted, #667); line-height: 1.3; }
.side-add { margin: 0 0 14px; }
.side-group { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; border-top: 1px solid var(--line); }
.side-group a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--text); font-size: .95rem; font-weight: 500;
}
.side-group a:hover { background: var(--line); }
.side-group a.active { background: var(--green-soft); color: var(--green); font-weight: 650; }
.side-group .ni { width: 22px; text-align: center; font-size: 1.1rem; flex: none; }

/* ---------- Building blocks ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin: 10px 0; border: 1px solid var(--line); min-width: 0; }
.card.link { display: block; color: inherit; transition: border-color .15s, box-shadow .15s; }
.card.link.row { display: flex; }
.card.link:hover { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.row { display: flex; align-items: center; gap: 10px; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pad { padding: 24px 8px; }
.pre { white-space: pre-line; }
.stack > * + * { margin-top: 10px; }

/* Lists of cards flow into as many columns as fit (one on phones). */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; margin: 10px 0; align-items: start; }
.cards > .card { margin: 0; height: 100%; }
.cards.tight { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 10px; }
.cards:empty { display: none; }

/* Two-column pages (Today, plant page). On narrower screens the columns dissolve and
   sections fall back into one column in the order given by style="order:N". */
.split { display: flex; flex-direction: column; }
.split > .col { display: contents; }
.split section { min-width: 0; }
/* Two panels side by side when there is room (harvest calendar + nutrition) */
.duo { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 0 24px; align-items: start; }
.duo > section { min-width: 0; }
/* Short bullet lists flow into newspaper columns when there is room */
.col-list { columns: 3 240px; column-gap: 24px; }
.col-list > * { break-inside: avoid; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--green-soft); color: var(--green); white-space: nowrap; }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.grey { background: var(--line); color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 14px; border-radius: 10px; cursor: pointer; min-height: 42px;
  text-align: center; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--green) 40%, var(--line)); }
.btn.primary { background: var(--green); color: var(--on-green); border-color: var(--green); }
.btn.primary:hover { background: var(--green-strong); border-color: var(--green-strong); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; min-height: 34px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Tasks ---------- */
.task { display: flex; gap: 12px; align-items: flex-start; }
.task .ico { font-size: 1.4rem; line-height: 1.2; width: 28px; text-align: center; flex: none; }
.task .title { font-weight: 600; overflow-wrap: anywhere; }
.task details { margin-top: 4px; }
.task summary { color: var(--muted); font-size: .85rem; cursor: pointer; }
.task .check {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--green); background: none; color: var(--green);
  font-size: 1.2rem; cursor: pointer; display: grid; place-items: center; transition: background .15s;
}
.task .check:hover, .task .check:active { background: var(--green-soft); }
.task.p1 { border-inline-start: 4px solid var(--red); }
.task.done { opacity: .6; }
.task.done .title { text-decoration: line-through; }
.task-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- Weather ---------- */
.weather { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; margin: 10px 0; scroll-snap-type: x proximity; }
.weather::-webkit-scrollbar { display: none; }
.weather .day { flex: 1 0 64px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; font-size: .8rem; scroll-snap-align: start; }
.weather .day b { display: block; font-size: .95rem; }
.weather .day .wi { font-size: 1.4rem; }
.weather .day.now { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 35%, var(--line)); }
.weather .day.now b { font-size: 1.2rem; color: var(--green-strong); }

.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--green); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 6px 0; position: relative; }
.timeline .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); background: var(--card); margin-top: 4px; flex: none; }
.timeline li.done .dot { background: var(--green); border-color: var(--green); }
.timeline li.current .dot { border-color: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin: 12px 0 4px; color: var(--muted); }
input, select, textarea {
  width: 100%; max-width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input[type="date"] { min-width: 0; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid2 > * { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 8px 14px; font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: color-mix(in srgb, var(--green) 40%, var(--line)); }
.chip.on { background: var(--green); color: var(--on-green); border-color: var(--green); }
.check-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-weight: 500; color: var(--text); font-size: .95rem; }
.check-row input { width: 22px; height: 22px; min-height: 0; flex: none; }
.search-list { max-height: 50vh; overflow-y: auto; }
.search-list button { display: block; width: 100%; text-align: start; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 4px; font: inherit; color: var(--text); cursor: pointer; }
.search-list button:hover { background: var(--green-soft); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* Inventory */
.inv-item.low { border-inline-start: 4px solid var(--amber); }
.inv-item.out { border-inline-start: 4px solid var(--red); }
.inv-item { display: flex; flex-direction: column; }
.inv-item > .btns { margin-top: auto !important; padding-top: 8px; }

/* AI top 10 */
.top-card .row.top { gap: 12px; }
.rank {
  flex: none; min-width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--green); color: var(--on-green); font-weight: 700; font-size: .95rem;
}
.rank.big { min-width: 48px; height: 48px; font-size: 1.2rem; }
.empty .big { font-size: 2.4rem; }

/* ---------- Bottom sheet (dialog on computers) ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); animation: fade .15s ease-out; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 90vh; max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 18px max(16px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  max-width: 680px; margin: 0 auto; box-shadow: var(--shadow-lg);
  animation: rise .2s ease-out;
}
.sheet-panel h3 { font-size: 1.1rem; padding-inline-end: 40px; }
.sheet-close {
  position: sticky; top: 0; float: inline-end; margin: -6px -6px 0 0; z-index: 1;
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--line); color: var(--text); font-size: .9rem; cursor: pointer;
}
html[dir="rtl"] .sheet-close { margin: -6px 0 0 -6px; }
.sheet-close:hover { background: color-mix(in srgb, var(--text) 18%, var(--line)); }
@keyframes rise { from { transform: translateY(24px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: calc(50% + var(--shift)); bottom: calc(var(--tabbar) + 26px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 40; font-size: .9rem;
  width: max-content; max-width: min(90vw, 520px); box-shadow: var(--shadow-lg);
}
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { background: var(--amber-soft); color: var(--text); border-radius: 12px; padding: 12px; font-size: .9rem; margin: 10px 0; }
.notice.info { background: var(--blue-soft); }

/* ---------- Assistant – laid out like the familiar chat apps ---------- */
.chat-top { gap: 6px; margin: 2px 0 6px; flex-wrap: wrap; }
.chip.icon { padding-inline: 10px; }
.chat { display: flex; flex-direction: column; gap: 14px; padding-bottom: 190px; }
.bubble { max-width: min(85%, 560px); padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; font-size: .97rem; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--green-soft); color: var(--text); border-end-end-radius: 6px; }
.msg { display: flex; flex-direction: column; min-width: 0; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: stretch; }
.msg .acts { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.msg-tools { display: flex; gap: 2px; margin-top: 2px; opacity: .7; }
.msg.assistant .msg-tools { margin-inline-start: -6px; }
.msg-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; justify-content: flex-end; }
.msg-photos img { width: min(140px, 38vw); height: min(140px, 38vw); object-fit: cover; border-radius: 12px; border: 1px solid var(--line); display: block; }
.error-note { background: var(--red-soft); margin: 0; }

/* Formatted replies */
.answer { font-size: 1rem; line-height: 1.55; overflow-wrap: anywhere; min-width: 0; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 .7em; }
.answer h4 { margin: .9em 0 .4em; font-size: 1.02rem; }
.answer ul, .answer ol { margin: 0 0 .7em; padding-inline-start: 1.4em; }
.answer li { margin: .2em 0; }
.answer li.sub { margin-inline-start: 1.2em; list-style-type: circle; }
.answer code { background: var(--line); border-radius: 5px; padding: 1px 5px; font-size: .9em; }
.answer pre { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; }
.answer pre code { background: none; padding: 0; }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.answer a { color: var(--blue); }
.table-wrap { overflow-x: auto; margin: 0 0 .7em; border: 1px solid var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch; }
.answer table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.answer th, .answer td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.answer th { background: var(--card); font-weight: 600; white-space: nowrap; }
.answer tr:last-child td { border-bottom: 0; }
.cursor { display: inline-block; width: .5em; height: 1em; margin-inline-start: 2px; vertical-align: -.12em; background: var(--green); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Live "working" line: which agent is doing what */
.work { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; padding: 4px 0; }
.answer:not([hidden]) + .work { margin-top: 6px; }
.work .dots { display: inline-flex; gap: 3px; }
.work .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: bounce 1.2s infinite ease-in-out; }
.work .dots i:nth-child(2) { animation-delay: .15s; }
.work .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.steps { margin-top: 6px; font-size: .85rem; color: var(--muted); }
.steps summary { cursor: pointer; width: fit-content; }
.steps ol { margin: 4px 0 0; padding-inline-start: 1.4em; }

/* Welcome screen */
.welcome { text-align: center; padding: 18px 4px 8px; }
.welcome .big { font-size: 2.6rem; }
.welcome h2 { margin: 6px 0 2px; font-size: 1.35rem; justify-content: center; }
.welcome > p { margin: 4px 0 14px; }
.suggest { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 8px; margin: 0 0 14px; text-align: start; }
.suggest-btn { display: flex; gap: 8px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font: inherit; font-size: .9rem; color: var(--text); cursor: pointer; text-align: start; }
.suggest-btn:hover, .suggest-btn:focus-visible { border-color: var(--green); }
.suggest-btn .ic { flex: none; }

/* Composer: pinned above the tab bar, centred on the content area */
.chat-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); z-index: 9;
  background: linear-gradient(to bottom, transparent, var(--bg) 14px);
  padding: 14px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  max-width: calc(var(--page-narrow) - 8px); margin: 0 auto;
}
.composer { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 6px 8px 6px; box-shadow: 0 2px 12px rgba(0, 0, 0, .08); }
.composer:focus-within { border-color: var(--green); }
.composer #msg { display: block; width: 100%; border: 0; outline: 0; background: transparent; box-shadow: none; min-height: 40px; max-height: 160px; resize: none; line-height: 1.4; padding: 8px 6px 4px; font-size: 1rem; color: var(--text); }
.composer-row { display: flex; align-items: center; gap: 6px; }
.c-btn { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 999px; height: 36px; min-width: 36px; padding: 0 10px; font: inherit; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.c-btn.on { background: var(--green-soft); border-color: var(--green); }
.mic {
  flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; font-size: 1.15rem; cursor: pointer;
  background: var(--green-soft); display: grid; place-items: center;
}
.mic.on { background: var(--red); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(179, 38, 30, .25); } }
.send { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--green); color: var(--on-green); font-size: 1.2rem; font-weight: 700; cursor: pointer; display: grid; place-items: center; }
.send:disabled { opacity: .35; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); font-size: .9rem; }
.editing { display: flex; align-items: center; justify-content: space-between; background: var(--amber-soft); border-radius: 10px; padding: 6px 10px; margin-bottom: 6px; }
.link-btn { background: none; border: 0; color: var(--blue); font: inherit; cursor: pointer; padding: 2px 4px; }
#interim { margin: 0 6px 6px; }
.jump { position: fixed; left: calc(50% + var(--shift)); transform: translateX(-50%); bottom: calc(var(--tabbar) + 132px + env(safe-area-inset-bottom)); z-index: 10; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--text); box-shadow: var(--shadow); cursor: pointer; font-size: 1.1rem; }
.photo-preview { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.photo-preview .thumb { position: relative; }
.photo-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; display: block; }
.photo-preview button { position: absolute; top: -6px; inset-inline-end: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #333; color: #fff; font-size: .7rem; cursor: pointer; }
.tool-btn { background: none; border: 0; font-size: 1rem; padding: 4px 6px; border-radius: 8px; cursor: pointer; min-width: 32px; min-height: 32px; }
.tool-btn:hover, .tool-btn:focus-visible { background: var(--line); opacity: 1; }
.fab {
  position: fixed; inset-inline-end: max(16px, env(safe-area-inset-right)); bottom: calc(var(--tabbar) + 18px + env(safe-area-inset-bottom)); z-index: 11;
  width: 56px; height: 56px; border-radius: 50%; background: var(--green); color: var(--on-green); font-size: 1.5rem;
  display: grid; place-items: center; box-shadow: 0 4px 12px rgba(0, 0, 0, .25); transition: transform .15s;
}
.fab:hover { transform: scale(1.06); }

/* ---------- Harvest planner ---------- */
/* Calendar: one row per week, each day coloured by how many vegetables are ready */
.hcal { display: flex; flex-direction: column; gap: 4px; }
.hcal-row { display: grid; grid-template-columns: 52px repeat(7, minmax(0, 1fr)); gap: 4px; align-items: center; }
.hcal-wk { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hcal-day {
  position: relative; border: 0; border-radius: 6px; height: 30px; font: inherit; font-size: .75rem; color: var(--text); cursor: pointer;
  display: grid; place-items: center; padding: 0; min-width: 0;
}
.hcal-day.good { background: var(--green-soft); }
.hcal-day.thin { background: var(--amber-soft); }
.hcal-day.none { background: var(--red-soft); }
.hcal-day.sel { outline: 2px solid var(--green); }
.hcal-day i { position: absolute; top: 3px; inset-inline-end: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.hcal-legend { flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.hcal-legend .hcal-day { width: 16px; height: 16px; display: inline-block; cursor: default; }
.hcal-legend .hcal-day i { top: 5px; inset-inline-end: 5px; }
#hcal-detail { margin-top: 8px; min-height: 1.2em; }

/* Nutrient coverage bars (light = with the sowing plan, solid = now) */
.nut-row { display: grid; grid-template-columns: minmax(7em, 10em) minmax(0, 1fr) 6.5em; gap: 8px; align-items: center; margin: 5px 0; }
.nut-bar { position: relative; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.nut-bar i { position: absolute; inset-block: 0; inset-inline-start: 0; background: var(--green); border-radius: 4px; }
.nut-bar i.plan { background: var(--green-soft); outline: 1px solid var(--green); outline-offset: -1px; }
.nut-pct { text-align: end; color: var(--muted); white-space: nowrap; }

/* ---------- Alerts (the watchdog) ---------- */
.card.alert { padding: 10px 12px; border-inline-start: 4px solid var(--muted); }
.card.alert.lvl-1 { border-inline-start-color: var(--red); background: var(--red-soft); }
.card.alert.lvl-2 { border-inline-start-color: var(--amber); background: var(--amber-soft); }
.card.alert.lvl-3 { border-inline-start-color: var(--blue); }
.card.alert.closed { opacity: .65; background: var(--card); border-inline-start-color: var(--line); }
.card.alert .row.top { gap: 10px; }
.a-ic { font-size: 1.35rem; line-height: 1.2; }
.a-title { font-weight: 600; font-size: .95rem; line-height: 1.3; }
.card.alert details { margin-top: 4px; }
.card.alert summary { cursor: pointer; color: var(--green); font-weight: 600; }
.card.alert details p { margin: 6px 0 2px; }
.a-meta { margin-top: 4px; }
.a-x { background: none; border: 0; color: var(--muted); font-size: 1rem; padding: 4px 6px; cursor: pointer; border-radius: 8px; min-width: 32px; min-height: 32px; }
.a-x:hover, .a-x:focus-visible { background: var(--line); }
.alerts-more { padding: 10px 14px; }
.closed-alerts summary { cursor: pointer; }

/* =================== Responsive =================== */

/* Small phones */
@media (max-width: 379px) {
  :root { --gutter: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 12px; }
  .lang-btn { padding: 2px 8px; }
  .topbar h1 { font-size: 1.05rem; }
  .c-btn { padding: 0 8px; }
}

/* Phones: stack the nutrient rows (name + percent on one line, the bar under them) */
@media (max-width: 519px) {
  .nut-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .nut-row .nut-bar { grid-column: 1 / -1; grid-row: 2; }
  .hcal-row { grid-template-columns: 44px repeat(7, minmax(0, 1fr)); gap: 3px; }
  .hcal-wk { font-size: .7rem; text-overflow: clip; }
  .hcal-day { height: 28px; }
}

/* Tablets */
@media (min-width: 640px) {
  :root { --gutter: 24px; }
  h2 { font-size: 1.12rem; margin-top: 26px; }
  .weather .day { flex-basis: 76px; }
  .card { padding: 16px; }
}

/* Computers: sidebar, light header, dialogs */
@media (min-width: 960px) {
  :root { --sidebar: 248px; --tabbar: 0px; --gutter: 32px; }
  body { padding-inline-start: var(--sidebar); }
  .tabbar { display: none; }

  .sidebar {
    display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 12;
    width: var(--sidebar); padding: 18px 14px; overflow-y: auto;
    background: var(--card); border-inline-end: 1px solid var(--line);
  }

  .topbar {
    background: color-mix(in srgb, var(--bg) 88%, transparent); color: var(--text);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 14px var(--gutter);
  }
  .topbar h1 { font-size: 1.4rem; font-weight: 700; }
  .settings-link { display: none; }
  .icon-btn:hover { background: var(--line); }
  .icon-btn.back { color: var(--green); }
  .head-btn { background: var(--green-soft); color: var(--green); }
  .head-btn:hover, .head-btn:focus-visible { background: color-mix(in srgb, var(--green) 22%, var(--green-soft)); }
  .lang-btn { background: var(--card); border-color: var(--line); color: var(--text); }
  .lang-btn:hover { border-color: var(--green); }

  main { padding-top: 12px; padding-bottom: 96px; }
  main[data-width="wide"] .btns > .btn.primary.grow { flex: 0 1 auto; min-width: 220px; }

  .sheet-panel {
    inset: 0; margin: auto; height: fit-content; max-height: 85vh;
    width: min(560px, calc(100vw - 48px)); max-width: none;
    border-radius: 18px; padding: 22px 24px; background: var(--bg); border: 1px solid var(--line);
    animation: pop .16s ease-out;
  }
  .sheet-panel:has(.search-list) { width: min(640px, calc(100vw - 48px)); }
  @keyframes pop { from { transform: scale(.97); opacity: .3; } }

  .toast { bottom: 28px; }
  .fab { bottom: 28px; inset-inline-end: 28px; }
  .chat-bar { inset-inline-start: var(--sidebar); padding-bottom: 18px; }
  .jump { bottom: 150px; }
  .chat { padding-bottom: 170px; }
}

/* Wide screens: two-column pages */
@media (min-width: 1200px) {
  .split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 0 28px; align-items: start; }
  .split > .col { display: block; min-width: 0; }
  .split > .col > section:first-child > h2:first-child { margin-top: 10px; }
  .split .weather .day { flex-basis: 52px; padding: 6px 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .sidebar, .tabbar, .topbar .icon-btn, .lang-btn, .fab, .chat-bar { display: none !important; }
  body { padding: 0; background: #fff; }
}
