:root {
  --bg: #0a0a0a;
  --panel: #161513;
  --panel-2: #201e1a;
  --well: #100f0d;
  --gold: #d4af37;
  --gold-2: #ecc862;
  --gold-soft: rgba(212, 175, 55, 0.12);
  --text: #f5f3ef;
  --muted: #a29b8c;
  --border: #302c26;
  --border-soft: #26231e;
  --green: #35a95a;
  --red: #db5248;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font-family: inherit; }
img { max-width: 100%; }

/* ---- Login ---- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at 50% 0%, rgba(212, 175, 55, 0.08), transparent 60%), var(--bg);
}
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 30px; width: 100%; max-width: 370px; text-align: center; box-shadow: var(--shadow); }
.auth-logo { width: 180px; margin: 0 auto 20px; display: block; }
.auth-card input { margin-bottom: 12px; }
.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1a1710; border: none; padding: 12px 20px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 700; transition: filter .15s ease, transform .05s ease; }
.btn-gold:hover { filter: brightness(1.08); }
.btn-gold:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 12px 20px; border-radius: var(--radius-sm); cursor: pointer; transition: color .15s ease, border-color .15s ease; }
.btn-ghost:hover { color: var(--text); border-color: var(--gold); }
.auth-msg { font-size: 13px; min-height: 18px; margin: 6px 0 0; }
.auth-hint { font-size: 11px; color: var(--muted); margin: 10px 0 0; }

/* ---- Layout ---- */
#app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; }
.side-logo { width: 152px; margin: 4px auto 22px; display: block; }
#nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
#nav button { text-align: left; background: transparent; color: var(--muted); border: none; padding: 12px 14px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: 14px; transition: background .15s ease, color .15s ease; }
#nav button:hover { background: var(--panel-2); color: var(--text); }
#nav button.active { background: var(--gold); color: #1a1710; box-shadow: 0 2px 10px rgba(212, 175, 55, 0.25); }
.side-user { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.role-pill { display: inline-block; margin-top: 6px; background: var(--gold-soft); color: var(--gold); border: 1px solid var(--gold); padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: capitalize; }

#content { padding: 26px 30px; overflow: auto; min-width: 0; }
.page-title { color: var(--gold); margin: 0 0 20px; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }

.view { display: none; }
.view.active { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1.5fr; gap: 20px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 16px; font-size: 16px; color: var(--text); font-weight: 700; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; font-weight: 500; }
input, select, textarea { width: 100%; margin-top: 6px; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--well); color: var(--text); font-size: 14px; transition: border-color .15s ease, box-shadow .15s ease; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.list-head input, .list-head select { width: auto; min-width: 200px; }

.table-wrap { max-height: 540px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); }
th { position: sticky; top: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.04em; z-index: 1; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s ease; }
tr:hover td { background: var(--gold-soft); }
tfoot td { background: var(--panel-2); border-top: 1px solid var(--border); }
.vazio { color: var(--muted); text-align: center; padding: 28px; }

/* chips / tags */
.chip { display: inline-block; background: var(--panel-2); color: var(--gold); border: 1px solid var(--gold); padding: 2px 9px; border-radius: 999px; font-size: 11px; margin: 2px; }
.tag { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; display: inline-block; }
.t-quente { background: #5a1d0c; color: #ffb499; }
.t-morno  { background: #4a3a10; color: #f2d479; }
.t-frio   { background: #14304a; color: #a9d4ff; }
.t-temp { background: var(--panel-2); color: var(--gold); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-btn { border: 1px solid var(--border); background: var(--well); color: var(--text); border-radius: 7px; padding: 6px 11px; cursor: pointer; font-size: 12px; transition: border-color .15s ease, color .15s ease; }
.icon-btn:hover { border-color: var(--gold); }
.icon-btn.edit:hover { border-color: var(--gold); color: var(--gold); }
.icon-btn.del:hover { border-color: var(--red); color: var(--red); }
.icon-btn.wa { border-color: var(--green); color: #86e5a3; }

/* Agenda alerta */
.alerta { background: linear-gradient(180deg, #2e160b, #241109); border: 1px solid var(--red); color: #ffc4b3; padding: 13px 17px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 600; }

/* Acomp — quadro numérico clicável (tally) */
.sqn {
  width: 42px; height: 34px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--well); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--muted); user-select: none; margin: 0 auto; transition: border-color .12s ease, color .12s ease;
}
.sqn:hover { border-color: var(--gold); color: var(--gold); }
.sqn.tem { background: var(--gold); border-color: var(--gold); color: #1a1710; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::before { content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%; background: var(--gold); opacity: 0.6; }
.stat .num { font-size: 30px; font-weight: 800; color: var(--gold); letter-spacing: -0.02em; }
.stat .lbl { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* Toast */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1a1710; padding: 13px 22px; border-radius: var(--radius-sm); font-weight: 700; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.4); }

/* Foto do imóvel */
.foto-preview { max-height: 110px; border-radius: var(--radius-sm); margin-top: 8px; display: block; border: 1px solid var(--border); }
.foto-mini { width: 58px; height: 44px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); }
#imovel-foto { padding: 8px; }

/* Link de lead (abre detalhe) */
.lead-link { color: var(--gold); cursor: pointer; font-weight: 600; }
.lead-link:hover { text-decoration: underline; }

/* Modal de detalhe */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; backdrop-filter: blur(2px); }
.modal-box { background: var(--panel); border: 1px solid var(--gold); border-radius: 18px; padding: 26px; max-width: 560px; width: 100%; max-height: 88vh; overflow: auto; position: relative; box-shadow: 0 12px 48px rgba(0,0,0,.6); }
.modal-close { position: absolute; top: 14px; right: 16px; background: transparent; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.modal-close:hover { color: var(--gold); }
.modal-box p { margin: 8px 0; font-size: 14px; }

/* Funil (barras) */
.bar { display: flex; align-items: center; gap: 12px; margin: 8px 0; font-size: 13px; }
.bar .label { width: 130px; color: var(--muted); flex-shrink: 0; }
.bar .track { flex: 1; background: var(--well); border-radius: 6px; overflow: hidden; height: 18px; }
.bar .fill { height: 100%; background: linear-gradient(90deg, var(--gold-2), var(--gold)); border-radius: 6px; }
.bar .val { width: 34px; text-align: right; color: var(--text); font-weight: 600; }

/* ============================================================
   RESPONSIVO — tablet
   ============================================================ */
@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
  #content { padding: 20px 16px; }
}

/* ============================================================
   RESPONSIVO — celular: tabelas viram cartoes empilhados
   ============================================================ */
@media (max-width: 680px) {
  html, body { overflow-x: hidden; max-width: 100%; }
  #app { grid-template-columns: 1fr; width: 100%; }
  #content { padding: 16px 14px; width: 100%; min-width: 0; }
  .grid-2 { grid-template-columns: 1fr; min-width: 0; }
  .card { padding: 18px; min-width: 0; overflow: hidden; }
  .row { grid-template-columns: 1fr; }
  .page-title { font-size: 21px; }
  .list-head { flex-direction: column; align-items: stretch; }
  .list-head input, .list-head select { width: 100%; min-width: 0; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat .num { font-size: 26px; }

  /* transforma cada linha de tabela num cartao legivel */
  .table-wrap { max-height: none; border: none; overflow: visible; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 12px; padding: 6px 4px; box-shadow: var(--shadow);
  }
  tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 9px 14px; border-bottom: 1px solid var(--border-soft); text-align: right;
  }
  tbody tr td:last-child { border-bottom: none; }
  tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.03em; text-align: left; flex-shrink: 0;
  }
  tr:hover td { background: transparent; }
  .row-actions { justify-content: flex-end; }
  tfoot td { justify-content: space-between; }
}

/* ============================================================
   TEMA CLARO
   ============================================================ */
body.tema-claro {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #faf6ea;
  --well: #ffffff;
  --gold: #a97c0a;
  --gold-2: #d4af37;
  --gold-soft: rgba(169, 124, 10, 0.09);
  --text: #1a1712;
  --muted: #6b6355;
  --border: #e3d9be;
  --border-soft: #efe8d6;
  --green: #227a3d;
  --red: #b8362c;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
body.tema-claro #nav button.active { color: #fff; box-shadow: 0 2px 8px rgba(169, 124, 10, 0.3); }
body.tema-claro .btn-gold { color: #fff; }
body.tema-claro .sqn.tem { color: #fff; }
body.tema-claro .toast { color: #fff; }
body.tema-claro input, body.tema-claro select, body.tema-claro textarea { border-width: 1.5px; }
body.tema-claro .alerta { background: #fbeceb; color: #8a2a20; border: 1px solid var(--red); }
body.tema-claro .icon-btn.wa { color: #1b7d3b; }
body.tema-claro .t-quente { background: #fbe3d8; color: #a8431e; }
body.tema-claro .t-morno  { background: #f7edcf; color: #8a6d16; }
body.tema-claro .t-frio   { background: #dceafa; color: #1e5a8a; }
