/* ============================================================
   Panel SCADA LOGO! 8.4 — estilos
   Tema claro/oscuro con variables. data-theme = auto|light|dark
   ============================================================ */

:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #d8dee7;
  --text: #14181f;
  --muted: #667085;
  --accent: #0b7d3e;
  --accent-ink: #ffffff;
  --on: #16a34a;
  --on-glow: rgba(22, 163, 74, 0.55);
  --off: #94a3b8;
  --pending: #d97706;
  --danger: #dc2626;
  --unknown: #cbd5e1;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0c1016;
    --surface: #151b24;
    --surface-2: #1b222d;
    --border: #2a333f;
    --text: #e8edf4;
    --muted: #93a1b3;
    --accent: #22c55e;
    --accent-ink: #06210f;
    --on: #22e06a;
    --on-glow: rgba(34, 224, 106, 0.6);
    --off: #46566b;
    --pending: #f59e0b;
    --danger: #f05252;
    --unknown: #37424f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0c1016;
  --surface: #151b24;
  --surface-2: #1b222d;
  --border: #2a333f;
  --text: #e8edf4;
  --muted: #93a1b3;
  --accent: #22c55e;
  --accent-ink: #06210f;
  --on: #22e06a;
  --on-glow: rgba(34, 224, 106, 0.6);
  --off: #46566b;
  --pending: #f59e0b;
  --danger: #f05252;
  --unknown: #37424f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
/* El atributo [hidden] debe ganar SIEMPRE, aunque el elemento tenga display:grid/flex. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- Botones ---------- */
.btn {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}
.btn-ghost { background: transparent; padding: 0.4rem 0.6rem; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 1rem;
  padding: 1.5rem;
}
.login-card {
  width: min(360px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.8rem; }
.brand h1 { font-size: 1.25rem; }
.brand-sub { margin: 0; color: var(--muted); font-size: 0.85rem; }
.brand-badge {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--accent), #0a5c2e);
  position: relative;
}
.brand-badge::before, .brand-badge::after {
  content: ""; position: absolute; top: 50%; transform: translateY(-50%);
  width: 9px; height: 9px; border-radius: 50%; background: #fff;
}
.brand-badge::before { left: 9px; }
.brand-badge::after { left: 22px; opacity: 0.55; }
.brand-badge.sm { width: 34px; height: 34px; }
.brand-badge.sm::before, .brand-badge.sm::after { width: 7px; height: 7px; }
.brand-badge.sm::before { left: 8px; }
.brand-badge.sm::after { left: 19px; }

.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.field input {
  font: inherit; color: var(--text);
  padding: 0.6rem 0.7rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error {
  margin: 0; color: var(--danger); font-size: 0.85rem;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  padding: 0.5rem 0.7rem; border-radius: 8px;
}
.footnote { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 0; }

/* ---------- Dashboard ---------- */
.dash-view { max-width: 1080px; margin: 0 auto; padding: 1.1rem 1.1rem 3rem; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 0.8rem;
  align-items: center; justify-content: space-between;
  padding: 0.4rem 0 1rem;
}
.topbar-title { display: flex; align-items: center; gap: 0.7rem; }
.topbar-title h1 { font-size: 1.15rem; }
.status-pills { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.last-update { font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.32rem 0.6rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.pill-on { color: var(--on); border-color: color-mix(in srgb, var(--on) 40%, var(--border)); }
.pill-on .dot { background: var(--on); box-shadow: 0 0 8px var(--on-glow); }
.pill-off { color: var(--muted); }

.banner {
  background: color-mix(in srgb, var(--pending) 15%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--pending) 45%, var(--border));
  color: var(--text);
  padding: 0.7rem 0.9rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.9rem;
}

.panel { margin-top: 1.2rem; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.7rem; }
.panel-head h2 { font-size: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.tag {
  font-size: 0.72rem; font-weight: 700; padding: 0.12rem 0.45rem; border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent);
}
.tag-out { background: color-mix(in srgb, #6366f1 20%, transparent); color: #6366f1; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.75rem;
}

/* ---------- Tarjeta de señal ---------- */
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.tile-head { display: flex; align-items: center; gap: 0.6rem; }
.lamp {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: var(--off);
  border: 2px solid color-mix(in srgb, var(--off) 60%, #000 10%);
  transition: background 0.2s, box-shadow 0.2s;
}
.tile.on .lamp {
  background: var(--on);
  border-color: color-mix(in srgb, var(--on) 70%, #000);
  box-shadow: 0 0 12px var(--on-glow);
}
.tile.unknown .lamp { background: var(--unknown); border-style: dashed; }
.tile-id { font-weight: 700; font-size: 0.95rem; }
.tile-label { color: var(--muted); font-size: 0.82rem; line-height: 1.2; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.state-text { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.tile.on .state-text { color: var(--on); }

.pending-badge {
  font-size: 0.7rem; font-weight: 700; color: var(--pending);
  display: inline-flex; align-items: center; gap: 0.3rem;
}
.pending-badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--pending); animation: pulse 1s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- Interruptor (toggle) ---------- */
.switch { position: relative; width: 48px; height: 27px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--off); transition: background 0.18s;
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  transition: transform 0.18s;
}
.switch input:checked + .track { background: var(--on); }
.switch input:checked + .track + .thumb { transform: translateX(21px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + .track { opacity: 0.5; }

.dash-footer { margin-top: 1.6rem; font-size: 0.8rem; text-align: center; }

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .tile-label { display: none; }
}
