/* AI AWD Monitor dashboard. Mobile first; colors follow the app mockup. */
:root {
    --bg: #f2f6f0; --surface: #ffffff; --surface2: #e9f0e6; --ink: #17261c; --muted: #5d6e62; --line: #d6e1d6;
    --brand: #1d5e33; --brand-ink: #ffffff; --accent: #2e8b47;
    --ok: #2e8b47; --flooded: #2a6fb0; --dry: #c0392b; --filling: #127a8a; --fault: #7a857c; --hold: #b7791f;
    --radius: 14px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1611; --surface: #16221a; --surface2: #1c2b21; --ink: #e5efe7; --muted: #9db1a3; --line: #2b3e31;
        --brand: #17492a; --accent: #5cc070;
        --ok: #4cb064; --flooded: #5a9ee0; --dry: #e46a5c; --filling: #3cb2c2; --fault: #8d998f; --hold: #e0a23c;
        color-scheme: dark;
    }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg); color: var(--ink);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--dry); font-size: 13px; margin: 6px 0 0; }
button { font: inherit; color: inherit; }

/* Top bar */
.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
    background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 30px; height: 30px; fill: none; stroke: #bfe6c4; stroke-width: 2; flex: none; }
.brand h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand > div { min-width: 0; }
.brand p { margin: 0; font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill-on { background: #d7f2dc; color: #135c26; }
.pill-off { background: #f6d9d5; color: #8c241a; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid rgba(255,255,255,.35); background: transparent; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; }
.icon-btn.unlocked { background: #f0b43c; border-color: #f0b43c; }
.icon-btn.unlocked svg { stroke: #2b1d00; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 24px; }

/* Summary cards */
.cards4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .cards4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.mini-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.mini b { font-size: 20px; font-variant-numeric: tabular-nums; }
.mini small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Field map */
.field {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px;
    border-radius: var(--radius); background: #6b4d2e;
}
.tile {
    position: relative; min-height: 118px; border: 0; border-radius: 10px; padding: 10px 12px;
    text-align: left; color: #fff; cursor: pointer; display: grid; align-content: space-between; gap: 6px;
    background: var(--fault);
}
.tile:focus-visible { outline: 3px solid #f0b43c; outline-offset: 2px; }
.tile .t-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tile .t-code { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.92); color: #17261c; display: grid; place-items: center; font-weight: 800; }
.tile .t-level { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .t-sub { font-size: 12px; opacity: .95; }
.tile .t-tag { font-size: 11px; font-weight: 700; background: rgba(0,0,0,.22); padding: 2px 8px; border-radius: 999px; }
.tile.gate-open::after {
    content: ""; position: absolute; left: 50%; top: -6px; width: 28px; height: 6px; margin-left: -14px;
    background: #8fd3ff; border-radius: 0 0 4px 4px; animation: flow 1s linear infinite;
}
@keyframes flow { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .tile.gate-open::after { animation: none; } }
.c-ok { background: var(--ok); } .c-flooded { background: var(--flooded); } .c-dry { background: var(--dry); }
.c-filling { background: var(--filling); } .c-fault, .c-offline { background: var(--fault); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Lists */
.list { display: grid; gap: 8px; }
.item { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.item .sev { width: 8px; align-self: stretch; border-radius: 4px; flex: none; background: var(--ok); }
.item .sev.warning { background: var(--hold); } .item .sev.critical { background: var(--dry); }
.item .body { min-width: 0; flex: 1; }
.item .meta { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.row-head h2 { margin-bottom: 10px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 16px; font-weight: 700; cursor: pointer; }
.chip[aria-selected="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.status-banner { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; color: #fff; }
.status-banner b { font-size: 18px; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.kv div { min-width: 0; }
.kv span { display: block; font-size: 12px; color: var(--muted); }
.kv strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.stages { display: flex; gap: 4px; margin-top: 6px; }
.stages i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.stages i.on { background: var(--accent); }
.ai-box { margin-top: 14px; background: var(--surface2); border-radius: 10px; padding: 10px 12px; font-size: 14px; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .ax { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 9px; }
.chart .lvl { fill: none; stroke: var(--flooded); stroke-width: 2.2; stroke-linejoin: round; }
.chart .thr-open { stroke: var(--dry); stroke-dasharray: 4 3; stroke-width: 1.2; }
.chart .thr-close { stroke: var(--ok); stroke-dasharray: 4 3; stroke-width: 1.2; }
.chart .soil { stroke: #8a5a2b; stroke-width: 1.4; }
.chart .gate { fill: var(--filling); opacity: .14; }

/* Controls */
.ctrl-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.ctrl-row:first-of-type { border-top: 0; }
.ctrl-row .txt { min-width: 0; }
.ctrl-row .txt small { display: block; color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--surface); padding: 7px 14px; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--brand); color: #fff; }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.switch { position: relative; width: 48px; height: 28px; flex: none; border-radius: 999px; border: 0; background: var(--line); cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 23px; }
.switch:focus-visible, .seg button:focus-visible, .btn:focus-visible, .chip:focus-visible { outline: 3px solid #f0b43c; outline-offset: 2px; }
.btn { border: 0; background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.wide { width: 100%; margin-top: 4px; }
.locked-note { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Weather */
.days { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; text-align: center; font-size: 12px; min-width: 0; }
.day b { display: block; font-size: 13px; }
.day .rain { color: var(--flooded); font-weight: 700; }
.now { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.now .temp { font-size: 34px; font-weight: 800; }

/* Bottom tabs */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.tabbar button { position: relative; border: 0; background: none; display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer; padding: 4px 0; }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.tabbar button.active { color: var(--brand); font-weight: 700; }
@media (prefers-color-scheme: dark) { .tabbar button.active { color: var(--accent); } }
.badge { position: absolute; top: 0; left: 55%; min-width: 16px; height: 16px; border-radius: 8px; background: var(--dry); color: #fff; font-size: 10px; line-height: 16px; padding: 0 4px; }

/* Dialog and toast */
dialog { border: 0; border-radius: 16px; padding: 18px; width: min(340px, calc(100% - 32px)); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog input { width: 100%; font-size: 20px; letter-spacing: .3em; padding: 10px 12px; margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #17261c; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10; max-width: calc(100% - 32px); }

/* ---------- Animated scenes (public/js/scene.js) ---------- */
:root {
    --s-soil: #c9a46b; --s-wet: #6e4b2a; --s-crack: #5a3a1c; --s-water: #3d9be6; --s-water-deep: #1f6fb3;
    --s-bank: #8a6a45; --s-bed: #6b4f33; --s-rice: #2f8a3c; --s-steel: #9aa7b1; --s-steel-dark: #5f6b74;
    --s-servo: #1f2a33; --s-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
    :root { --s-soil: #a8854f; --s-wet: #5a3d22; --s-bank: #6e5536; --s-bed: #4f3a26; --s-rice: #4cb064; }
}
.scene { border-radius: var(--radius); overflow: hidden; background: var(--s-bank); }
.scene-svg { display: block; width: 100%; height: auto; }
.scene-grid { cursor: pointer; }
.scene-grid:focus-visible { outline: none; }
.scene-grid:focus-visible .border { stroke: #f0b43c; stroke-width: 4; }
.fade { transition: opacity .6s ease; }

.bank { fill: var(--s-bank); }
.canal-bed { fill: var(--s-bed); }
.canal-water { fill: var(--s-water); transition: opacity .8s ease, transform 1.2s ease; transform-box: fill-box; transform-origin: bottom; }
.wave { fill: none; stroke: rgba(255,255,255,.55); stroke-width: 1.6; stroke-linecap: round; animation: wave-move 2.4s linear infinite; }
.wave.w2 { stroke: rgba(255,255,255,.35); animation-duration: 3.1s; }
.wave.w3 { stroke: rgba(255,255,255,.45); animation-duration: 2.7s; }
#f-flow, #g-flow { transition: opacity .6s ease; }
@keyframes wave-move { from { transform: translateX(0); } to { transform: translateX(60px); } }
.canal-label { fill: #fff; font: 700 13px system-ui, sans-serif; paint-order: stroke; stroke: rgba(0,0,0,.45); stroke-width: 3px; }
.pump-body { fill: var(--s-servo); stroke: #fff; stroke-width: 1.5; }
.pump-blade { fill: #8fd3ff; }
.spin { animation: spin .8s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.overflow { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }

.soil { fill: var(--s-soil); }
.wet { fill: var(--s-wet); transition: opacity 1s ease; }
.crack { fill: none; stroke: var(--s-crack); stroke-width: 1.4; stroke-linecap: round; }
.sheet { fill: var(--s-water); transition: opacity 1s ease; }
.rice { fill: none; stroke: var(--s-rice); stroke-width: 1.5; stroke-linecap: round; opacity: .9; }
.border { fill: none; stroke-width: 3; transition: stroke .4s ease; stroke: var(--fault); }
.border.b-ok { stroke: var(--ok); } .border.b-flooded { stroke: var(--flooded); } .border.b-dry { stroke: var(--dry); }
.border.b-filling { stroke: #8fd3ff; } .border.b-fault, .border.b-offline { stroke: var(--fault); }
.badge { fill: rgba(255,255,255,.95); }
.badge-text { fill: #17261c; font: 800 13px system-ui, sans-serif; }
.cond-text, .lvl-text { fill: var(--s-text); font: 700 12px system-ui, sans-serif; paint-order: stroke; stroke: rgba(0,0,0,.55); stroke-width: 3px; }
.lvl-text { font-size: 17px; font-variant-numeric: tabular-nums; }

.headwall { fill: #b9b4aa; stroke: #7d776c; stroke-width: 1.2; }
.opening { fill: #3d4a52; }
.servo-box { fill: var(--s-servo); stroke: #fff; stroke-width: 1; }
.plate { fill: var(--s-steel); stroke: var(--s-steel-dark); stroke-width: 1.2; transition: transform 1.1s ease-in-out; }
.stream.thin { stroke-width: 4; }
.stream { fill: none; stroke: #6cc0ff; stroke-width: 8; stroke-linecap: round; stroke-dasharray: 5 6; animation: dash .5s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -11; } }
.ripple { fill: none; stroke: #cfeaff; stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: ripple 1.8s ease-out infinite; }
.ripple.r2 { animation-delay: .9s; }
@keyframes ripple { from { transform: scale(.2); opacity: .9; } to { transform: scale(1.7); opacity: 0; } }
.drop { stroke: #cfeaff; stroke-width: 1.4; stroke-linecap: round; animation: fall .9s linear infinite; }
@keyframes fall { from { transform: translate(0, -40px); opacity: 0; } 20% { opacity: 1; } to { transform: translate(-10px, 40px); opacity: 0; } }

/* side view */
.gate-scene { background: linear-gradient(var(--surface2), var(--surface)); border-radius: 12px; overflow: hidden; }
.scene-cap { fill: var(--muted); font: 700 11px system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.scene-status { fill: var(--ink); font: 700 13px system-ui, sans-serif; }
.scene-level { fill: var(--muted); font: 600 12px system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.wall { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }
.wall.thin { stroke-width: 2; }
.guide { stroke: var(--s-steel-dark); stroke-width: 1.5; stroke-dasharray: 3 3; }
.link { stroke: var(--ink); stroke-width: 1.6; }
.seal { fill: #2b2b2b; }
.servo { fill: var(--s-servo); }
.servo-text { fill: #fff; font: 600 9px system-ui, sans-serif; }
.hub { fill: #f0b43c; }
.horn { stroke: #f0b43c; stroke-width: 4; stroke-linecap: round; }
.tube { stroke: var(--ink); stroke-width: 2.5; }
#g-tube-water, #g-jet, #g-ripple { transition: opacity .5s ease; }
.jet { fill: none; stroke: var(--s-water); stroke-width: 9; stroke-linecap: round; stroke-dasharray: 6 5; animation: dash .45s linear infinite; }
.pebble { fill: rgba(0,0,0,.18); }
.sat { fill: var(--s-water-deep); opacity: .62; }
.sheet-side { fill: var(--s-water); opacity: .75; }
.mark { stroke-width: 2.5; }
.mark.close { stroke: var(--ok); } .mark.open { stroke: var(--dry); }
.mark-text { fill: var(--ink); font: 700 9px system-ui, sans-serif; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }

@media (prefers-reduced-motion: reduce) {
    .wave, .spin, .stream, .ripple, .drop, .jet { animation: none; }
    .plate, .canal-water, .sheet, .wet { transition: none; }
}

/* ---------- Accounts ---------- */
.avatar-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); background: #f0b43c; color: #2b1d00; font-weight: 800; font-size: 14px; cursor: pointer; }
.avatar-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.scene-grid.not-mine { opacity: .35; pointer-events: none; }
.small { font-size: 12px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { color: var(--dry); border-color: var(--dry); }
.member { align-items: center; }
.member-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.sev.role-admin { background: #f0b43c; } .sev.role-farmer { background: var(--ok); } .sev.role-viewer { background: var(--fault); }
.form-grid { display: grid; gap: 8px; }
.form-grid label, .login-card label { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.form-grid input, .form-grid select, .login-card input, #grid-owners select {
    width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
}
#grid-owners select { width: auto; min-width: 0; max-width: 60%; }
#grid-owners .ctrl-row label { font-weight: 700; }
.qr-box { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 12px; margin-top: 12px; }
.qr-box svg { width: 220px; height: 220px; }
.qr-url { font-size: 12px; color: var(--muted); word-break: break-all; text-align: center; }
.tabbar { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }

/* Login page */
.login-page { padding-bottom: 0; min-height: 100vh; background: linear-gradient(var(--brand) 0 220px, var(--bg) 220px); }
.login-wrap { max-width: 400px; margin: 0 auto; padding: calc(32px + env(safe-area-inset-top, 0px)) 16px 32px; }
.login-brand { display: grid; justify-items: center; gap: 6px; color: #fff; text-align: center; margin-bottom: 20px; }
.login-brand img { border-radius: 16px; }
.login-brand h1 { font-size: 24px; }
.login-brand p { margin: 0; opacity: .85; font-size: 14px; }
.login-card { display: grid; gap: 6px; margin-top: 0; padding: 22px; }
.login-card h2 { margin: 0; }
.login-card .muted { margin: 0 0 6px; }
.login-card .btn { margin-top: 12px; padding: 12px 16px; font-size: 16px; }
@media (max-width: 480px) {
    .member, .lot-row { flex-wrap: wrap; }
    .member .body, .lot-row .body { flex: 1 1 70%; }
    .member-actions { width: 100%; justify-content: flex-start; padding-left: 18px; }
    .wide-only { display: none; }
}
@media (min-width: 481px) { .narrow-only { display: none; } }

/* ---------- Canal sharing and field setup ---------- */
:root { --waiting: #b7791f; }
@media (prefers-color-scheme: dark) { :root { --waiting: #e0a23c; } }
.c-waiting { background: var(--waiting); }
.border.b-waiting { stroke: var(--waiting); stroke-dasharray: 6 4; }
.section-label { fill: #fff; font: 700 10px system-ui, sans-serif; paint-order: stroke; stroke: rgba(0,0,0,.4); stroke-width: 2.5px; letter-spacing: .02em; }
.section-label.dark { fill: var(--ink); stroke: none; }
.gate-label { fill: #fff; font: 700 9px system-ui, sans-serif; paint-order: stroke; stroke: rgba(0,0,0,.55); stroke-width: 2.5px; }

.summary { margin-top: 14px; }
.sum-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0 4px; }
.sum-row div { background: var(--surface2); border-radius: 10px; padding: 8px; text-align: center; min-width: 0; }
.sum-row b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.sum-row span { font-size: 11px; color: var(--muted); }
.canal-status { margin-top: 10px; }
.queue-box { margin-top: 14px; background: color-mix(in srgb, var(--waiting) 16%, var(--surface)); border-left: 4px solid var(--waiting); border-radius: 8px; padding: 10px 12px; font-size: 14px; }

.setup-h { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.setup-row { flex-wrap: wrap; align-items: center; gap: 8px; }
.setup-row .code { min-width: 34px; height: 34px; border-radius: 50%; background: var(--surface2); display: inline-grid; place-items: center; font-size: 13px; }
.setup-row input, .setup-row select, .inline-form input, .inline-form select {
    font: inherit; font-size: 15px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); min-width: 0;
}
.setup-row > input:not([type]) { flex: 1 1 140px; }
.setup-row select { flex: 1 1 130px; }
.num-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.num-label input[type="number"] { width: 70px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.inline-form input, .inline-form select { flex: 1 1 120px; }
.inline-form input[type="number"] { flex: 0 1 100px; }

/* ---------- Rotation schedule ---------- */
.rot { font-size: 13px; font-weight: 700; }
.rot-open { color: var(--ok); }
.rot-closed { color: var(--waiting); }
.rotation-box { flex: 1 1 100%; display: grid; gap: 8px; border-top: 1px dashed var(--line); padding-top: 10px; }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.check-label input { width: 18px; height: 18px; }
.window-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--surface2); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.window-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.day-picks { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 100%; }
.day-picks label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.day-picks label:has(input:checked) { background: var(--brand); color: #fff; border-color: var(--brand); }
.day-picks input { width: 14px; height: 14px; margin: 0; }
.window-form input[type="time"] { font: inherit; font-size: 15px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }

/* ---------- farm lots, registration, simulation ---------- */
.map { height: 260px; border-radius: 10px; overflow: hidden; background: var(--surface2); margin: 6px 0 10px; z-index: 0; }
.map.tall { height: 320px; }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.form-grid .radio-row label, .radio-row label { flex: 1 1 140px; display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0;
    padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink); }
.form-grid .radio-row input, .login-card .radio-row input { width: auto; margin: 0; flex: none; }
.radio-row label:has(input:checked) { border-color: var(--brand); background: var(--surface2); }
.form-grid .check-label input { width: auto; }
.coords { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pill-sim { background: #6c3fb5; color: #fff; }
.sim-seg { display: flex; gap: 6px; flex-wrap: wrap; }
.sim-seg .btn[aria-pressed="true"], .scenarios .btn[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.scenarios { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin-top: 6px; }
.lot-row .meta a { color: inherit; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface2); margin-left: 4px; }
.tag.sim { background: #efe6fb; color: #5a2fa0; }
.tag.pump { background: #fff1d6; color: #8a5a00; }
.tag.pending { background: #fde7e4; color: #a33a2a; }
.success { background: var(--surface2); border: 1px solid var(--line); padding: 12px; border-radius: 10px; }

.fw-actions { justify-content: flex-start; flex-wrap: wrap; margin: 8px 0; }
code.wrap { word-break: break-all; }
details summary { cursor: pointer; margin-top: 6px; }

/* ---------- Manage sub-tabs ---------- */
.subtabs { position: sticky; top: 58px; z-index: 4;   /* just under the sticky top bar */ display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
    margin: 0 -16px 10px; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button { position: relative; flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    padding: 8px 14px; border-radius: 999px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.subtabs button[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.subtabs button:focus-visible { outline: 3px solid #f0b43c; outline-offset: 2px; }
.subtabs .badge { position: static; display: inline-block; margin-left: 6px; vertical-align: 1px; }
.badge[hidden] { display: none; }
.manage-pane > h2:first-child, .manage-pane > .row-head:first-child { margin-top: 4px; }
/* ---------- form dialogs (add member, add farm lot) ---------- */
dialog.form-dialog { width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 16px 18px 18px; }
dialog.form-dialog input, dialog.form-dialog select { font-size: 16px; letter-spacing: normal; margin-top: 0; }
dialog.form-dialog .form-grid .radio-row input { width: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: -16px;
    margin: -16px -18px 8px; padding: 14px 18px 10px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 2; }
.dialog-head h3 { margin: 0; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--surface2); }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 480px) { dialog.form-dialog { width: 100%; max-width: 100%; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; } }

/* ---------- Home: two columns on wide screens ---------- */
.hg-top > .card:first-child { margin-top: 12px; }
@media (min-width: 1000px) {
    main:has(#view-home:not([hidden])), main:has(#view-grid:not([hidden])) { max-width: 1240px; }
    .home-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); column-gap: 20px; align-items: start;
        /* The field drawing fills the left column; everything else stacks on the right, so both end together. */
        grid-template-areas: "tiles tiles" "field top" "field map" "field ai" "field alerts";
        grid-template-rows: auto auto auto auto 1fr; }
    .hg-tiles { grid-area: tiles; }
    .hg-top { grid-area: top; }
    .hg-field { grid-area: field; }
    .hg-map { grid-area: map; }
    .hg-ai { grid-area: ai; }
    .hg-alerts { grid-area: alerts; }
    .hg-top > .card:first-child, .hg-field > h2:first-child { margin-top: 22px; }
    .hg-map .map.tall { height: 300px; }
    /* without a farm map, the right column's cards sit next to the drawing */
    .home-grid:has(.hg-map[hidden]) { grid-template-areas: "tiles tiles" "field top" "field ai" "field alerts"; grid-template-rows: auto auto auto 1fr; }
}

/* ---------- Grid detail: two columns on wide screens ---------- */
@media (min-width: 1000px) {
    .grid-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 20px; align-items: start;
        grid-template-areas: "tabs tabs" "card gate" "controls chart"; }
    .gl-tabs { grid-area: tabs; }
    .gl-card { grid-area: card; }
    .gl-gate { grid-area: gate; }
    .gl-chart { grid-area: chart; }
    .gl-controls { grid-area: controls; }
}

/* ---------- Alerts: filters and days ---------- */
.alert-filters { flex-wrap: wrap; margin-bottom: 4px; }
.alert-filters .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--surface2); color: var(--muted); font-size: 11px; line-height: 18px; text-align: center; }
.alert-filters .chip[aria-selected="true"] .count { background: rgba(255,255,255,.25); color: inherit; }
.alert-filters .chip-warn .count { background: var(--dry); color: #fff; }
.day-head { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.tag-link { border: 0; cursor: pointer; font: inherit; font-size: 11px; color: inherit; }
.tag-link:hover { text-decoration: underline; }
