:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --transition: 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  --nav-width: 220px;
  --topbar-h: 64px;
}

[data-theme="dark"] {
  --bg-app: #0b0f17;
  --bg-surface: #121826;
  --bg-card: #171f30;
  --bg-card-hover: #1d273b;
  --bg-elevated: #212c42;
  --bg-input: #0e1420;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #4f8ef7;
  --accent-hover: #3b82f6;
  --accent-soft: rgba(79, 142, 247, 0.16);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-modal: 0 24px 64px rgba(0, 0, 0, 0.6);
  --glass: rgba(18, 24, 38, 0.88);
}

[data-theme="light"] {
  --bg-app: #eef2f7;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-elevated: #f1f5f9;
  --bg-input: #f8fafc;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.2);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --shadow-card: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-modal: 0 24px 64px rgba(15, 23, 42, 0.22);
  --glass: rgba(255, 255, 255, 0.92);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Shell Principal */
.app-shell {
  display: flex;
  min-height: 100dvh;
  width: 100%;
}

/* Barra lateral (Tablet 16:9 / Desktop) */
.app-nav {
  width: var(--nav-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 30;
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.nav-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
}

.nav-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.nav-brand-text strong {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-brand-text span {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), transform 0.12s;
  text-align: left;
  min-height: 44px;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
}

.nav-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sse-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.sse-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.sse-indicator.offline .dot {
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

/* Contenido principal */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 25;
  height: var(--topbar-h);
  background: var(--glass);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.top-title-group h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.top-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}

.status-pill.connected {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.meta-stat {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-clock {
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0 8px;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 40px;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-primary);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.btn-danger-ghost {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-compact {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-sm {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 0.82rem;
}

.btn-xs {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 0.76rem;
  border-radius: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color var(--transition);
}

.icon-btn:hover {
  background: var(--bg-card-hover);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}

.add-menu-wrap {
  position: relative;
}

.add-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 190px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 40;
}

.add-menu button {
  background: transparent;
  border: none;
  padding: 10px 12px;
  text-align: left;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}

.add-menu button:hover {
  background: var(--bg-elevated);
}

/* Vistas */
.view-container {
  padding: 18px 20px 32px;
  flex: 1;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

/* Layout Inicio 16:9 */
.home-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.52fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.home-primary {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.home-secondary {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  min-width: 0;
}

.panel-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.block-header h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

/* Cinta de Rutinas */
.routine-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.routine-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  min-height: 44px;
  transition: transform 0.14s, border-color var(--transition), background-color var(--transition);
}

.routine-chip:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.routine-chip:active {
  transform: scale(0.97);
}

.routine-chip.running {
  border-color: var(--success);
  background: var(--success-soft);
}

.routine-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Tabs de habitaciones */
.room-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  flex: 1;
}

.room-tab {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 34px;
  transition: all var(--transition);
}

.room-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Grilla de dispositivos */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 12px;
}

.device-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.15s, border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
  user-select: none;
}

.device-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.device-card.is-on {
  border-color: var(--device-border, rgba(79, 142, 247, 0.45));
  box-shadow: 0 0 0 1px var(--device-border, rgba(79, 142, 247, 0.18)), 0 8px 20px var(--device-glow, rgba(79, 142, 247, 0.12));
}

.device-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.device-icon-badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.device-card.is-on .device-icon-badge {
  background: var(--device-badge-bg, var(--accent-soft));
  color: var(--device-color, var(--accent));
}

.device-icon-badge svg {
  width: 20px;
  height: 20px;
}

.power-btn-mini {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--transition);
}

.device-card.is-on .power-btn-mini {
  background: var(--device-color, var(--accent));
  border-color: transparent;
  color: #fff;
}

.power-btn-mini svg {
  width: 17px;
  height: 17px;
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.device-name {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.rgb-swatch-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}

.device-quick-slider {
  width: 100%;
  margin-top: 2px;
  accent-color: var(--device-color, var(--accent));
  height: 20px;
  cursor: pointer;
}

/* Visor de Cámaras */
.camera-stage-host {
  width: 100%;
}

.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #060911;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.camera-stage.quad {
  aspect-ratio: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  background: transparent;
  border: none;
}

.camera-tile {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05080f;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
}

.camera-tile.active {
  border-color: var(--accent);
}

.camera-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-overlay-top {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  gap: 6px;
}

.cam-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 14, 23, 0.76);
  color: #f8fafc;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.cam-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulseDot 1.6s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.camera-overlay-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px 10px 8px;
  background: linear-gradient(transparent, rgba(5, 8, 15, 0.85));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #f8fafc;
}

.cam-title-label {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cam-controls-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cam-ctrl-btn {
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f8fafc;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.cam-ctrl-btn:hover {
  background: rgba(59, 130, 246, 0.85);
}

.camera-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  color: #cbd5e1;
  background: rgba(6, 9, 17, 0.88);
  font-size: 0.82rem;
  gap: 8px;
}

.camera-selector-strip {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.cam-sel-btn {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.cam-sel-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Actividad reciente */
.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 210px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.8rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.activity-msg {
  color: var(--text-primary);
}

.activity-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  flex-shrink: 0;
}

/* Toolbar & Otras Vistas */
.toolbar-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0;
  font-size: 1.05rem;
}

.section-subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  min-width: 220px;
  flex: 1 1 240px;
  max-width: 360px;
  height: 40px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-box input {
  border: none;
  background: transparent;
  width: 100%;
  outline: none;
  font-size: 0.88rem;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.rooms-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.room-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.room-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.room-section-header h3 {
  margin: 0;
  font-size: 0.98rem;
}

/* Centro de cámaras */
.camera-full-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(290px, 1fr);
  gap: 16px;
  align-items: start;
}

.camera-main-stage {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
}

.camera-cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.camera-info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.camera-info-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.camera-info-card h4 {
  margin: 0 0 4px;
  font-size: 0.94rem;
}

.camera-info-card p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

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

/* Grilla de Rutinas */
.routines-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.routine-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.routine-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.routine-badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}

.routine-card h3 {
  margin: 0;
  font-size: 1rem;
}

.routine-desc {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
  flex: 1;
}

.routine-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.routine-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Vista Conexión */
.settings-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

.settings-card h3 {
  margin: 0;
  font-size: 1.02rem;
}

.settings-card p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-input, .field-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.88rem;
  outline: none;
  min-height: 42px;
}

.field-input:focus, .field-select:focus {
  border-color: var(--accent);
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.copy-row code {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: nowrap;
}

.guide-details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg-elevated);
  font-size: 0.82rem;
}

.guide-details summary {
  cursor: pointer;
  font-weight: 600;
}

.guide-details ol {
  margin: 10px 0 4px;
  padding-left: 18px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* Modales & Bottom Sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.65);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}

.device-sheet, .crud-modal {
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-handle {
  display: none;
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 10px auto 0;
}

.sheet-header, .modal-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sheet-room {
  font-size: 0.76rem;
  color: var(--text-secondary);
  display: block;
}

.sheet-header h3, .modal-header h3 {
  margin: 2px 0 0;
  font-size: 1.08rem;
}

.sheet-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sheet-body, .modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sheet-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* Switch grande */
.switch-lg {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 30px;
}

.switch-lg input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: 0.2s;
}

.slider-round::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: 0.2s;
}

.switch-lg input:checked + .slider-round {
  background: var(--accent);
  border-color: transparent;
}

.switch-lg input:checked + .slider-round::before {
  transform: translateX(24px);
}

/* Controles táctiles del Sheet */
.control-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
  font-weight: 600;
}

.range-touch {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  background: transparent;
  cursor: pointer;
}

.range-touch::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.range-touch.temp-track::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, #ff9329 0%, #fff4e5 55%, #cce5ff 100%);
}

.range-touch::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  margin-top: -7px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.segmented-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.segmented-tabs button {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.segmented-tabs button.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

.rgb-wheel-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#rgb-wheel-canvas {
  width: 210px;
  height: 210px;
  touch-action: none;
  cursor: crosshair;
}

.rgb-readout-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.color-preview-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.preset-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.preset-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Termostato & Multimedia */
.thermostat-dial {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
}

.dial-step-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
}

.dial-temp-readout {
  text-align: center;
}

.dial-temp-readout strong {
  font-size: 2.2rem;
  display: block;
  font-variant-numeric: tabular-nums;
}

.dial-temp-readout span {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.mode-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-chip {
  flex: 1 1 70px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  color: var(--text-primary);
  padding: 11px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow-modal);
  font-size: 0.84rem;
  font-weight: 500;
}

.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* Responsive: Tablet 16:9 medio (840px - 1080px) */
@media (min-width: 840px) and (max-width: 1100px) {
  :root {
    --nav-width: 82px;
  }
  .nav-brand-text, .sse-text {
    display: none;
  }
  .nav-brand {
    justify-content: center;
    padding-bottom: 14px;
  }
  .nav-item {
    flex-direction: column;
    gap: 4px;
    padding: 10px 4px;
    font-size: 0.72rem;
    text-align: center;
  }
  .sse-indicator {
    justify-content: center;
    padding: 8px;
  }
}

/* Responsive: Teléfono 9:16 (< 840px) */
@media (max-width: 839px) {
  .app-shell {
    flex-direction: column;
  }

  .app-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 4px 6px env(safe-area-inset-bottom);
    border-right: none;
    border-top: 1px solid var(--border);
    background: var(--glass);
    backdrop-filter: blur(16px);
    flex-direction: row;
  }

  .nav-brand, .nav-footer {
    display: none;
  }

  .nav-links {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    gap: 2px;
  }

  .nav-item {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    font-size: 0.68rem;
    min-height: 52px;
  }

  .top-bar {
    padding: 0 12px;
    height: 58px;
  }

  .top-title-group h1 {
    font-size: 1rem;
  }

  .meta-stat, .hide-sm, .live-clock {
    display: none;
  }

  .view-container {
    padding: 12px 12px calc(82px + env(safe-area-inset-bottom));
  }

  .home-layout, .camera-full-layout {
    grid-template-columns: 1fr;
  }

  .home-secondary {
    position: static;
    order: -1;
  }

  .activity-panel {
    display: none;
  }

  .device-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .device-card {
    padding: 12px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .device-sheet, .crud-modal {
    max-width: 100%;
    border-radius: 22px 22px 0 0;
    max-height: 88dvh;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sheet-handle {
    display: block;
  }

  .toast-container {
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    max-width: none;
  }
}

/* Pantalla completa CSS fallback (iOS / tablet) */
.camera-stage.css-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 80 !important;
  width: 100vw !important;
  height: 100dvh !important;
  aspect-ratio: auto !important;
  border-radius: 0 !important;
  background: #000 !important;
}
