/* Feedsher PWA — mobile-first. Tokens: light on :root, dark via prefers-color-scheme + data-theme. */
:root {
  --bg: #eef3f1; --surface: #ffffff; --surface-2: #f5f8f7; --line: #d8e2df;
  --ink: #142326; --ink-2: #4a5f63; --ink-3: #7d9093;
  --accent: #0b7a86; --accent-ink: #ffffff; --accent-soft: #d9eff1;
  --good: #24955a; --good-soft: #dbf3e5; --warn: #c98a00; --warn-soft: #fff1cc; --crit: #cf3f3f; --crit-soft: #fde1e1;
  --water: #bfe0e6; --water-2: #8fc7d2; --rope: #3b3b3b;
  --font: "Noto Sans Thai", "Sarabun", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,35,38,.06), 0 6px 20px rgba(20,35,38,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e181b; --surface: #16242a; --surface-2: #1c2d33; --line: #2a3d43;
    --ink: #e6efef; --ink-2: #a9bcbf; --ink-3: #74898d;
    --accent: #3fb7c3; --accent-ink: #062024; --accent-soft: #163a40;
    --good: #4ccc85; --good-soft: #163d2a; --warn: #f0b429; --warn-soft: #3d3010; --crit: #ff6b6b; --crit-soft: #442020;
    --water: #16404a; --water-2: #1f5a68; --rope: #c8d3d5;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e181b; --surface: #16242a; --surface-2: #1c2d33; --line: #2a3d43;
  --ink: #e6efef; --ink-2: #a9bcbf; --ink-3: #74898d;
  --accent: #3fb7c3; --accent-ink: #062024; --accent-soft: #163a40;
  --good: #4ccc85; --good-soft: #163d2a; --warn: #f0b429; --warn-soft: #3d3010; --crit: #ff6b6b; --crit-soft: #442020;
  --water: #16404a; --water-2: #1f5a68; --rope: #c8d3d5;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; text-wrap: balance; font-weight: 600; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* shell */
.shell { display: flex; justify-content: center; gap: 24px; padding-inline: 16px; padding-block: 12px 0; min-height: 100%; }
.phone { width: 100%; max-width: 440px; display: flex; flex-direction: column; min-height: calc(100vh - 12px); }
.side { width: 360px; display: none; flex-direction: column; gap: 14px; position: sticky; top: 12px; align-self: flex-start; }
@media (min-width: 960px) { .side { display: flex; } }

.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .01em; }
.brand svg { width: 26px; height: 26px; }
.topbar .dev { margin-left: auto; text-align: right; line-height: 1.2; }
.topbar .dev .name { font-weight: 600; font-size: 14px; }
.topbar .dev .clock { font-size: 12px; color: var(--ink-2); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.crit { background: var(--crit-soft); color: var(--crit); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.busy::before { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .pill.busy::before { animation: none; } * { transition: none !important; } }

.content { flex: 1; padding-block: 12px 96px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.raised { box-shadow: var(--shadow); }
.card h2 { font-size: 15px; color: var(--ink-2); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .hint { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--ink-3); }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--ink-2); }
.tile .value { font-size: 24px; font-weight: 600; font-family: var(--mono); font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .value small { font-size: 13px; font-weight: 500; color: var(--ink-2); font-family: var(--font); margin-left: 4px; }
.tile .sub { font-size: 12px; color: var(--ink-3); }
.tile.warn { border-color: var(--warn); } .tile.crit { border-color: var(--crit); }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.bar.good > i { background: var(--good); } .bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.muted { color: var(--ink-2); font-size: 13px; }
.small { font-size: 12px; color: var(--ink-3); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; font-size: 14px; min-height: 42px; transition: transform .05s, background .15s; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--crit); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 56px; font-size: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.holding { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--ink-2); }
.input, select.input { width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 15px; min-height: 40px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.input.num { font-family: var(--mono); }

.slider { display: flex; flex-direction: column; gap: 4px; }
.slider .row { justify-content: space-between; }
.slider .val { font-family: var(--mono); font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }

.switch { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line); border: none; padding: 0; flex-shrink: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s; }
.switch.on { background: var(--good); } .switch.on::after { left: 21px; }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.list { display: flex; flex-direction: column; }
.list > .item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list > .item:first-child { border-top: 0; }
.item .t { flex: 1; min-width: 0; }
.item .t .primary { font-weight: 600; }
.item .t .secondary { font-size: 12px; color: var(--ink-2); }
.item .icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); flex-shrink: 0; font-size: 16px; }
.item .icon.good { background: var(--good-soft); color: var(--good); } .item .icon.warn { background: var(--warn-soft); color: var(--warn); } .item .icon.crit { background: var(--crit-soft); color: var(--crit); } .item .icon.accent { background: var(--accent-soft); color: var(--accent); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td.num, .tbl th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--mono); font-size: 10px; fill: var(--ink-3); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* pond view */
.pond { width: 100%; height: auto; display: block; border-radius: 12px; }

/* tabs */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: center; pointer-events: none; }
.tabbar > div { pointer-events: auto; width: 100%; max-width: 440px; margin: 0 16px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); padding: 6px 2px calc(6px + env(safe-area-inset-bottom, 0px)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border: 0; background: none; border-radius: 12px; color: var(--ink-3); font-size: 9.5px; font-weight: 600; min-width: 0; white-space: nowrap; }
.tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); background: var(--accent-soft); }
.tab:focus-visible { outline: 2px solid var(--accent); }

/* toast + dialogs */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--crit); color: #fff; }
.banner { border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; font-size: 13px; }
.banner.crit { background: var(--crit-soft); color: var(--crit); border: 1px solid var(--crit); }
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
.banner.accent { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }
.banner .btn { margin-left: auto; min-height: 34px; padding: 6px 10px; }

.overlay { position: fixed; inset: 0; background: rgba(6, 20, 24, .55); z-index: 30; display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.sheet { background: var(--surface); border-radius: 18px; padding: 18px; width: 100%; max-width: 440px; max-height: 85vh; overflow: auto; box-shadow: var(--shadow); }
.sheet h3 { font-size: 17px; margin-bottom: 6px; }
.steps { counter-reset: s; display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.steps > div { display: flex; gap: 10px; }
.steps > div::before { counter-increment: s; content: counter(s); width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 12px; display: grid; place-items: center; flex-shrink: 0; }

/* demo side panel */
.side .card h2 { margin-bottom: 8px; }
.demo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-actions .btn { min-height: 38px; font-size: 13px; padding: 6px 8px; }
.speed { display: flex; gap: 4px; }
.speed .btn { flex: 1; min-height: 34px; padding: 4px; font-size: 13px; }
.mini-log { font-family: var(--mono); font-size: 11px; color: var(--ink-2); max-height: 220px; overflow: auto; display: flex; flex-direction: column; gap: 3px; }
.mini-log span { color: var(--ink-3); margin-right: 6px; }
.fab { position: fixed; right: 16px; bottom: 100px; z-index: 7; width: 48px; height: 48px; border-radius: 50%; background: var(--warn); color: #1a1400; border: 0; font-weight: 700; box-shadow: var(--shadow); display: grid; place-items: center; font-size: 18px; }
@media (min-width: 960px) { .fab { display: none; } }
.login { max-width: 360px; margin: 60px auto; }

/* ---- farm map (multi-device dashboard) ---- */
.farm-wrap { position: relative; }
.farm-zoom { position: absolute; right: 6px; top: 6px; z-index: 2; display: flex; flex-direction: column; gap: 4px; }
.farm-zoom .btn { padding: 2px 10px; font-size: 18px; line-height: 1.2; background: var(--surface); }
.farm-scroll { overflow: hidden; border-radius: 12px; background: #e6ede9; touch-action: none; }
.farm-map { display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.farm-map .land { fill: #dfe8e2; }
.farm-map .grid { stroke: rgba(30, 60, 50, .12); stroke-width: .15; }
.farm-map .grid.major { stroke: rgba(30, 60, 50, .28); stroke-width: .3; }
.farm-map .pond { cursor: pointer; }
.farm-map.editing .pond { cursor: grab; }
.farm-map .pond-rect { stroke: rgba(255, 255, 255, .75); stroke-width: .4; }
.farm-map .pond-rect.none { fill: rgba(120, 130, 128, .12); stroke: #8f9a97; stroke-dasharray: 1.2 .8; }
.farm-map .pond-rect.off { fill: #9aa5a3; }
.farm-map .pond-text { fill: #fff; font-weight: 600; pointer-events: none; }
.farm-map .pond-text.title { font-weight: 700; }
.farm-map .pond-text.muted { fill: rgba(255, 255, 255, .8); font-weight: 500; }
.farm-map .pond.none .pond-text { fill: #35504a; }
.farm-map .pond.none .pond-text.muted { fill: #6b7c78; }
.farm-map .pond-text.crit { fill: #ffe4e0; }
.farm-map .pond-text.warn { fill: #fff2c9; }
.farm-map .pond.busy .pond-text { fill: var(--accent-ink, #fff); }
.farm-map .pond-progress { fill: rgba(255, 255, 255, .55); }
.btn.small { padding: 4px 10px; font-size: 12px; }
@media (prefers-color-scheme: dark) { .farm-scroll { background: #17221f; } .farm-map .land { fill: #1d2926; } .farm-map .grid { stroke: rgba(255, 255, 255, .08); } .farm-map .grid.major { stroke: rgba(255, 255, 255, .18); } .farm-map .pond.none .pond-text { fill: #cfe0da; } }
