:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #273449;
  --line: #334155;
  --txt: #e2e8f0;
  --muted: #94a3b8;
  --acc: #2563eb;
  --acc2: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(900px 460px at 85% -10%, rgba(56, 189, 248, 0.12), transparent 60%),
    radial-gradient(760px 400px at 5% 0%, rgba(37, 99, 235, 0.16), transparent 55%),
    var(--bg);
  color: var(--txt);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.hidden { display: none !important; }

.view { min-height: 100vh; }

/* AUTH */
.auth-bg { position: fixed; inset: 0; z-index: 1; overflow: hidden; }
.auth-bg-img {
  position: absolute;
  inset: -10%;
  width: 120%;
  height: 120%;
  background: url("https://i.ibb.co/QvWkt7Cv/fondo-02.jpg") center/cover no-repeat, #020617;
  filter: brightness(0.7) contrast(1.15) saturate(1.2);
  animation: bgPan 40s ease-in-out infinite alternate;
}
@keyframes bgPan {
  0% { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.15) translate(3%, 2%); }
}
.auth-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(2, 6, 23, 0.8) 0%, rgba(15, 23, 42, 0.4) 100%);
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.6;
  animation: floatOrb 12s infinite ease-in-out alternate;
  pointer-events: none;
}
.orb-1 { width: 500px; height: 500px; background: #0ea5e9; top: -15%; left: -15%; animation-duration: 22s; }
.orb-2 { width: 600px; height: 600px; background: #6366f1; bottom: -25%; right: -15%; animation-duration: 28s; animation-delay: -7s; }
@keyframes floatOrb {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(80px, 80px) scale(1.15); }
}

.auth-wrap {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.auth-card {
  width: 100%;
  max-width: 460px;
  margin: 20px;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 48px;
  border-radius: 32px;
  box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  animation: cardIn 1.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: none; }
}
.auth-header { text-align: center; margin-bottom: 36px; }
.logo {
  font-family: "Outfit", sans-serif;
  font-size: 40px;
  font-weight: 700;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  letter-spacing: -0.03em;
}
.logo-badge {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  padding: 10px 18px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(14, 165, 233, 0.4);
  font-size: 26px;
  line-height: 1;
}
.logo-text { color: #fff; }
.auth-sub { color: var(--muted); margin-top: 10px; font-size: 15px; }
.form-section { display: flex; flex-direction: column; gap: 18px; }
.form-section input {
  width: 100%;
  padding: 18px 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  color: #fff;
  font-size: 15px;
  font-family: "Inter", system-ui, sans-serif;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.form-section input::placeholder { color: rgba(255, 255, 255, 0.4); }
.form-section input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  border-color: #0ea5e9;
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15);
  transform: translateY(-2px);
}
.btn-entrar {
  display: block;
  width: 100%;
  background: linear-gradient(135deg, #0ea5e9, #4f46e5);
  color: #fff;
  border: none;
  padding: 18px;
  border-radius: 16px;
  font-family: "Outfit", sans-serif;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.35);
  position: relative;
  overflow: hidden;
}
.btn-entrar::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0) 100%);
  transform: skewX(-20deg);
  transition: all 0.7s ease;
}
.btn-entrar:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 36px rgba(14, 165, 233, 0.5);
  filter: brightness(1.1);
}
.btn-entrar:hover::after { left: 150%; }
.btn-entrar:disabled { opacity: 0.6; cursor: default; transform: none; }
.auth-status { text-align: center; font-size: 14px; color: #0ea5e9; min-height: 20px; font-weight: 500; }
.auth-status.error {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.45);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 12px;
  padding: 9px 12px;
  min-height: 0;
}

.brand { font-size: 24px; font-weight: 700; color: var(--acc2); }
.brand.small { font-size: 18px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
input, select {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--txt);
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--acc2); }

.btn {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  background: var(--bg3);
  color: var(--txt);
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--acc); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 16px; }

.error {
  background: #7f1d1d;
  color: #fecaca;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-top: 12px;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 14px 18px 0;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 14px;
  z-index: 30;
}
.brand.small {
  font-family: "Outfit", sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  box-shadow: 0 0 12px rgba(14, 165, 233, 0.8);
}
.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 4px;
}
.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 9px 14px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: "Outfit", sans-serif;
  transition: all 0.25s ease;
}
.topbar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.topbar nav a.active {
  background: linear-gradient(135deg, #0ea5e9, #4f46e5);
  color: #fff;
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.35);
}
.user { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  font-family: "Outfit", sans-serif;
  flex-shrink: 0;
}
#user-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn {
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(127, 29, 29, 0.35);
  color: #fca5a5;
  border-radius: 11px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: "Outfit", sans-serif;
}
.logout-btn:hover { background: rgba(239, 68, 68, 0.55); color: #fff; }

.content { padding: 24px; max-width: 1200px; margin: 0 auto; }
h2 { margin: 0 0 18px; font-size: 20px; }
h3 { margin: 24px 0 12px; font-size: 15px; color: var(--acc2); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sec-head h2 { margin-bottom: 0; }
.tools { display: flex; gap: 8px; align-items: center; }
.tools input { width: 240px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 14px; }

/* CARDS */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.card-stat {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.card-stat .n { font-size: 28px; font-weight: 700; }
.card-stat .l { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* LISTAS */
.list { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.row-item .grow { flex: 1; min-width: 200px; }
.row-item .title { font-weight: 600; font-size: 14px; }
.row-item .sub { color: var(--muted); font-size: 12px; margin-top: 3px; word-break: break-all; }
.row-item.clickable { cursor: pointer; }
.row-item.clickable:hover { border-color: var(--acc2); }
.list.small .row-item { padding: 8px 11px; font-size: 13px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
}
.badge.ok { background: #14532d; color: #86efac; }
.badge.pending { background: #78350f; color: #fcd34d; }
.badge.gray { background: var(--bg3); color: var(--muted); }

.actions-row { display: flex; gap: 6px; }

/* TABLA-like device list */
.dev-head, .dev-row {
  display: grid;
  grid-template-columns: 2fr 2fr 1fr 1fr 1.4fr auto;
  gap: 12px;
  padding: 10px 14px;
  align-items: center;
  font-size: 13px;
}
.dev-head { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.dev-row {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.dev-row:hover { border-color: var(--acc2); }

/* DETALLE */
.detail-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.panel-title { font-size: 13px; font-weight: 700; color: var(--acc2); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.live-dot { width: 8px; height: 8px; background: var(--danger); border-radius: 50%; display: inline-block; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.live-img { width: 100%; border-radius: 8px; background: #000; min-height: 200px; object-fit: contain; }
.meta { font-size: 13px; margin-top: 10px; color: var(--muted); }
.meta a, .kv a { color: var(--acc2); word-break: break-all; }
.history { max-height: 460px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.hist-item { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
.hist-item .u { color: var(--txt); word-break: break-all; }
.hist-item .t { color: var(--muted); font-size: 11px; margin-top: 3px; }

/* FOTOS */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 14px; }
.photo-cell {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}
.photo-cell:hover { border-color: var(--acc2); }
.photo-cell img { width: 100%; height: 130px; object-fit: cover; display: block; background: #000; }
.photo-cell .cap { padding: 8px 9px; font-size: 11px; color: var(--muted); word-break: break-all; }
.photo-big { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 8px; }

/* MODALES */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal .card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  width: 420px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
}
.modal .card.wide { width: 780px; }
.modal h3 { margin: 0 0 14px; color: var(--txt); }
.kv { font-size: 13px; margin-bottom: 8px; }
.kv span { color: var(--muted); }
.kv b { font-family: monospace; word-break: break-all; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.org-pick { display: flex; flex-direction: column; gap: 7px; max-height: 240px; overflow-y: auto; }
.org-opt {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
}
.org-opt:hover { border-color: var(--acc2); }
.org-opt.sel { border-color: var(--acc); background: #172554; }
.cfg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 16px; }
@media (max-width: 760px) { .cfg-grid { grid-template-columns: 1fr; } }
.empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; background: var(--bg2); border: 1px dashed var(--line); border-radius: 10px; }

@media (max-width: 860px) { .topbar { flex-wrap: wrap; gap: 10px; } .topbar nav { order: 3; width: 100%; overflow-x: auto; } #user-email { display: none; } }

/* BLOQUEAR URLS */
.blk-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 12px 0 16px; }
.blk-mode { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.blk-mode label { margin: 0 0 10px; font-weight: 600; color: var(--txt); }
.blk-mode .tools { display: flex; gap: 8px; }
.blk-mode .tools input { flex: 1; width: auto; }
.blk-mode textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--txt);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  padding: 10px;
  resize: vertical;
  margin-bottom: 10px;
}
.blk-mode textarea:focus { outline: none; border-color: var(--acc2); }
.blk-template {
  margin: 10px 0 0;
  padding: 10px;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  overflow-x: auto;
}
.cat-row { background: rgba(56, 189, 248, 0.06); border-left: 3px solid var(--acc2); }

/* CATEGORÍAS */
.cats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; max-height: 50vh; overflow-y: auto; }
.cat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.cat-item.forced { border-color: rgba(239, 68, 68, 0.5); background: rgba(127, 29, 29, 0.2); cursor: not-allowed; }
.cat-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-info b { font-size: 13px; }
.cat-info span { font-size: 11px; color: var(--muted); }
.cat-item input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--acc); }
@media (max-width: 760px) { .blk-modes, .cats-grid { grid-template-columns: 1fr; } }

/* LIBERTAD TOTAL */
.freedom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0;
}
.fb-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fb-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.mins-pick { display: flex; gap: 6px; }
.mins-pick button {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.mins-pick button:hover { color: var(--txt); border-color: var(--acc2); }
.mins-pick button.sel {
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

/* CONFIRMACIÓN */
.confirm-text p { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 10px 0; }
.confirm-text p b { color: var(--txt); }
.confirm-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.35);
  color: #7dd3fc;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
}

/* PICK LIST (asignar filtro) */
.pick-list { max-height: 45vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.pick-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
.pick-item:hover { border-color: var(--acc2); }
.pick-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--acc); flex-shrink: 0; }
.pick-item .grow { min-width: 0; }
.pick-item .sub { font-size: 11px; color: var(--muted); }

#modal-filter textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--txt);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  padding: 10px;
  resize: vertical;
  margin: 6px 0 14px;
}
#modal-filter textarea:focus { outline: none; border-color: var(--acc2); }
