/* ============================================================
   knhome — modern smart home dashboard
   ============================================================ */

:root {
  /* Surfaces */
  --bg-0: #070912;
  --bg-1: #0d1224;
  --bg-2: #14193090;

  /* Glass */
  --glass: rgba(255, 255, 255, 0.04);
  --glass-strong: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-strong: rgba(255, 255, 255, 0.14);

  /* Text */
  --text: rgba(255, 255, 255, 0.96);
  --text-dim: rgba(255, 255, 255, 0.62);
  --text-faint: rgba(255, 255, 255, 0.38);

  /* Accents */
  --cool: #5eead4;
  --cool-glow: rgba(94, 234, 212, 0.4);
  --warm: #fb923c;
  --warm-glow: rgba(251, 146, 60, 0.35);
  --violet: #a78bfa;
  --pink: #f0abfc;
  --success: #34d399;
  --danger: #f87171;
  --gold: #fbbf24;

  /* Gradients */
  --grad-cool: linear-gradient(135deg, #5eead4 0%, #818cf8 100%);
  --grad-warm: linear-gradient(135deg, #fb923c 0%, #f0abfc 100%);
  --grad-purple: linear-gradient(135deg, #a78bfa 0%, #f0abfc 100%);
  --grad-power: linear-gradient(135deg, #34d399 0%, #5eead4 100%);

  /* Radii & shadows */
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  --shadow-float: 0 24px 60px -12px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 255, 255, 0.06) inset;

  /* Motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
*:focus-visible { outline: 2px solid var(--cool); outline-offset: 2px; border-radius: 4px; }

html, body {
  margin: 0; padding: 0;
  min-height: 100vh;
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(120, 119, 198, 0.25), transparent 70%),
    radial-gradient(ellipse 60% 50% at 20% 110%, rgba(94, 234, 212, 0.15), transparent 70%),
    radial-gradient(ellipse 50% 50% at 80% 110%, rgba(251, 146, 60, 0.1), transparent 70%);
  pointer-events: none;
  z-index: -2;
}

/* ============================================================
   Animated aurora orbs
   ============================================================ */
.aurora {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  mix-blend-mode: screen;
}
.orb-1 { width: 500px; height: 500px; background: radial-gradient(circle, rgba(94, 234, 212, 0.55), transparent 70%); top: -10%; left: -10%; animation: drift1 22s ease-in-out infinite; }
.orb-2 { width: 600px; height: 600px; background: radial-gradient(circle, rgba(167, 139, 250, 0.5), transparent 70%); bottom: -20%; right: -15%; animation: drift2 28s ease-in-out infinite; }
.orb-3 { width: 400px; height: 400px; background: radial-gradient(circle, rgba(251, 146, 60, 0.35), transparent 70%); top: 40%; left: 50%; animation: drift3 35s ease-in-out infinite; }

@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, 60px) scale(1.1); }
}
@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-60px, -40px) scale(0.9); }
}
@keyframes drift3 {
  0%, 100% { transform: translate(-50%, 0) scale(1); }
  50% { transform: translate(-50%, -60px) scale(1.15); }
}

/* ============================================================
   Layout
   ============================================================ */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 18px calc(env(safe-area-inset-bottom) + 80px);
  position: relative;
  z-index: 1;
}

@media (min-width: 720px) {
  main { max-width: 560px; padding-top: 48px; }
}

/* ============================================================
   Glass card primitive
   ============================================================ */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow-card);
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 0;
  animation: fadeUp 0.6s var(--ease);
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.brand-mark {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: var(--grad-cool);
  display: inline-flex;
  align-items: center; justify-content: center;
  box-shadow: 0 16px 40px -10px var(--cool-glow), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  margin-bottom: 16px;
  animation: float 4s ease-in-out infinite;
}
.brand-mark svg { width: 36px; height: 36px; color: #0a0e1a; }
.brand-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0;
  background: linear-gradient(135deg, #fff 0%, #c4b5fd 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-tag { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

.login-card { padding: 28px 26px; }
.login-card h2 { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.login-card p { color: var(--text-dim); font-size: 13px; margin: 0 0 22px; }

.field { margin-bottom: 14px; position: relative; }
.field input {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 14px 16px 14px 44px;
  border-radius: var(--r);
  font: inherit;
  font-size: 15px;
  transition: border 0.2s, background 0.2s, box-shadow 0.2s;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus {
  outline: none;
  border-color: var(--cool);
  background: rgba(94, 234, 212, 0.04);
  box-shadow: 0 0 0 4px rgba(94, 234, 212, 0.1);
}
.field svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--text-faint);
  pointer-events: none;
}
.field input:focus + svg, .field:focus-within svg { color: var(--cool); }

/* Primary button */
.btn {
  display: inline-flex;
  align-items: center; justify-content: center;
  gap: 8px;
  background: var(--grad-cool);
  color: #0a0e1a;
  border: none;
  padding: 14px 18px;
  border-radius: var(--r);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.15s var(--ease), box-shadow 0.2s, filter 0.2s;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px -10px var(--cool-glow), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 14px 36px -10px var(--cool-glow), 0 1px 0 rgba(255, 255, 255, 0.3) inset; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--glass-border-strong);
  box-shadow: none;
}
.btn.ghost:hover { background: var(--glass); }
.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: #0a0e1a;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  animation: fadeUp 0.5s var(--ease);
}
.greet h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.4px;
}
.greet small { color: var(--text-dim); font-size: 13px; }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  position: relative;
}
.status-chip.online .dot { background: var(--success); }
.status-chip.online .dot::after {
  content: ""; position: absolute; inset: -4px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0.3;
  animation: pulse 2s ease-in-out infinite;
}
.status-chip.offline .dot { background: var(--danger); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.15s;
  margin-left: 8px;
}
.icon-btn:hover { background: var(--glass-strong); color: var(--text); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 16px; height: 16px; }

.topbar-right { display: flex; align-items: center; gap: 0; }

/* ============================================================
   Hero sensor card
   ============================================================ */
.hero {
  position: relative;
  padding: 28px 24px 24px;
  margin-bottom: 16px;
  overflow: hidden;
  border-radius: var(--r-xl);
  animation: fadeUp 0.6s var(--ease) 0.05s both;
}
.hero::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse 80% 60% at 30% 20%, rgba(94, 234, 212, 0.12), transparent 60%),
              radial-gradient(ellipse 60% 60% at 80% 80%, rgba(167, 139, 250, 0.1), transparent 60%);
  pointer-events: none;
}
.hero-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
  margin-bottom: 8px;
  position: relative;
}
.hero-label svg { width: 14px; height: 14px; color: var(--cool); }

.hero-stats {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  align-items: end;
  position: relative;
}
.stat-big {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: 'Space Grotesk', sans-serif;
}
.stat-big .num {
  font-size: 68px;
  font-weight: 600;
  letter-spacing: -2px;
  line-height: 0.95;
  background: var(--grad-cool);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-variant-numeric: tabular-nums;
  transition: filter 0.3s;
}
.stat-big .unit {
  font-size: 22px;
  color: var(--text-dim);
  font-weight: 500;
}
.stat-side {
  display: flex; flex-direction: column;
  align-items: flex-end;
  text-align: right;
}
.stat-side .label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 5px;
}
.stat-side .label svg { width: 12px; height: 12px; }
.stat-side .v {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -1px;
  color: var(--violet);
  font-variant-numeric: tabular-nums;
}
.stat-side .v .unit { font-size: 16px; color: var(--text-dim); font-weight: 500; }

.hero-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--glass-border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
  color: var(--text-dim);
  position: relative;
}
.live {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--success);
  font-weight: 500;
}
.live .dot { background: var(--success); width: 6px; height: 6px; }
.live .dot::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; background: var(--success); opacity: 0.4; animation: pulse 1.8s ease-in-out infinite; }

/* ============================================================
   AC card
   ============================================================ */
.ac-card {
  padding: 22px 22px 18px;
  margin-bottom: 16px;
  border-radius: var(--r-xl);
  animation: fadeUp 0.6s var(--ease) 0.1s both;
  position: relative;
  overflow: hidden;
  transition: background 0.6s var(--ease);
}
.ac-card.is-on {
  background: linear-gradient(165deg, rgba(94, 234, 212, 0.1) 0%, rgba(255, 255, 255, 0.04) 60%);
  border-color: rgba(94, 234, 212, 0.2);
}
.ac-card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.ac-title {
  display: flex; align-items: center; gap: 10px;
}
.ac-title-icon {
  width: 36px; height: 36px;
  border-radius: 12px;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--cool);
  transition: all 0.4s var(--ease);
}
.ac-card.is-on .ac-title-icon {
  background: var(--grad-cool);
  color: #0a0e1a;
  border-color: transparent;
  box-shadow: 0 8px 24px -6px var(--cool-glow);
}
.ac-title-icon svg { width: 18px; height: 18px; }
.ac-title h2 {
  font-size: 16px; font-weight: 600; margin: 0;
  font-family: 'Space Grotesk', sans-serif;
}
.ac-title small { color: var(--text-dim); font-size: 12px; }

/* iOS-style switch */
.switch {
  position: relative;
  width: 56px; height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.3s var(--ease);
  border: 1px solid var(--glass-border);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 26px; height: 26px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.32s var(--ease-bounce), background 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.switch.on { background: var(--grad-power); border-color: transparent; box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.1); }
.switch.on::after { transform: translateX(24px); }
.switch.busy { opacity: 0.6; pointer-events: none; }

/* Temperature dial (large) */
.temp-control {
  display: flex; flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 0 14px;
  opacity: 1;
  transition: opacity 0.4s, max-height 0.5s var(--ease);
  max-height: 240px;
  overflow: hidden;
}
.ac-card:not(.is-on) .temp-control { opacity: 0.3; pointer-events: none; }

.temp-stepper {
  display: flex; align-items: center; gap: 22px;
}
.step-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border-strong);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 24px;
  font-weight: 300;
  transition: all 0.15s var(--ease);
}
.step-btn:hover { background: rgba(94, 234, 212, 0.15); border-color: var(--cool); color: var(--cool); }
.step-btn:active { transform: scale(0.9); }
.step-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; background: var(--glass-strong); color: var(--text); border-color: var(--glass-border); }

.temp-display {
  display: flex; align-items: baseline; gap: 2px;
  font-family: 'Space Grotesk', sans-serif;
  font-variant-numeric: tabular-nums;
}
.temp-display .num {
  font-size: 64px;
  font-weight: 600;
  letter-spacing: -2px;
  line-height: 1;
  background: var(--grad-cool);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  min-width: 120px;
  text-align: center;
}
.temp-display .unit { font-size: 20px; color: var(--text-dim); margin-left: 2px; }

/* Segmented control */
.seg-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
  margin: 14px 4px 8px;
}
.seg {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 4px;
  gap: 2px;
}
.seg button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 9px 10px;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  position: relative;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--glass-strong);
  color: var(--text);
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}
.seg.cool-tint button.active { background: rgba(94, 234, 212, 0.18); color: var(--cool); }

/* Action row */
.ac-actions {
  margin-top: 16px;
  display: flex; gap: 10px;
}
.ac-actions .btn { flex: 1; }

/* ============================================================
   Footer / device info card
   ============================================================ */
.device-card {
  padding: 16px 18px;
  margin-bottom: 16px;
  border-radius: var(--r);
  animation: fadeUp 0.6s var(--ease) 0.15s both;
}
.device-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
  padding: 4px 0;
}
.device-row .k { color: var(--text-dim); }
.device-row .v { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 500; }

/* ============================================================
   Skeleton loader
   ============================================================ */
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--glass) 0%, var(--glass-strong) 50%, var(--glass) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
  color: transparent;
  user-select: none;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 50%;
  transform: translate(-50%, 60px);
  background: rgba(20, 24, 38, 0.92);
  border: 1px solid var(--glass-border-strong);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  padding: 12px 18px 12px 14px;
  border-radius: 14px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.4s var(--ease-bounce);
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px;
  max-width: calc(100% - 32px);
  box-shadow: var(--shadow-float);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast .ic {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.toast.success .ic { background: rgba(52, 211, 153, 0.2); color: var(--success); }
.toast.error .ic { background: rgba(248, 113, 113, 0.2); color: var(--danger); }
.toast .ic svg { width: 13px; height: 13px; }

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.6); opacity: 0; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes numFlash {
  0% { filter: brightness(1.4) drop-shadow(0 0 10px currentColor); }
  100% { filter: brightness(1); }
}
.flash { animation: numFlash 0.5s var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .orb { animation: none; }
}
