:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #18202e; --muted: #677387; --line: #e2e7ee;
  --brand: #0b3d6b; --brand-2: #0f6fae; --accent: #12a38a; --warn: #d9822b; --danger: #c0392b; --ok: #1f9d55;
  --side: #0b2540; --side-ink: #c9d6e6; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, sans-serif; font-size: 14px; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
a { color: var(--brand-2); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 18px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c4ccd8; }
button.primary, .btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: inherit; padding: 0; text-decoration: underline; }
button.sm, .btn.sm { padding: 4px 8px; font-size: 12px; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; color: var(--ink); width: 100%; }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #eef2f7; color: var(--muted); }
.pill.quente { background: #fde8e4; color: #b23b22; } .pill.morno { background: #fff3db; color: #9a6400; } .pill.frio { background: #e6f0fb; color: #285f9e; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: #fff; }
.brand .logo { width: 34px; height: 34px; border-radius: 8px; background: linear-gradient(135deg, var(--brand-2), var(--accent)); display: grid; place-items: center; font-weight: 700; }
.brand small { display: block; color: var(--side-ink); font-size: 11px; }
nav { display: flex; flex-direction: column; padding: 6px 8px; gap: 2px; flex: 1; overflow: auto; }
nav a { color: var(--side-ink); text-decoration: none; padding: 9px 10px; border-radius: 8px; }
nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.me { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; justify-content: space-between; font-size: 12px; }
.view { flex: 1; padding: 24px 28px; min-width: 0; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--side); }
.auth .card { width: 360px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfd; position: sticky; top: 0; }
tr.click:hover td { background: #f7f9fc; cursor: pointer; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 230px); }

/* Kanban */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: #e9edf3; border-radius: var(--radius); width: 250px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.col-h { padding: 10px 12px; font-weight: 600; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.col-h .cnt { margin-left: auto; color: var(--muted); font-weight: 500; }
.col-b { padding: 0 8px 8px; overflow-y: auto; min-height: 60px; }
.col-b.over { background: #dfe6f0; border-radius: 8px; }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; }
.kcard b { display: block; font-size: 13px; margin-bottom: 3px; }
.kcard .meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.kcard .late { color: var(--danger); font-weight: 600; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .v { font-size: 24px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
.bar { height: 7px; background: #edf1f6; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.low > i { background: var(--warn); }
.hbar { display: grid; grid-template-columns: 170px 1fr 60px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 12px; }
.hbar .track { background: #edf1f6; height: 16px; border-radius: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; }

/* Lead detail */
.detail { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.timeline .it { border-left: 2px solid var(--line); padding: 0 0 14px 14px; position: relative; }
.timeline .it::before { content: ''; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.timeline .it.pending::before { background: var(--warn); }
.timeline .it .when { font-size: 11px; color: var(--muted); }
.timeline .it pre { white-space: pre-wrap; font: inherit; margin: 4px 0 0; color: #3a4558; }
.stage-steps { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0 16px; }
.stage-steps button { font-size: 12px; padding: 5px 9px; }
.stage-steps button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.sol { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fbfcfe; }
.sol b { display: block; }
.sol .o { font-size: 11px; color: var(--accent); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.on { border-bottom-color: var(--brand); color: var(--ink); font-weight: 600; }

/* Map */
#map { height: calc(100vh - 170px); border-radius: var(--radius); border: 1px solid var(--line); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

/* Modal / toast */
.modal { position: fixed; inset: 0; background: rgba(11, 37, 64, .45); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal-card { background: #fff; border-radius: 12px; width: min(720px, 100%); max-height: 90vh; overflow: auto; padding: 20px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; z-index: 3000; max-width: 380px; }
.toast.err { background: var(--danger); }
.empty { text-align: center; padding: 30px; color: var(--muted); }
code.k { background: #eef2f7; padding: 2px 6px; border-radius: 4px; font-size: 12px; word-break: break-all; }
pre.code { background: #0f1b2b; color: #d6e2f0; padding: 12px; border-radius: 8px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  nav { flex-direction: row; overflow-x: auto; }
  nav a { white-space: nowrap; }
  .view { padding: 16px; }
  .detail, .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 110px 1fr 44px; }
}

/* Pré-venda: projeto */
.pj { display: grid; grid-template-columns: 250px minmax(0, 1fr) 290px; gap: 12px; height: calc(100vh - 150px); min-height: 520px; }
.pj-side { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-y: auto; }
.pj-side h3 { margin-bottom: 6px; }
.pj-main { position: relative; display: flex; flex-direction: column; min-width: 0; }
#pjmap { flex: 1; border-radius: var(--radius); border: 1px solid var(--line); background: #e9edf3; }
.pj-hint { font-size: 12px; color: var(--muted); padding: 0 2px 6px; min-height: 22px; }
.pj-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.pj-tools button { justify-content: center; }
button.on, .btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.pj-prods { display: flex; flex-direction: column; gap: 4px; }
.pj-prod { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.pj-prod .dot { margin-top: 5px; flex-shrink: 0; }
.pj-prod:hover { border-color: #b8c3d3; }
.pj-prod.on { border-color: var(--brand); background: #eef4fb; }
.pj-prod b { font-size: 12px; }
.pj-auto { padding: 10px; background: #fbfcfe; }
.pj-upload { height: 100%; display: grid; place-content: center; text-align: center; padding: 30px; }
.warn-box { background: #fff3db; color: #9a6400; border-radius: 6px; padding: 6px 8px; }
.pj-dev span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #fff; font: 700 10px Inter, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.pj-dev.sel span { outline: 3px solid #ffeb3b; }
.pj-vtx { background: #fff; border: 2px solid #18202e; border-radius: 2px; }
.pj-len-lbl span, .pj-len { background: rgba(15,27,43,.85) !important; color: #fff !important; border: 0 !important; border-radius: 4px; padding: 2px 6px; font: 600 11px Inter, sans-serif; white-space: nowrap; box-shadow: none !important; }
.pj-len-lbl span { display: inline-block; transform: translate(-50%, -50%); }
.pj-len::before { display: none; }
.pj-text span { display: inline-block; background: rgba(255,255,255,.92); color: var(--ink); padding: 2px 6px; border-radius: 4px; font: 600 12px Inter, sans-serif; white-space: nowrap; transform: translate(-50%, -50%); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.pj-text.sel span { outline: 2px solid #ffeb3b; }

/* Pré-venda: lead, levantamento, proposta */
.ct { padding: 6px 0; border-bottom: 1px solid var(--line); }
.ct:last-child { border-bottom: 0; }
.ct.click { cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 12px; }
.checks label { margin: 0; color: var(--ink); font-weight: 400; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.photo { border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.photo img { width: 100%; height: 130px; object-fit: cover; border-radius: 6px; display: block; }
.sol.on { border-color: var(--accent); background: #f3fbf9; }
table.items { margin-top: 8px; }
table.items th, table.items td { padding: 4px; }
table.items input { padding: 5px 6px; font-size: 12px; }
.chip { border-radius: 99px; }
.cover-prev { max-width: 160px; border: 1px solid var(--line); border-radius: 6px; margin-top: 10px; display: block; }
.cover-prev.wide { max-width: 100%; max-height: 180px; object-fit: cover; width: 100%; }
.logo-slot { border: 1px dashed var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.logo-slot img { max-height: 56px; max-width: 100%; }
.logo-slot .ph { height: 56px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
@media (max-width: 1100px) { .pj { grid-template-columns: 1fr; height: auto; } #pjmap { height: 70vh; } }

/* Menu lateral em grupos expansíveis */
nav .nav-group { display: flex; flex-direction: column; }
nav .nav-h { display: flex; align-items: center; justify-content: space-between; width: 100%; background: none; border: 0; border-radius: 6px; cursor: pointer;
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: #8fa3bb; padding: 12px 10px 6px; }
nav .nav-h:hover { color: #fff; background: none; }
nav .nav-h .chev { width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); margin: 0 4px 3px 0; transition: transform .15s; }
nav .nav-group.closed .nav-h .chev { transform: rotate(-45deg); margin-bottom: 0; }
nav .nav-items { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
nav .nav-group.closed .nav-items { display: none; }
@media (max-width: 900px) {
  nav .nav-group, nav .nav-items { flex-direction: row; }
  nav .nav-h { display: none; }
  nav .nav-group.closed .nav-items { display: flex; }
}
.tabs button.on { background: none; }
