:root {
  --ceu1: #7fb4e6; --ceu2: #cfe6f7;
  --fachada: #8a5a44; --fachada-esc: #6b4433; --tijolo: #7a4e3b;
  --laje: #4a3a33; --texto: #1d2230; --sub: #5d6577;
  --papel: #fffdf7; --linha: #e4ddcf; --acento: #2f6fde; --ok: #2e9b5f; --alerta: #e0483d; --amarelo: #ffd34d;
  --gaveta: #fbf8f1; --bolha-eu: #2f6fde; --bolha-ag: #ffffff;
  --pixel: 'Press Start 2P', monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ceu1: #0f1830; --ceu2: #24345c;
    --fachada: #4b3229; --fachada-esc: #3a2620; --tijolo: #43291f; --laje: #241b18;
    --texto: #e8ebf2; --sub: #9aa3b5; --papel: #1b2030; --linha: #2e3547; --gaveta: #151a27; --bolha-ag: #232a3d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, sans-serif; color: var(--texto); background: var(--ceu2); overflow: hidden; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- login ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(var(--ceu1), var(--ceu2)); }
.login-card { background: var(--papel); padding: 32px 28px; border: 3px solid var(--laje); box-shadow: 6px 6px 0 var(--laje); text-align: center; max-width: 340px; width: calc(100% - 32px); }
.login-card h1 { font-family: var(--pixel); font-size: 15px; line-height: 1.6; margin: 16px 0 8px; }
.login-card p { color: var(--sub); font-size: 14px; }
.login-predio { margin: 0 auto; width: 64px; height: 80px; background:
  linear-gradient(90deg, transparent 12px, var(--amarelo) 12px 24px, transparent 24px 40px, var(--amarelo) 40px 52px, transparent 52px) 0 12px / 64px 20px repeat-y,
  var(--fachada); border: 3px solid var(--laje); image-rendering: pixelated; }
#gbtn { display: flex; justify-content: center; margin: 16px 0 4px; }
#devlogin { display: flex; gap: 6px; margin-top: 12px; }
#devlogin input { flex: 1; padding: 8px; border: 2px solid var(--linha); background: var(--papel); color: var(--texto); }
.erro { color: var(--alerta) !important; }

/* ---------- topo ---------- */
.topo { position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--laje); color: #fff; border-bottom: 3px solid #000a; }
.marca { font-family: var(--pixel); font-size: 13px; letter-spacing: 1px; }
.marca span { font-family: Inter; font-size: 12px; letter-spacing: 0; opacity: .7; margin-left: 8px; }
.topo-acoes { display: flex; align-items: center; gap: 8px; }
.btn { background: #ffffff1a; color: #fff; border: 2px solid #ffffff40; padding: 6px 12px; font-size: 13px; font-weight: 600; position: relative; }
.btn:hover { background: #ffffff30; }
.btn.ghost { border-color: transparent; }
.btn b { background: var(--alerta); border-radius: 10px; padding: 0 6px; margin-left: 4px; font-size: 12px; }
.eu { font-size: 13px; opacity: .85; }
@media (max-width: 640px) { .eu, .marca span { display: none; } .btn { padding: 6px 8px; font-size: 12px; } }

/* ---------- cena ---------- */
.cena { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; display: flex; }
#ceu { flex: 1; overflow-y: auto; overflow-x: hidden; background: linear-gradient(var(--ceu1), var(--ceu2) 70%); padding: 40px 16px 0; scroll-behavior: smooth; }
#predio { max-width: 1040px; margin: 0 auto; }

.telhado { height: 46px; background: var(--laje); margin: 0 -10px; position: relative; display: grid; place-items: center;
  border-bottom: 6px solid #00000040; }
.telhado span { font-family: var(--pixel); font-size: 14px; color: var(--amarelo); text-shadow: 2px 2px 0 #000; letter-spacing: 2px; }
.telhado::before { content: ''; position: absolute; left: 14%; top: -24px; width: 10px; height: 24px; background: var(--laje); }

.andar { position: relative; background: var(--fachada);
  background-image: linear-gradient(var(--tijolo) 2px, transparent 2px), linear-gradient(90deg, var(--tijolo) 2px, transparent 2px);
  background-size: 24px 12px; padding: 10px 12px 14px; border-bottom: 10px solid var(--laje); }
.placa { display: inline-flex; align-items: center; gap: 8px; background: var(--laje); color: #fff; padding: 6px 10px; margin-bottom: 8px;
  font-family: var(--pixel); font-size: 10px; box-shadow: 3px 3px 0 #0005; }
.placa .luz { width: 8px; height: 8px; background: #555; box-shadow: 0 0 0 2px #0006; }
.andar.online .placa .luz { background: #57e389; box-shadow: 0 0 6px #57e389; }
.placa small { font-family: Inter; font-size: 11px; opacity: .75; }
.andar.meu .placa { background: var(--acento); }

.salas { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.sala { position: relative; background: #000; border: 4px solid var(--fachada-esc); padding: 0; cursor: pointer; display: block; text-align: left;
  box-shadow: inset 0 0 0 2px #0005; transition: transform .12s; }
.sala:hover, .sala:focus-visible { transform: translateY(-2px); outline: 3px solid var(--amarelo); outline-offset: 0; }
.sala canvas { display: block; width: 100%; aspect-ratio: 3 / 2; image-rendering: pixelated; }
.sala .nome { position: absolute; left: 6px; bottom: 6px; background: #000c; color: #fff; font-family: var(--pixel); font-size: 9px; padding: 4px 6px; }
.sala .status { position: absolute; right: 6px; bottom: 6px; background: var(--ok); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 6px; display: none; }
.sala.busy .status { display: block; }
.sala .badge { position: absolute; right: 6px; top: 6px; background: var(--alerta); color: #fff; font-weight: 700; font-size: 12px; min-width: 22px; height: 22px;
  display: none; place-items: center; padding: 0 6px; border: 2px solid #fff; animation: pula 1s infinite; }
.sala.pend .badge { display: grid; }
@keyframes pula { 50% { transform: translateY(-3px); } }
.vazio { color: #fff; font-size: 13px; opacity: .85; padding: 10px 4px; }

.terreo { background: var(--laje); padding: 16px; display: flex; justify-content: center; align-items: flex-end; gap: 24px; min-height: 90px; margin: 0 -10px; }
.porta { width: 70px; height: 64px; background: #2a3550; border: 4px solid #000a; position: relative; }
.porta::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; border-left: 3px solid #000a; }
.terreo .placa-rua { font-family: var(--pixel); font-size: 9px; color: #fff; opacity: .7; }
.chao { height: 40px; background: #5a6b4a; margin: 0 -16px; }

/* ---------- elevador ---------- */
#elevador { width: 64px; background: var(--laje); border-right: 3px solid #000a; padding: 8px 6px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
#elevador .rot { font-family: var(--pixel); font-size: 7px; color: #fffa; text-align: center; margin-bottom: 4px; line-height: 1.6; }
#elevador button { background: #2c2522; color: #fff; border: 2px solid #000; font-family: var(--pixel); font-size: 10px; padding: 8px 0; position: relative; }
#elevador button.on { background: var(--amarelo); color: #000; }
#elevador button .p { position: absolute; right: -3px; top: -3px; width: 8px; height: 8px; background: var(--alerta); }
#elevador button.apagado { opacity: .5; }
@media (max-width: 640px) { #elevador { width: 46px; } #ceu { padding: 32px 10px 0; } }

/* ---------- gaveta (chat) ---------- */
#gaveta, #painel-solic { position: fixed; top: 56px; right: 0; bottom: 0; width: min(440px, 100%); background: var(--gaveta); z-index: 30;
  border-left: 3px solid var(--laje); display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s; box-shadow: -8px 0 24px #0003; }
#gaveta.on, #painel-solic.on { transform: none; }
.g-topo { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 2px solid var(--linha); }
.g-topo canvas { width: 40px; height: 48px; image-rendering: pixelated; background: var(--linha); }
.g-nome { font-family: var(--pixel); font-size: 12px; line-height: 1.6; }
.g-sub { font-size: 12px; color: var(--sub); }
.x { margin-left: auto; background: none; border: none; font-size: 26px; color: var(--sub); line-height: 1; }
#g-corpo { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; border: 2px solid var(--linha); }
.msg.eu { align-self: flex-end; background: var(--bolha-eu); color: #fff; border-color: transparent; }
.msg.agente { align-self: flex-start; background: var(--bolha-ag); }
.msg.erro { align-self: flex-start; background: #fde8e6; color: #8a1f17; border-color: #f3b9b3; }
.msg code { background: #0001; padding: 1px 4px; font-size: 13px; }
.msg.eu code { background: #fff3; }
.ferramenta { align-self: flex-start; font-size: 12px; color: var(--sub); font-style: italic; }
.digitando { align-self: flex-start; font-size: 12px; color: var(--sub); }
.digitando i { display: inline-block; width: 6px; height: 6px; background: var(--sub); margin-right: 3px; animation: pisca 1s infinite; }
.digitando i:nth-child(2) { animation-delay: .2s; } .digitando i:nth-child(3) { animation-delay: .4s; }
@keyframes pisca { 50% { opacity: .2; } }
.dica { color: var(--sub); font-size: 13px; text-align: center; margin: auto 20px; line-height: 1.5; }

.compor { border-top: 2px solid var(--linha); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.compor textarea { width: 100%; min-height: 64px; max-height: 200px; resize: vertical; padding: 10px; font: inherit; font-size: 14px; border: 2px solid var(--linha); background: var(--papel); color: var(--texto); }
.compor textarea:focus { outline: none; border-color: var(--acento); }
.linha-btn { display: flex; gap: 8px; align-items: center; }
.b { border: 2px solid var(--laje); background: var(--papel); color: var(--texto); padding: 7px 12px; font-size: 13px; font-weight: 600; }
.b.pri { background: var(--acento); border-color: var(--acento); color: #fff; }
.b.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.b.ruim { color: var(--alerta); border-color: var(--alerta); }
.b:disabled { opacity: .5; cursor: default; }
.b.dir { margin-left: auto; }

.aviso-off { margin: 12px 14px 0; padding: 10px 12px; background: #2a2f3d; color: #fff; font-size: 13px; }
.descr { padding: 10px 14px; font-size: 13px; color: var(--sub); border-bottom: 2px solid var(--linha); line-height: 1.45; max-height: 92px; overflow: auto; }

.cards { padding: 10px 14px 0; display: flex; flex-direction: column; gap: 8px; }
.card { border: 2px solid var(--linha); background: var(--papel); padding: 10px 12px; font-size: 13px; }
.card .cab { display: flex; justify-content: space-between; gap: 8px; color: var(--sub); font-size: 12px; margin-bottom: 4px; }
.card .txt { white-space: pre-wrap; line-height: 1.45; }
.card .resp { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--linha); color: var(--sub); white-space: pre-wrap; }
.card .linha-btn { margin-top: 8px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; text-transform: uppercase; letter-spacing: .3px; }
.tag.aberta { background: #fff1c2; color: #7a5a00; }
.tag.em_andamento { background: #dbe8ff; color: #1d4fa8; }
.tag.concluida { background: #d6f2e1; color: #1d6b40; }
.tag.recusada, .tag.cancelada { background: #f5dcd9; color: #8a1f17; }
.secao { font-family: var(--pixel); font-size: 9px; color: var(--sub); padding: 14px 14px 0; }

.abas { display: flex; border-bottom: 2px solid var(--linha); }
.abas button { flex: 1; background: none; border: none; padding: 10px; font-weight: 600; color: var(--sub); border-bottom: 3px solid transparent; }
.abas button.on { color: var(--texto); border-color: var(--acento); }
#ps-lista { flex: 1; overflow-y: auto; padding-bottom: 14px; }

/* ---------- modal / toasts ---------- */
#modal { position: fixed; inset: 0; background: #0008; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--papel); border: 3px solid var(--laje); box-shadow: 6px 6px 0 #0008; padding: 20px; max-width: 560px; width: 100%; position: relative; }
.modal-card .x { position: absolute; right: 10px; top: 8px; }
.modal-card h2 { font-family: var(--pixel); font-size: 12px; line-height: 1.6; margin: 0 0 12px; }
.modal-card p, .modal-card li { font-size: 14px; line-height: 1.5; }
.cmd { display: block; background: #12161f; color: #9ef0b5; padding: 12px; font-size: 12px; word-break: break-all; font-family: Consolas, monospace; margin: 8px 0; }

#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--laje); color: #fff; padding: 10px 16px; font-size: 14px; box-shadow: 4px 4px 0 #0006; max-width: 90vw; animation: sobe .2s; }
@keyframes sobe { from { transform: translateY(10px); opacity: 0; } }
