/* ═══════════════════════════════════════════════════════════
   Arcadea Design System
   ═══════════════════════════════════════════════════════════ */

:root {
  --sand:    #F5F0E8;
  --clay:    #C4A882;
  --clay-d:  #9E7E58;
  --ink:     #1A1612;
  --muted:   #8A7A68;
  --white:   #FDFAF5;
  --green:   #2D4A3E;

  --radius-card: 24px;
  --radius-inner: 14px;
  --radius-pill: 100px;

  --shadow-card: 0 2px 12px rgba(26,22,18,.06), 0 1px 3px rgba(26,22,18,.04);
  --shadow-hover: 0 8px 28px rgba(26,22,18,.10), 0 2px 6px rgba(26,22,18,.06);
  --shadow-btn:   0 4px 16px rgba(26,22,18,.22);

  --transition: 220ms cubic-bezier(.4,0,.2,1);
}

/* ── Reset & base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Garantiza que [hidden] funcione aunque CSS defina display explícito */
[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-weight: 400;
  background: var(--sand);
  color: var(--ink);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Header ────────────────────────────────────────────── */
.app-header {
  background: var(--white);
  border-bottom: 1px solid rgba(196,168,130,.2);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--clay-d);
}

.brand-name {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink);
}

.header-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--ink);
  flex: 1;
  text-align: center;
}

.header-title em {
  font-style: italic;
  color: var(--clay-d);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* ── Status badge ───────────────────────────────────────── */
.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: var(--sand);
  border-radius: var(--radius-pill);
  font-size: .75rem;
  font-weight: 500;
  color: var(--muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  transition: background var(--transition);
}

.status-dot.connected { background: var(--green); box-shadow: 0 0 0 2px rgba(45,74,62,.2); }
.status-dot.error     { background: #B35C44; box-shadow: 0 0 0 2px rgba(179,92,68,.2); }

/* ── Buttons ─────────────────────────────────────────────
   Primary: ink bg, hover lifts 2px + shadow
   Ghost: clay border, hover fills sand
   ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1;
  padding: 10px 20px;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--ink);
  color: var(--white);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-btn);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--clay-d);
  border: 1.5px solid var(--clay);
}
.btn-ghost:hover {
  background: var(--sand);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(196,168,130,.18);
}
.btn-ghost:active { transform: translateY(0); }

.btn-sm { padding: 7px 14px; font-size: .8125rem; }

/* ── Main ───────────────────────────────────────────────── */
.app-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ── Loading / Error states ─────────────────────────────── */
.state-loading,
.state-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 320px;
  color: var(--muted);
  font-size: .9375rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2.5px solid rgba(196,168,130,.25);
  border-top-color: var(--clay);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.state-icon {
  width: 44px;
  height: 44px;
  color: rgba(196,168,130,.5);
}

.state-message {
  color: var(--muted);
}

/* ── Zones grid ─────────────────────────────────────────── */
.zones-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

/* ── Zone card ──────────────────────────────────────────── */
.zone-card {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: fadeUp .35s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.zone-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid rgba(196,168,130,.12);
}

.zone-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink);
}

.zone-title em {
  font-style: italic;
  color: var(--clay-d);
}

.zone-count {
  font-size: .75rem;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}

.device-list {
  padding: 8px 0;
}

/* ── Device item ─────────────────────────────────────────── */
.device-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  transition: background var(--transition);
  position: relative;
}
.device-item:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 22px;
  right: 22px;
  height: 1px;
  background: rgba(196,168,130,.1);
}
.device-item:hover { background: rgba(245,240,232,.5); }

.device-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-inner);
  background: var(--sand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}

.device-icon-wrap svg {
  width: 20px;
  height: 20px;
  color: var(--muted);
  transition: color var(--transition);
}

.device-item.is-on .device-icon-wrap {
  background: rgba(45,74,62,.1);
}
.device-item.is-on .device-icon-wrap svg {
  color: var(--green);
}

.device-info {
  flex: 1;
  min-width: 0;
}

.device-name {
  display: block;
  font-size: .9rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-type {
  display: block;
  font-size: .75rem;
  color: var(--muted);
  margin-top: 1px;
}

/* ── Dim row ─────────────────────────────────────────────── */
.dim-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.dim-row svg {
  width: 13px;
  height: 13px;
  color: var(--clay);
  flex-shrink: 0;
}

.dim-value {
  font-size: .72rem;
  color: var(--muted);
  width: 30px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Range slider ─────────────────────────────────────────── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--sand);
  border-radius: var(--radius-pill);
  outline: none;
  border: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: linear-gradient(to right, var(--clay) var(--pct, 0%), var(--sand) var(--pct, 0%));
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--sand);
}
input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--clay);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--clay-d);
  border: 2px solid var(--white);
  box-shadow: 0 1px 4px rgba(26,22,18,.18);
  transition: transform var(--transition), box-shadow var(--transition);
  margin-top: -6px;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--clay-d);
  border: 2px solid var(--white);
  box-shadow: 0 1px 4px rgba(26,22,18,.18);
  cursor: pointer;
}
input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(26,22,18,.22);
}
input[type="range"]:disabled {
  opacity: .35;
  cursor: not-allowed;
}
input[type="range"]:disabled::-webkit-slider-thumb { transform: none; }

/* ── Toggle switch ───────────────────────────────────────── */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: rgba(138,122,104,.25);
  border-radius: var(--radius-pill);
  transition: background var(--transition);
}

.toggle-thumb {
  position: absolute;
  width: 20px;
  height: 20px;
  top: 3px;
  left: 3px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(26,22,18,.2);
  transition: transform var(--transition), box-shadow var(--transition);
}

.toggle input:checked ~ .toggle-track {
  background: var(--green);
}

.toggle input:checked ~ .toggle-thumb {
  transform: translateX(22px);
  box-shadow: 0 2px 6px rgba(45,74,62,.35);
}

.toggle input:focus-visible ~ .toggle-track {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
}

.toggle.is-loading .toggle-track {
  opacity: .5;
}

/* ── Footer ──────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 16px 24px;
  font-size: .75rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ── Empty zone ──────────────────────────────────────────── */
.zone-empty {
  padding: 20px 22px;
  font-size: .85rem;
  color: var(--muted);
  font-style: italic;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .header-inner { padding: 0 16px; height: 60px; gap: 12px; }
  .header-title { font-size: 1.25rem; }
  .brand-name   { display: none; }
  .status-badge { display: none; }
  .app-main     { padding: 20px 16px; }
  .zones-grid   { grid-template-columns: 1fr; gap: 14px; }
  .app-footer   { padding: 12px 16px; }
}

@media (min-width: 1024px) {
  .zones-grid { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
}
