/* =========================================================================
   SMART HOME ESP32 - CORE DESIGN SYSTEM & STYLES
   Modern Glassmorphism & Cybernetic IoT Dark Aesthetic
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg-primary: #070a12;
  --bg-secondary: #0d1322;
  --bg-card: rgba(18, 26, 44, 0.72);
  --bg-card-hover: rgba(26, 37, 62, 0.85);
  --bg-card-active: rgba(22, 34, 58, 0.95);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(56, 189, 248, 0.3);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.4);
  --accent-blue: #38bdf8;
  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.4);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.35);
  --accent-rose: #f43f5e;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow-glow-cyan: 0 0 25px rgba(6, 182, 212, 0.35);
  --shadow-glow-amber: 0 0 25px rgba(245, 158, 11, 0.35);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(6, 182, 212, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(245, 158, 11, 0.06) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(13, 19, 34, 0.7) 0%, transparent 100%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: 90px; /* space for mobile dock */
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* ================= APP LAYOUT ================= */

.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px;
}

/* HEADER */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(13, 19, 34, 0.85);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  position: sticky;
  top: 12px;
  z-index: 100;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 15px var(--accent-cyan-glow);
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.brand-title h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, #ffffff 40%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-title p {
  font-size: 0.72rem;
  color: var(--accent-cyan);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-title p .pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulseBeacon 2s infinite;
}

@keyframes pulseBeacon {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Header Controls & Status Pill */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.esp-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.esp-status-pill:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.esp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  transition: all 0.3s;
}

.esp-status-pill.is-connected .esp-dot {
  background: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
}

.esp-status-pill.is-simulated .esp-dot {
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-highlight);
  color: var(--accent-cyan);
  transform: translateY(-2px);
}

.btn-icon:active {
  transform: translateY(0);
}

.btn-icon.is-active {
  background: rgba(6, 182, 212, 0.2);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 15px var(--accent-cyan-glow);
}

.btn-install {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4);
  transition: all 0.25s;
}

.btn-install:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.6);
}

/* ================= TELEMETRY STATS BANNER ================= */

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s, border-color 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
}

.stat-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-wrapper.cyan {
  background: rgba(6, 182, 212, 0.12);
  color: var(--accent-cyan);
}

.stat-icon-wrapper.amber {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-amber);
}

.stat-icon-wrapper.emerald {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
}

.stat-icon-wrapper.blue {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-blue);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* ================= SCENE PRESETS BAR ================= */

.scenes-section {
  margin-bottom: 24px;
}

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

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.scenes-section {
  width: 100%;
  margin-bottom: 20px;
}

.scenes-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.scene-btn {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.scene-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-highlight);
  transform: translateY(-2px);
  color: var(--accent-cyan);
}

.scene-btn[data-scene="all_on"] {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.28);
  color: #f8fafc;
}

.scene-btn[data-scene="all_on"]:hover {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fbbf24;
  box-shadow: 0 4px 18px rgba(245, 158, 11, 0.35);
}

.scene-btn[data-scene="all_off"] {
  background: rgba(30, 41, 59, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
}

.scene-btn[data-scene="all_off"]:hover {
  background: rgba(51, 65, 85, 0.8);
  border-color: rgba(255, 255, 255, 0.3);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

.scene-btn:active {
  transform: translateY(0);
}

.scene-icon {
  font-size: 1.15rem;
}

/* ================= VIEW NAVIGATION TABS ================= */

.view-tabs {
  display: flex;
  gap: 6px;
  background: rgba(13, 19, 34, 0.9);
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  margin-bottom: 22px;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.is-active {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(56, 189, 248, 0.25));
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.25);
}

/* ================= TAB CONTENT SECTIONS ================= */

.tab-content {
  display: none;
  animation: fadeIn 0.25s ease;
}

.tab-content.is-active {
  display: block;
}

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

/* ================= ROOMS & DEVICES GRID ================= */

.devices-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

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

.filter-pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-pill:hover, .filter-pill.is-active {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

/* Rooms Toolbar */
.rooms-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 4px 2px;
}

.rooms-toolbar-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

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

.btn-toolbar {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}

.btn-toolbar:hover {
  background: rgba(6, 182, 212, 0.12);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.rooms-masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

/* Room Box Card (Collapsible Accordion) */
.room-box {
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.room-box:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.room-box.is-open {
  border-color: rgba(56, 189, 248, 0.28);
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.6);
}

.room-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-sm);
  padding: 2px 0;
  transition: opacity 0.2s;
}

.room-box-header:hover {
  opacity: 0.9;
}

.room-box-header:active {
  transform: scale(0.99);
}

.room-box-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-box-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-cyan);
  transition: all 0.2s;
}

.room-box.is-open .room-box-icon {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-blue);
}

.room-box-title h3 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.room-box-title span {
  font-size: 0.68rem;
  color: var(--text-dim);
}

.room-box-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-box-badge {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  font-weight: 600;
  transition: all 0.2s;
}

.room-box-badge.has-active {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.2);
}

.room-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s;
}

.room-box.is-open .room-chevron {
  transform: rotate(180deg);
  color: var(--accent-cyan);
}

.room-box-devices {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin-top 0.25s ease;
}

.room-box.is-open .room-box-devices {
  max-height: 900px;
  opacity: 1;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Single Device Card inside Room */
.device-item {
  background: rgba(13, 19, 34, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: all 0.25s;
}

.device-item.is-on {
  background: rgba(15, 25, 46, 0.9);
  border-color: rgba(56, 189, 248, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.device-item.is-on.type-light {
  border-color: rgba(245, 158, 11, 0.4);
}

.device-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.device-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.device-icon-box {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.device-item.is-on.type-light .device-icon-box {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  box-shadow: 0 0 12px var(--accent-amber-glow);
}

.device-item.is-on.type-fan .device-icon-box {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-blue);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

.device-item.is-on.type-fan .device-icon-box svg {
  animation: fanSpin 0.6s linear infinite;
}

.device-meta h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.device-meta p {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.device-meta p .gpio-tag {
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

/* CUSTOM SWITCH */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

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

.slider-switch {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  border-radius: 30px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.slider-switch::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 2px;
  background-color: #f8fafc;
  border-radius: 50%;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.toggle-switch input:checked + .slider-switch {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

.type-light .toggle-switch input:checked + .slider-switch {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  box-shadow: 0 0 12px var(--accent-amber-glow);
}

.toggle-switch input:checked + .slider-switch::before {
  transform: translateX(20px);
}

/* Fan Speed Stepper Selector */
.fan-stepper-row {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fan-stepper-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.speed-buttons {
  display: flex;
  gap: 4px;
}

.btn-speed {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  width: 32px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-speed:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.btn-speed.is-active {
  background: #0284c7;
  color: #fff;
  border-color: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
}

/* Dimmer slider for lights */
.dimmer-row {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 10px;
}

.dimmer-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: #334155;
  outline: none;
}

.dimmer-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-amber);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-amber);
}

.dimmer-val {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-width: 34px;
  text-align: right;
}

/* ================= ESP32 & IOT BRIDGE TAB ================= */

.esp-dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.esp-card {
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.esp-card-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--text-main);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input, .form-select {
  width: 100%;
  background: rgba(13, 19, 34, 0.8);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.3);
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.5);
}

/* Console Log Terminal */
.console-terminal {
  background: #030712;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 12px;
  height: 280px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.6;
}

.log-entry {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.log-time {
  color: #64748b;
  flex-shrink: 0;
}

.log-tag {
  font-weight: 700;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.65rem;
  flex-shrink: 0;
}

.log-tag.TX { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
.log-tag.RX { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.log-tag.WS { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.log-tag.SYS { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.log-tag.ERR { background: rgba(244, 63, 94, 0.2); color: #f43f5e; }

.log-msg {
  color: #cbd5e1;
  word-break: break-all;
}

/* Arduino Code Viewer */
.code-container {
  position: relative;
  margin-top: 16px;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f172a;
  padding: 8px 14px;
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.code-box {
  background: #050811;
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
  padding: 14px;
  height: 380px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #38bdf8;
  white-space: pre;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
}

/* ================= MODAL DIALOGS ================= */

.modal-backdrop {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  background: var(--bg-card-active);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  padding: 24px;
}

.modal-backdrop.is-open .modal-box {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 800;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}

/* ================= TOAST NOTIFICATION ================= */

.toast-container {
  position: fixed;
  bottom: 85px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-highlight);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideToastUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast.success { border-color: var(--accent-emerald); }
.toast.warning { border-color: var(--accent-amber); }

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

/* ================= MOBILE BOTTOM DOCK (PWA EXPERIENCE) ================= */

.mobile-dock {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 68px;
  background: rgba(9, 13, 22, 0.92);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 100;
  padding: 6px 12px;
  justify-content: space-around;
  align-items: center;
}

.dock-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.dock-item svg {
  width: 20px;
  height: 20px;
  transition: transform 0.2s;
}

.dock-item.is-active {
  color: var(--accent-cyan);
}

.dock-item.is-active svg {
  transform: translateY(-2px);
  filter: drop-shadow(0 0 6px var(--accent-cyan-glow));
}

/* Voice Mic Pulse Effect */
.mic-btn.is-listening {
  background: #f43f5e !important;
  color: #fff !important;
  animation: micPulse 1.2s infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.7); }
  50% { box-shadow: 0 0 0 12px rgba(244, 63, 94, 0); }
}

/* ================= RESPONSIVE MEDIA QUERIES ================= */

@media (max-width: 900px) {
  .esp-dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding-bottom: 68px;
  }
  .app-container {
    padding: 8px 10px;
  }
  .app-header {
    padding: 8px 12px;
    margin-bottom: 10px;
    border-radius: 14px;
  }
  .brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }
  .brand-title h1 {
    font-size: 0.9rem;
    line-height: 1.15;
  }
  .brand-title p {
    font-size: 0.62rem;
  }
  .header-actions {
    gap: 6px;
  }
  .esp-status-pill {
    padding: 4px 8px;
    font-size: 0.66rem;
    gap: 5px;
  }
  .btn-icon {
    width: 32px;
    height: 32px;
  }
  .btn-icon svg {
    width: 16px;
    height: 16px;
  }
  .btn-install {
    padding: 6px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    justify-content: center;
  }
  .btn-install span {
    display: none;
  }

  /* Telemetry Grid: Compact 2x2 cards */
  .telemetry-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
  }
  .stat-card {
    padding: 8px 10px;
    border-radius: 10px;
    gap: 8px;
  }
  .stat-icon-wrapper {
    width: 30px;
    height: 30px;
    border-radius: 6px;
  }
  .stat-icon-wrapper svg {
    width: 15px;
    height: 15px;
  }
  .stat-label {
    font-size: 0.58rem;
    letter-spacing: 0.2px;
  }
  .stat-value {
    font-size: 0.95rem;
    font-weight: 800;
  }
  .stat-sub {
    display: none; /* Hide subtitle on mobile for sleek card height */
  }

  /* Scenes row */
  .scenes-section {
    margin-bottom: 10px;
  }
  .section-header {
    margin-bottom: 6px;
  }
  .section-title {
    font-size: 0.78rem;
    gap: 6px;
  }
  .section-title svg {
    width: 14px;
    height: 14px;
  }
  .scenes-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .scene-btn {
    width: 100%;
    padding: 9px 8px;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 9px;
    gap: 6px;
    justify-content: center;
  }
  .scene-icon {
    font-size: 0.95rem;
  }

  /* Navigation: Dock active, top tabs hidden */
  .mobile-dock {
    display: flex;
    height: 56px;
    padding: 4px 8px;
  }
  .dock-item {
    gap: 2px;
    font-size: 0.64rem;
    padding: 3px 8px;
  }
  .dock-item svg {
    width: 18px;
    height: 18px;
  }
  .view-tabs {
    display: none;
  }

  /* Room & Device Cards */
  .rooms-masonry {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .room-box {
    padding: 10px 12px;
    border-radius: 12px;
  }
  .room-box-header {
    padding: 2px 0;
    margin-bottom: 0;
  }
  .room-box.is-open .room-box-header {
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }
  .room-box-icon {
    width: 26px;
    height: 26px;
  }
  .room-box-icon svg {
    width: 14px;
    height: 14px;
  }
  .room-box-title h3 {
    font-size: 0.82rem;
  }
  .room-box-title span {
    font-size: 0.6rem;
  }
  .room-box-badge {
    font-size: 0.62rem;
    padding: 2px 6px;
  }
  .room-chevron {
    width: 20px;
    height: 20px;
  }
  .room-chevron svg {
    width: 15px;
    height: 15px;
  }
  .device-item {
    padding: 8px 10px;
    border-radius: 8px;
  }
  .device-icon-box {
    width: 30px;
    height: 30px;
  }
  .device-icon-box svg {
    width: 15px;
    height: 15px;
  }
  .device-meta h4 {
    font-size: 0.78rem;
  }
  .device-meta p {
    font-size: 0.62rem;
    gap: 5px;
  }
  .device-meta p .gpio-tag {
    font-size: 0.58rem;
    padding: 1px 4px;
  }
  .toggle-switch {
    width: 38px;
    height: 20px;
  }
  .slider-switch::before {
    width: 14px;
    height: 14px;
    left: 3px;
    bottom: 2px;
  }
  .toggle-switch input:checked + .slider-switch::before {
    transform: translateX(18px);
  }
  .fan-stepper-row {
    margin-top: 6px;
    padding-top: 6px;
  }
  .fan-stepper-label {
    font-size: 0.66rem;
  }
  .btn-speed {
    width: 26px;
    height: 22px;
    font-size: 0.66rem;
  }
  .dimmer-row {
    margin-top: 6px;
    padding-top: 6px;
    gap: 6px;
  }
  .dimmer-val {
    font-size: 0.64rem;
    min-width: 28px;
  }
  .filter-pill {
    padding: 4px 10px;
    font-size: 0.68rem;
  }

  /* Toast & Modals */
  .toast {
    font-size: 0.74rem;
    padding: 7px 14px;
    bottom: 66px;
  }
  .modal-box {
    padding: 16px;
    border-radius: 16px;
    max-width: 95vw;
  }
  .modal-header h2 {
    font-size: 0.95rem;
  }
}
