/* ===========================================================
   ReurbDSS — gestão de território municipal   Layout de workspace: chat à esquerda, mapa ao centro, camadas à direita.
   =========================================================== */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #f1f5f9;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff6ff;
  --ok: #059669;
  --warn: #d97706;
  --err: #dc2626;
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 34px rgba(15, 23, 42, .16);
  --r: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); color: var(--ink); background: var(--bg);
  font-size: 14px; line-height: 1.5; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }

/* ---------- Casca ---------- */
#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 56px; flex: 0 0 56px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px; gap: 16px; z-index: 900;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand .name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand .sub { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 2px; background: var(--line-2); padding: 3px; border-radius: 9px; }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; transition: .15s;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

.top-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--line-2); border-color: #cbd5e1; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--err); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Corpo: 3 colunas ---------- */
.body { flex: 1; display: flex; min-height: 0; position: relative; }

.side {
  width: 340px; flex: 0 0 340px; background: var(--panel); display: flex; flex-direction: column;
  min-height: 0; transition: margin .2s;
}
.side.left { border-right: 1px solid var(--line); }
.side.right { border-left: 1px solid var(--line); width: 330px; flex-basis: 330px; }
.side.left.off { margin-left: -340px; }
.side.right.off { margin-right: -330px; }

.side-head {
  padding: 13px 15px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.side-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.side-body { flex: 1; overflow: auto; }

.center { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; }

/* ---------- Chat ---------- */
.chat-msgs { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 12px; font-size: 13px; }
.msg.eu { align-self: flex-end; background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #dbeafe; }
.msg.bot { align-self: flex-start; background: var(--line-2); border: 1px solid var(--line); }
.msg .titulo { font-weight: 600; margin-bottom: 3px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.chat-in { border-top: 1px solid var(--line); padding: 11px; display: flex; gap: 8px; }
.chat-in input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; outline: none;
}
.chat-in input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.sugestoes { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 12px; }
.sugestoes button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 20px;
  padding: 6px 12px; font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.sugestoes button:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ---------- Camadas ---------- */
.grupo { border-bottom: 1px solid var(--line); padding: 12px 15px; }
.grupo h3 {
  margin: 0 0 9px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.cam {
  display: flex; align-items: center; gap: 9px; padding: 7px 0; font-size: 13px;
}
.cam input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }
.cam .cor { width: 13px; height: 13px; border-radius: 3px; border: 1px solid rgba(0,0,0,.15); flex: 0 0 13px; }
.cam .txt { flex: 1; min-width: 0; }
.cam .txt b { display: block; font-weight: 500; }
.cam .txt span { font-size: 11px; color: var(--muted); }

/* Alça de reordenação: discreta até o mouse passar pela linha. */
.cam .arrasta {
  flex: 0 0 10px; margin-right: -3px; font-size: 12px; line-height: 1;
  color: var(--muted); opacity: .35; cursor: grab; user-select: none;
}
.cam:hover .arrasta { opacity: .9; }
.cam .arrasta:active { cursor: grabbing; }
.cam.arrastando { opacity: .4; background: var(--line-2); border-radius: 6px; }

/* ---------- Barra de desenho flutuante ---------- */
.sig-bar {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 700;
  display: flex; align-items: center; gap: 3px; padding: 6px 9px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-lg);
}
.sig-bar button {
  width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; cursor: pointer;
  font-size: 16px; color: var(--ink-2); display: grid; place-items: center; transition: .15s;
}
.sig-bar button:hover { background: var(--line-2); }
.sig-bar button.on { background: var(--brand); color: #fff; }
.sig-bar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

.sig-dica {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 700;
  background: rgba(15,23,42,.92); color: #fff; padding: 8px 15px; border-radius: 8px;
  font-size: 12.5px; white-space: nowrap; pointer-events: none;
}

/* ---------- Edição de vértices ---------- */
.ed-vertice {
  background: #fff; border: 2px solid var(--brand); border-radius: 3px;
  width: 12px !important; height: 12px !important; margin-left: -6px !important; margin-top: -6px !important;
  cursor: grab; box-shadow: 0 1px 3px rgba(15,23,42,.4);
}
.ed-meio {
  background: #fff; border: 1.5px solid var(--brand); border-radius: 50%; opacity: .65;
  width: 9px !important; height: 9px !important; margin-left: -4.5px !important; margin-top: -4.5px !important;
  cursor: copy;
}
.ed-meio:hover { opacity: 1; }

/* ---------- Escala / contador do mapa ---------- */
.mapa-info {
  position: absolute; top: 12px; left: 12px; z-index: 600;
  background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 12px; font-size: 12px; color: var(--ink-2); box-shadow: var(--shadow);
}
.mapa-info b { color: var(--ink); }
.mapa-info .aviso { color: var(--warn); }

/* ---------- Painéis de conteúdo (Plano Diretor, IPTU, Cadastro) ---------- */
.pagina { position: absolute; inset: 0; overflow: auto; background: var(--bg); padding: 20px 24px; }
.pagina h1 { font-size: 20px; margin: 0 0 3px; }
.pagina .lead { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.secao { margin-bottom: 26px; }
.secao > h2 { font-size: 14px; margin: 0 0 10px; font-weight: 600; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 15px 17px;
}
.card .rot { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card .val { font-size: 25px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -.02em; }
.card .val.sm { font-size: 19px; }
.card .sub { font-size: 12px; color: var(--muted); }
.card.ok .val { color: var(--ok); } .card.warn .val { color: var(--warn); } .card.err .val { color: var(--err); }

.tabela { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 13px; background: var(--line-2); color: var(--muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  position: sticky; top: 0; z-index: 1;
}
td { padding: 9px 13px; border-top: 1px solid var(--line-2); }
tbody tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clicavel { cursor: pointer; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
}
.tag.ok { background: #d1fae5; color: #065f46; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.err { background: #fee2e2; color: #991b1b; }
.tag.n { background: var(--line-2); color: var(--muted); }

.campo { margin-bottom: 11px; }
.campo label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; outline: none; background: var(--panel);
}
.campo input:focus, .campo select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.linha-campos { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.vazio { padding: 26px; text-align: center; color: var(--muted); font-size: 13px; }
.barra-ferramentas { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.barra-ferramentas input, .barra-ferramentas select {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); outline: none;
}
.busca { min-width: 260px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 2000; }
.modal.hidden, .hidden { display: none !important; }
.modal-card {
  background: var(--panel); border-radius: 14px; width: 520px; max-width: 94vw; max-height: 88vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-acoes { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); }
.icone-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 17px; padding: 3px 7px; border-radius: 6px; }
.icone-btn:hover { background: var(--line-2); color: var(--ink); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 9px;
  font-size: 13px; z-index: 3000; box-shadow: var(--shadow-lg);
}
.toast.err { background: var(--err); }

/* ---------- Gestão (tela de gestão da base cartográfica) ---------- */
.subabas {
  display: flex; gap: 4px; flex-wrap: wrap; background: var(--line-2);
  padding: 3px; border-radius: 9px; margin-bottom: 18px; width: fit-content;
}
.subabas button {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer; transition: .15s;
}
.subabas button:hover { color: var(--ink); }
.subabas button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

.diag-lista { display: flex; flex-direction: column; gap: 8px; }
.diag-item {
  display: flex; gap: 11px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px;
}
.diag-item .sinal {
  flex: 0 0 10px; width: 10px; height: 10px; border-radius: 50%; margin-top: 4px;
}
.diag-item .sinal.ok { background: var(--ok); }
.diag-item .sinal.warn { background: var(--warn); }
.diag-item .sinal.err { background: var(--err); }
.diag-item .sinal.n { background: var(--muted); }
.diag-item .txt { flex: 1; min-width: 0; }
.diag-item .tit { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.diag-item .det { font-size: 12px; color: var(--muted); margin-top: 3px; }

.previa { background: var(--line-2); border-radius: var(--r); padding: 4px 14px; margin: 10px 0; }
.problemas { max-height: 240px; overflow: auto; margin: 10px 0; }

.tabela.versoes .linha.truncada { opacity: .55; }
.tabela.versoes .linha.truncada td { font-style: italic; }

.barra-progresso {
  height: 6px; background: var(--line-2); border-radius: 999px; overflow: hidden; margin: 10px 0;
}
.barra-progresso > i { display: block; height: 100%; background: var(--brand); transition: width .2s; }

/* ---------- Detalhe (linha chave/valor) ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 500; text-align: right; }

/* ---------- Leaflet ---------- */
.leaflet-container { font-family: var(--font); background: #e8eaed; }
.poi-pin {
  display: grid; place-items: center; width: 22px; height: 22px; font-size: 11px;
  background: #fff; color: var(--brand); border: 1px solid var(--brand);
  border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.leaflet-popup-content b { display: block; margin-bottom: 6px; }

/* Ficha de equipamento (UBS, escola) no popup */
.popup-equip { min-width: 200px; }
.popup-ficha { border-collapse: collapse; width: 100%; margin-top: 4px; }
.popup-ficha th, .popup-ficha td { padding: 3px 6px; font-size: 12px; vertical-align: top; text-align: left; }
.popup-ficha th { color: #64748b; font-weight: 600; white-space: nowrap; padding-right: 10px; }
.popup-ficha tr:not(:last-child) th,
.popup-ficha tr:not(:last-child) td { border-bottom: 1px solid #f1f5f9; }

/* Rótulo fixo dos bairros no mapa */
.leaflet-tooltip.rotulo-bairro {
  background: transparent; border: 0; box-shadow: none; padding: 0;
  color: #fff; font-weight: 600; font-size: 12px; letter-spacing: .02em;
  text-shadow: 0 1px 3px rgba(0,0,0,.95), 0 0 8px rgba(0,0,0,.7);
}
.leaflet-tooltip.rotulo-bairro::before { display: none; }


/* Botão de remover uma camada de consulta */
.x-cam {
  margin-left: auto; border: 0; background: none; cursor: pointer;
  color: #94a3b8; font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.x-cam:hover { background: #fee2e2; color: #b91c1c; }

/* Equipamentos públicos (UBS, escolas) */
.equip-pin span {
  display: grid; place-items: center; width: 24px; height: 24px;
  color: #fff; font-size: 13px; font-weight: 700; line-height: 1;
  border: 2px solid #fff; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.45);
}

/* Legenda inline nas respostas do assistente (mapa temático) */
.msg .cor {
  display: inline-block; width: 11px; height: 11px; border-radius: 3px;
  margin-right: 4px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.15);
}

/* Seletor de cor das camadas monocromáticas */
.cam .cor-picker {
  width: 15px; height: 15px; flex: 0 0 15px; padding: 0; cursor: pointer;
  border: 1px solid rgba(0,0,0,.2); border-radius: 3px; background: none;
  -webkit-appearance: none; appearance: none;
}
.cam .cor-picker::-webkit-color-swatch-wrapper { padding: 0; }
.cam .cor-picker::-webkit-color-swatch { border: 0; border-radius: 2px; }

/* Legenda das espécies CNEFE (camada de imóveis-ponto) */
.legenda-cnefe{background:rgba(255,255,255,.93);border-radius:8px;padding:8px 10px;
  font-size:11px;line-height:1.55;color:#0f172a;box-shadow:0 1px 4px rgba(0,0,0,.25)}
.legenda-cnefe b{display:block;margin-bottom:3px;font-size:11px}
.legenda-cnefe span{display:flex;align-items:center;gap:6px;white-space:nowrap}
.legenda-cnefe i{width:10px;height:10px;border-radius:50%;display:inline-block;border:1px solid #1e293b}

/* ===========================================================
   Smartphone (≤760px) — páginas de conteúdo, tabelas em cartões
   e modal em tela quase cheia (uso em campo).
   =========================================================== */
@media (max-width: 760px) {
  /* Casca */
  .topbar { padding: 0 10px; gap: 8px; }
  .brand .sub { display: none; }
  .brand .name { font-size: 14px; }
  .tabs { overflow-x: auto; max-width: 46vw; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { padding: 7px 9px; font-size: 12px; flex: 0 0 auto; }
  .top-actions { gap: 5px; }
  .top-actions .btn { padding: 7px 9px; font-size: 12px; }

  /* Páginas (Painel, REURB, Cadastro…) */
  .pagina { padding: 14px 12px; }
  .pagina h1 { font-size: 17px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .card { padding: 12px 13px; }
  .card .val { font-size: 20px; }

  /* Tabela vira cartões: cada célula mostra o rótulo da coluna */
  .tab-resp { border: 0; background: transparent; overflow: visible; }
  .tab-resp table, .tab-resp tbody, .tab-resp tr, .tab-resp td { display: block; width: 100%; }
  .tab-resp thead { display: none; }
  .tab-resp tr {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    margin-bottom: 10px; padding: 6px 2px; box-shadow: var(--shadow);
  }
  .tab-resp td {
    border: 0; padding: 6px 14px; display: flex; justify-content: space-between;
    align-items: center; gap: 12px; text-align: right;
  }
  .tab-resp td::before {
    content: attr(data-label); font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left;
  }
  .tab-resp td[colspan] { justify-content: center; }
  .tab-resp td[colspan]::before { content: none; }

  /* Modal ocupa a tela toda no campo */
  .modal { place-items: end center; }
  .modal-card { width: 100%; max-width: 100%; max-height: 94vh; border-radius: 14px 14px 0 0; }
  .modal-body { padding: 14px; }

  /* Barra de desenho não vaza da tela */
  .sig-bar { max-width: 96vw; overflow-x: auto; }
}


/* Animação do marcador da localização atual (GPS) */
@keyframes pingEu {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(3.5); opacity: 0; }
}
