/* =====================================================================
   app.css — Estilo de «ThermoGuard IoT»
   Idea visual: sala de control nocturna. Fondo azul hielo muy oscuro,
   cifras grandes en letra de ancho fijo y colores de semáforo:
   verde = bien, ámbar = vigilar, rojo = alarma.
   ===================================================================== */

/* ---------- Colores y medidas ---------- */
:root {
  --bg: #0a1520;
  --bg-2: #0e1c2a;
  --card: #112333;
  --card-2: #162d41;
  --ink: #e6f1f8;
  --ink-2: #b6c8d6;
  --muted: #7f97aa;
  --line: #22384c;
  --ice: #5ed3f3;
  --ice-2: #22b5dd;
  --ok: #3ddc97;
  --warn: #fbbf24;
  --bad: #ff6b6b;
  --bad-bg: #3a1620;
  --radius: 14px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); color: var(--ink); background: var(--bg); overflow-x: hidden; padding-bottom: 74px;
  background-image: radial-gradient(circle at 90% -10%, rgba(94, 211, 243, .12), transparent 40%); min-height: 100vh; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
a { color: var(--ice); }
:focus-visible { outline: 3px solid var(--ice); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.dim { color: #8aa4b8; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; border: 1px solid transparent; border-radius: 10px; padding: .6em 1.1em; font: 700 .95rem var(--font); cursor: pointer; text-decoration: none; min-height: 44px; transition: background .2s, transform .1s; color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ice); color: #04202b; }
.btn-primary:hover { background: #8be1f7; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #35546e; color: var(--ink); }
.btn-alarm { background: var(--bad-bg); border-color: #6b2632; color: #ffb3b3; }
.btn-alarm:hover { background: #4d1b27; }
.btn-ok { background: #123a2c; border-color: #1f6049; color: var(--ok); }
.btn-danger { background: var(--bad); color: #2a0a0f; }
.btn-small { padding: .35em .8em; font-size: .85rem; min-height: 36px; }
.btn-lg { padding: .9em 1.8em; font-size: 1.05rem; }
.icon-btn { background: none; border: 1px solid var(--line); font-size: 1.1rem; cursor: pointer; color: var(--ink-2); width: 36px; height: 36px; border-radius: 10px; }

/* ---------- Bienvenida ---------- */
.welcome { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; transition: opacity .35s;
  background: radial-gradient(circle at 50% 0%, #17405a, var(--bg) 65%); }
.welcome.out { opacity: 0; }
.welcome-card { max-width: 480px; text-align: center; }
.welcome-card h1 { font-size: 2.5rem; margin-top: .2em; }
.welcome-card .lead { color: var(--ink-2); }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--ice); margin: 10px 0 0; font-weight: 700; }

/* ---------- Cabecera ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center;
  padding: 10px 16px; background: rgba(10, 21, 32, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; min-width: 0; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; overflow: hidden; }
.brand strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .hide-sm { display: none; } }
.brand small { color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.top-actions [data-install] { display: none; }
.status-pill { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; text-align: center; text-decoration: none; font-weight: 700; font-size: .85rem;
  padding: 6px 12px; border-radius: 999px; background: #0f2d25; color: var(--ok); border: 1px solid #1d5a45; }
.status-pill.alarm { background: var(--bad-bg); color: #ffb3b3; border-color: #6b2632; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 107, 107, .15); } }
.tabs { display: none; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #2a0a0f; font-size: .7rem; font-weight: 800; margin-left: 4px; }

/* Barra inferior (móvil) */
.bottombar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--bg-2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottombar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; font-size: .68rem; color: var(--muted); font-weight: 700; text-decoration: none; }
.bottombar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottombar a.active { color: var(--ice); }
.bottombar .badge { position: absolute; top: 3px; left: 54%; }

/* ---------- Contenido ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 16px 16px 24px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { font-size: 1.6rem; margin: 0; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.section-title { font-size: .85rem; margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.list { display: grid; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; border: 1px dashed var(--line); border-radius: var(--radius); }
.sim-note { font-size: .8rem; color: var(--muted); margin: -4px 0 12px; }

/* Banda de estado general */
.banner { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid #1d5a45; background: linear-gradient(90deg, #0f2d25, var(--card)); }
.banner b { font-size: 1.05rem; }
.banner.alarm { border-color: #6b2632; background: linear-gradient(90deg, var(--bad-bg), var(--card)); }
.banner .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 5px rgba(61, 220, 151, .15); flex: none; }
.banner.alarm .dot { background: var(--bad); box-shadow: 0 0 0 5px rgba(255, 107, 107, .2); animation: pulse 1.4s infinite; }
.banner .grow { flex: 1; min-width: 0; }

/* ---------- Tarjetas de cámara ---------- */
.rooms { display: grid; grid-template-columns: 1fr; gap: 12px; }
.room { display: grid; gap: 8px; position: relative; overflow: hidden; }
.room.st-warn { border-color: #6a5418; }
.room.st-bad { border-color: #7a2a36; background: linear-gradient(180deg, #2a1520, var(--card) 60%); }
.room-head { display: flex; gap: 8px; align-items: flex-start; }
.room-head h3 { font-size: 1rem; margin: 0; flex: 1; min-width: 0; }
.room-head h3 small { display: block; color: var(--muted); font-weight: 500; font-size: .8rem; }
.st { display: inline-block; font-size: .72rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.st.ok { background: #0f2d25; color: var(--ok); }
.st.warn { background: #2e2610; color: var(--warn); }
.st.bad { background: var(--bad-bg); color: #ffb3b3; }
.reading { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.temp { font-family: var(--mono); font-size: 2.6rem; font-weight: 700; line-height: 1; letter-spacing: -.03em; }
.temp small { font-size: 1.1rem; color: var(--muted); margin-left: 2px; }
.st-bad .temp { color: var(--bad); }
.st-warn .temp { color: var(--warn); }
.hum { font-family: var(--mono); font-size: 1.1rem; color: var(--ice); }
.room-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.room-meta .door-open { color: var(--warn); font-weight: 700; }
.spark svg { width: 100%; height: 54px; display: block; }
.room-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Gráfica grande ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink-2); border-radius: 999px; padding: 7px 13px; font: 700 .84rem var(--font); cursor: pointer; white-space: nowrap; min-height: 38px; }
.chip[aria-pressed="true"] { background: var(--ice); border-color: var(--ice); color: #04202b; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--card-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--mono); font-size: 1.3rem; }
.stat span { font-size: .78rem; color: var(--muted); }

/* ---------- Alertas e incidencias ---------- */
.alert { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: start; }
.alert .ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 1.1rem; background: var(--bad-bg); grid-row: span 2; }
.alert.resuelta .ico, .alert.reconocida .ico { background: var(--card-2); }
.alert h3 { margin: 0; font-size: 1rem; }
.alert p { margin: 0; color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.alert .acts { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.notif { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.notif span { font-size: .72rem; background: var(--card-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; color: var(--ink-2); }
.inc h3 { margin: 0; font-size: 1rem; }
.inc dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0 0; font-size: .88rem; }
.inc dt { color: var(--muted); }
.inc dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Registro APPCC ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--card); }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--bg-2); }
td.out { color: var(--bad); font-weight: 800; }
td .firma { height: 30px; background: #fff; border-radius: 4px; }
.sign-wrap { display: grid; gap: 6px; }
.sign-pad { background: #fff; border-radius: 10px; width: 100%; height: 120px; touch-action: none; cursor: crosshair; border: 2px dashed #8aa4b8; }
.readings-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.readings-grid .rd { display: grid; grid-template-columns: 1fr 86px 76px; gap: 8px; align-items: center; font-size: .88rem; }
.readings-grid .rd input { min-height: 38px; padding: 6px 8px; }

/* ---------- Ajustes ---------- */
.settings { display: grid; gap: 12px; }
.set-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.set-row .name { grid-column: 1 / -1; font-weight: 700; }

/* ---------- Ventanas y formularios ---------- */
.modal { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--bg-2); color: var(--ink); box-shadow: 0 24px 60px rgba(0, 0, 0, .5); }
.modal-wide { width: min(800px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(2, 8, 14, .7); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px 20px; position: sticky; top: 0; background: var(--bg-2); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-head .icon-btn { border: 0; }
.modal-body { padding: 6px 20px 20px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-weight: 700; font-size: .85rem; color: var(--ink-2); }
.field small { color: var(--muted); }
.field-check { grid-template-columns: auto 1fr; align-items: center; }
.field-check label { order: 2; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid #2d4860; border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--ice); }
input:focus, select:focus, textarea:focus { border-color: var(--ice); outline: 2px solid rgba(94, 211, 243, .2); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.steps { padding-left: 1.2em; }

#toasts { position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--card-2); color: var(--ink); padding: 10px 16px; border-radius: 10px; font-weight: 700; border-left: 4px solid var(--ice); box-shadow: 0 8px 24px rgba(0, 0, 0, .4); transition: opacity .4s, transform .4s; }
.toast-bad { border-left-color: var(--bad); background: var(--bad-bg); }
.toast.out { opacity: 0; transform: translateY(8px); }
.demo-note { text-align: center; font-size: .8rem; color: var(--muted); padding: 10px 16px 18px; }

/* ---------- Pantallas medianas ---------- */
@media (min-width: 640px) {
  .rooms { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .full { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .readings-grid { grid-template-columns: 1fr 1fr; }
  .set-row { grid-template-columns: 1.4fr repeat(4, 1fr); }
  .set-row .name { grid-column: auto; }
  .top-actions [data-install] { display: inline-flex; }
}
/* ---------- Escritorio ---------- */
@media (min-width: 960px) {
  body { padding-bottom: 0; }
  .bottombar { display: none; }
  .topbar { grid-template-columns: auto auto 1fr auto; padding: 10px 24px; }
  .status-pill { grid-column: auto; grid-row: auto; justify-self: start; }
  .tabs { display: flex; gap: 4px; grid-column: 1 / -1; grid-row: 2; }
  .tabs a { color: var(--ink-2); text-decoration: none; padding: 8px 14px; border-radius: 8px; font-weight: 700; font-size: .92rem; }
  .tabs a:hover { background: var(--card); }
  .tabs a.active { background: var(--card-2); color: var(--ice); box-shadow: inset 0 -2px 0 var(--ice); }
  .top-actions { grid-column: 4; }
  main { padding: 22px 24px 30px; }
  .rooms { grid-template-columns: repeat(3, 1fr); }
  #toasts { bottom: 28px; }
}

/* ---------- Impresión del registro APPCC (en claro, para papel) ---------- */
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing { background: #fff; color: #000; padding: 0; }
  body.printing #print-area { display: block; padding: 8mm; color: #000; font: 11px/1.4 Arial, sans-serif; }
  #print-area table { background: #fff; }
  #print-area th { background: #eee; color: #000; }
  #print-area th, #print-area td { border: 1px solid #999; color: #000; white-space: normal; }
  #print-area td.out { color: #b00; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
