/* ==========================================================================
   Nusa Farm UI — base layout + components
   Visual tokens live in theme.css.
   Breakpoints: 600 / 768 / 1000 / 1200
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: clip; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: var(--fs);
    line-height: 1.4;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
/* iOS WebKit keeps a native min-width on date inputs and ignores width:100%, so they
   overflow narrow panels; flatten them and center the value */
input:where([type=date], [type=datetime-local], [type=month], [type=time]) {
    -webkit-appearance: none;
    appearance: none;
    min-width: 0;
    max-width: 100%;
    text-align: center;
}
input:where([type=date], [type=datetime-local], [type=month], [type=time])::-webkit-date-and-time-value {
    text-align: center;
    min-height: 1.2em;
}
button { cursor: pointer; }
h1, h2, h3, h4, p, dl, dd, ul { margin: 0; padding: 0; }
ul { list-style: none; }
small { font-size: .78em; }
[hidden] { display: none !important; }

.ic {
    width: 18px; height: 18px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
}
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.num small { color: var(--text-2); font-weight: 400; }

.tone-ok   { color: var(--ok) !important; }
.tone-warn { color: var(--warn) !important; }
.tone-bad  { color: var(--bad) !important; }
.tone-muted{ color: var(--text-3) !important; }
.muted { color: var(--text-2); }
b { font-weight: 600; }

.dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-3); flex: none;
}

/* ── App shell ────────────────────────────────────────────────────────── */
.app { min-height: 100vh; }
.main-col { min-width: 0; }

.sidebar { display: none; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: var(--topbar-h);
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
}
.topbar-title { min-width: 0; display: flex; flex-direction: column; }
.topbar-title h1 { font-size: 1.15em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb { font-size: .72em; color: var(--text-3); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8em; color: var(--text-2); }
.live .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live-text { display: none; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.content {
    padding: 16px;
    max-width: 1440px;
    margin: 0 auto;
    display: flex; flex-direction: column; gap: var(--gap-lg);
}

/* ── Tab bar ──────────────────────────────────────────────────────────── */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--tabbar-bg);
    border-top: 1px solid var(--border);
}
.tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: .68em; color: var(--text-3);
    position: relative; min-width: 0;
}
.tab span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab .ic { width: 22px; height: 22px; }
.tab.is-active { color: var(--primary); }

/* ── Sheets ───────────────────────────────────────────────────────────── */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(0, 0, 0, .6);
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    max-height: 88vh; overflow: auto;
    background: var(--surface);
    border-top: 1px solid var(--border-strong);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateY(105%); transition: transform .25s ease;
}
.sheet.is-open { transform: none; }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.sheet-title { font-size: 1.05em; }
.sheet-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.menu-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px; }
.menu-group h3 { font-size: .72em; color: var(--text-3); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.menu-group a { display: block; padding: 7px 0; color: var(--text); border-bottom: 1px solid var(--border); font-size: .92em; }
.menu-logout { grid-column: 1 / -1; color: var(--bad); padding: 10px 0; }

/* ── Common blocks ────────────────────────────────────────────────────── */
.block { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.section-h {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: var(--fs-section); font-weight: 600; color: var(--section-color);
}
.section-h .ic { width: 16px; height: 16px; color: var(--primary); }
.section-h .count {
    font-size: .8em; font-weight: 600; padding: 1px 7px; border-radius: 99px;
    background: var(--surface-2); color: var(--text-2);
}
.section-note { font-weight: 400; font-size: .85em; color: var(--text-3); text-transform: none; letter-spacing: 0; }
.section-link { margin-left: auto; display: inline-flex; align-items: center; gap: 2px; font-size: .85em; font-weight: 500; color: var(--primary); text-transform: none; letter-spacing: 0; }
.section-link .ic { width: 14px; height: 14px; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.tag {
    display: inline-block; font-size: .72em; font-weight: 600; padding: 2px 7px;
    border-radius: var(--radius-xs); background: var(--primary-soft); color: var(--primary);
}
.tag-muted { background: var(--surface-2); color: var(--text-2); }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: .78em; color: var(--text-2); white-space: nowrap; }
.conn.is-online .dot { background: var(--ok); }
.conn.is-offline { color: var(--bad); }
.conn.is-offline .dot { background: var(--bad); }

.spark { display: block; width: 100%; height: 28px; overflow: visible; }
.spark polyline { fill: none; stroke: currentColor; stroke-width: var(--spark-w); vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.spark.tone-ok { color: var(--ok); } .spark.tone-warn { color: var(--warn); } .spark.tone-bad { color: var(--bad); } .spark.tone-muted { color: var(--text-3); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 8px 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text);
    font-size: .85em; font-weight: 500; white-space: nowrap;
}
.btn .ic { width: 16px; height: 16px; color: var(--text-2); }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary .ic { color: var(--on-primary); }
.pill-btn {
    padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface); color: var(--text-2); font-size: .78em; font-weight: 700;
}
.pill-btn.is-active { color: var(--primary); border-color: var(--primary); }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); font-size: .85em; }
.banner.tone-bad { background: var(--bad-soft); color: var(--text) !important; border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.banner .ic { color: var(--bad); }

/* ==========================================================================
   DASHBOARD
   ========================================================================== */
.hero { display: flex; flex-direction: column; gap: 12px; }
.eyebrow { font-size: .78em; color: var(--text-3); }
.hero-h { font-size: 1.5em; font-weight: 600; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-stats li {
    display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.hero-stats .num { font-size: 1.35em; font-weight: 600; }
.hero-stats .lbl { font-size: .72em; color: var(--text-3); }

.dash-layout { display: grid; gap: var(--gap-lg); }
.dash-main, .dash-side { display: flex; flex-direction: column; gap: var(--gap-lg); min-width: 0; }

.alert-list { display: flex; flex-direction: column; gap: 6px; }
.alert {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
    padding: 10px 8px 10px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    border-left: 3px solid var(--text-3);
}
.alert.tone-bad  { border-left-color: var(--bad); color: var(--text) !important; }
.alert.tone-warn { border-left-color: var(--warn); color: var(--text) !important; }
.alert.tone-bad > .ic  { color: var(--bad); }
.alert.tone-warn > .ic { color: var(--warn); }
.alert-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alert-text strong { font-size: .92em; font-weight: 600; }
.alert-text > span { font-size: .8em; color: var(--text-2); }
.alert-go { display: grid; place-items: center; width: 32px; height: 32px; color: var(--text-3); border-radius: var(--radius-sm); }
.alert-go:hover { color: var(--primary); background: var(--surface-2); }

.farm-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
.farm-card {
    display: flex; flex-direction: column; gap: 12px; padding: 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color .15s, transform .15s;
    container-type: inline-size;
}
.farm-card:hover { border-color: var(--primary); }
.farm-card.is-warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.farm-card.is-offline { border-style: dashed; }
.farm-card.is-offline .fc-metrics, .farm-card.is-offline .fc-climate { opacity: .55; }

.fc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fc-id { display: flex; align-items: center; gap: 8px; }
.fc-name { font-size: 1.05em; font-weight: 700; white-space: nowrap; }
.fc-id { flex-wrap: wrap; }
.fc-climate { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; }
.fc-temp { font-size: 2em; font-weight: 600; line-height: 1; grid-row: 1 / 3; }
.fc-temp small { font-size: .45em; }
.fc-climate-sub { display: flex; gap: 10px; font-size: .78em; color: var(--text-2); }
.fc-climate .spark { height: 22px; }
.is-stale { color: var(--text-3) !important; text-decoration: line-through; text-decoration-thickness: 1px; }

.fc-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.fc-metrics .m { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fc-metrics dt { font-size: .7em; color: var(--text-3); }
.fc-metrics dd { font-size: 1.1em; font-weight: 600; }
.fc-metrics .sub { font-size: .7em; color: var(--text-2); white-space: nowrap; }
@container (min-width: 440px) { .fc-metrics { grid-template-columns: repeat(4, 1fr); } }

/* actual vs standard bar: scale 0..120% of std, tick at std (83.3%) */
.vs-bar { position: relative; display: block; height: 4px; margin-top: 4px; background: var(--surface-2); border-radius: 2px; }
.vs-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: var(--v); background: var(--primary); border-radius: 2px; }
.vs-bar::after { content: ""; position: absolute; left: 83.3%; top: -3px; bottom: -3px; width: 2px; background: var(--text); }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px;
    padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.action .ic { grid-row: 1 / 3; width: 22px; height: 22px; color: var(--primary); align-self: center; }
.action span { font-weight: 600; font-size: .9em; }
.action small { color: var(--text-3); font-size: .72em; }
.action:hover { border-color: var(--primary); }

.stat-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stat-list li { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.stat-list li:last-child { border-bottom: 0; }
.stat-list .lbl { font-size: .85em; color: var(--text-2); }
.stat-list .num { grid-row: 1 / 3; grid-column: 2; align-self: center; font-size: 1.15em; font-weight: 600; }
.stat-list .sub { font-size: .72em; color: var(--text-3); }

/* ==========================================================================
   GLOBAL HISTORY
   ========================================================================== */
.toolbar {
    position: sticky; top: var(--topbar-h); z-index: 15;
    display: flex; flex-direction: column; gap: 10px;
    margin: -16px -16px 0; padding: 12px 16px;
    background: var(--topbar-bg); border-bottom: 1px solid var(--border);
}
.datepicker { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: center; }
.dp-center {
    position: relative; display: flex; align-items: center; justify-content: center; gap: 10px;
    height: 40px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.dp-center .ic { color: var(--primary); }
.dp-text { display: flex; flex-direction: column; line-height: 1.1; }
.dp-text strong { font-size: .95em; }
.dp-text small { color: var(--text-3); font-size: .7em; }
.dp-center input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px; flex: none;
    padding: 6px 12px; border-radius: var(--radius-pill);
    border: 1px solid var(--primary); background: var(--primary-soft); color: var(--text);
    font-size: .8em; font-weight: 600;
}
.chip .dot { background: var(--primary); }
.chip small { color: var(--text-3); font-weight: 400; }
.chip.is-off { border-color: var(--border); background: transparent; color: var(--text-3); }
.chip.is-off .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-3); }

.kpi-hero { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi {
    display: flex; flex-direction: column; gap: 2px; padding: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); min-width: 0;
}
.kpi-lbl { font-size: .72em; color: var(--text-3); }
.kpi-val { font-size: 1.55em; font-weight: 600; line-height: 1.15; }
.kpi-val small { font-size: .55em; }
.kpi-delta { font-size: .75em; color: var(--text-2); }
.kpi .spark { margin-top: 6px; height: 24px; }

.kpi-groups { display: grid; gap: var(--gap-lg); grid-template-columns: 1fr; }
.group { padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.kv > div { display: grid; grid-template-columns: 1fr auto; align-items: baseline; column-gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.kv > div:last-child { border-bottom: 0; padding-bottom: 0; }
.kv dt { font-size: .85em; color: var(--text-2); }
.kv dd { text-align: right; font-weight: 600; }
.kv dd.std { grid-column: 2; font-size: .72em; font-weight: 400; color: var(--text-3); font-family: var(--font-num); }

.table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.cmp { width: 100%; min-width: 620px; border-collapse: separate; border-spacing: 0; font-size: .88em; }
.cmp th, .cmp td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; white-space: nowrap; }
.cmp thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; vertical-align: bottom; }
.cmp .rowh {
    position: sticky; left: 0; z-index: 1;
    text-align: left; font-weight: 500; color: var(--text-2);
    background: var(--surface); border-right: 1px solid var(--border);
}
.cmp thead .rowh { background: var(--surface-2); z-index: 2; }
.cmp td small { display: block; font-size: .78em; color: var(--text-3); font-weight: 400; }
.cmp tr.grp th {
    text-align: left; font-size: .7em; letter-spacing: .08em; text-transform: uppercase;
    color: var(--primary); background: var(--surface); padding-top: 14px; border-right: 0;
}
.cmp td.is-best  { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.cmp td.is-worst { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.cmp tbody tr:hover td { background: var(--surface-2); }
.th-farm { display: flex; align-items: center; justify-content: flex-end; gap: 6px; color: var(--text); }
.th-farm .dot.is-off { background: var(--bad); }
.cycle-select {
    margin-top: 4px; padding: 3px 6px; border-radius: var(--radius-xs);
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: .82em;
}

/* ==========================================================================
   CONTROL CENTER
   ========================================================================== */
.overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ov { display: flex; flex-direction: column; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ov.is-warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }
.ov.is-warn .ov-val { color: var(--warn); }
.ov-lbl { font-size: .66em; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-val { font-size: 1.3em; font-weight: 600; }

.segmented {
    position: sticky; top: var(--topbar-h); z-index: 15;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
    margin: 0 -16px; padding: 8px 16px;
    background: var(--topbar-bg); border-bottom: 1px solid var(--border);
}
.seg {
    display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
    padding: 7px 4px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2); font-size: .82em; font-weight: 600;
}
.seg small { font-weight: 400; color: var(--text-3); }
.seg.is-active { border-color: var(--primary); color: var(--text); background: var(--primary-soft); }
.seg .dot.is-on { background: var(--ok); } .seg .dot.is-off { background: var(--bad); }

.cc-grid { display: grid; gap: var(--gap-lg); }
.cc-farm {
    display: none; flex-direction: column; gap: 14px; padding: 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    scroll-margin-top: calc(var(--topbar-h) + 60px);
}
.cc-farm.is-active { display: flex; }
.cc-farm.is-offline { border-style: dashed; }
.cc-farm.is-offline > :not(.cc-head):not(.banner):not(.cc-actions) { opacity: .5; }
.cc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.cc-climate { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.reading { display: flex; flex-direction: column; gap: 2px; }
.r-lbl { display: flex; align-items: center; gap: 6px; font-size: .75em; color: var(--text-3); }
.r-lbl .ic { width: 14px; height: 14px; }
.r-val { font-size: 2.4em; font-weight: 600; line-height: 1.05; }
.r-val small { font-size: .42em; }
.r-sub { font-size: .75em; color: var(--text-2); }

.band { grid-column: 1 / -1; padding-top: 4px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 8px; }
.band-end { font-size: .66em; color: var(--text-3); white-space: nowrap; }
.band-track {
    position: relative; height: 10px; border-radius: 5px; min-width: 0;
    background: linear-gradient(to right,
        var(--cold) 0 var(--heat),
        var(--ok) var(--heat) var(--cool),
        var(--warn) var(--cool) 88%,
        var(--bad) 88% 100%);
    opacity: .9;
}
.band-mark {
    position: absolute; top: -5px; left: var(--mark); width: 4px; height: 20px; margin-left: -2px;
    background: var(--text); border-radius: 2px; box-shadow: 0 0 0 2px var(--surface);
}
/* thresholds grow away from the ok zone so they never collide;
   each box spans track edge → tick but never narrower than its text, so labels stay inside the track */
.band-scale { grid-column: 2; position: relative; height: 16px; margin-top: 6px; font-size: .66em; color: var(--text-3); }
.band-scale span { position: absolute; white-space: nowrap; min-width: max-content; }
.band-scale span:nth-child(1) { left: 0; width: var(--heat); text-align: right; }
.band-scale span:nth-child(2) { right: 0; width: calc(100% - var(--cool)); }

.st-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.st-tile { display: flex; flex-direction: column; gap: 4px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.st-top { display: flex; align-items: center; gap: 6px; }
.st-top .ic { width: 15px; height: 15px; color: var(--text-3); }
.st-lbl { font-size: .75em; color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .st-top { flex-wrap: wrap; } .st-lbl { overflow: visible; } }
.st-state { font-size: .68em; font-weight: 700; padding: 1px 6px; border-radius: var(--radius-xs); background: var(--surface); color: var(--text-3); }
.st-tile.is-on { border-color: color-mix(in srgb, var(--ok) 50%, var(--border)); }
.st-tile.is-on .st-state { background: var(--ok); color: var(--on-primary); }
.st-heat.is-on { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }
.st-heat.is-on .st-state { background: var(--warn); }
.st-heat.is-on .ic { color: var(--warn); }
.st-cool.is-on .ic { color: var(--cold); }
.st-cool.is-on { border-color: color-mix(in srgb, var(--cold) 60%, var(--border)); }
.st-cool.is-on .st-state { background: var(--cold); }
.st-alarm.is-on .ic { color: var(--ok); }
.st-inv-val { font-size: 1.5em; font-weight: 700; line-height: 1; }
.st-inv-val small { font-size: .55em; color: var(--text-3); margin-left: 1px; }
.st-inv-bar { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.st-inv-bar i { display: block; height: 100%; width: var(--p); background: var(--text-3); }
.st-inv.is-on { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.st-inv.is-on .st-state, .st-inv.is-on .st-inv-bar i { background: var(--primary); }
.st-inv.is-on .ic, .st-inv.is-on .st-inv-val { color: var(--primary); }
.st-tile.is-unknown .st-state { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }
.st-th { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: .78em; }
.st-th .adj { color: var(--primary); }
.st-last { font-size: .68em; color: var(--text-3); }

.cc-sub { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.sub-h { display: flex; align-items: center; gap: 8px; font-size: .8em; font-weight: 600; color: var(--text-2); }
.sub-note { font-weight: 400; color: var(--text-3); font-size: .95em; }

.sensor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.sensor {
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "id age" "t t" "h h";
    padding: 7px 8px; border-radius: var(--radius-sm);
    background: var(--tone-bg, var(--surface-2)); border: 1px solid var(--tone-bd, var(--border));
}
.sensor .s-id { grid-area: id; font-size: .66em; color: var(--text-3); font-weight: 700; }
.sensor .s-age { grid-area: age; font-size: .62em; color: var(--text-3); }
.sensor .s-t { grid-area: t; font-size: 1.05em; font-weight: 600; color: var(--tone-fg, var(--text)); }
.sensor .s-h { grid-area: h; font-size: .72em; color: var(--text-2); }
.sensor.is-outside { --tone-bg: var(--surface); --tone-bd: var(--border-strong); border-style: dotted; }
.sensor.is-old { --tone-bg: color-mix(in srgb, var(--warn) 14%, var(--surface)); --tone-bd: color-mix(in srgb, var(--warn) 40%, transparent); }
.sensor.is-old .s-age { color: var(--warn); }
.sensor.is-inactive { --tone-bg: var(--surface); --tone-bd: var(--border-strong); opacity: .45; border-style: dashed; }

.fan-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px; }
.fan {
    display: flex; flex-direction: column; align-items: center; padding: 4px 0;
    border-radius: var(--radius-xs); border: 1px solid var(--border); background: var(--surface-2);
    line-height: 1.1;
}
.fan b { font-size: .8em; }
.fan small { font-size: .58em; font-weight: 700; color: var(--text-3); }
.fan.is-on { border-color: color-mix(in srgb, var(--ok) 50%, transparent); background: var(--ok-soft); }
.fan.is-on small { color: var(--ok); }
.fan.is-int { border-color: color-mix(in srgb, var(--primary) 50%, transparent); background: var(--primary-soft); }
.fan.is-int small { color: var(--primary); }

.vent { display: flex; flex-direction: column; gap: 4px; }
.vent-top { display: flex; justify-content: space-between; font-size: .75em; color: var(--text-2); }
.vent-bar { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; }
.vent-fill { position: absolute; left: 0; top: 0; bottom: 0; width: var(--v); border-radius: 4px; background: currentColor; }
.vent-req { position: absolute; left: var(--req); top: -3px; bottom: -3px; width: 2px; background: var(--text); }
.vent-nums { display: flex; justify-content: space-between; font-size: .68em; color: var(--text-3); }

.timing { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.timing > div { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.timing dt { font-size: .68em; color: var(--text-3); font-family: var(--font-ui); }
.timing dd { font-size: .82em; }

.et summary { list-style: none; cursor: pointer; }
.et summary::-webkit-details-marker { display: none; }
.et .chev { margin-left: auto; width: 16px; height: 16px; transition: transform .2s; }
.et[open] .chev { transform: rotate(180deg); }
.et-inline { font-weight: 400; display: inline-flex; gap: 6px; align-items: baseline; }
.et-inline b { color: var(--text); font-family: var(--font-num); }
.et-status { font-size: .9em; }
.et-status.tone-ok { color: var(--ok); } .et-status.tone-warn { color: var(--warn); } .et-status.tone-bad { color: var(--bad); }
.et-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.et-form label, .form label { display: flex; flex-direction: column; gap: 4px; font-size: .7em; color: var(--text-3); }
.et-form input, .form input {
    width: 100%; padding: 8px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
    font-family: var(--font-num); font-size: 1.25em; text-align: center;
}
.et-form input:focus, .form input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.cc-actions { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.btn-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.btn-row .btn { padding: 8px 4px; font-size: .75em; flex-direction: column; gap: 3px; min-height: 52px; }
.btn-row .btn .ic { width: 18px; height: 18px; }

/* climate sheet form */
.form fieldset { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form legend { grid-column: 1 / -1; font-size: .72em; text-transform: uppercase; letter-spacing: .08em; color: var(--primary); font-weight: 700; margin-bottom: 8px; }
.form label { position: relative; font-size: .78em; }
.form label small { position: absolute; right: 10px; bottom: 11px; color: var(--text-3); pointer-events: none; }
.form input { text-align: left; padding-right: 64px; }
.form-diff { display: flex; gap: 8px; align-items: center; font-size: .78em; color: var(--text-2); padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.form-diff .ic { color: var(--warn); width: 16px; height: 16px; }
.sheet-actions { position: sticky; bottom: 0; display: grid; grid-template-columns: 1fr 2fr; gap: 8px; padding: 12px 0 4px; background: var(--surface); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 600px) {
    .content { padding: 20px; }
    .toolbar { margin: -20px -20px 0; padding: 12px 20px; flex-direction: row; align-items: center; }
    .toolbar .chips { margin: 0; padding: 0; }
    .segmented { margin: 0 -20px; padding: 8px 20px; }
    .live-text { display: inline; }
    .farm-grid { grid-template-columns: 1fr 1fr; }
    .kpi-hero { grid-template-columns: repeat(3, 1fr); }
    .menu-groups { grid-template-columns: repeat(3, 1fr); }
    .hero { flex-direction: row; align-items: flex-end; justify-content: space-between; }
    .hero-stats { min-width: 380px; }
}

@media (min-width: 768px) {
    .sheet {
        left: 50%; right: auto; bottom: auto; top: 50%; width: 560px;
        border-radius: var(--radius-lg); border: 1px solid var(--border-strong);
        transform: translate(-50%, -46%); opacity: 0; pointer-events: none;
        transition: transform .2s ease, opacity .2s;
    }
    .sheet.is-open { transform: translate(-50%, -50%); opacity: 1; pointer-events: auto; }
    .sheet-grip { display: none; }
    #sheet-more { width: 720px; }
    .kpi-groups { grid-template-columns: 1fr 1fr; }
    .btn-row .btn { flex-direction: row; min-height: 40px; font-size: .8em; }
}

@media (min-width: 1000px) {
    body { padding-bottom: 0; }
    .tabbar { display: none; }
    .app { display: grid; grid-template-columns: 232px 1fr; }
    .sidebar {
        display: flex; flex-direction: column;
        position: sticky; top: 0; height: 100vh;
        background: var(--sidebar-bg); border-right: 1px solid var(--border);
    }
    .brand { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border); }
    .brand-mark {
        display: grid; place-items: center; width: 34px; height: 34px;
        border-radius: var(--radius-sm); background: var(--primary); color: var(--on-primary);
        font-weight: 800; font-size: .85em;
    }
    .brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.15; }
    .brand-text small { font-weight: 400; color: var(--text-3); font-size: .72em; }
    .side-nav { flex: 1; overflow-y: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 1px; }
    .side-link {
        display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
        font-size: .86em; color: var(--text-2);
    }
    .side-link .ic { width: 17px; height: 17px; }
    .side-link:hover { background: var(--surface-2); color: var(--text); }
    .side-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
    .side-group { margin: 14px 10px 4px; font-size: .66em; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3); }
    .side-user { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: .85em; }
    .avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); font-weight: 700; }
    .side-user-text { display: flex; flex-direction: column; flex: 1; line-height: 1.15; }
    .side-user-text small { color: var(--text-3); }
    .side-logout { font-size: .8em; color: var(--text-3); }
    .side-logout:hover { color: var(--bad); }

    .content { padding: 24px 28px; }
    .toolbar { margin: -24px -28px 0; padding: 12px 28px; }
    .segmented { margin: 0 -28px; padding: 8px 28px; }
    .topbar { padding: 0 28px; }
    .kpi-hero { grid-template-columns: repeat(6, 1fr); }
}

@media (min-width: 1200px) {
    .dash-layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
    .dash-side { position: sticky; top: calc(var(--topbar-h) + 24px); }
    .kpi-groups { grid-template-columns: repeat(4, 1fr); }

    /* control center: all farms visible, no tabs */
    .segmented { display: none; }
    .cc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
    .cc-farm { display: flex; }
}

/* ── Print: page content only ─────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .tabbar, .sheet, .sheet-backdrop { display: none !important; }
    body { padding: 0 !important; }
    .app { display: block !important; }
    .content { max-width: none; padding: 0; }
}
