:root {
  --accent: #ff2e6e;
  --accent-press: #e01b58;
  --accent-soft: #ffe6ef;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #15181f;
  --muted: #8a909c;
  --line: #e7e9ee;
  --hero: #0e0f13;
  --ok: #1fb877;
  --off: #c9ced8;
  --danger: #e2445c;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16,19,28,.06), 0 8px 24px rgba(16,19,28,.05);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; -webkit-font-smoothing: antialiased;
}

/* ---------- Marca ---------- */
.brand { display: flex; align-items: baseline; gap: 8px; padding: 4px 6px; }
.logo { font-size: 20px; font-weight: 800; letter-spacing: -.5px; color: var(--ink); }
.logo::first-letter { color: var(--accent); }
.logo-sub { font-size: 11px; font-weight: 700; letter-spacing: 2px; color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.brand-login { padding: 0 0 14px; }

/* ---------- Tarjetas / controles ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.top-accent { position: relative; overflow: hidden; }
.top-accent::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), #ff7aa6);
}
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 500; }
input, select {
  width: 100%; padding: 11px 13px; border-radius: 10px; font-size: 16px; /* 16px evita zoom en iOS */
  border: 1px solid var(--line); background: #fbfbfc; color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button {
  border: none; border-radius: 10px; padding: 12px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; color: #fff; background: var(--accent); white-space: nowrap; transition: background .15s, transform .05s;
}
button:hover { background: var(--accent-press); }
button:active { transform: translateY(1px); }
button.secondary { background: #eef0f4; color: var(--ink); }
button.secondary:hover { background: #e3e6ec; }
button.block { width: 100%; }
button.link { background: none; color: var(--accent); padding: 4px 6px; font-weight: 600; }
button.link:hover { background: none; text-decoration: underline; }
button.link.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }

/* Filas: por defecto (móvil) se apilan; vuelven a fila en pantallas grandes */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
.mt { margin-top: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }
.hidden { display: none !important; }
.empty { text-align: center; color: var(--muted); padding: 26px 0; }
.secs { max-width: 110px; }

/* ---------- Layout (base = móvil) ---------- */
.app { display: flex; min-height: 100vh; }

/* Sidebar: cajón deslizable fuera de pantalla en móvil */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 60; width: 264px;
  transform: translateX(-100%); transition: transform .2s ease;
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.app.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
.nav-scrim {
  position: fixed; inset: 0; background: rgba(15,18,25,.45); z-index: 55;
  opacity: 0; visibility: hidden; transition: opacity .2s;
}
.app.nav-open .nav-scrim { opacity: 1; visibility: visible; }

.sidebar .brand { margin-bottom: 18px; }
nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; color: #aab0bc; padding: 16px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px;
  text-decoration: none; color: #565d6b; font-size: 14px; font-weight: 500;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: #f4f5f8; color: var(--ink); }
.nav-item.active { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(255,46,110,.30); }
.sidebar-foot { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }

/* User chip */
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--accent);
  color: #fff; font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.u-meta { min-width: 0; }
.u-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-role { font-size: 12px; color: var(--muted); }

/* Main + topbar */
.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; width: 100%; }
.main-wrap.full { max-width: 920px; margin: 0 auto; width: 100%; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.collapse-btn {
  width: 40px; height: 40px; flex: none; border-radius: 50%; padding: 0; font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 18px rgba(255,46,110,.35);
}
.search { display: none; flex: 1; max-width: 520px; position: relative; align-items: center; }
.search svg { width: 18px; height: 18px; position: absolute; left: 14px; color: var(--muted); }
.search input { padding-left: 40px; border-radius: 999px; background: #f4f5f8; font-size: 14px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar .u-meta { display: none; }

.content { padding: 18px 16px; width: 100%; }
.section { animation: fade .16s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Hero banner ---------- */
.hero {
  position: relative; background: var(--hero); color: #fff; border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; overflow: hidden;
  background-image:
    linear-gradient(0deg, rgba(255,46,110,.05), rgba(255,46,110,0) 40%),
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 100% 100%, 26px 26px, 26px 26px;
}
.hero::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--accent); }
.hero-pill {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 1px;
  padding: 6px 12px; border-radius: 999px; color: var(--accent);
  border: 1px solid rgba(255,46,110,.45); background: rgba(255,46,110,.08); margin-bottom: 14px;
}
.hero-title { font-size: 21px; font-weight: 800; margin: 0 0 8px; letter-spacing: -.5px; line-height: 1.2; }
.hero-title span { color: var(--accent); }
.hero-sub { margin: 0; color: #aeb3bd; font-size: 14px; max-width: 640px; line-height: 1.5; }

/* ---------- Dispositivos ---------- */
.device {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; background: #fff;
}
.device .info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.device .name { font-weight: 600; font-size: 15px; }
.device .meta { font-size: 12px; color: var(--muted); word-break: break-all; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.online { background: var(--ok); }
.dot.offline { background: var(--off); }

.toggle { position: relative; width: 52px; height: 30px; flex: none; }
.toggle input { display: none; }
.slider { position: absolute; inset: 0; background: var(--off); border-radius: 30px; transition: .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; height: 24px; width: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(22px); }
.toggle input:disabled + .slider { opacity: .45; cursor: default; }

.pulse-btn { background: var(--accent); min-width: 120px; position: relative; overflow: hidden; }
.pulse-btn.active { background: var(--ok); }

/* Botón circular de encendido (dispositivos modo Pulso) */
.pulse-circle {
  width: 50px; height: 50px; flex: none; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); box-shadow: 0 6px 16px rgba(255,46,110,.30); transition: background .15s, transform .08s;
}
.pulse-circle svg { width: 23px; height: 23px; }
.pulse-circle:hover { background: var(--accent-press); }
.pulse-circle.active { background: var(--ok); box-shadow: 0 6px 16px rgba(31,184,119,.35); }
.pulse-circle:disabled { opacity: .45; box-shadow: none; cursor: default; }

/* Select de tipo en el mantenedor */
.mode-edit { width: auto; min-width: 128px; padding: 7px 9px; font-size: 13px; border-radius: 8px; }
.pb-label { position: relative; z-index: 1; }
.pb-bar { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: rgba(255,255,255,.9); z-index: 0; }
.pulse-btn.locked {
  background: #eef0f4; color: #a2a8b4; box-shadow: none; cursor: not-allowed;
  display: inline-flex; align-items: center; gap: 8px;
}
.pulse-btn.locked:hover { background: #e8eaef; }
.pulse-btn.locked svg { width: 16px; height: 16px; }

/* ---------- Tablas (scroll horizontal en móvil) ---------- */
#deviceTable, #usersTable { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
.tbl th, .tbl td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.tbl tr:last-child td { border-bottom: none; }
.badge { display: inline-block; font-size: 11px; padding: 3px 10px; border-radius: 999px; background: #eaf0ff; color: #3a63d6; font-weight: 700; }
.badge.demo { background: #f1e9ff; color: #7c4dff; }
.status-pill { font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 999px; background: #eef0f4; color: var(--muted); }
.pulse-mini { background: var(--accent); padding: 6px 12px; font-size: 13px; border-radius: 8px; min-width: 0; }
.pulse-mini.active { background: var(--ok); }

/* ---------- Select gráfico de usuario (Permisos) ---------- */
.gselect { position: relative; max-width: 360px; }
.gselect-trigger {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: #fbfbfc; color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font: inherit; cursor: pointer; text-align: left;
}
.gselect-trigger:hover { background: #f4f5f8; }
.gselect-value { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.gs-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 18px; height: 18px; color: var(--muted); flex: none; transition: transform .15s; }
.gselect-trigger[aria-expanded="true"] .chev { transform: rotate(180deg); }

.gselect-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; max-height: 300px; overflow-y: auto;
}
.gselect-opt {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: none; color: var(--ink); border: none; border-radius: 9px;
  padding: 9px 10px; font: inherit; cursor: pointer; text-align: left;
}
.gselect-opt:hover { background: #f4f5f8; }
.gselect-opt.active { background: var(--accent-soft); }
.gselect-opt .check { width: 18px; height: 18px; color: var(--accent); margin-left: auto; flex: none; }
.gs-meta { display: flex; flex-direction: column; min-width: 0; }
.gs-role { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.gselect-empty { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Alta de dispositivo: modo segmentado gráfico ---------- */
.add-device { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.seg { display: inline-flex; background: #f0f2f6; border-radius: 12px; padding: 4px; gap: 4px; align-self: flex-start; max-width: 100%; }
.seg-opt {
  background: none; color: var(--muted); border: none; border-radius: 9px;
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.seg-opt svg { width: 18px; height: 18px; }
.seg-opt:hover { color: var(--ink); }
.seg-opt.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-opt.active:hover { color: var(--accent); }
.secs-wrap { display: inline-flex; align-items: center; gap: 10px; }
.secs-wrap .secs { width: 84px; max-width: 84px; }

.msg { font-size: 13px; padding: 11px 13px; border-radius: 10px; margin-top: 12px; }
.msg.err { background: #fdeced; color: #c0334a; }
.msg.ok  { background: #e7f7ef; color: #138a5a; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,18,25,.55); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .15s ease;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 384px; padding: 26px;
  text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,.32);
}
.modal-icon {
  width: 58px; height: 58px; border-radius: 50%; margin: 0 auto 16px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.modal-icon svg { width: 28px; height: 28px; }
.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Cuenta regresiva (anillo) */
.countdown { position: relative; width: 120px; height: 120px; margin: 0 auto 18px; }
.cd-svg { width: 120px; height: 120px; transform: rotate(-90deg); }
.cd-track { fill: none; stroke: var(--line); stroke-width: 8; }
.cd-ring { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; }
.cd-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 800; color: var(--ink);
}

/* ---------- Tablet / escritorio (mejoras progresivas) ---------- */
@media (min-width: 768px) {
  .sidebar {
    position: static; transform: none; z-index: auto; box-shadow: none;
    width: 244px; flex: none; transition: width .18s;
  }
  .nav-scrim { display: none; }
  .topbar { gap: 16px; padding: 14px 28px; }
  .search { display: flex; }
  .topbar .u-meta { display: block; }
  .content { padding: 28px; max-width: 980px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .hero { padding: 26px 28px; margin-bottom: 18px; }
  .hero-title { font-size: 26px; }
  .card { padding: 22px; }
  select { width: auto; min-width: 190px; }
  input, select { font-size: 14px; }
  .tbl { min-width: 0; }
  .tbl th, .tbl td { white-space: normal; }

  /* Sidebar contraído (solo escritorio) */
  .app.collapsed .sidebar { width: 76px; }
  .app.collapsed .label-text,
  .app.collapsed .nav-label,
  .app.collapsed .logo-sub,
  .app.collapsed .sidebar .u-meta { display: none; }
  .app.collapsed .sidebar .brand { justify-content: center; }
  .app.collapsed .nav-item { justify-content: center; gap: 0; }
  .app.collapsed .sidebar-foot .user-chip { justify-content: center; }
  .app.collapsed .collapse-btn { transform: rotate(180deg); }
}
