:root {
  --bg: #0b0e16;
  --bg2: #11151f;
  --card: #161b27;
  --card2: #1c2230;
  --line: #232a3a;
  --txt: #e8ebf2;
  --muted: #8b93a7;
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font-family: inherit; cursor: pointer; border: none; }
input, textarea, select {
  font-family: inherit; font-size: 16px;
  background: var(--bg2); color: var(--txt);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; width: 100%; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
label { font-size: 13px; color: var(--muted); display: block; margin: 14px 0 6px; }

/* ---------- LOGIN ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 100% at 50% 0%, #1a2236 0%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 340px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px; }
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 2px; font-size: 26px; }
.login-card p { margin: 0 0 22px; font-size: 14px; }
.login-card input { margin-bottom: 12px; }
.login-card button { width: 100%; padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.erro { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 16px; }

/* ---------- APP SHELL ---------- */
.topbar { position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 14px) 18px 14px; display: flex; align-items: center; gap: 12px;
  background: rgba(11,14,22,.82); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar-title { font-size: 22px; font-weight: 700; flex: 1; }
.icon-btn { background: var(--card2); color: var(--txt); width: 38px; height: 38px; border-radius: 11px;
  font-size: 16px; display: grid; place-items: center; flex: 0 0 auto; }
.view { padding: 16px 16px calc(120px + var(--safe-b)); max-width: 860px; width: 100%; margin: 0 auto; }

/* ---------- SIDEBAR ---------- */
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: 248px;
  background: var(--bg2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: calc(var(--safe-t) + 16px) 12px 16px;
  transform: translateX(-100%); transition: transform .22s ease; }
.sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.5); }
.sidebar-brand { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 800;
  padding: 6px 10px 18px; }
.sidebar-brand .logo { font-size: 22px; }
.sidenav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.navitem { display: flex; align-items: center; gap: 13px; width: 100%;
  background: none; color: var(--muted); font-size: 15px; font-weight: 600; text-align: left;
  padding: 12px 14px; border-radius: 12px; transition: .14s; }
.navitem span { font-size: 19px; width: 24px; text-align: center; }
.navitem:hover { background: var(--card); color: var(--txt); }
.navitem.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.navitem-sair { margin-top: auto; color: var(--muted); }
.navitem-sair:hover { color: var(--red); background: none; }
#btn-conta { margin-top: auto; }
#btn-sair-side { margin-top: 2px; }
.scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }

@media (min-width: 880px) {
  .sidebar { transform: translateX(0); box-shadow: none; }
  .main-area { margin-left: 248px; }
  .menu-btn, #btn-sair { display: none; }
  .scrim { display: none; }
}

/* ---------- FAB ---------- */
.fab { position: fixed; right: 18px; bottom: calc(22px + var(--safe-b)); z-index: 31;
  width: 58px; height: 58px; border-radius: 50%; font-size: 30px; color: #fff; line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 28px rgba(99,102,241,.45); }
.fab:active { transform: scale(.92); }
@media (min-width: 880px) { .fab { right: 28px; bottom: 28px; } }

/* ---------- CARDS ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 22px 4px 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--card2); color: var(--muted); white-space: nowrap; }
.pill.andamento { background: rgba(99,102,241,.18); color: #a5b4fc; }
.pill.concluida { background: rgba(34,197,94,.16); color: #86efac; }
.pill.pausada { background: rgba(245,158,11,.16); color: #fcd34d; }
.pill.vendida { background: rgba(6,182,212,.18); color: #67e8f9; }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 12px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 4px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 24px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.kpi.big { grid-column: 1 / -1; background: linear-gradient(135deg, #1c2336, #161b27); }
.kpi.big .val { font-size: 30px; background: linear-gradient(135deg, #a5b4fc, #c4b5fd); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

/* barra de proporção */
.bar { height: 8px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

/* obra item */
.obra-item { display: flex; align-items: center; gap: 13px; }
.obra-dot { width: 12px; height: 12px; border-radius: 4px; flex: 0 0 auto; }
.obra-item .nome { font-weight: 700; font-size: 16px; }
.obra-item .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.obra-total { font-weight: 800; font-size: 16px; }
.obra-clic { cursor: pointer; border-radius: 12px; transition: background .14s; padding: 6px; margin: -6px -6px 0; }
.obra-clic:hover { background: var(--card2); }
.obra-chev { color: var(--muted); font-size: 24px; line-height: 1; margin-left: 6px; flex: 0 0 auto; opacity: .6; }

/* lista de gastos */
.gasto { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.gasto:last-child { border-bottom: none; }
.gasto .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px;
  background: var(--card2); flex: 0 0 auto; }
.gasto .meio { flex: 1; min-width: 0; }
.gasto .desc { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gasto .meta { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gasto .val { font-weight: 700; font-size: 15px; white-space: nowrap; }

/* legenda do split macro por obra */
.macro-legenda { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.macro-legenda span { display: inline-flex; align-items: center; gap: 5px; }
.macro-legenda i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* configurações (listas de cidades/vendedores) */
.cfg-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.cfg-row:last-child { border-bottom: none; }
.pill.alvo { background: rgba(234,179,8,.16); color: #fcd34d; }

/* anexos (escritura/documentos) */
.anexo-row { display: flex; align-items: center; gap: 9px; padding: 9px 11px; margin-top: 7px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 11px; }
.anexo-ico { font-size: 17px; flex: 0 0 auto; }
.anexo-nome { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; cursor: pointer; color: var(--accent); }
.anexo-nome:hover { text-decoration: underline; }
.anexo-x { background: none; color: var(--muted); font-size: 14px; padding: 2px 6px; flex: 0 0 auto; }
.anexo-x:hover { color: var(--red); }

/* ---------- TIMELINE (Histórico) ---------- */
.timeline { position: relative; padding-left: 6px; }
.tl-ano { font-size: 13px; font-weight: 800; color: var(--muted); letter-spacing: .5px; margin: 18px 0 12px 44px; }
.tl-ano:first-child { margin-top: 4px; }
.tl-item { position: relative; display: flex; gap: 14px; padding-bottom: 14px; cursor: pointer; }
.tl-item::before { content: ""; position: absolute; left: 18px; top: 38px; bottom: -2px; width: 2px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center;
  font-size: 18px; z-index: 1; box-shadow: 0 0 0 4px var(--bg); }
.tl-card { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; transition: .14s; }
.tl-item:active .tl-card { background: var(--card2); }
.tl-tipo { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tl-texto { font-size: 15px; font-weight: 600; margin: 4px 0 0; }
.tl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 9px; }

/* seletor de obra no Resumo */
.r-obra { font-weight: 600; font-size: 15px; border-color: var(--accent); background: var(--card); margin-bottom: 4px; }

/* gráfico de rosca (donut) + legenda */
.pie-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: center; }
.donut { width: 132px; height: 132px; flex: 0 0 auto; }
.donut circle { transition: stroke-dasharray .4s ease; }
.donut-total { font-size: 4.6px; fill: var(--txt); text-anchor: middle; font-weight: 800; }
.pie-leg { flex: 1; min-width: 165px; display: flex; flex-direction: column; gap: 9px; }
.leg-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.leg-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.leg-lbl { flex: 1; color: var(--txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leg-val { color: var(--muted); white-space: nowrap; font-weight: 600; }
.leg-val i { font-style: normal; opacity: .65; margin-left: 3px; }

/* categoria barras */
.catrow { display: grid; grid-template-columns: 110px 1fr 88px; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.catrow .cbar { height: 8px; background: var(--bg2); border-radius: 999px; overflow: hidden; }
.catrow .cbar > i { display: block; height: 100%; border-radius: 999px; }
.catrow .cval { text-align: right; font-weight: 700; }

/* filtros */
.filtros { display: flex; gap: 8px; margin-bottom: 6px; overflow-x: auto; padding-bottom: 4px; }
.filtros select { width: auto; min-width: 130px; padding: 9px 12px; font-size: 14px; }

/* botões */
.btn { padding: 13px; border-radius: 12px; font-weight: 600; font-size: 15px; width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn-ghost { background: var(--card2); color: var(--txt); }
.btn-danger { background: rgba(239,68,68,.14); color: #fca5a5; }
.btn-sm { padding: 8px 14px; font-size: 13px; width: auto; border-radius: 10px; }
.btn-link { background: none; color: var(--muted); font-size: 13px; padding: 6px; width: auto; }
.actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- MODAL ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal { position: relative; width: 100%; max-width: 480px; background: var(--card);
  border: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + var(--safe-b));
  max-height: 92vh; overflow-y: auto; animation: up .22s ease; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0;
  background: var(--card); padding: 12px 0 10px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-body .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip { padding: 9px 13px; border-radius: 999px; background: var(--card2); color: var(--muted);
  font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.chip.on { background: rgba(99,102,241,.18); color: #c4b5fd; border-color: var(--accent); }
/* tag pequena de destino da liberação da Caixa (terreno × obra) */
.cx-tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; vertical-align: middle;
  text-transform: uppercase; letter-spacing: .3px; }
.cx-tag.cx-terr { background: rgba(34,197,94,.16); color: #4ade80; }
.cx-tag.cx-obra { background: rgba(99,102,241,.16); color: #a5b4fc; }
@media (min-width: 560px) {
  .modal-wrap { align-items: center; }
  .modal { border-radius: 22px; }
}

/* toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b));
  z-index: 80; background: var(--card2); color: var(--txt); padding: 12px 20px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); }

/* aba Logs */
.log-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); }
.log-item:last-child { border-bottom: none; }
.log-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  font-size: 16px; flex: 0 0 auto; }
.log-meio { flex: 1; min-width: 0; }
.log-acao { font-size: 14px; }
.log-desc { font-size: 12px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-data { font-size: 11px; flex: 0 0 auto; white-space: nowrap; }

/* modo cliente: esconde sidebar + nav, mostra só "Minha obra" */
.cliente-mode .sidebar, .cliente-mode #menu-btn, .cliente-mode #scrim, .cliente-mode .menu-btn { display: none !important; }
.cliente-mode #btn-sair { display: grid !important; }
.cliente-mode .main-area { margin-left: 0 !important; }
.cliente-mode .fab { display: none !important; }
.cli-hero { background: linear-gradient(135deg, #1c2336, #161b27);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.cli-fase { display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--line); }
.cli-fase:last-child { border-bottom: none; }
.cli-fase-ico { font-size: 22px; width: 32px; text-align: center; flex: 0 0 auto; }

/* legenda do donut + catrow clicáveis (filtram a lista no detalhe da obra) */
.leg-row.leg-clic { cursor: pointer; padding: 4px 6px; margin: 0 -6px; border-radius: 8px;
  transition: background .14s; }
.leg-row.leg-clic:hover { background: var(--card2); }
.catrow.catrow-clic { cursor: pointer; padding: 4px 6px; margin: 0 -6px 6px; border-radius: 8px;
  transition: background .14s; }
.catrow.catrow-clic:hover { background: var(--card2); }

/* seções recolhíveis na aba Terrenos */
.section-title.terr-sec { cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; transition: color .14s; }
.section-title.terr-sec:hover { color: var(--txt); }
.terr-sec-chev { display: inline-block; font-size: 10px; opacity: .7;
  transition: transform .2s ease; line-height: 1; }
.section-title.terr-sec.col .terr-sec-chev { transform: rotate(-90deg); }
.terr-sec-body.col { display: none; }

/* seções recolhíveis na página da obra (mesma vibe) */
.section-title.sec-tog { cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; transition: color .14s; }
.section-title.sec-tog::before { content: "▾"; font-size: 10px; opacity: .7;
  display: inline-block; transition: transform .2s ease; line-height: 1; }
.section-title.sec-tog.fechada::before { transform: rotate(-90deg); }
.section-title.sec-tog:hover { color: var(--txt); }

/* breakdown de custos do terreno (preço do terreno × impostos × total investido) */
.invest-block { margin-top: 14px; }
.invest-bar { height: 22px; background: var(--bg2); border-radius: 999px; overflow: hidden; }
.invest-bar > i { display: flex; align-items: center; justify-content: center; height: 100%;
  transition: width .3s ease; color: #fff; }
.invest-bar > i > b { font-size: 11px; font-weight: 800; letter-spacing: .3px;
  text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.invest-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px;
  font-size: 12px; color: var(--muted); font-weight: 600; }
.invest-legend > span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.invest-legend > span > i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.invest-legend em { font-style: normal; color: var(--txt); opacity: .85; margin-left: 4px; }
.invest-total { display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.invest-total-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; }
.invest-total-val { font-size: 24px; font-weight: 800; letter-spacing: -.5px;
  background: linear-gradient(135deg, #a5b4fc, #c4b5fd);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

/* endereço da obra que vem do terreno vinculado (read-only no modal da obra) */
.end-do-terreno { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; }

/* demonstrativo do Financeiro (categorias expansíveis) */
.fin-cat { display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer;
  border-radius: 10px; transition: background .14s; }
.fin-cat:hover { background: var(--card2); }
.fin-cat-chev { font-size: 10px; opacity: .7; transition: transform .2s ease; transform: rotate(-90deg); }
.fin-cat-chev.on { transform: rotate(0deg); }
.fin-cat-tit { flex: 1; font-weight: 600; font-size: 15px; }
.fin-cat-val { font-weight: 800; font-size: 15px; white-space: nowrap; }
.fin-itens { padding: 0 12px 8px 32px; }
.fin-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.fin-item:last-child { border-bottom: none; }
.fin-item-val { font-weight: 700; white-space: nowrap; }
.fin-fechamento { background: linear-gradient(135deg, #1c2336, #161b27); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-top: 14px; }
