/* ============================================
   Liton - Dashboard Styles
   Dark-first, responsive, touch-optimized
   ============================================ */

/* --- Custom Properties / Theming --- */

:root {
  /* Dark theme (default) */
  --bg-primary: #08080d;
  --bg-secondary: #0f0f16;
  --bg-card: #1e1e34;
  --bg-card-hover: #282845;
  --bg-input: #16162a;
  --border-color: #33335a;
  --border-subtle: #282848;

  --text-primary: #f0f0f5;
  --text-secondary: #9999b5;
  --text-muted: #6e6e90;

  --accent-blue: #4361ee;
  --accent-blue-soft: rgba(67, 97, 238, 0.15);
  --accent-amber: #f59e0b;
  --accent-amber-soft: rgba(245, 158, 11, 0.12);
  --accent-amber-glow: rgba(245, 158, 11, 0.25);
  --accent-green: #22c55e;
  --accent-green-soft: rgba(34, 197, 94, 0.15);
  --accent-red: #ef4444;
  --accent-red-soft: rgba(239, 68, 68, 0.15);

  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-card-on: 0 4px 20px rgba(245, 158, 11, 0.2);
  --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.4);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --font-stack: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;

  --header-height: 60px;
  --tabs-height: 48px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ebebef;
  --bg-card: #ffffff;
  --bg-card-hover: #f8f8fa;
  --bg-input: #f0f0f4;
  --border-color: #d8d8e0;
  --border-subtle: #e8e8ee;

  --text-primary: #1a1a2e;
  --text-secondary: #6b6b80;
  --text-muted: #9999aa;

  --accent-amber-soft: rgba(245, 158, 11, 0.08);
  --accent-amber-glow: rgba(245, 158, 11, 0.18);
  --accent-blue-soft: rgba(67, 97, 238, 0.1);
  --accent-green-soft: rgba(34, 197, 94, 0.1);
  --accent-red-soft: rgba(239, 68, 68, 0.1);

  --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-card-on: 0 2px 12px rgba(245, 158, 11, 0.15);
  --shadow-elevated: 0 4px 16px rgba(0, 0, 0, 0.1);
}


/* --- Reset / Base --- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-stack);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

input, button {
  font-family: inherit;
  font-size: inherit;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
}


/* --- Login Screen --- */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #06060b;
  position: relative;
  overflow: hidden;
}

/* Animated background layer */
.login-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  isolation: isolate;
  transform: translateZ(0);
}

/* Pulsating flares */
.login-flare {
  position: absolute;
  transform: translateZ(0);
}

.flare-core {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.flare-streak {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.flare-streak-h {
  border-radius: 50%;
}

.flare-streak-v {
  border-radius: 50%;
}

/* Flare 1 - top-left, blue */
.login-flare-1 {
  top: 8%;
  left: 15%;
  width: 200px;
  height: 200px;
  animation: flare-pulse-1 5s ease-in-out infinite;
}

.login-flare-1 .flare-core {
  width: 8px;
  height: 8px;
  background: #6b8aff;
  box-shadow:
    0 0 20px 8px rgba(67, 97, 238, 0.6),
    0 0 60px 20px rgba(67, 97, 238, 0.3),
    0 0 100px 40px rgba(67, 97, 238, 0.1);
}

.login-flare-1 .flare-streak-h {
  width: 240px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(67, 97, 238, 0.4), rgba(107, 138, 255, 0.6), rgba(67, 97, 238, 0.4), transparent);
}

.login-flare-1 .flare-streak-v {
  width: 2px;
  height: 120px;
  background: linear-gradient(180deg, transparent, rgba(67, 97, 238, 0.3), rgba(107, 138, 255, 0.5), rgba(67, 97, 238, 0.3), transparent);
}

/* Flare 2 - bottom-right, purple */
.login-flare-2 {
  bottom: 12%;
  right: 12%;
  width: 200px;
  height: 200px;
  animation: flare-pulse-2 7s ease-in-out infinite;
}

.login-flare-2 .flare-core {
  width: 6px;
  height: 6px;
  background: #a78bfa;
  box-shadow:
    0 0 16px 6px rgba(124, 58, 237, 0.5),
    0 0 50px 16px rgba(124, 58, 237, 0.25),
    0 0 80px 30px rgba(124, 58, 237, 0.08);
}

.login-flare-2 .flare-streak-h {
  width: 180px;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, rgba(124, 58, 237, 0.3), rgba(167, 139, 250, 0.5), rgba(124, 58, 237, 0.3), transparent);
}

.login-flare-2 .flare-streak-v {
  width: 1.5px;
  height: 90px;
  background: linear-gradient(180deg, transparent, rgba(124, 58, 237, 0.25), rgba(167, 139, 250, 0.4), rgba(124, 58, 237, 0.25), transparent);
}

/* Flare 3 - center-right, amber (warm accent) */
.login-flare-3 {
  top: 35%;
  right: 22%;
  width: 200px;
  height: 200px;
  animation: flare-pulse-3 6s ease-in-out infinite;
}

.login-flare-3 .flare-core {
  width: 5px;
  height: 5px;
  background: #fbbf24;
  box-shadow:
    0 0 14px 5px rgba(245, 158, 11, 0.5),
    0 0 40px 14px rgba(245, 158, 11, 0.2),
    0 0 70px 28px rgba(245, 158, 11, 0.06);
}

.login-flare-3 .flare-streak-h {
  width: 160px;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, rgba(245, 158, 11, 0.3), rgba(251, 191, 36, 0.5), rgba(245, 158, 11, 0.3), transparent);
}

.login-flare-3 .flare-streak-v {
  width: 1.5px;
  height: 80px;
  background: linear-gradient(180deg, transparent, rgba(245, 158, 11, 0.2), rgba(251, 191, 36, 0.4), rgba(245, 158, 11, 0.2), transparent);
}

/* Flare pulse animations - breathe in/out at different rates */
@keyframes flare-pulse-1 {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

@keyframes flare-pulse-2 {
  0%, 100% { opacity: 0.3; transform: scale(0.7); }
  40% { opacity: 0.9; transform: scale(1.15); }
  70% { opacity: 0.5; transform: scale(0.9); }
}

@keyframes flare-pulse-3 {
  0%, 100% { opacity: 0.35; transform: scale(0.75); }
  30% { opacity: 0.6; transform: scale(1); }
  60% { opacity: 1; transform: scale(1.25); }
  80% { opacity: 0.5; transform: scale(0.85); }
}

/* Animated smart home blueprint SVG */
.login-blueprint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90vw;
  max-width: 1200px;
  height: auto;
  opacity: 1;
  z-index: 0;
}

/* House outline draw-in */
.bp-house {
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  animation: bp-draw 3s ease-out 0.5s forwards;
}

@keyframes bp-draw {
  to { stroke-dashoffset: 0; }
}

/* Connection paths - animated flowing dashes */
.bp-path {
  animation: bp-flow 3s linear infinite;
}

.bp-path-1 { animation-delay: 0s; }
.bp-path-2 { animation-delay: 0.8s; }
.bp-path-3 { animation-delay: 1.6s; }
.bp-path-4 { animation-delay: 2.4s; }

@keyframes bp-flow {
  to { stroke-dashoffset: -40; }
}

/* Device nodes - glowing dots */
.bp-node {
  fill: #4361ee;
  opacity: 0;
  animation: bp-node-in 0.6s ease-out forwards;
}

.bp-node-1 { animation-delay: 1.5s; }
.bp-node-2 { animation-delay: 1.8s; }
.bp-node-3 { animation-delay: 2.1s; }
.bp-node-4 { animation-delay: 2.4s; }

.bp-hub {
  fill: #f59e0b;
  opacity: 0;
  animation: bp-node-in 0.6s ease-out 1s forwards;
}

@keyframes bp-node-in {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 0.9; transform: scale(1); }
}

/* Node glow rings - pulsing halos */
.bp-ring {
  fill: none;
  stroke: #4361ee;
  stroke-width: 1;
  opacity: 0;
  animation: bp-ring-pulse 3s ease-in-out infinite;
}

.bp-ring-1 { animation-delay: 1.5s; }
.bp-ring-2 { animation-delay: 2s; }
.bp-ring-3 { animation-delay: 2.5s; }
.bp-ring-4 { animation-delay: 3s; }

.bp-ring-hub {
  stroke: #f59e0b;
  stroke-width: 1.5;
  animation-delay: 1s;
}

@keyframes bp-ring-pulse {
  0%, 100% { opacity: 0; transform: scale(0.8); }
  50% { opacity: 0.4; transform: scale(1.8); }
}

/* Floating ambient particles */
.bp-particle {
  fill: #4361ee;
  opacity: 0;
  animation: bp-particle-float 8s ease-in-out infinite;
}

.bp-particle-1 { animation-delay: 0s; }
.bp-particle-2 { animation-delay: 1.5s; }
.bp-particle-3 { animation-delay: 3s; }
.bp-particle-4 { animation-delay: 4.5s; }
.bp-particle-5 { animation-delay: 2s; fill: #f59e0b; }
.bp-particle-6 { animation-delay: 5.5s; }

@keyframes bp-particle-float {
  0%, 100% { opacity: 0; transform: translateY(0); }
  25% { opacity: 0.6; }
  50% { opacity: 0.3; transform: translateY(-30px); }
  75% { opacity: 0.5; }
}

/* Glassmorphic card */
.login-card {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 48px 40px 36px;
  max-width: 400px;
  width: calc(100% - 32px);
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
  animation: card-enter 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.3s both;
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Logo with glow */
.login-logo {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  width: 88px;
  height: 88px;
}

.login-logo svg {
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 4px 16px rgba(245, 158, 11, 0.3)) drop-shadow(0 2px 8px rgba(67, 97, 238, 0.3));
}

.login-logo-glow {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.2) 0%, rgba(67, 97, 238, 0.15) 40%, transparent 70%);
  animation: logo-pulse 3s ease-in-out infinite;
}

@keyframes logo-pulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 1; }
}

/* Brand title - two-tone treatment */
.login-title {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -1.2px;
  margin-bottom: 8px;
  line-height: 1.2;
  color: #ffffff;
}

.brand-lit {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-on {
  background: linear-gradient(135deg, #e0e7ff, #ffffff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 32px;
  letter-spacing: 0.3px;
  font-weight: 400;
}

/* Google sign-in button */
.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 32px;
  width: 100%;
  background: #ffffff;
  color: #1f1f1f;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  min-height: 52px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

@media (hover: hover) {
  .btn-google:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
  }
}

.btn-google:active {
  transform: scale(0.98);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Insteon badge */
.login-badge {
  display: inline-block;
  margin-top: 20px;
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.03);
}

.login-footer {
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
  opacity: 0.7;
}

/* Light theme login adjustments */
[data-theme="light"] #login-screen {
  background: #f0f2f8;
}

[data-theme="light"] .login-flare { opacity: 0.5; }

[data-theme="light"] .login-blueprint { opacity: 0.6; }

[data-theme="light"] .login-card {
  background: rgba(255, 255, 255, 0.75);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

[data-theme="light"] .brand-lit {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  -webkit-background-clip: text;
  background-clip: text;
}

[data-theme="light"] .brand-on {
  background: linear-gradient(135deg, #1e293b, #334155);
  -webkit-background-clip: text;
  background-clip: text;
}

[data-theme="light"] .login-badge {
  color: rgba(0, 0, 0, 0.4);
  border-color: rgba(0, 0, 0, 0.1);
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .btn-google {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}


/* --- Setup Wizard --- */

#setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 24px;
}

.setup-container {
  max-width: 420px;
  width: 100%;
}

.setup-header {
  text-align: center;
  margin-bottom: 32px;
}

.setup-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.setup-header p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* Step indicators */
.setup-steps {
  margin-bottom: 32px;
}

.step-indicators {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-color);
  transition: background var(--transition-normal), box-shadow var(--transition-normal);
  flex-shrink: 0;
}

.step-dot.active {
  background: var(--accent-blue);
  box-shadow: 0 0 8px rgba(67, 97, 238, 0.4);
}

.step-dot.complete {
  background: var(--accent-green);
}

.step-line {
  width: 40px;
  height: 2px;
  background: var(--border-color);
  flex-shrink: 0;
}

/* Setup form */
.setup-step {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  border: 1px solid var(--border-subtle);
}

.setup-step h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
  text-align: center;
}

.setup-step > p {
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition-normal);
  min-height: 48px;
}

.form-group input:focus {
  border-color: var(--accent-blue);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.setup-buttons {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.setup-buttons .btn-secondary {
  flex: 0 0 auto;
}

.setup-buttons .btn-primary {
  flex: 1;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px 24px;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition-normal);
  min-height: 48px;
  margin-top: 8px;
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  display: block;
  padding: 14px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  min-height: 48px;
  transition: background var(--transition-normal);
}

.btn-secondary:active {
  background: var(--bg-card-hover);
}

/* Spinner */
.setup-spinner {
  display: flex;
  justify-content: center;
  padding: 24px 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.setup-status {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Setup success */
.setup-success-icon {
  text-align: center;
  margin-bottom: 16px;
}

.setup-device-preview {
  margin: 16px 0;
  max-height: 200px;
  overflow-y: auto;
}

.setup-device-preview .preview-device {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 14px;
  color: var(--text-secondary);
}

.setup-device-preview .preview-device:last-child {
  border-bottom: none;
}

.preview-device-icon {
  font-size: 18px;
  width: 28px;
  text-align: center;
}


/* --- Dashboard --- */

#dashboard-screen {
  padding-top: calc(var(--safe-area-top) + var(--header-height) + var(--tabs-height));
  padding-bottom: var(--safe-area-bottom);
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.dashboard-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--safe-area-top) + var(--header-height));
  padding-top: var(--safe-area-top);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 16px;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background var(--transition-normal), box-shadow var(--transition-normal);
}

.status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-dot.connecting {
  background: var(--accent-amber);
  animation: pulse-dot 1.2s ease infinite;
}

.status-dot.disconnected {
  background: var(--accent-red);
}

.status-dot.updating {
  background: var(--accent-amber);
  animation: pulse-dot 1.2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  min-width: 48px;
  min-height: 48px;
}

.btn-icon:active {
  background: var(--bg-card);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-blue-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#user-avatar-fallback {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-blue);
}

/* User Menu */
.user-menu-wrapper {
  position: relative;
}

.user-avatar {
  cursor: pointer;
  border: none;
  padding: 0;
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  z-index: 200;
  overflow: hidden;
  animation: menu-fade-in 150ms ease;
}

@keyframes menu-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.user-menu-info {
  padding: 14px 16px;
}

.user-menu-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.user-menu-email {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-divider {
  height: 1px;
  background: var(--border-subtle);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.user-menu-item:active {
  background: var(--bg-card-hover);
}

.user-menu-item:last-child {
  color: var(--accent-red);
}

/* Master Toggle */
#master-toggle {
  color: var(--text-secondary);
}

#master-toggle.all-on {
  color: var(--accent-amber);
}

/* Room Toggle Button */
.room-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
}

.room-toggle:active {
  background: var(--bg-card-hover);
}

.room-toggle .toggle-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-fast);
}

.room-toggle.some-on .toggle-dot {
  background: var(--accent-amber);
}

.room-toggle.some-on {
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--accent-amber);
}


/* Room Tabs */
.room-tabs {
  position: fixed;
  top: calc(var(--safe-area-top) + var(--header-height));
  left: 0;
  right: 0;
  height: var(--tabs-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 99;
}

.room-tabs-scroll {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  height: 100%;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.room-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
  min-height: 36px;
}

@media (hover: hover) {
  .room-tab:not(.active):hover {
    background: var(--bg-card);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  .room-tab.active:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(67, 97, 238, 0.25);
  }
}

.room-tab.active {
  background: rgba(67, 97, 238, 0.2);
  color: #6b8aff;
}

.room-tab:not(.active):active {
  background: var(--bg-card);
}


/* Device Grid */
.dashboard-content {
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-area-bottom));
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.room-section {
  grid-column: 1 / -1;
  margin-top: 8px;
}

.room-section:first-child {
  margin-top: 0;
}

.room-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 4px 6px;
}

.room-toggle-row {
  padding: 0 4px 10px;
}

.room-devices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}


/* Device Tile */
.device-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px;
  cursor: pointer;
  transition:
    background var(--transition-normal),
    border-color var(--transition-normal),
    box-shadow var(--transition-normal),
    transform var(--transition-fast);
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

@media (hover: hover) {
  .device-tile:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--border-color);
  }

  .device-tile.on:hover {
    box-shadow: 0 8px 28px rgba(245, 158, 11, 0.3), 0 0 0 1px rgba(245, 158, 11, 0.25);
  }
}

.device-tile:active {
  transform: scale(0.97);
}

/* ON state */
.device-tile.on {
  background: var(--accent-amber-soft);
  border-color: rgba(245, 158, 11, 0.2);
  box-shadow: var(--shadow-card-on);
}

.device-tile-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.device-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--bg-secondary);
  transition: background var(--transition-normal), color var(--transition-normal);
}

.device-tile.on .device-icon {
  background: var(--accent-amber);
  color: #000;
}

.device-toggle {
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--border-color);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background var(--transition-normal);
  flex-shrink: 0;
  min-width: 44px;
  min-height: 26px;
  padding: 0;
}

.device-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition-normal);
}

.device-toggle.on {
  background: var(--accent-amber);
}

.device-toggle.on::after {
  transform: translateX(18px);
}

.device-tile-bottom {
  margin-top: 12px;
}

.device-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
}

.device-state {
  font-size: 12px;
  color: var(--text-muted);
  transition: color var(--transition-normal);
}

.device-tile.on .device-state {
  color: var(--accent-amber);
}


/* Dimmer Slider */
.dimmer-control {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.dimmer-slider-container {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
}

.dimmer-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-color);
  outline: none;
  transition: background var(--transition-normal);
}

.dimmer-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-amber);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  transition: transform var(--transition-fast);
}

.dimmer-slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
}

.dimmer-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-amber);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.dimmer-level {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}


/* Thermostat */
.thermostat-display {
  display: flex;
  align-items: baseline;
  gap: 2px;
  margin-top: 4px;
}

.thermostat-temp {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.thermostat-unit {
  font-size: 14px;
  color: var(--text-secondary);
}

.thermostat-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.thermostat-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
  min-width: 48px;
  min-height: 48px;
}

.thermostat-btn:active {
  background: var(--bg-card-hover);
}

.thermostat-setpoint {
  font-size: 12px;
  color: var(--text-muted);
}

.thermostat-mode {
  font-size: 11px;
  color: var(--accent-blue);
  font-weight: 500;
  margin-top: 2px;
}


/* Scene tile */
.device-tile.scene {
  cursor: pointer;
}

.device-tile.scene .device-icon {
  background: var(--accent-blue-soft);
  color: var(--accent-blue);
}

.device-tile.scene:active .device-icon {
  background: var(--accent-blue);
  color: #fff;
}

.scene-activating .device-icon {
  animation: scene-pulse 0.6s ease;
}

@keyframes scene-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}


/* Sensor tile */
.device-tile.sensor {
  cursor: default;
}

.device-tile.sensor .device-icon {
  background: var(--accent-green-soft);
  color: var(--accent-green);
}

.device-tile.sensor.triggered .device-icon {
  background: var(--accent-red-soft);
  color: var(--accent-red);
}


/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state p {
  margin-top: 12px;
  font-size: 15px;
}

.empty-hint {
  font-size: 13px !important;
  color: var(--text-muted);
}


/* --- Responsive Breakpoints --- */

/* Phone - 2 columns (default above) */

/* Tablet portrait - 3 columns */
@media (min-width: 600px) {
  .device-grid,
  .room-devices {
    grid-template-columns: repeat(3, 1fr);
  }

  .dashboard-content {
    padding: 20px;
  }
}

/* Tablet landscape / small desktop - 4 columns */
@media (min-width: 900px) {
  .device-grid,
  .room-devices {
    grid-template-columns: repeat(4, 1fr);
  }

  .dashboard-content {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
  }
}

/* Desktop - 5+ columns */
@media (min-width: 1200px) {
  .device-grid,
  .room-devices {
    grid-template-columns: repeat(5, 1fr);
  }

  .dashboard-content {
    max-width: 1400px;
  }
}

/* Large desktop */
@media (min-width: 1600px) {
  .device-grid,
  .room-devices {
    grid-template-columns: repeat(6, 1fr);
  }
}


/* --- Utility --- */

[hidden] {
  display: none !important;
}

/* Focus visible for keyboard accessibility */
:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Prevent text selection on tiles */
.device-tile, .room-tab, .btn-primary, .btn-secondary, .btn-icon, .btn-google {
  -webkit-touch-callout: none;
}

/* --- Modal --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-elevated);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  color: var(--text-secondary);
}

.modal-body {
  padding: 0 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0 0 20px;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px 20px;
}

.modal-footer-right {
  display: flex;
  gap: 12px;
}

.btn-danger-text {
  background: none;
  border: none;
  color: var(--accent-red);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 4px;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.btn-danger-text:hover {
  opacity: 1;
}

/* --- Import File Groups --- */

.import-files {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.import-file-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.import-file-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.import-file-group .required {
  color: var(--accent-red);
}

.file-input {
  font-size: 0.85rem;
  color: var(--text-primary);
  padding: 10px 12px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
}

.file-input:hover {
  border-color: var(--accent-blue);
}

.file-input::file-selector-button {
  background: var(--accent-blue-soft);
  color: var(--accent-blue);
  border: none;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-right: 8px;
}

.file-status {
  font-size: 0.75rem;
  color: var(--accent-green);
}

/* --- Import Preview --- */

.import-preview {
  margin-bottom: 16px;
}

.preview-summary {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.preview-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.preview-stat-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-blue);
}

.preview-stat-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-rooms {
  font-size: 0.8rem;
  color: var(--text-secondary);
  flex: 1;
  min-width: 200px;
}

/* --- Import Result --- */

.import-success {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--accent-green-soft);
  border-radius: var(--radius-sm);
  color: var(--accent-green);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 16px;
}

.import-error {
  padding: 16px;
  background: var(--accent-red-soft);
  border-radius: var(--radius-sm);
  color: var(--accent-red);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
