:root {
  --bg:        #0d0d14;
  --surface:   #16161f;
  --card:      #1c1c28;
  --border:    #2a2a3c;
  --accent:    #7c6dff;
  --accent2:   #00d2ff;
  --text:      #e8e8f0;
  --text-muted:#8888a8;
  --on:        #22c55e;
  --off:       #ef4444;
  --radius:    14px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: .04em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: .82rem;
  color: var(--text-muted);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--off);
  transition: background .4s;
}
.status-dot.online { background: var(--on); box-shadow: 0 0 6px var(--on); }

/* ── Main grid ───────────────────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  main { grid-template-columns: 1fr 1fr; }
  #secTira { grid-column: 1 / -1; }
}

/* ── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }

/* ── Toggle switch ───────────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 48px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background .3s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 4px; top: 4px;
  background: #fff;
  border-radius: 50%;
  transition: transform .3s;
}
input:checked + .slider { background: var(--accent); }
input:checked + .slider::before { transform: translateX(22px); }

/* ── Controls ────────────────────────────────────────────────────── */
.controls { display: flex; flex-direction: column; gap: 14px; }
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.control-row label { color: var(--text-muted); font-size: .88rem; white-space: nowrap; }
.control-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}
.control-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.control-row input[type="color"] {
  width: 40px; height: 30px;
  border: none; background: none; cursor: pointer;
  border-radius: 6px; overflow: hidden;
}

/* ── Efectos ─────────────────────────────────────────────────────── */
.efectos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
@media (max-width: 400px) { .efectos-grid { grid-template-columns: repeat(2, 1fr); } }
.efecto-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 10px 6px;
  cursor: pointer;
  font-size: .78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: background .2s, border-color .2s, color .2s;
}
.efecto-btn:hover { border-color: var(--accent); color: var(--text); }
.efecto-btn.active {
  background: rgba(124,109,255,.15);
  border-color: var(--accent);
  color: var(--accent);
}
.efecto-icon { font-size: 1.1rem; }

/* ── Device list (bombillas) ─────────────────────────────────────── */
.device-list { display: flex; flex-direction: column; gap: 12px; }
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.device-card .device-name { flex: 1; font-size: .9rem; }
.device-card input[type="color"] {
  width: 32px; height: 24px;
  border: none; background: none; cursor: pointer; border-radius: 4px;
}
.device-card input[type="range"] {
  width: 80px;
  -webkit-appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}
.device-card input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent2);
  cursor: pointer;
}
.device-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1rem; padding: 2px 4px;
}
.device-remove:hover { color: var(--off); }

/* ── Espacios ────────────────────────────────────────────────────── */
.espacios-list { display: flex; flex-direction: column; gap: 10px; }
.espacio-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.espacio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.espacio-name { font-weight: 600; }
.espacio-devices { font-size: .78rem; color: var(--text-muted); }
.espacio-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.espacio-actions button { font-size: .75rem; padding: 5px 10px; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  transition: opacity .2s;
}
.btn-primary:hover { opacity: .85; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: .85rem;
  transition: border-color .2s;
}
.btn-secondary:hover { border-color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay[hidden] { display: none !important; }
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h3 { font-size: 1.05rem; }
.modal label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: .85rem;
  color: var(--text-muted);
}
.modal input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: .92rem;
  outline: none;
  width: 100%;
}
.modal input[type="text"]:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.dispositivos-check {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 160px; overflow-y: auto;
}
.dispositivos-check label {
  flex-direction: row; align-items: center; gap: 8px;
  color: var(--text); font-size: .9rem; cursor: pointer;
}

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: .85rem;
  pointer-events: none;
  transition: transform .3s ease, opacity .3s;
  opacity: 0;
  z-index: 300;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
