:root {
  color-scheme: dark;
  --background: #141b25;
  --background-end: #202838;
  --surface: rgba(39, 48, 62, .82);
  --surface-strong: #303a4b;
  --surface-soft: rgba(255, 255, 255, .055);
  --border: rgba(255, 255, 255, .105);
  --text: #f7f5f0;
  --muted: #b9c1cd;
  --subtle: #99a4b3;
  --accent: #f2c783;
  --accent-text: #282018;
  --focus: #ffe0aa;
  --danger: #ffc2bc;
  --toast: #344050;
  --shadow: 0 18px 55px rgba(0, 0, 0, .18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(ellipse 85% 48% at 50% -12%, rgba(90, 111, 137, .24), transparent 80%),
    linear-gradient(165deg, var(--background), var(--background-end));
  font-family: -apple-system, "SF Pro Text", system-ui, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
}

[hidden] {
  display: none !important;
}

.screen {
  min-height: 100vh;
}

.splash,
.login {
  display: grid;
  place-items: center;
  padding: calc(40px + env(safe-area-inset-top)) calc(24px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(24px + env(safe-area-inset-left));
}

.splash-content,
.login-panel {
  width: min(100%, 390px);
}

.splash-content {
  text-align: center;
}

.brand-icon {
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  margin: 0 auto 26px;
  border: 1px solid rgba(242, 199, 131, .3);
  border-radius: 24px;
  color: var(--accent);
  background: rgba(242, 199, 131, .09);
  box-shadow: 0 16px 48px rgba(242, 199, 131, .08);
}

.brand-icon svg {
  width: 35px;
  height: 35px;
}

.splash h1,
.login h1 {
  margin: 0;
  font-size: clamp(44px, 12vw, 58px);
  font-weight: 650;
  letter-spacing: -.065em;
  line-height: 1.05;
}

.splash p {
  margin: 18px 0 28px;
  color: var(--muted);
}

.login-panel .brand-icon {
  margin-left: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.login-intro {
  max-width: 270px;
  margin: 16px 0 42px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.5;
}

#login-form label {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 650;
}

.password-field {
  display: flex;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.password-field:focus-within {
  border-color: var(--accent);
}

.password-field input {
  width: 100%;
  min-width: 0;
  height: 56px;
  padding: 0 4px 0 18px;
  border: 0;
  border-radius: 18px;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 17px;
}

.password-field input:focus-visible {
  outline: 0;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  flex: none;
  place-items: center;
  border: 0;
  border-radius: 15px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.password-toggle {
  margin-right: 5px;
  color: var(--muted);
}

.button {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  padding: 12px 22px;
  border: 0;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s ease, background-color .2s ease, opacity .2s ease;
}

.button:active:not(:disabled),
.icon-button:active:not(:disabled),
.scene-button:active:not(:disabled),
.power-button:active:not(:disabled),
.channel-power:active:not(:disabled) {
  transform: scale(.97);
}

.button:disabled {
  opacity: .65;
}

.button-primary {
  color: var(--accent-text);
  background: var(--accent);
}

.button-secondary {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
}

.login-submit {
  width: 100%;
  margin-top: 22px;
}

.form-error {
  margin: 12px 2px 0;
  color: var(--danger);
  font-size: 14px;
  line-height: 1.45;
}

.dashboard {
  padding: calc(34px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(50px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

.dashboard-inner {
  width: min(100%, 560px);
  margin: 0 auto;
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.dashboard-header h1 {
  margin: 0;
  font-size: clamp(32px, 8vw, 40px);
  font-weight: 680;
  letter-spacing: -.055em;
  line-height: 1.13;
}

.summary {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.menu-wrap {
  position: relative;
  z-index: 10;
}

.menu-button {
  border: 1px solid var(--border);
  background: var(--surface);
}

.menu {
  position: absolute;
  top: 58px;
  right: 0;
  width: min(285px, calc(100vw - 36px));
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.menu button {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 0;
  border-radius: 12px;
  color: var(--text);
  background: transparent;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.menu button:active {
  background: var(--surface-soft);
}

.status-row {
  display: flex;
  min-height: 30px;
  align-items: center;
  gap: 12px;
  margin: 9px 0 22px;
  color: var(--subtle);
  font-size: 12px;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--danger);
}

.connection-status::before,
.update-status::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.update-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.update-status.busy::before {
  animation: pulse 1s ease-in-out infinite;
}

.content-section,
.room-section {
  margin-top: 31px;
}

.section-heading {
  margin-bottom: 15px;
}

.section-heading h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 680;
  letter-spacing: -.03em;
}

.section-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.scene-button {
  display: flex;
  min-height: 95px;
  align-items: flex-start;
  gap: 12px;
  padding: 17px 15px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, background-color .2s ease;
}

.scene-button:disabled {
  opacity: .56;
}

.scene-button .scene-icon {
  display: grid;
  width: 30px;
  height: 30px;
  flex: none;
  place-items: center;
  border-radius: 10px;
  color: var(--accent);
  background: rgba(242, 199, 131, .11);
}

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

.scene-copy {
  min-width: 0;
}

.scene-name {
  display: block;
  font-size: 14px;
  font-weight: 680;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.scene-description {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.running-section {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 18px;
  border: 1px solid rgba(242, 199, 131, .29);
  border-radius: 18px;
  background: rgba(242, 199, 131, .09);
}

.running-icon {
  display: grid;
  width: 36px;
  height: 36px;
  flex: none;
  place-items: center;
  color: var(--accent);
}

.running-icon svg {
  width: 24px;
  height: 24px;
  animation: pulse 1.5s ease-in-out infinite;
}

.running-section strong {
  font-size: 14px;
}

.running-section p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.rooms {
  display: grid;
  gap: 8px;
}

.room-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
}

.room-heading h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 680;
  letter-spacing: -.03em;
  overflow-wrap: anywhere;
}

.room-count {
  flex: none;
  color: var(--subtle);
  font-size: 12px;
}

.room-cards {
  display: grid;
  gap: 11px;
}

.device-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .055);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: border-color .2s ease, opacity .2s ease, box-shadow .2s ease;
}

.device-card.lit {
  border-color: color-mix(in srgb, var(--lamp-glow) 42%, transparent);
  box-shadow: inset 0 0 36px color-mix(in srgb, var(--lamp-glow) 10%, transparent), 0 10px 42px color-mix(in srgb, var(--lamp-glow) 13%, transparent);
}

.device-card.offline {
  opacity: .62;
}

.device-card.pending::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  animation: loading 1.15s ease-in-out infinite;
  content: "";
}

.device-main {
  display: flex;
  min-height: 88px;
  align-items: center;
  gap: 9px;
  padding: 13px;
}

.device-heading {
  display: flex;
  min-width: 0;
  min-height: 60px;
  flex: 1;
  align-items: center;
  gap: 12px;
  padding: 4px;
  border: 0;
  border-radius: 13px;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.device-heading:disabled {
  cursor: default;
}

.device-icon {
  display: grid;
  width: 43px;
  height: 43px;
  flex: none;
  place-items: center;
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface-soft);
}

.lit .device-icon {
  color: var(--accent);
  background: color-mix(in srgb, var(--lamp-glow) 15%, transparent);
}

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

.device-copy {
  display: block;
  min-width: 0;
  flex: 1;
}

.device-name {
  display: block;
  font-size: 15px;
  font-weight: 680;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.device-state {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.chevron {
  width: 17px;
  height: 17px;
  flex: none;
  color: var(--subtle);
  transition: transform .2s ease;
}

.device-card.expanded .chevron {
  transform: rotate(180deg);
}

.power-button {
  display: grid;
  width: 54px;
  height: 54px;
  flex: none;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--muted);
  background: var(--surface-soft);
  cursor: pointer;
  transition: transform .2s ease, background-color .2s ease, color .2s ease;
}

.power-button svg {
  width: 24px;
  height: 24px;
}

.power-button.on {
  border-color: transparent;
  color: var(--accent-text);
  background: var(--accent);
}

.power-button:disabled,
.channel-power:disabled {
  opacity: .55;
}

.offline-badge {
  display: inline-block;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.device-details {
  padding: 0 18px 20px;
  border-top: 1px solid var(--border);
}

.control-group {
  padding-top: 19px;
}

.control-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 650;
}

.control-value {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.range {
  display: block;
  width: 100%;
  height: 30px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.range:disabled {
  cursor: default;
}

.temperature-range {
  accent-color: #e9ae72;
}

.temperature-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  color: var(--subtle);
  font-size: 11px;
}

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

.mode-button {
  min-height: 44px;
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

.mode-button.selected {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(242, 199, 131, .12);
}

.mode-button:disabled {
  opacity: .5;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 13px;
}

.swatch,
.custom-color {
  display: grid;
  width: 44px;
  height: 44px;
  flex: none;
  place-items: center;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--surface-soft);
  cursor: pointer;
}

.swatch.selected {
  border-color: var(--text);
}

.swatch-dot {
  width: 27px;
  height: 27px;
  border-radius: 9px;
  background: var(--swatch-color);
}

.custom-color {
  position: relative;
  overflow: hidden;
  border-color: var(--border);
}

.custom-color input {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.custom-color input::-webkit-color-swatch-wrapper {
  padding: 5px;
}

.custom-color input::-webkit-color-swatch {
  border: 0;
  border-radius: 8px;
}

.channel-list {
  display: grid;
  gap: 9px;
  padding: 0 13px 14px;
}

.channel-row {
  display: flex;
  min-height: 58px;
  align-items: center;
  gap: 7px;
  padding: 6px 7px 6px 13px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-soft);
}

.channel-label {
  min-width: 0;
  flex: 1;
  font-size: 14px;
  font-weight: 620;
  overflow-wrap: anywhere;
}

.rename-button {
  width: 44px;
  height: 44px;
  color: var(--muted);
}

.rename-button svg {
  width: 18px;
  height: 18px;
}

.channel-power {
  min-width: 84px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.channel-power.on {
  border-color: transparent;
  color: var(--accent-text);
  background: var(--accent);
}

.passive-note {
  margin: -2px 18px 18px 72px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 26px 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
}

.toasts {
  position: fixed;
  z-index: 30;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: calc(16px + env(safe-area-inset-left));
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(100%, 520px);
  padding: 13px 17px;
  border: 1px solid var(--border);
  border-radius: 15px;
  color: var(--text);
  background: var(--toast);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  pointer-events: auto;
}

@keyframes pulse {
  50% { opacity: .4; }
}

@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

@media (min-width: 760px) {
  .dashboard-inner {
    width: min(100%, 930px);
  }

  .room-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .scenes-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --background: #f2f0eb;
    --background-end: #e9edf0;
    --surface: rgba(255, 255, 255, .84);
    --surface-strong: #ffffff;
    --surface-soft: rgba(38, 49, 64, .055);
    --border: rgba(35, 48, 65, .15);
    --text: #202b37;
    --muted: #586572;
    --subtle: #687583;
    --accent: #8a5a25;
    --accent-text: #ffffff;
    --focus: #80521d;
    --danger: #a22b2b;
    --toast: #303d4b;
    --shadow: 0 18px 55px rgba(35, 48, 65, .14);
  }

  .brand-icon,
  .running-section,
  .scene-button .scene-icon,
  .mode-button.selected {
    background: rgba(138, 90, 37, .11);
  }

  .toast {
    color: #ffffff;
  }

  .lit .device-icon {
    color: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* Campo de usuário oculto (só para o gerenciador de senhas do iOS) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
