/* ── CSS custom properties — Dark theme (default) ──────────────────────────── */
:root,
[data-theme="dark"] {
  --bg:            #0d0805;
  --bg-ambient:    rgba(217, 119, 6, 0.07);
  --bg-ambient-on: rgba(217, 119, 6, 0.14);
  --bg-ambient-off:rgba(71, 85, 105, 0.12);
  --bg-card:       rgba(255, 255, 255, 0.05);
  --border-card:   rgba(255, 180, 50, 0.15);
  --border-card-off:rgba(71, 85, 105, 0.2);
  --shadow-card:   0 24px 60px rgba(0, 0, 0, 0.5);
  --shadow-card-off:0 24px 60px rgba(0, 0, 0, 0.5);
  --accent:        #fbbf24;
  --accent-dark:   #d97706;
  --accent-glow:   rgba(251, 191, 36, 0.4);
  --accent-glow-off:rgba(71, 85, 105, 0.25);
  --track-off:     #334155;
  --thumb-bg:      #1e1208;
  --text-primary:  #fef3c7;
  --text-secondary:rgba(254, 243, 199, 0.55);
  --text-error:    #fca5a5;
  --text-success:  #86efac;
  --input-bg:      rgba(255, 255, 255, 0.07);
  --input-border:  rgba(255, 180, 50, 0.25);
  --input-focus:   rgba(251, 191, 36, 0.5);
  --btn-login-bg:  linear-gradient(135deg, #f59e0b, #d97706);
  --btn-login-shadow: rgba(245, 158, 11, 0.35);
  --theme-icon:    "☀";
}

[data-theme="light"] {
  --bg:            #fdf6ee;
  --bg-ambient:    rgba(217, 119, 6, 0.05);
  --bg-ambient-on: rgba(217, 119, 6, 0.10);
  --bg-ambient-off:rgba(100, 116, 139, 0.08);
  --bg-card:       rgba(255, 255, 255, 0.72);
  --border-card:   rgba(217, 119, 6, 0.2);
  --border-card-off:rgba(100, 116, 139, 0.2);
  --shadow-card:   0 24px 60px rgba(180, 100, 0, 0.12);
  --shadow-card-off:0 24px 60px rgba(100, 116, 139, 0.08);
  --accent:        #d97706;
  --accent-dark:   #b45309;
  --accent-glow:   rgba(217, 119, 6, 0.35);
  --accent-glow-off:rgba(100, 116, 139, 0.2);
  --track-off:     #94a3b8;
  --thumb-bg:      #fff8ee;
  --text-primary:  #1c1209;
  --text-secondary:rgba(28, 18, 9, 0.5);
  --text-error:    #b91c1c;
  --text-success:  #15803d;
  --input-bg:      rgba(0, 0, 0, 0.04);
  --input-border:  rgba(217, 119, 6, 0.3);
  --input-focus:   rgba(217, 119, 6, 0.45);
  --btn-login-bg:  linear-gradient(135deg, #d97706, #b45309);
  --btn-login-shadow: rgba(180, 83, 9, 0.3);
  --theme-icon:    "☾";
}

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

html { height: 100%; }

body {
  height: 100%;
  font-family: -apple-system, 'SF Pro Display', BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  transition: background-color 0.4s ease, color 0.4s ease;
  overflow: hidden;
  position: relative;
}

/* ambient glow */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 60%, var(--bg-ambient) 0%, transparent 70%);
  pointer-events: none;
  transition: background 1.2s ease;
}
body.heat-on::before {
  background: radial-gradient(ellipse at 50% 60%, var(--bg-ambient-on) 0%, transparent 65%);
}
body.heat-off::before {
  background: radial-gradient(ellipse at 50% 60%, var(--bg-ambient-off) 0%, transparent 70%);
}

/* ── Card ───────────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  width: min(380px, calc(100vw - 32px));
  padding: 40px 32px 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 28px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  animation: card-enter 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) both;
  transition: box-shadow 1.2s ease, border-color 1.2s ease;
}

body.heat-off .card {
  border-color: var(--border-card-off);
  box-shadow: var(--shadow-card-off);
}

@keyframes card-enter {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.card.shake {
  animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-7px); }
  40%       { transform: translateX(7px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}

/* ── Page-level buttons (outside card, fixed to viewport corners) ────────────── */
.page-btn {
  position: fixed;
  top: 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 8px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: color 0.3s, background 0.3s;
  user-select: none;
  z-index: 10;
}
.page-btn--left  { left: 20px; }
.page-btn--right { right: 20px; }

/* ── Badges: test mode + feedback toast ──────────────────────────────────────── */
.test-badge,
.toast-badge {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 99px;
  white-space: nowrap;
  pointer-events: none;
}

.test-badge {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
  z-index: 10;
}

/* ── Device feedback pill (below toggle, inside card) ────────────────────────── */
.device-feedback {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
  margin-top: 8px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.device-feedback.visible {
  opacity: 1;
  transform: translateY(0);
}
.device-feedback--success {
  background: rgba(134, 239, 172, 0.12);
  color: #86efac;
  border: 1px solid rgba(134, 239, 172, 0.3);
}
.device-feedback--error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.page-btn:hover {
  color: var(--accent);
  background: rgba(251, 191, 36, 0.1);
}

/* ── Theme toggle button (inside cards: login, setup) ────────────────────────── */
.theme-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 6px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: color 0.3s, background 0.3s;
  user-select: none;
}
.theme-btn:hover {
  color: var(--accent);
  background: rgba(251, 191, 36, 0.1);
}

.history-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 6px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: color 0.3s, background 0.3s;
  user-select: none;
}
.history-btn:hover {
  color: var(--text-error);
  background: rgba(239, 68, 68, 0.1);
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
}

.flame-icon {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 0 10px var(--accent-glow));
  transition: transform 0.6s cubic-bezier(0.34, 1.2, 0.64, 1),
              opacity 0.6s ease,
              filter 1.2s ease;
  transform-origin: center bottom;
}

body.heat-off .flame-icon {
  transform: scale(0.3);
  opacity: 0;
  filter: drop-shadow(0 0 0 transparent);
}

body.heat-on .flame-icon {
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.flame-body {
  animation: flicker 2.1s ease-in-out infinite;
  transform-origin: center bottom;
}

@keyframes flicker {
  0%   { transform: scale(1)    translateY(0);    opacity: 1; }
  25%  { transform: scale(1.04) translateY(-1px); opacity: 0.92; }
  50%  { transform: scale(0.97) translateY(1px);  opacity: 1; }
  75%  { transform: scale(1.03) translateY(-1px); opacity: 0.95; }
  100% { transform: scale(1)    translateY(0);    opacity: 1; }
}

.app-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
}

/* ── Status label ───────────────────────────────────────────────────────────── */
.status-label {
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  margin-bottom: 8px;
  min-height: 1.5em;
  text-align: center;
  transition: color 0.3s;
}

.status-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  letter-spacing: 0.02em;
}

/* ── Toggle ─────────────────────────────────────────────────────────────────── */
.toggle-wrap {
  background: none;
  border: none;
  cursor: pointer;
  padding: 12px;
  border-radius: 56px;
  transition: transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  margin-bottom: 28px;
  position: relative;
}
.toggle-wrap:active { transform: scale(0.96); }
.toggle-wrap:disabled { cursor: not-allowed; opacity: 0.7; }

.toggle-track {
  width: 140px;
  height: 72px;
  border-radius: 40px;
  background: var(--track-off);
  position: relative;
  transition: background 0.35s ease;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.3);
}

/* on state — track */
.toggle-wrap[data-state="idle-on"] .toggle-track {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,0.2),
    0 0 24px var(--accent-glow),
    0 0 48px rgba(251, 191, 36, 0.15);
  animation: pulse-glow 2.5s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: inset 0 2px 6px rgba(0,0,0,0.2), 0 0 20px var(--accent-glow), 0 0 40px rgba(251,191,36,0.12); }
  50%       { box-shadow: inset 0 2px 6px rgba(0,0,0,0.2), 0 0 32px var(--accent-glow), 0 0 64px rgba(251,191,36,0.2); }
}

/* thumb */
.toggle-thumb {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--thumb-bg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.35s ease;
}

.toggle-wrap[data-state="idle-on"] .toggle-thumb {
  transform: translateX(68px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toggle-wrap[data-state="loading"] .toggle-thumb {
  transform: translateX(34px); /* center during loading */
}

/* loading spinner on thumb */
.toggle-wrap[data-state="loading"] .toggle-thumb::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Multi-device layout ─────────────────────────────────────────────────────── */
#devicesContainer {
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Single device: centered like the original */
.device-row--single {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.device-row--single .status-label {
  margin-bottom: 8px;
}

.device-row--single .status-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  letter-spacing: 0.02em;
}

.device-row--single .toggle-wrap {
  margin-bottom: 28px;
}

.device-row--single .device-toggle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* Multi device: name left, toggle right */
.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  gap: 16px;
  width: 100%;
}

.device-row:first-child {
  padding-top: 0;
}

.device-row:last-child {
  padding-bottom: 0;
}

.device-row--centered {
  justify-content: center;
}

.device-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 1;
  letter-spacing: 0.02em;
}

.device-toggle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* In multi mode, status label is smaller */
.device-row:not(.device-row--single) .status-label {
  font-size: 0.75rem;
  margin-bottom: 2px;
}

.device-row:not(.device-row--single) .toggle-wrap {
  margin-bottom: 0;
  padding: 8px;
}

/* Scale down toggle for multi-device */
.device-row:not(.device-row--single) .toggle-track {
  width: 100px;
  height: 52px;
  border-radius: 30px;
}

.device-row:not(.device-row--single) .toggle-thumb {
  width: 40px;
  height: 40px;
  top: 6px;
  left: 6px;
}

.device-row:not(.device-row--single) .toggle-wrap[data-state="idle-on"] .toggle-thumb {
  transform: translateX(48px); /* 100 - 40 - 6 - 6 */
}

.device-row:not(.device-row--single) .toggle-wrap[data-state="loading"] .toggle-thumb {
  transform: translateX(24px);
}

.device-row:not(.device-row--single) .icon-flame {
  width: 18px;
  height: 20px;
}

.device-row:not(.device-row--single) .icon-off {
  width: 15px;
  height: 15px;
}

/* ── Meter card (temperature, above main card) ───────────────────────────────── */
.meter-card {
  width: min(380px, calc(100vw - 32px));
  padding: 28px 28px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  animation: card-enter 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) both;
  transition: box-shadow 1.2s ease, border-color 1.2s ease;
}

body.heat-off .meter-card {
  border-color: var(--border-card-off);
  box-shadow: var(--shadow-card-off);
}

/* ── Temperature display (Meter devices) ─────────────────────────────────────── */
.device-temp-wrap {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex-shrink: 0;
}

.device-temp-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.device-row--single .device-temp-value {
  font-size: 3rem;
}

.device-temp-unit {
  font-size: 0.8rem;
  color: var(--text-secondary);
  align-self: flex-end;
  padding-bottom: 3px;
}

.device-row--single .device-temp-unit {
  font-size: 1.2rem;
  padding-bottom: 6px;
}

/* ── Sensor type select (setup page) ─────────────────────────────────────────── */
.device-sensortype-select {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-family: inherit;
  padding: 2px 0;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.device-sensortype-select:focus {
  border-bottom-color: var(--accent);
  color: var(--text-primary);
}

/* ── Setup page ──────────────────────────────────────────────────────────────── */
.setup-card {
  position: relative;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 36px 28px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 28px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: card-enter 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

.setup-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-card);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.setup-device-item {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 12px;
  transition: border-color 0.2s, background 0.2s;
}

.setup-device-item:has(.setup-checkbox-input:checked) {
  border-color: var(--accent);
  background: rgba(251, 191, 36, 0.06);
}

.setup-device-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  width: 100%;
}

/* Custom checkbox */
.setup-checkbox-wrap {
  position: relative;
  flex-shrink: 0;
}

.setup-checkbox-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.setup-checkbox-custom {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--input-border);
  background: var(--input-bg);
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

.setup-checkbox-input:checked + .setup-checkbox-custom {
  background: var(--accent);
  border-color: var(--accent);
}

.setup-checkbox-input:checked + .setup-checkbox-custom::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

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

.device-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  padding: 2px 0;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

.device-name-input:focus {
  border-bottom-color: var(--accent);
}

.setup-device-type {
  font-size: 0.72rem;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.setup-retry-btn {
  background: none;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  color: var(--text-secondary);
  padding: 8px 20px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.setup-retry-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.setup-cancel-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  padding: 8px;
  text-align: center;
  transition: color 0.2s;
}
.setup-cancel-btn:hover { color: var(--text-primary); }

/* ── Login page ─────────────────────────────────────────────────────────────── */
.login-card {
  width: min(360px, calc(100vw - 32px));
  padding: 40px 32px 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 28px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  animation: card-enter 0.5s cubic-bezier(0.34, 1.2, 0.64, 1) both;
  position: relative;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
.input-group input::placeholder { color: var(--text-secondary); }
.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--input-focus);
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.login-btn {
  margin-top: 8px;
  width: 100%;
  padding: 14px;
  background: var(--btn-login-bg);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--btn-login-shadow);
  transition: opacity 0.2s, transform 0.1s;
}
.login-btn:hover   { opacity: 0.92; }
.login-btn:active  { transform: scale(0.98); }

.login-error {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--text-error);
  text-align: center;
  min-height: 1.2em;
}

/* ── Test mode temperature simulator ────────────────────────────────────────── */
.test-sim {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 4px;
  border-top: 1px solid rgba(252, 165, 165, 0.15);
}
.test-sim__label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(252, 165, 165, 0.55);
  white-space: nowrap;
  flex-shrink: 0;
}
.test-sim__range {
  flex: 1;
  height: 3px;
  accent-color: #fca5a5;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(252, 165, 165, 0.2);
  border-radius: 2px;
}
.test-sim__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fca5a5;
  box-shadow: 0 0 6px rgba(252, 165, 165, 0.5);
  cursor: pointer;
}
.test-sim__range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: #fca5a5;
  box-shadow: 0 0 6px rgba(252, 165, 165, 0.5);
  cursor: pointer;
}
.test-sim__value {
  font-size: 0.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: rgba(252, 165, 165, 0.7);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 3.2em;
  text-align: right;
}

/* ── Activity log bottom sheet ───────────────────────────────────────────────── */
.log-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.log-overlay.visible { opacity: 1; }

.log-sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: min(420px, 100vw);
  max-height: 70vh;
  background: var(--bg-card);
  backdrop-filter: blur(28px) saturate(2);
  -webkit-backdrop-filter: blur(28px) saturate(2);
  border: 1px solid var(--border-card);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  z-index: 51;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.34, 1.1, 0.64, 1);
  box-shadow: 0 -8px 48px rgba(0, 0, 0, 0.45);
}
.log-sheet.visible { transform: translateX(-50%) translateY(0); }

.log-sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-secondary);
  opacity: 0.25;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.log-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  flex-shrink: 0;
}
.log-sheet__title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}
.log-sheet__close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  line-height: 0;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}
.log-sheet__close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.log-sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 24px;
  -webkit-overflow-scrolling: touch;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.log-entry:last-child { border-bottom: none; }

.log-entry__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.log-entry__dot--ok    { background: #86efac; box-shadow: 0 0 6px rgba(134, 239, 172, 0.5); }
.log-entry__dot--error { background: #fca5a5; box-shadow: 0 0 6px rgba(252, 165, 165, 0.5); }

.log-entry__main { flex: 1; min-width: 0; }
.log-entry__action {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-entry__meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.log-entry__time {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
}
.log-entry__time span {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.log-entry__time span:last-child { font-variant-numeric: tabular-nums; }

.log-empty {
  text-align: center;
  padding: 32px 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* ── Device item two-column layout (setup page) ─────────────────────────────── */
.setup-device-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.setup-device-row .setup-device-label { flex: 1; min-width: 0; }

/* ── Temp style picker (setup page) ──────────────────────────────────────────── */
.tempstyle-picker {
  position: relative;
  flex-shrink: 0;
}
.tempstyle-picker__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.tempstyle-picker__btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(251, 191, 36, 0.06);
}

.tempstyle-popup {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  background: rgba(20, 16, 12, 0.92);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(32px) saturate(2);
  -webkit-backdrop-filter: blur(32px) saturate(2);
  padding: 6px;
  min-width: 150px;
  animation: popup-enter 0.18s ease;
}
.tempstyle-popup.open { display: flex; flex-direction: column; }

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

.tempstyle-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tempstyle-opt:hover { background: rgba(251, 191, 36, 0.08); color: var(--text-primary); }
.tempstyle-opt.active {
  background: rgba(251, 191, 36, 0.12);
  color: var(--accent);
}
.tempstyle-opt svg { flex-shrink: 0; opacity: 0.7; }
.tempstyle-opt.active svg { opacity: 1; }

[data-theme="light"] .tempstyle-popup {
  background: rgba(253, 246, 238, 0.94);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

/* ── Meter card: position:relative for ambient ::before ──────────────────────── */
.meter-card { position: relative; }

/* ── Temperature display styles ──────────────────────────────────────────────── */

/* Reset size override from .device-row--single inside styled components */
.temp-minimal .device-temp-value,
.temp-gauge   .device-temp-value,
.temp-bar     .device-temp-value,
.temp-ambient .device-temp-value,
.temp-ring    .device-temp-value { font-size: inherit; }

/* 1 · Minimal ────────────────────────────────────────────────────────────────── */
.temp-minimal {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
}
.temp-minimal__label {
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
  opacity: 0.5;
}
.temp-minimal__row {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.temp-minimal__num {
  font-size: 3.8rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.temp-minimal__unit {
  font-size: 1.4rem;
  color: var(--text-secondary);
  align-self: flex-end;
  padding-bottom: 8px;
}
.temp-minimal__updated {
  font-size: 0.68rem;
  color: var(--text-secondary);
  opacity: 0.45;
}
.temp-minimal__updated::before { content: '· '; }

@keyframes temp-appear {
  from { opacity: 0; transform: scale(0.88) translateY(4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}
.temp-appear {
  animation: temp-appear 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}

/* 2 · Gauge ──────────────────────────────────────────────────────────────────── */
.temp-gauge {
  width: 220px;
  margin: 0 auto;
  position: relative;
  padding-bottom: 4px;
}
.temp-gauge__svg { width: 100%; overflow: visible; }
.temp-gauge__bg {
  fill: none;
  stroke: rgba(255,255,255,0.07);
  stroke-width: 9;
  stroke-linecap: round;
}
.temp-gauge__fill {
  fill: none;
  stroke: #60a5fa;
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s ease, stroke 1s ease;
}
.temp-gauge__inner {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 3px;
}
.temp-gauge .device-temp-value {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.temp-gauge__unit {
  font-size: 1rem;
  color: var(--text-secondary);
  padding-bottom: 4px;
}

/* 3 · Bar ────────────────────────────────────────────────────────────────────── */
.temp-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 8px 16px;
}
.temp-bar__left {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.temp-bar__num {
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.temp-bar__unit {
  font-size: 1.1rem;
  color: var(--text-secondary);
  padding-bottom: 4px;
}
.temp-bar__track {
  width: 8px;
  height: 90px;
  border-radius: 8px;
  background: rgba(255,255,255,0.07);
  position: relative;
  flex-shrink: 0;
}
.temp-bar__fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 8px;
  background: linear-gradient(to top, #f59e0b 0%, #fb923c 35%, #a3e635 65%, #60a5fa 100%);
  transition: height 1.2s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.temp-bar__dot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  left: -3px;
  bottom: -7px;
  box-shadow: 0 0 8px rgba(255,255,255,0.7), 0 0 16px rgba(255,255,255,0.3);
  transition: bottom 1.2s cubic-bezier(0.34, 1.2, 0.64, 1);
  z-index: 1;
}

/* 4 · Ambient ────────────────────────────────────────────────────────────────── */
.temp-ambient {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  position: relative;
  z-index: 1;
}
.temp-ambient__num {
  font-size: 3.2rem;
  font-weight: 800;
  color: white;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.temp-ambient__unit {
  font-size: 1.2rem;
  color: rgba(255,255,255,0.7);
}
.temp-ambient__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.6);
  display: block;
  margin-top: 4px;
}

@keyframes ambient-pulse {
  0%, 100% { opacity: 0.65; }
  50%       { opacity: 1; }
}

.meter-card--cold::before,
.meter-card--cool::before,
.meter-card--warm::before,
.meter-card--hot::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  animation: ambient-pulse 3s ease-in-out infinite;
}

/* Override heat-off border for ambient meters (same specificity, later position wins) */
body .meter-card.meter-card--cold { border-color: rgba(96, 165, 250, 0.45); }
body .meter-card.meter-card--cool { border-color: rgba(52, 211, 153, 0.45); }
body .meter-card.meter-card--warm { border-color: rgba(245, 158, 11, 0.35); }
body .meter-card.meter-card--hot  { border-color: rgba(239, 68, 68, 0.45); }

.meter-card--cold::before { background: radial-gradient(ellipse at 50% 90%, rgba(96, 165, 250, 0.35) 0%, transparent 70%); }
.meter-card--cool::before { background: radial-gradient(ellipse at 50% 90%, rgba(52, 211, 153, 0.30) 0%, transparent 70%); }
.meter-card--warm::before { background: radial-gradient(ellipse at 50% 90%, rgba(245, 158, 11, 0.30) 0%, transparent 70%); }
.meter-card--hot::before  { background: radial-gradient(ellipse at 50% 90%, rgba(239, 68, 68, 0.35) 0%, transparent 70%); }

/* 5 · Ring ───────────────────────────────────────────────────────────────────── */
.temp-ring {
  width: 140px;
  height: 140px;
  position: relative;
  margin: 0 auto;
}
.temp-ring__svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.temp-ring__bg {
  fill: none;
  stroke: rgba(255,255,255,0.07);
  stroke-width: 10;
}
.temp-ring__fill {
  fill: none;
  stroke: #60a5fa;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.2s ease, stroke 1.2s ease;
}
.temp-ring__inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.temp-ring .device-temp-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.temp-ring__unit {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
