/* =========================================================
   KHU VƯỜN THÔNG MINH - DASHBOARD
   ========================================================= */
:root {
    --bg: #f3f6f1;
    --bg-accent: radial-gradient(1200px 600px at 10% -10%, #dcfce7 0%, transparent 60%),
                 radial-gradient(900px 500px at 110% 0%, #e0f2fe 0%, transparent 55%);
    --surface: #ffffff;
    --surface-2: #f7faf6;
    --border: #e3e9e1;
    --text: #13201a;
    --muted: #64748b;
    --brand: #16a34a;
    --brand-strong: #15803d;
    --brand-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --info: #0284c7;
    --info-soft: #e0f2fe;
    --temp: #ea580c;
    --temp-soft: #ffedd5;
    --humi: #0891b2;
    --humi-soft: #cffafe;
    --soil: #a16207;
    --soil-soft: #fef9c3;
    --violet: #7c3aed;
    --violet-soft: #ede9fe;
    --shadow: 0 1px 2px rgba(16, 24, 20, .04), 0 8px 24px rgba(16, 24, 20, .06);
    --radius: 18px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1210;
        --bg-accent: radial-gradient(1200px 600px at 10% -10%, rgba(22, 163, 74, .18) 0%, transparent 60%),
                     radial-gradient(900px 500px at 110% 0%, rgba(2, 132, 199, .14) 0%, transparent 55%);
        --surface: #121c18;
        --surface-2: #17231e;
        --border: #23332c;
        --text: #e6efe9;
        --muted: #8ea39a;
        --brand: #22c55e;
        --brand-strong: #4ade80;
        --brand-soft: rgba(34, 197, 94, .14);
        --danger: #f87171;
        --danger-soft: rgba(248, 113, 113, .14);
        --warn: #fbbf24;
        --warn-soft: rgba(251, 191, 36, .14);
        --info: #38bdf8;
        --info-soft: rgba(56, 189, 248, .14);
        --temp: #fb923c;
        --temp-soft: rgba(251, 146, 60, .14);
        --humi: #22d3ee;
        --humi-soft: rgba(34, 211, 238, .14);
        --soil: #facc15;
        --soil-soft: rgba(250, 204, 21, .12);
        --violet: #a78bfa;
        --violet-soft: rgba(167, 139, 250, .14);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Be Vietnam Pro', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-accent), var(--bg);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

svg {
    width: 20px; height: 20px;
    fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
    flex-shrink: 0;
}

.app {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 20px 32px;
}

.muted { color: var(--muted); font-size: 13.5px; }

/* ===== HEADER ===== */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand-logo {
    width: 52px; height: 52px;
    border-radius: 16px;
    display: grid; place-items: center;
    background: linear-gradient(145deg, #22c55e, #15803d);
    color: #fff;
    box-shadow: 0 8px 20px rgba(22, 163, 74, .35);
    flex-shrink: 0;
}
.brand-logo svg { width: 28px; height: 28px; stroke-width: 2.2; }

h1 {
    font-size: clamp(22px, 3vw, 28px);
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.15;
}
.brand-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 13px; font-weight: 600;
    color: var(--muted);
    box-shadow: var(--shadow);
}
.chip .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #94a3b8;
}
.chip.online { color: var(--brand-strong); }
.chip.online .dot { background: var(--brand); box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: pulse 2s infinite; }
.chip.warn { color: var(--warn); }
.chip.warn .dot { background: var(--warn); }
.chip.offline { color: var(--danger); }
.chip.offline .dot { background: var(--danger); }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
    70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ===== LAYOUT ===== */
.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

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

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.panel-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }

/* ===== CAMERA ===== */
.live {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 12px; font-weight: 800; letter-spacing: .08em;
}
.live i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite; }
.live.off { background: var(--surface-2); color: var(--muted); }
.live.off i { animation: none; }
@keyframes blink { 50% { opacity: .25; } }

.cam-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.shot-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit; font-size: 13.5px; font-weight: 700;
    cursor: pointer;
    transition: background .2s, border-color .2s, transform .1s;
}
.shot-btn svg { width: 17px; height: 17px; }
.shot-btn:hover { border-color: var(--brand); color: var(--brand-strong); }
.shot-btn:active { transform: scale(.96); }
.shot-btn:disabled { opacity: .6; cursor: wait; }
.shot-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.shot-btn em {
    font-style: normal; font-size: 12px;
    padding: 0 7px; border-radius: 999px;
    background: var(--brand-soft); color: var(--brand-strong);
}
.shot-btn em:empty { display: none; }

.ai-btn { color: var(--brand-strong); border-color: var(--brand); background: var(--brand-soft); }
.ai-btn.off { color: var(--muted); border-color: var(--border); background: var(--surface-2); }
.ai-verdict.paused { background: var(--surface-2); color: var(--muted); }
.ai-verdict.paused svg { display: none; }

.camera-frame.flash::after {
    content: ""; position: absolute; inset: 0;
    background: #fff;
    animation: flash .35s ease-out forwards;
    pointer-events: none;
}
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

.camera-frame {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    background: #0b1210;
    min-height: 180px;          /* ảnh đã cắt theo lòng khay -> khung tự theo tỉ lệ ảnh */
    border: 1px solid var(--border);
}
.camera-frame img {
    width: 100%; height: auto;
    object-fit: contain;
    display: block;
}

.ai-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: 12px;
    margin-top: 14px;
}

.ai-stat {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: background .25s, border-color .25s;
}
.ai-icon { font-size: 24px; line-height: 1; }
.ai-label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.ai-stat strong { font-size: 22px; font-weight: 800; line-height: 1.1; }
.ai-stat.alert { background: var(--danger-soft); border-color: transparent; }
.ai-stat.alert strong { color: var(--danger); }
.ai-stat.warn { background: var(--warn-soft); border-color: transparent; }
.ai-stat.warn strong { color: var(--warn); }

.ai-verdict {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    border-radius: 14px;
    font-weight: 700; font-size: 14.5px;
}
.ai-verdict svg { width: 22px; height: 22px; stroke-width: 2.6; }
.ai-verdict.ok { background: var(--brand-soft); color: var(--brand-strong); }
.ai-verdict.warn { background: var(--warn-soft); color: var(--warn); }
.ai-verdict.danger { background: var(--danger-soft); color: var(--danger); animation: shake .5s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ===== SENSOR CARDS ===== */
.sensors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.metric {
    --c: var(--brand); --c-soft: var(--brand-soft);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    position: relative;
    overflow: hidden;
    transition: transform .2s ease, box-shadow .2s ease;
}
.metric:hover { transform: translateY(-2px); }
.metric.wide { grid-column: 1 / -1; }

.metric-temp  { --c: var(--temp);   --c-soft: var(--temp-soft); }
.metric-humi  { --c: var(--humi);   --c-soft: var(--humi-soft); }
.metric-soil  { --c: var(--soil);   --c-soft: var(--soil-soft); }
.metric-rain  { --c: var(--info);   --c-soft: var(--info-soft); }
.metric-light { --c: var(--warn);   --c-soft: var(--warn-soft); }
.metric-light.night { --c: var(--violet); --c-soft: var(--violet-soft); }
.metric-rain.active { background: var(--info-soft); border-color: transparent; }

.metric-top { display: flex; align-items: center; gap: 10px; }
.metric-icon {
    width: 36px; height: 36px;
    border-radius: 11px;
    display: grid; place-items: center;
    background: var(--c-soft);
    color: var(--c);
}
.metric-name { font-size: 13.5px; font-weight: 600; color: var(--muted); }

.metric-value {
    margin-top: 12px;
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -.03em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.metric-value small { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }

.metric-text { margin-top: 14px; font-size: 17px; font-weight: 700; }

/* Độ ẩm đất */
.soil-state {
    margin-left: auto;
    font-size: 12px; font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
}
.soil-state[data-level="dry"] { background: var(--danger-soft); color: var(--danger); }
.soil-state[data-level="mid"] { background: var(--warn-soft); color: var(--warn); }
.soil-state[data-level="wet"] { background: var(--brand-soft); color: var(--brand-strong); }

.soil-bar {
    position: relative;
    height: 10px;
    margin-top: 14px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}
.soil-fill {
    height: 100%; width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #f59e0b, #22c55e);
    transition: width .6s ease;
}
.soil-fill[data-level="dry"] { background: linear-gradient(90deg, #ef4444, #f59e0b); }
.soil-fill[data-level="wet"] { background: linear-gradient(90deg, #22c55e, #0ea5e9); }
.soil-bar .mark {
    position: absolute; top: -1px; bottom: -1px;
    width: 2px;
    background: var(--text);
    opacity: .25;
}
.soil-legend {
    display: flex; justify-content: space-between;
    margin-top: 6px;
    font-size: 11.5px; color: var(--muted);
}

/* ===== PUMP ===== */
.pump-state {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 14px 6px 6px;
    border-radius: 999px;
    font-weight: 700; font-size: 14px;
    white-space: nowrap;
}
.pump-ring {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
}
.pump-ring svg { width: 16px; height: 16px; }
.pump-state.off { background: var(--surface-2); color: var(--muted); }
.pump-state.off .pump-ring { background: var(--border); }
.pump-state.on { background: var(--info-soft); color: var(--info); }
.pump-state.on .pump-ring { background: var(--info); color: #fff; animation: drip 1.4s ease-in-out infinite; }
@keyframes drip { 50% { transform: translateY(2px) scale(.94); } }

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 6px;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.seg {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    padding: 12px 8px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font: inherit; font-size: 14px; font-weight: 700;
    cursor: pointer;
    transition: background .2s, color .2s, box-shadow .2s, transform .1s;
}
.seg svg { width: 17px; height: 17px; }
.seg:hover { color: var(--text); background: var(--surface); }
.seg:active { transform: scale(.97); }
.seg:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
#btn_auto.active { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(22, 163, 74, .3); }
#btn_on.active   { background: var(--info); color: #fff; box-shadow: 0 6px 16px rgba(2, 132, 199, .3); }
#btn_off.active  { background: var(--danger); color: #fff; box-shadow: 0 6px 16px rgba(220, 38, 38, .3); }

/* Trạm cảm biến mất kết nối -> làm mờ số liệu cũ */
.layout.stale .metric { opacity: .55; filter: grayscale(.6); }
.layout.stale .pump-state { opacity: .55; }
.layout.stale #mode_desc { color: var(--danger); font-weight: 600; }

/* ===== FOOTER ===== */
.footer {
    margin-top: 22px;
    display: flex; justify-content: space-between; align-items: center;
    gap: 10px; flex-wrap: wrap;
    padding: 14px 18px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--muted);
}
.footer a { color: var(--brand-strong); font-weight: 700; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* ===== TOAST ===== */
.toast {
    position: fixed;
    left: 50%; bottom: 24px;
    transform: translate(-50%, 20px);
    padding: 11px 18px;
    border-radius: 12px;
    background: #13201a;
    color: #fff;
    font-size: 14px; font-weight: 600;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== BAY HƠI NƯỚC ===== */
.evap-panel { margin-top: 20px; }
.evap-head { flex-wrap: wrap; }

.range {
    display: inline-flex;
    padding: 4px;
    gap: 2px;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.range button {
    border: 0; background: transparent;
    padding: 6px 12px;
    border-radius: 8px;
    font: inherit; font-size: 13px; font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}
.range button:hover { color: var(--text); }
.range button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.range button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi {
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    min-width: 0;
}
.kpi-label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.kpi strong { font-size: 24px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi small { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.kpi-accent { background: var(--humi-soft); border-color: transparent; }

.charts { position: relative; }
.chart-block + .chart-block { margin-top: 10px; }
.chart-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.chart-title span { color: var(--muted); font-weight: 500; }
.chart { display: block; width: 100%; height: 170px; touch-action: pan-y; overflow: visible; }
.charts.is-empty .chart { opacity: .35; }

.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-opacity: .5; stroke-width: 1; }
.chart .thr { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: .8; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; opacity: .14; }
.chart .band-pump { fill: var(--info); opacity: .2; }
.chart .band-rain { fill: var(--muted); opacity: .14; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }

.s-rate { --s: var(--humi); }
.s-soil { --s: var(--soil); }
.chart .line.s-rate, .chart .line.s-soil { stroke: var(--s); }
.chart .area.s-rate, .chart .area.s-soil,
.chart .dot.s-rate, .chart .dot.s-soil,
.chart .pt.s-rate, .chart .pt.s-soil { fill: var(--s); }

.chart-legend {
    display: flex; flex-wrap: wrap; gap: 6px 16px;
    margin-top: 10px;
    font-size: 12px; color: var(--muted);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.lg-pump { background: var(--info); opacity: .3; }
.lg-rain { background: var(--muted); opacity: .35; }
.lg-thr { height: 0; border-top: 2px dashed var(--muted); border-radius: 0; }

.chart-tip {
    position: absolute;
    z-index: 5;
    min-width: 170px;
    padding: 9px 11px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
    font-size: 12.5px;
    line-height: 1.55;
    pointer-events: none;
}
.chart-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--s); }

.chart-empty {
    position: absolute; inset: 40px 12% auto;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px dashed var(--border);
    color: var(--muted);
    font-size: 13px; text-align: center;
}

.table-view { margin-top: 14px; font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.table-wrap { max-height: 260px; overflow: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: 10px; }
.table-view table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table-view th { position: sticky; top: 0; background: var(--surface-2); font-weight: 700; font-size: 12px; color: var(--muted); }

/* ===== RESPONSIVE ===== */
html, body { max-width: 100%; overflow-x: hidden; }
.layout > *, .side > *, .panel { min-width: 0; }

@media (max-width: 980px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.sensors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.camera-frame img { max-width: 100%; }
.chart .cross, .chart .dot { visibility: hidden; }
.chart.hovering .cross, .chart.hovering .dot.on { visibility: visible; }

@media (max-width: 560px) {
    .app { padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
    .topbar { margin-bottom: 14px; gap: 10px; }
    .brand { gap: 10px; }
    .brand-logo { width: 40px; height: 40px; border-radius: 12px; }
    .brand-logo svg { width: 22px; height: 22px; }
    h1 { font-size: 20px; }
    .brand-sub { display: none; }
    .chips { width: 100%; gap: 6px; }
    .chip { padding: 5px 9px; font-size: 12px; box-shadow: none; }

    .layout, .side { gap: 12px; }
    .panel { padding: 14px; border-radius: 16px; }
    .panel-head { margin-bottom: 12px; flex-wrap: wrap; }
    .panel-head h2 { font-size: 16px; }
    .muted { font-size: 12.5px; }

    .cam-actions { width: 100%; justify-content: space-between; }
    .camera-frame { border-radius: 12px; }
    .ai-row { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
    .ai-stat { padding: 10px; gap: 8px; }
    .ai-icon { font-size: 20px; }
    .ai-stat strong { font-size: 19px; }
    .ai-verdict { grid-column: 1 / -1; padding: 10px 12px; font-size: 14px; }

    .sensors { gap: 10px; }
    .metric { padding: 12px; border-radius: 16px; }
    .metric-icon { width: 30px; height: 30px; border-radius: 9px; }
    .metric-icon svg { width: 17px; height: 17px; }
    .metric-name { font-size: 12.5px; }
    .metric-value { font-size: 28px; margin-top: 8px; }
    .metric-value small { font-size: 14px; }
    .metric-text { font-size: 15px; margin-top: 10px; }
    .metric:hover { transform: none; }

    .pump-state { padding: 4px 10px 4px 4px; font-size: 13px; }
    .pump-ring { width: 26px; height: 26px; }
    .seg { flex-direction: column; gap: 4px; font-size: 12.5px; padding: 10px 4px; }

    .evap-panel { margin-top: 12px; }
    .range { width: 100%; }
    .range button { flex: 1; padding: 7px 4px; font-size: 12.5px; }
    .kpis { gap: 8px; margin-bottom: 12px; }
    .kpi { padding: 10px 12px; }
    .kpi strong { font-size: 20px; }
    .chart { height: 150px; }
    .chart-empty { inset: 36px 4% auto; font-size: 12.5px; }
    .chart-tip { min-width: 150px; font-size: 12px; }

    .footer { flex-direction: column; align-items: flex-start; margin-top: 12px; padding: 12px 14px; font-size: 12.5px; }
    .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
    .ai-row { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 360px) {
    .ai-row { grid-template-columns: minmax(0, 1fr); }
    .sensors { grid-template-columns: minmax(0, 1fr); }
    .metric.wide { grid-column: auto; }
    .seg svg { display: none; }
}

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