/*!
 * Simulador de Aeração - Layout da aplicação (barra lateral, cabeçalho, palco e indicadores)
 * Desenvolvido por Guilherme Almeida Alamini
 */

:root {
    --bg: #0b1220;
    --surface-1: #0f1729;
    --surface-2: #141e33;
    --surface-3: #1b2742;
    --surface-4: #24324f;
    --border: rgba(148, 163, 184, .14);
    --border-strong: rgba(148, 163, 184, .28);
    --text: #e6edf7;
    --text-muted: #91a2bb;
    --text-faint: #64748b;
    --accent: #3b82f6;
    --accent-strong: #2563eb;
    --accent-soft: rgba(59, 130, 246, .16);
    --ok: #22c55e;
    --ok-soft: rgba(34, 197, 94, .14);
    --danger: #ef4444;
    --warn: #f59e0b;
    --radius: 10px;
    --radius-sm: 7px;
    --rail-w: 76px;
    --panel-w: 312px;
    --topbar-h: 58px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 var(--font);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.icon-sprite { display: none; }

.ico {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.ico.fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------------
 * Estrutura
 * ------------------------------------------------------------------ */
.app {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    height: 100vh;
}

.sidebar {
    display: flex;
    min-height: 0;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
}

.main {
    display: grid;
    grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 0;
}

/* ------------------------------------------------------------------
 * Trilho de navegação
 * ------------------------------------------------------------------ */
.rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: var(--rail-w);
    padding: 10px 0 12px;
    border-right: 1px solid var(--border);
}

.rail-brand {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: 10px;
    border-radius: 12px;
    background: linear-gradient(135deg, #3b82f6, #22c55e);
    color: #fff;
}
.rail-brand .ico { width: 24px; height: 24px; stroke-width: 2; }

.rail-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 64px;
    padding: 9px 0 7px;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--text-muted);
    font-size: 11px;
    transition: background .15s, color .15s;
}
.rail-item:hover { background: var(--surface-3); color: var(--text); }
.rail-item.active { background: var(--accent-soft); color: #9cc3ff; }
.rail-item.active::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 3px;
    background: var(--accent);
}
.rail-spacer { flex: 1; }

.badge {
    position: absolute;
    top: 4px;
    right: 10px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

/* ------------------------------------------------------------------
 * Painéis laterais (um por recurso)
 * ------------------------------------------------------------------ */
.panel-host {
    width: var(--panel-w);
    overflow-y: auto;
    background: var(--surface-2);
}
.app.panel-collapsed .panel-host { display: none; }

.side-panel { display: none; }
.side-panel.active { display: block; }

.side-panel-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 4px;
    height: var(--topbar-h);
    padding: 0 10px 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.side-panel-header h2 { flex: 1; font-size: 16px; font-weight: 600; }

.side-panel-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 20px 24px;
}
.side-panel-body h3 {
    margin-top: 4px;
    margin-bottom: -6px;
    color: var(--text-faint);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
}
.icon-button:hover { background: var(--surface-3); color: var(--text); }

.hint { color: var(--text-faint); font-size: 12.5px; }

/* Campos */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { color: var(--text-muted); font-size: 12.5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field select,
.field input,
.time-range input {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field select:focus,
.field input:focus,
.time-range input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.field select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 17px) 16px, calc(100% - 12px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
.field select option { background: var(--surface-2); }

.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 34px; }
.input-unit i {
    position: absolute;
    top: 0;
    right: 12px;
    color: var(--text-faint);
    font-style: normal;
    line-height: 38px;
    pointer-events: none;
}

.time-range { display: flex; align-items: center; gap: 10px; color: var(--text-muted); }
.time-range input { width: 84px; text-align: center; }

/* Grupo de botões / opções */
.segmented {
    display: flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-1);
}
.segmented > button,
.segmented > label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.segmented > button .ico { width: 17px; height: 17px; }
.segmented > button:hover,
.segmented > label:hover { background: var(--surface-3); color: var(--text); }
.segmented > button.active { background: var(--accent); color: #fff; }
.segmented.radios label { position: relative; }   /* o input escondido fica dentro do rótulo (não estica a página) */
.segmented.radios input { position: absolute; opacity: 0; pointer-events: none; }
.segmented.radios label:has(input:checked) { background: var(--accent); color: #fff; }

/* Regras de aeração (painel mais largo para o editor de condições) */
.app[data-panel="rules"] .panel-host { width: 440px; }
.rules-list-view { display: flex; flex-direction: column; gap: 14px; }
.rules-list-view[hidden], .rule-editor[hidden] { display: none; }
.rules-vars {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 3px 10px;
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-muted);
    font-size: 12px;
}
.rules-vars dt { color: var(--text); font-weight: 700; }
.rules-vars dd { margin: 0; }
.rules-list { display: flex; flex-direction: column; gap: 10px; }
.rule-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-1);
}
.rule-card.in-use { border-color: rgba(59, 130, 246, .55); box-shadow: inset 3px 0 0 var(--accent); }
.rule-card-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rule-card-head b { flex: 1; min-width: 0; font-size: 14px; }
.tag { padding: 1px 8px; border-radius: 10px; background: var(--surface-4); color: var(--text-muted); font-size: 11px; font-weight: 600; }
.tag-active { background: var(--accent); color: #fff; }
.rule-formula { display: flex; gap: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.rule-formula-label { flex: none; width: 52px; color: var(--text-faint); font-size: 11.5px; line-height: 19px; text-transform: uppercase; letter-spacing: .05em; }
.rule-note { color: var(--warn); font-size: 12px; }
.rule-now { font-size: 12.5px; font-weight: 600; }
.rule-now.yes { color: #86efac; }
.rule-now.no { color: var(--text-muted); }
.rule-now.na { color: var(--text-faint); font-weight: 400; }
.rule-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.mini-button {
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: none;
    color: var(--text);
    font-size: 12.5px;
    font-weight: 600;
}
.mini-button:hover:not(:disabled) { background: var(--surface-3); }
.mini-button.primary { border-color: transparent; background: var(--accent); color: #fff; }
.mini-button.primary:hover:not(:disabled) { background: var(--accent-strong); }
.mini-button.primary:disabled { background: var(--accent-soft); color: #9cc3ff; cursor: default; }
.mini-button.danger { color: #fca5a5; }
.mini-button.danger[data-confirm] { border-color: var(--danger); background: rgba(239, 68, 68, .18); }

.rule-editor { display: flex; flex-direction: column; gap: 12px; }
.cond-list { display: flex; flex-direction: column; gap: 8px; }
.cond-list[hidden], .add-cond[hidden] { display: none; }
.cond-row {
    display: grid;
    grid-template-columns: 70px 12px 62px 52px 80px 1fr 30px;
    align-items: center;
    gap: 5px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
}
.cond-row select,
.cond-row input {
    width: 100%;
    height: 32px;
    padding: 0 6px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.cond-row select option { background: var(--surface-2); }
.cond-row input[hidden] { visibility: hidden; display: block; }
.c-plus { color: var(--text-faint); text-align: center; }
.c-remove { width: 30px; height: 30px; font-size: 18px; }
.c-live { grid-column: 1 / -1; color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.c-live.yes { color: #86efac; }
.c-live.no { color: #fca5a5; }
.c-live.warn::after { content: " ⚠"; color: var(--warn); }
.add-cond { align-self: flex-start; }
/* Operador E entre condições e faixa ("entre mín. e máx.") */
.cond-and { align-self: center; padding: 0 8px; border-radius: 4px; background: var(--surface-4); color: var(--text-muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.c-v2 { display: none !important; }
.cond-row.is-range .c-b { display: none; }
.cond-row.is-range { grid-template-columns: 64px 10px 46px 66px minmax(0, 1fr) minmax(0, 1fr) 28px; }
.cond-row.is-range .c-v2 { display: block !important; }
.rule-templates { display: flex; flex-direction: column; gap: 6px; }
.rule-template-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.rule-verdict { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
.rule-verdict.yes { background: var(--ok-soft); color: #86efac; }
.rule-verdict.no { background: rgba(239, 68, 68, .1); color: #fca5a5; }
.rule-errors { padding: 10px 12px; border-radius: var(--radius-sm); background: rgba(239, 68, 68, .12); color: #fca5a5; font-size: 12.5px; }
.rule-errors[hidden] { display: none; }
.editor-actions { display: flex; gap: 8px; }
.editor-actions .primary-button { flex: 1; }
.editor-actions .ghost-button { height: 40px; }

/* Termometria real */
.thermo-mode {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 600;
}
.thermo-mode.active { border-color: rgba(34, 197, 94, .45); background: var(--ok-soft); color: #86efac; }
.field textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
    resize: vertical;
    outline: none;
}
.field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field[hidden] { display: none; }
.button-row { display: flex; gap: 8px; }
.button-row .primary-button { flex: 1; }
.button-row .ghost-button { height: 40px; }
.forecast-status[data-kind="warn"] { background: rgba(245, 158, 11, .12); color: #fcd34d; }
.thermo-summary[hidden] { display: none; }
.thermo-summary { display: flex; flex-direction: column; gap: 10px; }
.thermo-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.thermo-stats div { display: flex; flex-direction: column; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-1); }
.thermo-stats span { color: var(--text-faint); font-size: 11px; }
.thermo-stats b { font-size: 15px; font-variant-numeric: tabular-nums; }
.thermo-cables { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.thermo-cables div { display: grid; grid-template-columns: 58px 1fr auto; gap: 8px; padding: 5px 10px; border-radius: 6px; background: var(--surface-1); }
.thermo-cables span { color: var(--text-muted); }
.thermo-cables em { font-style: normal; font-weight: 600; font-variant-numeric: tabular-nums; }
.thermo-import { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.thermo-import summary { padding: 10px 12px; cursor: pointer; color: var(--text-muted); font-weight: 600; font-size: 13px; }
.thermo-import-body { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; }
.thermo-import-body textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: 11.5px/1.4 Consolas, "Cascadia Mono", monospace;
    resize: vertical;
}
.thermo-import-body .ghost-button { align-self: flex-start; }
.thermo-note { display: none; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); color: #bcd6ff; font-size: 12.5px; }
.app.thermo-real .thermo-note { display: block; }
.app.thermo-real #grain-temperature-input,
.app.thermo-real #shape-type-input { opacity: .45; pointer-events: none; }

/* Comando manual */
.manual-control { display: flex; flex-direction: column; gap: 8px; margin-top: -4px; }
.power-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    height: 42px;
    border: 1px solid rgba(34, 197, 94, .45);
    border-radius: var(--radius-sm);
    background: var(--ok-soft);
    color: #86efac;
    font-weight: 700;
}
.power-button .ico { width: 18px; height: 18px; stroke-width: 2.2; }
.power-button:hover:not(:disabled) { background: rgba(34, 197, 94, .24); }
.power-button.on { border-color: rgba(239, 68, 68, .5); background: rgba(239, 68, 68, .14); color: #fca5a5; }
.power-button.on:hover:not(:disabled) { background: rgba(239, 68, 68, .24); }
.power-button:disabled { border-color: var(--border); background: var(--surface-1); color: var(--text-faint); cursor: not-allowed; }

/* Aeradores */
.fan-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fan-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: 8px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-1);
}
.fan-card b { font-size: 13px; }
.fan-card-status { grid-column: 2; color: var(--text-muted); font-size: 12.5px; }
.fan-dot { grid-row: span 2; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 4px rgba(239, 68, 68, .15); }
.fan-card.on { border-color: rgba(34, 197, 94, .4); background: var(--ok-soft); }
.fan-card.on .fan-dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(34, 197, 94, .2); }
.fan-card.on .fan-card-status { color: #86efac; }

.program-help {
    margin: 4px 0 0;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface-1);
    color: var(--text-muted);
    font-size: 12.5px;
}
.program-help dt { color: var(--text); font-weight: 600; }
.program-help dd { margin: 0 0 8px; }
.program-help dd:last-child { margin-bottom: 0; }

/* Eventos */
.notification-panel .body { display: flex; flex-direction: column; gap: 8px; }
.notification-panel .body:not(:empty) + .empty-state { display: none; }
.empty-state { color: var(--text-faint); font-size: 13px; text-align: center; padding: 24px 8px; }
.notification {
    padding: 10px 12px;
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
}
.notification .title { color: var(--text-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.notification .content { margin-top: 2px; font-size: 13px; }

/* Botão principal */
.primary-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}
.primary-button .ico { width: 17px; height: 17px; }
.primary-button:hover { background: var(--accent-strong); }
.primary-button:disabled { opacity: .55; cursor: progress; }
.primary-button.secondary { background: var(--surface-4); color: var(--text); }
.primary-button.secondary:hover { background: #2d3d5e; }

/* Previsão real */
.location-row { grid-template-columns: 112px 1fr; }
.forecast-status { padding: 9px 12px; border-radius: var(--radius-sm); background: var(--surface-1); color: var(--text-muted); font-size: 13px; }
.forecast-status[data-kind="error"] { background: rgba(239, 68, 68, .12); color: #fca5a5; }
.forecast-status[data-kind="warn"] { background: rgba(245, 158, 11, .12); color: #fcd34d; }
.forecast-status[data-kind="busy"]::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 8px;
    border: 2px solid var(--text-faint);
    border-top-color: var(--accent);
    border-radius: 50%;
    vertical-align: -1px;
    animation: spin .8s linear infinite;
}
.forecast-result { display: flex; flex-direction: column; gap: 14px; }
.forecast-result[hidden] { display: none; }
.location-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-1);
}
.location-card > .ico { color: var(--accent); }
.location-card b { display: block; font-size: 15px; }
.location-card span { color: var(--text-faint); font-size: 12px; }
.forecast-summary { color: var(--text-muted); font-size: 12.5px; }
.forecast-summary b { color: var(--text); }

.forecast-days { display: flex; flex-direction: column; gap: 10px; }
.fday-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; font-size: 12.5px; }
.fday-head b { min-width: 72px; }
.fday-head span { flex: 1; color: var(--text-faint); white-space: nowrap; }
.fday-head em { color: var(--text-faint); font-style: normal; font-variant-numeric: tabular-nums; }
.fday-head em.yes { color: #86efac; font-weight: 600; }
.fday-strip,
.fday-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; }
.fday-strip i,
.forecast-legend i {
    display: block;
    height: 16px;
    border-radius: 3px;
    background: var(--surface-4);
}
.fday-strip i.on,
.forecast-legend i.on { background: var(--ok); }
.fday-strip i.forbidden,
.forecast-legend i.forbidden { background: repeating-linear-gradient(135deg, #7c5a12 0 3px, #4a3a16 3px 6px); }
.fday-strip i.rainblock,
.forecast-legend i.rainblock { background: repeating-linear-gradient(135deg, #1e4e7a 0 3px, #1b2f45 3px 6px); }
.fday-strip i.none { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }
.fday-strip i.coarse,
.forecast-legend i.coarse { opacity: .6; }
.fday-strip i:hover,
.fday-strip i.current { outline: 2px solid var(--text); outline-offset: 1px; }
.fday-axis { grid-template-columns: repeat(4, 1fr) auto; margin-top: -6px; color: var(--text-faint); font-size: 10.5px; }
.forecast-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--text-muted); font-size: 12px; }
.forecast-legend span { display: flex; align-items: center; gap: 6px; }
.forecast-legend i { width: 14px; height: 12px; }
.attribution { color: var(--text-faint); font-size: 11.5px; }
.attribution a { color: #9cc3ff; }

/* Com previsão ativa, o clima sintético fica bloqueado */
.forecast-note { display: none; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); color: #bcd6ff; font-size: 12.5px; }
.app.forecast-active .forecast-note { display: block; }
.app.forecast-active [data-panel="weather"] .side-panel-body > :not(.forecast-note) { opacity: .4; pointer-events: none; }

/* ------------------------------------------------------------------
 * Cabeçalho
 * ------------------------------------------------------------------ */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-1);
}
.topbar-title { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.topbar h1 { font-size: 16px; font-weight: 600; white-space: nowrap; }

.clock-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.clock-chip .ico { width: 16px; height: 16px; }
.clock-chip label { color: var(--text); }

.playback {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}
.playback button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 34px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
}
.playback button .icon { display: grid; place-items: center; }
.playback button .ico { width: 17px; height: 17px; }
.playback button:hover { background: var(--surface-4); color: var(--text); }
.playback button.active { background: var(--accent); color: #fff; }
.playback-sep { width: 1px; height: 20px; margin: 0 4px; background: var(--border-strong); }

.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid rgba(59, 130, 246, .45);
    border-radius: 16px;
    background: var(--accent-soft);
    color: #bcd6ff;
    font-weight: 600;
    white-space: nowrap;
}
.source-chip[hidden] { display: none; }
.source-chip .ico { width: 16px; height: 16px; }

.view-switch { flex: none; }
.view-switch > button { min-width: 52px; }
.view-switch > button[hidden] { display: none; }

/* ------------------------------------------------------------------
 * Palco (cena 2D escalada ou 3D em tela cheia)
 * ------------------------------------------------------------------ */
.stage {
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 40%, #16233d 0%, var(--bg) 75%);
}

.stage-2d {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1024px;
    height: 768px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .45), 0 0 0 1px var(--border);
    transform: translate(-50%, -50%);
    transform-origin: center;
}
.app.mode-3d .stage-2d { display: none; }

/* ------------------------------------------------------------------
 * Gráficos da previsão (paleta validada para o fundo escuro)
 * ------------------------------------------------------------------ */
.view-charts {
    --series-1: #3987e5;   /* previsto */
    --series-2: #d95926;   /* simulado */
    --status-good: #0ca30c;
    --chart-grid: rgba(148, 163, 184, .13);
    --chart-axis: rgba(148, 163, 184, .32);
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    gap: 14px;
    padding: 18px 22px 20px;
    overflow: hidden;
}
.app.mode-charts .view-charts { display: flex; }
.app.mode-charts .stage-2d { display: none; }

.charts-header { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.charts-heading { flex: 1; min-width: 240px; }
.charts-heading h2 { font-size: 18px; font-weight: 600; }
.charts-heading p { color: var(--text-muted); font-size: 12.5px; }
.charts-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-muted); font-size: 12.5px; }
.charts-legend span { display: inline-flex; align-items: center; gap: 7px; }
.charts-legend span[hidden] { display: none; }
.key-line { width: 16px; height: 2px; border-radius: 1px; }
.key-line.forecast, .tt-key.forecast { background: var(--series-1); }
.key-line.simulated, .tt-key.simulated { background: var(--series-2); }
.key-ref { width: 16px; height: 0; border-top: 1px solid var(--text-muted); }
.key-band { width: 12px; height: 12px; border-radius: 3px; background: rgba(12, 163, 12, .28); }

.ghost-button {
    height: 32px;
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font-weight: 600;
}
.ghost-button:hover { background: var(--surface-3); }

.charts-empty {
    margin: auto;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}
.charts-empty[hidden] { display: none; }
.charts-empty > .ico { width: 36px; height: 36px; color: var(--text-faint); }
.charts-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.charts-content[hidden] { display: none; }
.charts-grid { flex: 1; min-height: 0; display: grid; grid-template-rows: repeat(4, minmax(0, 1fr)); gap: 12px; }
.charts-grid[hidden] { display: none; }
.chart-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 12px 6px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}
.chart-card header { display: flex; align-items: baseline; gap: 8px; }
.chart-card h3 { font-size: 13.5px; font-weight: 600; }
.chart-unit { color: var(--text-faint); font-size: 12px; }
.chart-readout { margin-left: auto; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-svg { flex: 1; min-height: 0; width: 100%; display: block; outline: none; overflow: visible; }
.chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.c-gridline { stroke: var(--chart-grid); stroke-width: 1; }
.c-daysep { stroke: var(--chart-axis); stroke-width: 1; }
.c-coarse { stroke: var(--chart-axis); stroke-width: 1; opacity: .6; }
.c-tick { fill: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-note { fill: var(--text-faint); font-size: 11px; }
.c-band-on { fill: var(--status-good); opacity: .16; }
.c-ref { stroke: var(--text-muted); stroke-width: 1; }
.c-ref-label { fill: var(--text-muted); font-size: 11px; }
.c-end-label { fill: var(--text); font-size: 11.5px; font-weight: 600; }
.c-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-forecast { stroke: var(--series-1); }
.c-simulated { stroke: var(--series-2); }
.c-dot { stroke: var(--surface-2); stroke-width: 2; }
.c-forecast-dot { fill: var(--series-1); }
.c-simulated-dot { fill: var(--series-2); }
.c-now { stroke: var(--text); stroke-width: 1; opacity: .7; }
.c-now-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.c-cursor-line { stroke: var(--text-muted); stroke-width: 1; }

.chart-tooltip {
    position: absolute;
    z-index: 5;
    min-width: 220px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: #0a1120;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    pointer-events: none;
    font-size: 12.5px;
}
.chart-tooltip[hidden] { display: none; }
.tt-head { margin-bottom: 6px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tt-row b { min-width: 58px; font-variant-numeric: tabular-nums; }
.tt-row span { color: var(--text-muted); }
.tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tt-key.status-on { height: 10px; border-radius: 2px; background: var(--status-good); }
.tt-key.status-off { height: 10px; border-radius: 2px; background: var(--surface-4); }
.tt-key.status-forbidden { height: 10px; border-radius: 2px; background: repeating-linear-gradient(135deg, #7c5a12 0 3px, #4a3a16 3px 6px); }
.tt-key.status-rainblock { height: 10px; border-radius: 2px; background: repeating-linear-gradient(135deg, #1e4e7a 0 3px, #1b2f45 3px 6px); }

.charts-table { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.charts-table[hidden] { display: none; }
.charts-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.charts-table th { position: sticky; top: 0; padding: 9px 12px; background: var(--surface-3); color: var(--text-muted); font-weight: 600; text-align: left; }
.charts-table td { padding: 6px 12px; border-top: 1px solid var(--border); }
.charts-table tr.on td:last-child { color: #86efac; font-weight: 600; }
.charts-table tr.forbidden td:last-child { color: var(--warn); }
.charts-table tr.rainblock td:last-child { color: #93c5fd; }
.charts-table .hint { padding: 10px 12px; }

/* ------------------------------------------------------------------
 * Indicadores
 * ------------------------------------------------------------------ */
.statusbar {
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface-1);
    overflow-x: auto;
}

.kpi-group {
    display: flex;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
}
.kpi-group:last-child { margin-left: auto; }

.kpi {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 132px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
}
.kpi > .ico { color: var(--text-faint); }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { background: var(--surface-3); }
.kpi-body { display: flex; flex-direction: column; min-width: 0; }
.kpi-label { color: var(--text-muted); font-size: 11.5px; white-space: nowrap; }
.kpi-value {
    font-size: 19px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
    white-space: nowrap;
}
.kpi-value .unit { margin-left: 3px; color: var(--text-muted); font-size: 13px; font-weight: 500; }

.kpi .lock { display: none; position: absolute; top: 5px; right: 6px; color: var(--warn); }
.kpi .lock .ico { width: 14px; height: 14px; }
.kpi .lock.locked { display: block; }

.kpi-fan .kpi-value { color: #fca5a5; }
.kpi-fan.on .kpi-value { color: #86efac; }
.kpi-fan.on > .ico { color: var(--ok); animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------
 * Sobre
 * ------------------------------------------------------------------ */
.about-overlay,
.about-panel { display: none; }
.about-overlay {
    position: fixed;
    inset: 0;
    z-index: 98;
    background: rgba(2, 6, 23, .6);
}
.about-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 99;
    width: 320px;
    padding: 28px 24px 24px;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: var(--surface-2);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
    text-align: center;
    transform: translate(-50%, -50%);
}
.about-panel .close { position: absolute; top: 8px; right: 8px; font-size: 22px; }
.about-logo {
    display: inline-grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin-bottom: 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, #3b82f6, #22c55e);
    color: #fff;
}
.about-logo .ico { width: 28px; height: 28px; }
.about-panel .title { font-size: 18px; font-weight: 600; }
.about-panel .version { margin-bottom: 16px; color: var(--text-muted); font-size: 13px; }
.about-panel .section { color: var(--text-faint); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

/* ------------------------------------------------------------------
 * Tooltips (jQuery UI)
 * ------------------------------------------------------------------ */
.ui-tooltip {
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: #0a1120;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
    color: var(--text);
    font: 12.5px var(--font);
}
.ui-tooltip .arrow { display: none; }

/* Barras de rolagem discretas */
.panel-host::-webkit-scrollbar { width: 10px; }
.panel-host::-webkit-scrollbar-thumb { border: 3px solid var(--surface-2); border-radius: 6px; background: var(--surface-4); }

/* Telas estreitas: painel lateral flutua sobre o palco */
@media (max-width: 1100px) {
    .panel-host {
        position: absolute;
        top: 0;
        bottom: 0;
        left: var(--rail-w);
        z-index: 30;
        box-shadow: 12px 0 40px rgba(0, 0, 0, .45);
    }
    .topbar h1 { display: none; }
}

/* Chuva prevista: gota na célula da grade, barras no gráfico, chave no tooltip */
.fday-strip i.rain,
.forecast-legend i.rain { position: relative; }
.fday-strip i.rain::after,
.forecast-legend i.rain::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 4px;
    width: 6px;
    height: 8px;
    margin-left: -3px;
    background: #7cc4ff;
    border-radius: 50% 50% 50% 50% / 35% 35% 65% 65%;
    box-shadow: 0 0 0 1px rgba(11, 18, 32, .55);
}
.c-bar { fill: var(--series-1); }
.tt-key.rain { height: 10px; border-radius: 2px; background: var(--series-1); }
.c-cursor .is-hidden { display: none; }

/* Switch (toggle) — horário de pico no painel Aeração */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
    width: 38px;
    height: 22px;
    border-radius: 11px;
    background: var(--surface-4);
    box-shadow: inset 0 0 0 1px var(--border);
    transition: background .18s;
}
.switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
    transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--accent, #3b82f6); box-shadow: none; }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--text); outline-offset: 2px; }
.switch-state { color: var(--text-muted); font-size: 12px; }
.peak-field.is-off .time-range { opacity: .45; }
.peak-field.is-off .switch-state,
.rain-field.is-off .switch-state { color: #86efac; }

/* ------------------------------------------------------------------
 * Tabela de equilíbrio higroscópico (menu EH / visualização "Tabela EH")
 * ------------------------------------------------------------------ */
.field-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.field-sub { color: var(--text-faint); font-size: 11.5px; }
.form-error { color: #fca5a5; font-size: 12.5px; }
.view-eh {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 18px 22px 20px;
    overflow: hidden;
}
.app.mode-eh .view-eh { display: flex; }
.app.mode-eh .stage-2d { display: none; }
.view-eh .charts-heading h2 { font-size: 17px; }
.view-eh .charts-heading p { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.eh-table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
}
.eh-table { border-collapse: separate; border-spacing: 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.eh-table th,
.eh-table td { padding: 5px 12px; text-align: center; white-space: nowrap; border-right: 1px solid rgba(0, 0, 0, .18); border-bottom: 1px solid rgba(0, 0, 0, .18); }
.eh-table td { min-width: 64px; color: #111; }
.eh-table thead th,
.eh-table tbody th {
    position: sticky;
    background: #e9ecf1;
    color: #111;
    font-weight: 600;
}
.eh-table thead th { top: 0; z-index: 2; }
.eh-table tbody th { left: 0; z-index: 1; }
.eh-table .eh-corner { left: 0; z-index: 3; }
/* Faixas do produto (cores da legenda de referência) */
.eh-dry { background: #5fd39b; }
.eh-safe { background: #fff3c4; }
.eh-critical { background: #ebb6d8; }
.eh-wet { background: #c06b6b; }
/* Momento da simulação: borda dupla (escura + branca), visível sobre qualquer faixa */
.eh-table td.air-now {
    font-weight: 700;
    outline: 3px solid #0b1220;
    outline-offset: -3px;
    box-shadow: inset 0 0 0 5px #fff;
    animation: eh-pulse 1.6s ease-in-out infinite;
}
@keyframes eh-pulse { 50% { box-shadow: inset 0 0 0 5px rgba(255, 255, 255, .35); } }
.eh-table th.air-axis { background: #0b1220; color: #fff; }
.eh-grain-note { color: #fcd34d; font-size: 12.5px; }
@media (prefers-reduced-motion: reduce) { .eh-table td.air-now { animation: none; } }
.eh-table tbody tr:hover td { filter: brightness(.92); }
.eh-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--text-muted); font-size: 12.5px; }
.eh-legend span { display: inline-flex; align-items: center; gap: 7px; }
.eh-swatch { display: inline-block; width: 22px; height: 12px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); vertical-align: middle; flex: none; }
.field-sub .eh-swatch { width: 10px; height: 10px; margin-right: 5px; }
.eh-swatch.air-now { background: #e9ecf1; outline: 2px solid #0b1220; outline-offset: -2px; box-shadow: inset 0 0 0 3px #fff; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

/* ------------------------------------------------------------------
 * Conta: usuário, silos e simulações salvos
 * ------------------------------------------------------------------ */
.account-card { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.account-avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #3b82f6, #22c55e); color: #fff; font-size: 17px; font-weight: 700; }
.account-who { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.account-who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-who span { overflow: hidden; color: var(--text-muted); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
#account-logout { align-self: flex-start; height: 34px; }
.account-save { display: flex; gap: 8px; }
.account-save input {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text);
    outline: none;
}
.account-save input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.account-save .primary-button { flex: none; padding: 0 16px; }
.account-list { display: flex; flex-direction: column; gap: 8px; }
.account-item { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.account-item.is-current { border-color: rgba(59, 130, 246, .55); }
.account-item-head { display: flex; align-items: center; gap: 6px; }
.account-item-head b { flex: 1; min-width: 0; font-size: 13.5px; overflow-wrap: anywhere; }
.account-item-meta { color: var(--text-muted); font-size: 12.5px; }
.account-item-meta.faint { color: var(--text-faint); font-size: 11.5px; }
.account-item .rule-actions { margin-top: 4px; }
.forecast-status[data-kind="ok"] { background: var(--ok-soft); color: #86efac; }
#sim-hint-noforecast[hidden] { display: none; }
a.ghost-button, a.primary-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.silo-manage { align-self: flex-start; height: 36px; }
.silo-panel-empty { display: flex; flex-direction: column; gap: 12px; color: var(--text-muted); }
.silo-panel-empty[hidden], .silo-panel-form[hidden] { display: none; }
.silo-panel-form { display: flex; flex-direction: column; gap: 14px; }
.silo-info:empty { display: none; }
.silo-info { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.silo-info-current { margin-bottom: 8px; }
.silo-info-specs { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 12.5px; }
.silo-info-specs dt { color: var(--text-faint); }
.silo-info-specs dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.silo-info-specs .sub { display: block; color: var(--text-muted); font-size: 11.5px; }
.source-chip.silo-chip { border-color: rgba(34, 197, 94, .45); background: var(--ok-soft); color: #bbf7d0; }

/* ------------------------------------------------------------------
 * Responsividade
 * O layout se adapta à largura da área principal (container "main"), que muda
 * com o painel lateral aberto ou fechado, e não só à largura da janela.
 * Nenhuma área tem rolagem horizontal: cabeçalho e indicadores quebram linha
 * e a tabela EH reduz a fonte para caber na largura disponível.
 * ------------------------------------------------------------------ */
.main {
    grid-template-rows: auto minmax(0, 1fr) auto;
    container: main / inline-size;
}

.clock-chip { flex: none; }
.topbar-title { min-width: auto; }
/* O título some antes de o cabeçalho precisar quebrar linha */
@container main (max-width: 1000px) { .topbar h1 { display: none; } }
.topbar {
    flex-wrap: wrap;
    row-gap: 8px;
    min-height: var(--topbar-h);
    padding-top: 8px;
    padding-bottom: 8px;
}

.statusbar {
    flex-wrap: wrap;
    overflow-x: visible;
}
.kpi-group { flex: 1 1 auto; min-width: 0; }
.kpi-group:last-child { margin-left: 0; }
.kpi { flex: 1 1 auto; min-width: 0; }

.panel-host { max-width: calc(100vw - var(--rail-w)); }

/* Tabela EH: ocupa a largura do palco; fonte e espaçamento acompanham a largura de cada coluna */
.eh-table-wrap { container-type: inline-size; overflow-x: hidden; overflow-y: auto; }
.eh-table {
    --eh-col: calc(100cqi / var(--eh-cols, 13));
    width: 100%;
    max-width: calc(var(--eh-cols, 13) * 120px);
    table-layout: fixed;
    font-size: clamp(7px, calc(var(--eh-col) / 4.4), 13.5px);
}
.eh-table th,
.eh-table td {
    padding: clamp(3px, calc(var(--eh-col) / 14), 5px) clamp(1px, calc(var(--eh-col) / 10), 12px);
    overflow: hidden;
    text-overflow: clip;
}
.eh-table td { min-width: 0; }

/* Área principal média: indicadores compactos e sem ícones */
@container main (max-width: 1180px) {
    .statusbar { gap: 8px; padding: 8px 10px; }
    .kpi { gap: 0; padding: 5px 8px; }
    .kpi > .ico { display: none; }
    .kpi-label { font-size: 11px; }
    .kpi-value { font-size: 17px; }
    .kpi-value .unit { font-size: 12px; }
}

/* Área principal estreita: o cabeçalho quebra em duas linhas e os indicadores viram uma grade de 4 colunas */
@container main (max-width: 820px) {
    .topbar { gap: 8px 10px; padding-left: 12px; padding-right: 12px; }
    .topbar h1 { display: none; }
    .topbar-title { flex: 0 1 auto; }
    .playback { flex: none; }
    .view-switch { flex: 1 1 260px; display: flex; }
    .view-switch > button { flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px; }
    .view-eh,
    .view-charts { padding: 12px 12px 14px; gap: 10px; }
    .charts-heading { min-width: 0; flex-basis: 100%; }

    .statusbar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .kpi-group { display: contents; }
    .kpi { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
    .kpi.clickable:hover { background: var(--surface-3); }
}

/* Celular */
@container main (max-width: 520px) {
    .statusbar { gap: 4px; padding: 6px; }
    .kpi { padding: 4px 6px; }
    .kpi-label { font-size: 10.5px; white-space: normal; line-height: 1.2; }
    .kpi-value { font-size: 15px; }
    .playback button { width: 32px; height: 30px; }
    .playback-sep { margin: 0 2px; }
    .clock-chip, .source-chip { height: 30px; padding: 0 10px; }
    .clock-chip .ico { display: none; }
    .topbar { gap: 6px; padding-left: 8px; padding-right: 8px; }
    .playback { padding: 3px; }
    .eh-table .eh-corner { white-space: normal; line-height: 1.1; }
    .source-chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .ghost-button { padding-left: 10px; padding-right: 10px; }
}

/* Janela estreita: trilho compacto (só ícones; o nome aparece na dica) */
@media (max-width: 640px) {
    :root { --rail-w: 56px; --panel-w: calc(100vw - 56px); }
    .rail { overflow-y: auto; padding: 8px 0; gap: 2px; }
    .rail-brand { width: 38px; height: 38px; margin-bottom: 6px; flex: none; }
    .rail-item { width: 44px; padding: 10px 0; flex: none; }
    .rail-item span { display: none; }
    .rail-item.active::before { left: -6px; }
    .badge { top: 2px; right: 0; }
    .app[data-panel="rules"] .panel-host { width: var(--panel-w); }
    .side-panel-body { padding: 14px 14px 20px; }
    .side-panel-header { padding-left: 14px; }
}

/* Janela baixa (celular deitado): trilho rola na vertical; indicadores numa linha só */
@media (max-height: 560px) {
    .rail { overflow-y: auto; }
    .rail-item, .rail-brand { flex: none; }
}
@media (max-height: 560px) and (min-width: 700px) {
    .statusbar { grid-template-columns: repeat(8, minmax(0, 1fr)); }
    .kpi-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* Editor de programas em painel estreito: colunas da condição flexíveis */
@media (max-width: 640px) {
    .cond-row,
    .cond-row.is-range {
        grid-template-columns: minmax(0, 1.25fr) 8px minmax(0, 1fr) minmax(0, .9fr) minmax(0, 1.3fr) minmax(0, 1fr) 26px;
        gap: 4px;
    }
    .cond-row.is-range { grid-template-columns: minmax(0, 1.25fr) 8px minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr) 26px; }
    .cond-row select,
    .cond-row input { min-width: 0; padding-left: 4px; padding-right: 4px; }
    .c-remove { width: 26px; }
}
