:root {
  --azul: #071f73;
  --azul2: #1f3b97;
  --laranja: #f36118;
  --verde: #2e9e44;
  --verde2: #43c160;
  --vermelho: #d32f2f;
  --cinza: #f2f4f8;
  --texto: #1a1a2e;
  --borda: #d1dce5;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

body {
  background: var(--cinza);
  color: var(--texto);
  line-height: 1.5;
}

/* ---------- Morador ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, var(--azul2), #8a93c4);
}

.panel {
  background: #fff;
  border-radius: 20px;
  width: 100%;
  max-width: 460px;
  padding: 1.75rem 1.5rem 2rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.brand {
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--azul);
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}
.brand span {
  color: var(--laranja);
}

h1.tower {
  font-size: 1.5rem;
  color: var(--azul);
  margin: 0.25rem 0 1.25rem;
}

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--cinza);
  border-radius: 16px;
  padding: 0.9rem;
  margin-bottom: 1.25rem;
  font-size: 1.25rem;
  font-weight: 700;
}
.light {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #bbb;
  flex-shrink: 0;
}
.light.on {
  background: radial-gradient(circle at 30% 30%, var(--verde2), var(--verde));
  box-shadow: 0 0 14px rgba(46, 158, 68, 0.6);
}
.light.off {
  background: radial-gradient(circle at 30% 30%, #ff7a5c, var(--vermelho));
}
.light.loading {
  background: #ffb74d;
  animation: pulse 1.2s infinite;
}
.fan {
  font-size: 1.5rem;
}
.fan.spin {
  animation: spin 2s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes pulse {
  50% {
    opacity: 0.4;
  }
}

.hint {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #333;
}

.apt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin-bottom: 1.25rem;
}
.apt-btn {
  min-height: 64px;
  border: 2px solid var(--borda);
  border-radius: 14px;
  background: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--azul);
  cursor: pointer;
  transition: all 0.15s ease;
}
.apt-btn:hover {
  border-color: var(--azul2);
}
.apt-btn.selected {
  background: var(--azul);
  color: #fff;
  border-color: var(--azul);
  transform: scale(1.03);
}

.apt-identified {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--azul);
  background: var(--cinza);
  border-radius: 14px;
  padding: 0.9rem;
  margin-bottom: 1.25rem;
}

.apt-fallback {
  margin-bottom: 1.25rem;
}
.apt-fallback input {
  width: 100%;
  font-size: 1.6rem;
  text-align: center;
  padding: 0.75rem;
  border: 2px solid var(--borda);
  border-radius: 14px;
}

.action-btn {
  width: 100%;
  min-height: 80px;
  border: none;
  border-radius: 16px;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform 0.1s ease, filter 0.2s ease;
}
.action-btn:active {
  transform: scale(0.98);
}
.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.action-btn.ligar {
  background: linear-gradient(45deg, var(--verde), var(--verde2));
}
.action-btn.desligar {
  background: linear-gradient(45deg, var(--vermelho), #f05545);
}

.countdown {
  margin-top: 1.25rem;
  background: var(--cinza);
  border-radius: 14px;
  padding: 1rem;
}
.countdown .time {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--azul);
}
.bar {
  margin-top: 0.6rem;
  height: 10px;
  background: #dfe4ee;
  border-radius: 6px;
  overflow: hidden;
}
.bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--verde), var(--verde2));
  width: 0;
  transition: width 1s linear;
}

.msg {
  margin-top: 1rem;
  min-height: 1.4rem;
  font-weight: 600;
}
.msg.error {
  color: var(--vermelho);
}
.msg.success {
  color: var(--verde);
}

.center-info {
  text-align: center;
  color: #fff;
  max-width: 420px;
}
.center-info .brand {
  color: #fff;
  font-size: 2rem;
}
.center-info .brand span {
  color: var(--laranja);
}

/* ---------- Admin ---------- */
.admin-body {
  background: var(--cinza);
}
.topbar {
  background: var(--azul);
  color: #fff;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar .brand {
  color: #fff;
  margin: 0;
}
.topbar .brand span {
  color: var(--laranja);
}
.topbar button {
  background: transparent;
  border: 1.5px solid #fff;
  color: #fff;
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
}
#condoSelect {
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  color: var(--azul);
  max-width: 220px;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem 0;
  background: var(--azul);
}
.tabs button {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-weight: 600;
}
.tabs button.active {
  background: var(--cinza);
  color: var(--azul);
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.card {
  background: #fff;
  border: 1px solid var(--borda);
  border-radius: 14px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--borda);
  font-size: 0.95rem;
  vertical-align: middle;
}
th {
  color: var(--azul);
  font-weight: 700;
}
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}
.badge.on {
  background: #e3f6e8;
  color: var(--verde);
}
.badge.off {
  background: #fde8e6;
  color: var(--vermelho);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
.btn.ligar {
  background: var(--verde);
}
.btn.desligar {
  background: var(--vermelho);
}
.btn.primary {
  background: var(--azul);
}
.btn.warn {
  background: var(--laranja);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Spinner exibido dentro de botões enquanto a requisição está em andamento. */
.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(128, 128, 128, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: exa-spin 0.6s linear infinite;
  vertical-align: middle;
}
button.is-busy {
  opacity: 0.85;
  cursor: progress;
}
@keyframes exa-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Botões compactos para ações em tabela (estilo discreto/outline). */
.btn.sm {
  padding: 0.32rem 0.6rem;
  font-size: 0.82rem;
  border-radius: 6px;
  font-weight: 600;
}
.btn.ghost {
  background: #fff;
  border: 1px solid #d9deea;
  color: var(--azul);
}
.btn.ghost:hover:not(:disabled) {
  background: #f1f5fd;
  border-color: var(--azul2);
}
.btn.ghost.danger {
  color: var(--vermelho);
  border-color: #f0c9c7;
}
.btn.ghost.danger:hover:not(:disabled) {
  background: #fdecea;
  border-color: var(--vermelho);
}
.actions-cell {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}
.btn.sm {
  white-space: nowrap;
}

/* Botão de ajuda "?" ao lado de campos/títulos. */
.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--azul2);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  vertical-align: middle;
  margin-left: 4px;
  padding: 0;
}
.help-btn:hover {
  background: var(--azul);
}
.help-btn.label {
  width: auto;
  height: auto;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  gap: 0.3rem;
}

/* Modal de ajuda (overlay). */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 31, 115, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-overlay.hidden {
  display: none !important;
}
.modal {
  background: #fff;
  border-radius: 16px;
  max-width: 680px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 1.5rem 1.75rem 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.modal-head h3 {
  color: var(--azul);
  font-size: 1.3rem;
}
.modal-x {
  border: none;
  background: var(--cinza, #eef1f7);
  color: var(--azul);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.modal-x:hover {
  background: #dfe5f2;
}
.modal-body {
  color: var(--azul);
  line-height: 1.6;
  font-size: 0.97rem;
}
.modal-body h4 {
  color: var(--azul);
  margin: 1.1rem 0 0.4rem;
  font-size: 1.05rem;
}
.modal-body ol,
.modal-body ul {
  margin: 0.4rem 0 0.4rem 1.2rem;
}
.modal-body li {
  margin-bottom: 0.5rem;
}
.modal-body code {
  background: #eef2fb;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  font-size: 0.88rem;
}
.modal-body table {
  margin: 0.5rem 0;
}
.modal-body a {
  color: var(--azul2);
  font-weight: 600;
}
.modal-note {
  background: #fff7ed;
  border: 1px solid #f5d6ad;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin-top: 1rem;
  font-size: 0.92rem;
}

/* Edição inline dentro de uma célula de tabela (renomear condo, trocar síndico). */
.cell-edit {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.cell-edit select,
.cell-edit input {
  padding: 0.4rem 0.55rem;
  border: 1.5px solid var(--borda);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--azul);
  background-color: #fff;
  min-width: 130px;
  height: 34px;
  box-sizing: border-box;
  font-family: inherit;
}
.cell-edit select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 1.9rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2316235c' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}
.condo-pill {
  display: inline-block;
  background: #eef2fb;
  color: var(--azul);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* Seletor de condomínio (tenant) no topo. */
.condo-switch {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
}
.condo-switch select {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: none;
  font-weight: 700;
  color: var(--azul);
  cursor: pointer;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--azul2), #8a93c4);
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}
.login-card h2 {
  color: var(--azul);
  margin-bottom: 1.25rem;
  text-align: center;
}
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.field input,
.field select {
  width: 100%;
  padding: 0.7rem;
  border: 1.5px solid var(--borda);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--azul);
  background-color: #fff;
  box-sizing: border-box;
  height: 44px;
}
/* Select com aparência custom (some a seta nativa "Windows 98" e põe um chevron). */
.field select {
  cursor: pointer;
  min-width: 130px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2316235c' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--azul2);
}
.full {
  width: 100%;
  padding: 0.8rem;
  font-size: 1.05rem;
}

.row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
}
.row .field {
  margin-bottom: 0;
}
.muted {
  color: #667;
  font-size: 0.9rem;
}
.qr-box {
  text-align: center;
  margin-top: 1rem;
}
.hidden {
  display: none !important;
}

/* ---------- Placas 7×14 cm (QR por apartamento) ---------- */
:root {
  --plate-navy: #16235c;
  --plate-orange: #f15a22;
}
.plate-sheet {
  display: flex;
  flex-wrap: wrap;
  gap: 6mm;
  margin-top: 1rem;
}
.plate {
  width: 70mm;
  height: 140mm;
  position: relative;
  overflow: hidden;
  background: #fff;
  color: var(--plate-navy);
  border: 0.2mm solid #e2e2e2;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8mm 5mm 5mm;
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  break-inside: avoid;
  page-break-inside: avoid;
}
.plate .corner {
  position: absolute;
  width: 24mm;
  height: 24mm;
  z-index: 0;
}
.plate .corner.tr {
  top: 0;
  right: 0;
}
.plate .corner.bl {
  bottom: 0;
  left: 0;
}
.plate .corner svg {
  width: 100%;
  height: 100%;
  display: block;
}
.plate-title,
.plate-qr,
.plate-steps,
.plate-contact,
.plate-foot {
  position: relative;
  z-index: 1;
}

.plate-title {
  font-size: 13pt;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  margin-bottom: 3mm;
}
.wm {
  display: inline-flex;
  align-items: center;
  font-size: 17pt;
  font-weight: 800;
  letter-spacing: -0.3pt;
}
.wm svg {
  width: 1em;
  height: 1em;
  vertical-align: middle;
}

.plate-qr {
  border: 1mm solid var(--plate-orange);
  border-radius: 2mm;
  padding: 3mm;
  width: 50mm;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.plate-qr .qr {
  width: 42mm;
  height: 42mm;
  position: relative;
}
.plate-qr .qr canvas,
.plate-qr .qr img {
  width: 100% !important;
  height: 100% !important;
}
.plate-qr .qr-logo {
  position: absolute;
  top: 24mm;
  left: 50%;
  width: 11mm;
  height: 11mm;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.plate-qr .qr-logo svg {
  width: 8mm;
  height: 8mm;
}
.plate-qr .qr-label {
  margin-top: 2.5mm;
  color: var(--plate-orange);
  font-weight: 800;
  font-size: 12pt;
  text-align: center;
}

.plate-steps {
  list-style: none;
  margin: 4mm 0 0;
  padding: 0;
  width: 100%;
}
.plate-steps li {
  display: flex;
  gap: 2mm;
  align-items: flex-start;
  font-size: 8pt;
  line-height: 1.25;
  margin-bottom: 1.8mm;
}
.plate-steps .n {
  background: var(--plate-navy);
  color: #fff;
  border-radius: 50%;
  min-width: 5mm;
  height: 5mm;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 7.5pt;
  flex-shrink: 0;
}

.plate-contact {
  margin-top: auto;
  background: var(--plate-navy);
  color: #fff;
  border-radius: 2mm;
  text-align: center;
  font-size: 8.5pt;
  font-weight: 700;
  padding: 2.5mm 2mm;
  width: 100%;
}
.plate-foot {
  margin-top: 2.5mm;
  font-size: 7.5pt;
  font-weight: 600;
  color: #333;
  text-align: center;
}

.chart-wrap {
  height: 280px;
  margin-top: 1rem;
}

/* ---------- Responsivo (celular / tablet) ---------- */
@media (max-width: 760px) {
  .container {
    padding: 1rem 0.8rem 2.5rem;
  }

  /* Topbar: encolhe e permite quebra */
  .topbar {
    padding: 0.7rem 0.85rem;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
  }
  .topbar .brand {
    font-size: 1.2rem;
  }
  .condo-switch {
    font-size: 0.82rem;
    padding: 0.25rem 0.5rem;
  }

  /* Abas roláveis na horizontal (não quebram a tela) */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.6rem 0.6rem 0;
    scrollbar-width: thin;
  }
  .tabs button {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
  }

  /* Cards e tabelas: a tabela rola na horizontal dentro do card */
  .card {
    padding: 1rem;
    overflow-x: auto;
  }
  .card table {
    min-width: 540px;
  }

  /* Formulários: campos e botões empilhados em coluna, largura total */
  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.7rem;
  }
  .row .field {
    margin-bottom: 0;
  }
  .row > .btn,
  .row > button,
  .row > .help-btn.label {
    width: 100%;
  }

  /* Modal de ajuda ocupa melhor a tela pequena */
  .modal {
    padding: 1.25rem 1.1rem 1.5rem;
    max-height: 92vh;
    border-radius: 14px;
  }
  .modal-head h3 {
    font-size: 1.12rem;
  }

  .chart-wrap {
    height: 220px;
  }
}

/* Telas bem estreitas: reduz mais o respiro */
@media (max-width: 420px) {
  .container {
    padding: 0.85rem 0.6rem 2.5rem;
  }
  .card {
    padding: 0.85rem;
  }
  .topbar .brand {
    font-size: 1.05rem;
  }
}

/* Impressão: mostra só a folha de placas */
@media print {
  @page {
    margin: 8mm;
  }
  body * {
    visibility: hidden;
  }
  #plateSheet,
  #plateSheet * {
    visibility: visible;
  }
  #plateSheet {
    position: absolute;
    top: 0;
    left: 0;
  }
}
