/* Ingenio Verde - panel de control. Mobile-first; menu lateral con boton hamburguesa. */
:root {
  --bg: #eef1ec;
  --card: #ffffff;
  --card-2: #f5f8f4;
  --ink: #17261f;
  --muted: #5b6b63;
  --line: #d6ded5;
  --side: #153828;
  --side-ink: #d9e8de;
  --side-line: rgba(255, 255, 255, 0.12);
  --brand: #2a7a4b;
  --brand-ink: #ffffff;
  --leaf: #8cbf3f;
  --ok: #2a7a4b;
  --alarm: #c62828;
  --alarm-bg: #fdeae7;
  --warn: #a8610a;
  --warn-bg: #fff2d9;
  --off: #8a978f;
  --shadow: 0 1px 2px rgba(23, 38, 31, 0.08);
  --radius: 12px;
  --side-w: 268px;
  --font: "Bahnschrift", "DIN Alternate", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1713;
    --card: #15221c;
    --card-2: #1a2a23;
    --ink: #e5eee8;
    --muted: #9aaca2;
    --line: #26392f;
    --side: #09110e;
    --brand: #43a56f;
    --ok: #4cb27a;
    --alarm: #ff6f61;
    --alarm-bg: #3a1815;
    --warn: #f0b24b;
    --warn-bg: #33270e;
    --off: #6f8077;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  font-size: 15px;
  min-height: 100vh;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--leaf); outline-offset: 2px; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon.sm { width: 18px; height: 18px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- estructura ---------- */
.side {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--side-w);
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform 0.22s ease;
  padding-top: env(safe-area-inset-top);
}
body.nav-open .side { transform: none; }
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(5, 12, 9, 0.55); }
.side-head { display: flex; align-items: center; gap: 12px; padding: 18px 16px 14px; border-bottom: 1px solid var(--side-line); }
.side-head img { width: 40px; height: 40px; }
.side-title { font-weight: 700; font-size: 1.1rem; line-height: 1.1; }
.side-sub { font-size: 0.8rem; opacity: 0.7; }
.nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.nav-group { font-size: 0.78rem; opacity: 0.6; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  text-decoration: none; color: var(--side-ink); font-weight: 500; position: relative;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, 0.14); color: #fff; }
.nav a[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--leaf); }
.nav .tag { margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--alarm); color: #fff; font-size: 0.78rem; font-weight: 700; display: grid; place-items: center; }
.side-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--side-line); font-size: 0.85rem; }
.side-foot .who { opacity: 0.75; margin-bottom: 8px; }
.side-foot button { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--side-line); background: transparent; color: var(--side-ink); }
.side-foot button:hover { background: rgba(255, 255, 255, 0.08); }

.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px; background: var(--card); border-bottom: 1px solid var(--line);
}
.burger { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); display: grid; place-items: center; }
.burger:hover { background: var(--line); }
.top-title { font-weight: 700; font-size: 1.05rem; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-plant { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.link-chip { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 0.85rem; padding: 6px 12px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex-shrink: 0; }
.dot.on { background: var(--ok); }
.dot.bad { background: var(--alarm); }

.alert-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--alarm); color: #fff; font-weight: 700; text-decoration: none; }
.alert-bar.warn { background: var(--warn); }
.alert-bar span { flex: 1; min-width: 0; }
.alert-bar u { font-weight: 500; white-space: nowrap; }
.banner { background: var(--warn-bg); color: var(--warn); text-align: center; font-weight: 600; font-size: 0.88rem; padding: 6px 12px; }
.demo-bar { background: var(--leaf); color: #1b2a0c; text-align: center; font-weight: 600; font-size: 0.85rem; padding: 5px 12px; }

.main { padding: 16px 14px calc(40px + env(safe-area-inset-bottom)); max-width: 1180px; margin: 0 auto; }
.view-title { font-size: 1.45rem; font-weight: 700; margin-bottom: 4px; }
.view-sub { color: var(--muted); margin-bottom: 16px; max-width: 70ch; }

@media (min-width: 1000px) {
  .shell { transition: margin-left 0.22s ease; }
  body.nav-open .shell { margin-left: var(--side-w); }
  .scrim { display: none; }
  .main { padding: 24px 28px 48px; }
}

/* ---------- tarjetas y piezas comunes ---------- */
.grid { display: grid; gap: 14px; }
@media (min-width: 720px) { .grid.c2 { grid-template-columns: 1fr 1fr; } .grid.c3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .grid.c4 { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 560px) and (max-width: 1099px) { .grid.c4 { grid-template-columns: 1fr 1fr; } }
.stack > * + * { margin-top: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h2, .card h2 { font-size: 1.02rem; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }
.note { font-size: 0.88rem; color: var(--muted); margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px;
  border-radius: 10px; border: 1px solid transparent; background: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; }
.btn.danger { background: var(--alarm); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--card-2); filter: none; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 0.88rem; }
.btn.busy { opacity: 0.7; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.switch { position: relative; width: 58px; height: 34px; border-radius: 17px; border: 0; background: var(--off); flex-shrink: 0; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(24px); }
.switch:disabled { opacity: 0.45; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.toggle-title { font-weight: 700; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; background: var(--card-2); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); }
.pill.alarm { background: var(--alarm-bg); color: var(--alarm); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

/* ---------- estado general ---------- */
.status {
  border-radius: var(--radius); padding: 18px 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-left: 8px solid var(--off);
}
.status.armed { border-left-color: var(--ok); }
.status.attention { border-left-color: var(--warn); background: var(--warn-bg); }
.status.emergency { border-left-color: var(--alarm); background: var(--alarm-bg); }
.status-main { flex: 1; min-width: 220px; }
.status-title { font-size: 1.5rem; font-weight: 700; line-height: 1.15; }
.status.emergency .status-title { color: var(--alarm); }
.status.attention .status-title { color: var(--warn); }
.status-sub { color: var(--muted); margin-top: 4px; }
.status .btn { min-width: 180px; }

/* tablero de zonas (estilo tablero de anunciadores) */
.annun { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .annun { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .annun { grid-template-columns: repeat(4, 1fr); } }
.zone-tile { border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 132px; text-decoration: none; }
.zone-tile .zt-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.zone-tile .zt-name { font-weight: 700; font-size: 1.1rem; }
.zone-tile .zt-num { color: var(--muted); font-size: 0.85rem; }
.zone-tile .zt-state { font-size: 0.95rem; font-weight: 600; color: var(--ok); margin-top: auto; }
.lamps { display: flex; gap: 8px; flex-wrap: wrap; }
.lamp { width: 20px; height: 20px; border-radius: 50%; background: var(--ok); opacity: 0.35; border: 2px solid transparent; }
.lamp.alarm { background: var(--alarm); opacity: 1; box-shadow: 0 0 0 4px var(--alarm-bg), 0 0 14px var(--alarm); }
.lamp.ignored { background: transparent; border-color: var(--warn); opacity: 1; }
.lamp.off { background: var(--off); opacity: 0.5; }
.zone-tile.alarm { border-color: var(--alarm); background: var(--alarm-bg); }
.zone-tile.alarm .zt-state { color: var(--alarm); }
.zone-tile.off .zt-state { color: var(--muted); }
@keyframes blink { 50% { opacity: 0.35; } }
.zone-tile.alarm .lamp.alarm, .alert-bar.blink { animation: blink 1s steps(2, jump-none) infinite; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* datos en grande */
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-v { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-v small { font-size: 1rem; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat-l { color: var(--muted); font-size: 0.88rem; }
.stat.alert .stat-v { color: var(--alarm); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; word-break: break-word; }

.rows > .row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.rows > .row:first-child { border-top: 0; }
.row .row-name { flex: 1; min-width: 0; font-weight: 600; }
.row .row-state { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--muted); text-align: right; }
.row.alarm .row-state { color: var(--alarm); font-weight: 700; }
.row.alarm .row-name { color: var(--alarm); }
.row.ignored .row-state { color: var(--warn); }
.row .dot.alarm { background: var(--alarm); }
.row .dot.ok { background: var(--ok); }
.row .dot.warn { background: var(--warn); }

/* ambiente */
.gauge { width: 100%; max-width: 220px; margin: 0 auto; display: block; }
.gauge .track { stroke: var(--line); }
.gauge .fill { stroke: var(--ok); }
.gauge.alert .fill { stroke: var(--alarm); }
.gauge text { fill: var(--ink); }
.gauge .g-val { font-size: 26px; font-weight: 700; text-anchor: middle; }
.gauge .g-unit { font-size: 12px; text-anchor: middle; fill: var(--muted); }
.gauge-card { text-align: center; }
.gauge-card h3 { font-size: 0.98rem; margin-bottom: 4px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; }
.chart .limit { stroke: var(--alarm); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .limit-t { fill: var(--alarm); font-size: 11px; }

/* camaras simuladas */
.cam { position: relative; border-radius: var(--radius); overflow: hidden; background: #0b1410; aspect-ratio: 16 / 9; border: 1px solid var(--line); width: 100%; padding: 0; display: block; text-align: left; color: #cfe8d6; }
.cam svg.scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px); }
.cam .scan { position: absolute; left: 0; right: 0; height: 22%; background: linear-gradient(180deg, transparent, rgba(140, 220, 160, 0.12), transparent); animation: scan 5s linear infinite; }
@keyframes scan { from { top: -25%; } to { top: 100%; } }
.cam-hud { position: absolute; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; text-shadow: 0 1px 2px #000; z-index: 2; }
.cam-hud.t { top: 8px; }
.cam-hud.b { bottom: 8px; }
.rec { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.rec::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #ff4d3d; animation: blink 1.4s steps(2, jump-none) infinite; }
.sim-tag { background: rgba(255, 255, 255, 0.9); color: #14342a; border-radius: 4px; padding: 1px 6px; font-weight: 700; }
.cam-big { max-width: 860px; }

/* tablas */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tbl th, .tbl td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.tbl td.n, .tbl th.n { text-align: right; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; }
.tbl tr.today th, .tbl th.today { color: var(--brand); }
.tbl .cell-link { background: none; border: 0; padding: 4px 6px; border-radius: 6px; }
.tbl .cell-link:hover { background: var(--card-2); }
.tbl .zero { color: var(--off); }
.person { display: flex; flex-direction: column; }
.person b { font-weight: 600; }
.person span { font-size: 0.8rem; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 8px 16px; min-height: 40px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.range-label { font-weight: 700; min-width: 150px; text-align: center; }
.fichada { display: inline-flex; align-items: center; gap: 4px; background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 4px 2px 8px; margin: 2px 4px 2px 0; font-size: 0.85rem; }
.fichada button { border: 0; background: transparent; color: var(--muted); width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; }
.fichada button:hover { color: var(--alarm); background: var(--alarm-bg); }

/* empleados */
.emp-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .emp-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .emp-grid { grid-template-columns: repeat(3, 1fr); } }
.emp { display: flex; flex-direction: column; gap: 10px; }
.emp-top { display: flex; gap: 12px; align-items: center; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.emp.inactive .avatar { background: var(--off); }
.emp-name { font-weight: 700; }
.emp-card-id { font-size: 0.88rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.emp-card-id code { background: var(--card-2); border: 1px solid var(--line); padding: 1px 8px; border-radius: 6px; font-family: inherit; letter-spacing: 0.04em; }
.emp-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.lastcard { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-left: 6px solid var(--ok); }
.lastcard.bad { border-left-color: var(--warn); }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }

/* eventos */
.events { list-style: none; }
.ev { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.ev:first-child { border-top: 0; }
.ev-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--off); margin-top: 6px; flex-shrink: 0; }
.ev.alarm .ev-mark { background: var(--alarm); }
.ev.ok .ev-mark { background: var(--ok); }
.ev.cmd .ev-mark { background: var(--brand); }
.ev.warn .ev-mark { background: var(--warn); }
.ev-body { flex: 1; min-width: 0; }
.ev-text { font-weight: 600; word-break: break-word; }
.ev.alarm .ev-text { color: var(--alarm); }
.ev-meta { font-size: 0.82rem; color: var(--muted); }
.ev-time { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.pres-chip { display: inline-flex; flex-direction: column; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; }
.pres-chip b { font-weight: 600; }
.pres-chip span { font-size: 0.78rem; color: var(--muted); }
.card.evac { border: 2px solid var(--alarm); background: var(--alarm-bg); }

/* formularios y dialogos */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 0.88rem; font-weight: 600; }
.field .hint { font-size: 0.82rem; color: var(--muted); }
input[type="text"], input[type="number"], input[type="password"], input[type="time"], input[type="date"], select {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.form-grid { display: grid; gap: 0 14px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-error { background: var(--alarm-bg); color: var(--alarm); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; }
dialog { border: 0; border-radius: 14px; padding: 0; max-width: min(520px, calc(100vw - 28px)); width: 100%; background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); }
dialog.wide { max-width: min(920px, calc(100vw - 28px)); }
dialog::backdrop { background: rgba(5, 12, 9, 0.6); }
dialog form, dialog .dlg-in { padding: 20px; }
dialog h3 { font-size: 1.15rem; margin-bottom: 8px; }
dialog p { color: var(--muted); margin-bottom: 16px; }
.dlg-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 90; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 10px; font-weight: 600; max-width: calc(100vw - 28px); }
.toast.good { background: var(--ok); color: #fff; }
.toast.error { background: var(--alarm); color: #fff; }

/* ingreso */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--side), #1f5a3c); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 28px 24px; }
.login-card img { width: 64px; height: 64px; display: block; margin: 0 auto 10px; }
.login-card h1 { font-size: 1.4rem; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); margin: 4px 0 20px; }
.login-card .btn { width: 100%; }
.login-foot { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 16px; }

.mt { margin-top: 12px; }
.w100 { width: 100%; }
.steps { padding-left: 1.3em; display: grid; gap: 6px; }
@keyframes drift { 0%, 100% { transform: translateX(-14px); } 50% { transform: translateX(26px); } }
.drift { animation: drift 9s ease-in-out infinite; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
