:root {
  --bg: #0e1015;
  --surface: #171a21;
  --surface-hover: #1f232c;
  --border: #262b36;
  --text: #e8eaed;
  --text-dim: #8b8f9a;
  --accent: #4f9dff;
  --on: #34d399;
  --off: #5a5f6b;
  --warn: #f5a623;
  --radius: 16px;

  /* Cores de identidade de cada card — tons que combinam com o azul escuro de fundo */
  --c-clock: #7dd3fc;   /* azul claro, neutro */
  --c-light: #fbbf24;   /* âmbar quente, luz */
  --c-ac: #38bdf8;      /* azul gelo, ar frio */
  --c-weather: #a5b4fc; /* índigo suave, céu */
  --c-outlet: #2dd4bf;  /* teal, energia */
  --c-timer: #c084fc;   /* violeta, agendamento */
  --c-admin: #fb7185;   /* rosa, acesso restrito */
}

/* Layout dimensionado tendo como referência o display de 5" do Raspberry Pi (800x480) */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden; /* sem scroll em kiosk */
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.screen {
  position: fixed;
  inset: 0;
  height: 100vh;
  width: 100vw;
}

.hidden { display: none !important; }

/* ---------- Tela de proteção ---------- */
.screensaver {
  /* Placeholder de imagem de fundo — troque por uma foto real da sala/empresa
     (ex: background-image: url("../assets/screensaver.jpg"); background-size: cover;) */
  background: linear-gradient(160deg, #0b0d12 0%, #1a1f2b 55%, #14171f 100%);
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 48px;
  cursor: pointer;
  position: relative;
}

.screensaver__logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 75vw;
  max-width: 720px;
  height: auto;
  pointer-events: none;
}

.screensaver__time {
  font-size: 4.5rem;
  font-weight: 300;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.screensaver__date {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-top: 8px;
  text-transform: capitalize;
}

/* Notificações de timer na tela de proteção — estilo lock screen.
   Estado padrão: pilha de cartões. Toque: expande para a lista completa (rolável). */
.ss-notifications {
  position: absolute;
  right: 40px;
  bottom: 40px;
  width: min(42vw, 340px);
  cursor: pointer;
}

.ss-notif-stack {
  position: relative;
  width: 100%;
}

/* Cartões "fantasma" que espiam atrás do principal, indicando mais timers agendados */
.ss-notif-ghost {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  border-radius: 18px;
  background: rgba(38, 33, 51, 0.6);
  border: 1px solid rgba(192, 132, 252, 0.18);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.ss-notif-ghost--1 {
  left: 18px;
  transform: translateY(-14px);
  opacity: 0.85;
  z-index: 1;
}

.ss-notif-ghost--2 {
  left: 36px;
  transform: translateY(-26px);
  opacity: 0.5;
  z-index: 0;
}

.ss-notif-ghost.hidden {
  opacity: 0;
  transform: translateY(0);
}

/* Lista completa, revelada ao tocar na pilha */
.ss-notif-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.ss-notif-list::-webkit-scrollbar {
  display: none;
}

.ss-notif {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02)), rgba(23, 26, 33, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: ss-notif-in 0.3s ease;
}

@keyframes ss-notif-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.ss-notif__icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(192, 132, 252, 0.16);
  color: var(--c-timer);
}

.ss-notif__icon svg {
  width: 22px;
  height: 22px;
}

.ss-notif__body {
  min-width: 0;
  flex: 1;
}

.ss-notif__label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.ss-notif__detail {
  margin-top: 3px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.ss-notif__count {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--c-timer);
  color: #1a0e2e;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---------- Painel: só os cards ---------- */
.panel {
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active {
  background: var(--surface-hover);
}

/* ---------- Grid de tiles (7 cartões: 4 na 1.ª linha, 3 na 2.ª) ----------
   Grelha de 12 colunas: os 4 primeiros ocupam 3 colunas, os restantes 4.
   No ecrã de 800x480 cada linha fica com ~209px — sem scroll. */
.tile-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.tile-grid > .tile { grid-column: span 3; }
.tile-grid > .tile:nth-child(n + 5) { grid-column: span 4; }

@media (min-width: 1100px) and (min-height: 640px) {
  .tile-grid { gap: 20px; }
}

/* Cor de identidade de cada card, aplicada via atributo data-modal */
.tile[data-modal="clock"] { --card-color: var(--c-clock); }
.tile[data-modal="lights"] { --card-color: var(--c-light); }
.tile[data-modal="ac"] { --card-color: var(--c-ac); }
.tile[data-modal="weather"] { --card-color: var(--c-weather); }
.tile[data-modal="outlets"] { --card-color: var(--c-outlet); }
.tile[data-modal="timer"] { --card-color: var(--c-timer); }
.tile[data-modal="admin"] { --card-color: var(--c-admin); }

.tile {
  background:
    radial-gradient(circle at 50% 12%, color-mix(in srgb, var(--card-color) 14%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 10px;
  min-width: 0;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.tile:active {
  background: var(--surface-hover);
}

.tile__icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  color: var(--card-color);
  opacity: 0.55;
  transition: opacity 0.15s ease, filter 0.15s ease;
}

.tile.is-on .tile__icon {
  opacity: 1;
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--card-color) 70%, transparent));
}

.tile__label {
  font-size: 1rem;
  font-weight: 600;
}

.tile__value {
  font-size: 0.85rem;
  line-height: 1.25;
  color: var(--text-dim);
}

.tile.is-on .tile__value {
  color: var(--on);
}

/* Tile informativo (relógio/clima) — sem estado on/off, não reage a toque */
.tile--info {
  cursor: default;
}

.tile--info:active {
  background: var(--surface);
}

.tile--info .tile__icon {
  opacity: 0.9;
}

.tile__badge {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--off);
}

.tile.is-on .tile__badge {
  background: var(--on);
  box-shadow: 0 0 8px var(--on);
}

/* ---------- Modais fullscreen (sem header — só a seta flutuante) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.modal-back {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 5;
}

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 88px 24px 24px;
  overflow-y: auto;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none; /* Firefox */
}

.modal-body::-webkit-scrollbar {
  display: none; /* Chrome/Chromium (Pi) */
}

/* Timer: centraliza a lista + formulário na tela quando cabem sem rolagem.
   Aplicado via JS (classe is-centered) — "justify-content: center" fixo quebraria
   o acesso ao topo por scroll quando o conteúdo excede a tela. */
#timer-body.is-centered {
  justify-content: center;
}

/* Layout do Timer em duas colunas: conteúdo rolável + coluna isolada para as setas
   de rolar. Antes as setas ficavam fixas por cima do conteúdo e podiam bloquear
   toques no "Adicionar" e no "remover" — agora cada uma tem seu próprio espaço. */
.timer-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.timer-layout__content {
  flex: 1;
  min-width: 0;
}

.timer-layout__scroll {
  flex-shrink: 0;
  width: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 16px;
  border-left: 1px solid var(--border);
}

.scroll-btn {
  width: 80px;
  height: 80px;
  background: var(--surface-hover);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* Lista de sub-dispositivos (luzes, tomadas) */
.sublist {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.subtoggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  min-height: 84px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.subtoggle:active {
  background: var(--surface-hover);
}

/* Dispositivo desconectado: sem interação, sem feedback de toque */
.subtoggle.is-offline {
  cursor: default;
  opacity: 0.6;
}

.subtoggle.is-offline:active {
  background: var(--surface);
}

.subtoggle__label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.2rem;
  min-width: 0;
  flex: 1;
}

.subtoggle__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subtoggle__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--off);
  flex-shrink: 0;
}

.subtoggle.is-on .subtoggle__dot {
  background: var(--on);
  box-shadow: 0 0 8px var(--on);
}

.subtoggle__right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.subtoggle__state {
  font-size: 1rem;
  font-weight: 600;
  color: var(--off);
}

.subtoggle__state--offline {
  color: var(--text-dim);
}

/* Botão de editar nome — canto direito do card, não deve acionar o toggle */
.subtoggle__edit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.subtoggle__edit svg {
  width: 18px;
  height: 18px;
}

.subtoggle__edit:active {
  background: var(--border);
  color: var(--text);
}

.subtoggle.is-on .subtoggle__state {
  color: var(--on);
}

/* Controle do A.C.: liga/desliga + stepper de temperatura + modo */
.ac-power {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  min-height: 84px;
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 600;
}

.ac-power .subtoggle__state { font-weight: 700; }

.ac-power.is-on .subtoggle__dot {
  background: var(--on);
  box-shadow: 0 0 8px var(--on);
}

.ac-power.is-on .subtoggle__state {
  color: var(--on);
}

.ac-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 36px;
  padding: 20px 0;
}

.ac-stepper__btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 2.2rem;
  line-height: 1;
  cursor: pointer;
}

.ac-stepper__btn:active {
  background: var(--surface-hover);
}

.ac-stepper__value {
  font-size: 3.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 150px;
  text-align: center;
}

.mode-chips {
  display: flex;
  gap: 10px;
}

.mode-chip {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  text-align: center;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mode-chip.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 157, 255, 0.1);
}

.ac-section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

/* Velocidade da ventoinha: 5 botões touch-friendly, 3 por linha (2 na última linha) */
.mode-chips--fan {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (max-width: 420px) {
  .mode-chips--fan {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Modal de Clima — valor centralizado na tela, informações logo abaixo */
.weather-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.weather-summary {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
}

.weather-summary__temp {
  font-size: 7rem;
  font-weight: 700;
}

.weather-summary__condition {
  color: var(--text-dim);
  font-size: 1.8rem;
}

.weather-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  font-size: 1.4rem;
  color: var(--text-dim);
}

.weather-stats strong {
  color: var(--text);
  font-weight: 600;
}

.forecast-list {
  display: flex;
  gap: 16px;
  width: min(95%, 600px);
}

.forecast-item {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 16px;
  text-align: center;
}

.forecast-item__hour {
  font-size: 1.1rem;
  color: var(--text-dim);
}

.forecast-item__temp {
  font-size: 1.7rem;
  font-weight: 600;
  margin-top: 8px;
}

/* Modal de Relógio */
.clock-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1;
}

.clock-modal__time {
  font-size: 11rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.clock-modal__date {
  font-size: 1.8rem;
  color: var(--text-dim);
  text-transform: capitalize;
}

/* ---------- Modal do Timer ---------- */
.timer-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timer-list__empty {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 12px 0;
}

.timer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  min-height: 64px;
  font-size: 1.05rem;
}

.timer-item__remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px 10px;
}

.timer-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timer-form__label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-top: 8px;
}

.timer-form__label:first-child {
  margin-top: 0;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.chip-grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.chip-grid .mode-chip {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-form__field {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1.1rem;
  min-height: 84px;
}

.timer-form__add {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #061018;
  font-weight: 600;
  font-size: 1.15rem;
  min-height: 92px;
  cursor: pointer;
  margin-top: 8px;
}

/* Popup de confirmação ao criar um timer */
.popup {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup__card {
  width: min(420px, 85vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.popup__icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(52, 211, 153, 0.15);
  color: var(--on);
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup__title {
  font-size: 1.4rem;
  font-weight: 700;
}

.popup__detail {
  font-size: 1.15rem;
  color: var(--text-dim);
}

.popup__detail strong,
.popup__detail span {
  color: var(--text);
  font-weight: 600;
}

.popup__ok {
  width: 100%;
  min-height: 56px;
  margin-top: 8px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #061018;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}

/* Popup para renomear tomada/lâmpada */
.rename-input {
  width: 100%;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 14px 16px;
  font-size: 1.1rem;
  text-align: center;
}

.rename-input:focus {
  outline: none;
  border-color: var(--accent);
}

.rename-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 6px;
}

.rename-btn {
  flex: 1;
  min-height: 56px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  border: 1px solid var(--border);
}

.rename-btn--ghost {
  background: var(--surface-hover);
  color: var(--text);
}

.rename-btn--primary {
  background: var(--accent);
  border: none;
  color: #061018;
}
