:root {
  --navy: #333F50;
  --navy-2: #252F3D;
  --navy-3: #44536a;
  --gold: #B89A4A;
  --gold-2: #d8c48e;
  --gold-bg: #f7f2e4;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2430;
  --muted: #667085;
  --line: #e3e6eb;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --warn: #9a6400;
  --warn-bg: #fdf2dc;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --info-bg: #e9eef6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --heading: #333F50;     /* títulos e números (navy no claro) */
  --surface-2: #f7f8fa;   /* fundos secundários: cabeçalho de tabela, caixas */
  --line-2: #eef0f3;      /* divisórias leves, trilhos */
  --input-line: #cfd4dc;
  --ink-2: #475467;
  --label: #344054;
  --gold-ink: #7d6526;
  --hover: #f2f4f7;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f141b;
  --card: #18202a;
  --text: #e6e9ee;
  --muted: #98a2b3;
  --line: #2c3643;
  --ok: #4cc38a; --ok-bg: #12301f;
  --warn: #f0b545; --warn-bg: #3a2a08;
  --bad: #f97066; --bad-bg: #3b1513;
  --info-bg: #1c2a3d;
  --gold-bg: #2e2716;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .3);
  --heading: #e9edf3;
  --surface-2: #1f2833;
  --line-2: #26303c;
  --input-line: #3a4655;
  --ink-2: #c0c7d2;
  --label: #c0c7d2;
  --gold-ink: #d8c48e;
  --hover: #222c38;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--heading); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.serif { font-family: "Cormorant Garamond", Georgia, serif; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, var(--navy-2), var(--navy) 55%, var(--navy-3)); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 14px; padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand-mark { width: 44px; height: 44px; border-radius: 10px; background: var(--navy); color: var(--gold); display: grid; place-items: center;
  font-family: "Cormorant Garamond", Georgia, serif; font-weight: 700; font-size: 1.35rem; border: 1.5px solid var(--gold); flex: none; }
.brand-name { font-weight: 700; color: var(--heading); line-height: 1.15; }
.brand-sub { font-size: .78rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.gold-rule { height: 2px; background: linear-gradient(90deg, var(--gold), transparent); border: 0; margin: 14px 0 18px; }

/* ---------- forms ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--label); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--input-line); border-radius: 8px; font: inherit; background: var(--card); color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-2); border-color: var(--gold); }
.field { margin-bottom: 12px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
.grid-form .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px;
  padding: 9px 15px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; background: var(--navy); color: #fff; }
.btn:hover { background: var(--navy-2); }
.btn.gold { background: var(--gold); color: #fff; }
.btn.gold:hover { background: #a3873e; }
.btn.ghost { background: var(--card); color: var(--heading); border-color: var(--input-line); }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { background: var(--card); color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: .9rem; margin: 10px 0; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--heading); }

/* ---------- layout app ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #dfe4ec; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { margin: 4px 6px 18px; }
.side .brand-name { color: #fff; }
.side .brand-sub { color: #aeb8c8; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #dfe4ec; text-decoration: none; font-weight: 500; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.on { background: rgba(184,154,74,.18); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav .sec { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #8e9bb0; margin: 16px 10px 6px; }
.nav .badge { margin-left: auto; }
.main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--navy); }
.kpi.gold { border-top-color: var(--gold); }
.kpi.bad { border-top-color: var(--bad); }
.kpi.ok { border-top-color: var(--ok); }
.kpi .lbl { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 1.45rem; font-weight: 700; margin-top: 4px; color: var(--heading); font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- tabelas ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: var(--surface-2); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--heading); }
.badge.gold { background: var(--gold-bg); color: var(--gold-ink); }

.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 18px; margin: 0; }
.dl div dt { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.dl div dd { margin: 2px 0 0; font-weight: 500; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--heading); border-bottom-color: var(--gold); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--card); z-index: 1; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--card); }
.x { background: none; border: 0; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); }

.toast { position: fixed; bottom: 18px; right: 18px; background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 80; max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; padding: 4px; }
.msg { max-width: 80%; padding: 9px 12px; border-radius: 12px; font-size: .92rem; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--line-2); border-bottom-left-radius: 4px; }
.msg .when { display: block; font-size: .7rem; opacity: .7; margin-top: 3px; }

/* ---------- portal ---------- */
.portal-top { background: var(--navy); color: #fff; }
.portal-top .in { max-width: 1080px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.portal-top .brand { margin: 0; }
.portal-top .brand-name { color: #fff; }
.portal-top .brand-sub { color: #aeb8c8; }
.portal-main { max-width: 1080px; margin: 0 auto; padding: 22px 16px 60px; }
.hero { background: linear-gradient(135deg, var(--navy), var(--navy-3)); color: #fff; border-radius: 14px; padding: 22px; margin-bottom: 16px; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border: 2px solid rgba(184,154,74,.35); border-radius: 50%; }
.hero h1 { color: #fff; }
.hero .muted { color: #c6cfdc; }
.imovel-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }

/* ---------- relatório (impressão) ---------- */
.rel { background: #fff; max-width: 1000px; margin: 0 auto; padding: 28px 32px; color: #000; }
.rel h1 { font-family: "Cormorant Garamond", Georgia, serif; font-size: 1.8rem; color: #333F50; margin: 0; }
.rel .rule { height: 2px; background: var(--gold); margin: 10px 0 16px; }
.rel table { font-size: .82rem; }
.rel .kpis { grid-template-columns: repeat(4, 1fr); }
.rel .sec-t { font-weight: 700; color: var(--heading); text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; margin: 20px 0 6px; border-bottom: 1px solid var(--gold); padding-bottom: 4px; }
.rel .assin { margin-top: 36px; text-align: center; }
.rel .rodape { margin-top: 24px; font-size: .72rem; color: var(--muted); text-align: center; border-top: 1px solid var(--line); padding-top: 8px; }

@media print {
  body { background: var(--card); }
  .no-print, .side, .topbar, .portal-top, .tabs, .toolbar { display: none !important; }
  .app { display: block; }
  .main, .portal-main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .rel { padding: 0; max-width: none; }
  .kpi { box-shadow: none; break-inside: avoid; }
  tr { break-inside: avoid; }
  @page { size: A4; margin: 14mm; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: -260px; width: 250px; z-index: 40; transition: left .2s; }
  .side.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .two { grid-template-columns: 1fr; }
  .rel .kpis { grid-template-columns: repeat(2, 1fr); }
  .rel { padding: 16px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 11px 12px; }
  .kpi .lbl { font-size: .66rem; }
  .kpi .val { font-size: 1.2rem; }
  .portal-top .who { display: none; }
}

/* relatório: sempre como papel claro */
.rel { --card: #fff; --text: #000; --muted: #667085; --line: #e3e6eb; --line-2: #eef0f3; --surface-2: #fafbfc; --heading: #333F50;
  --ok: #1f7a4d; --ok-bg: #e5f4ec; --warn: #9a6400; --warn-bg: #fdf2dc; --bad: #b42318; --bad-bg: #fde8e6; --info-bg: #e9eef6; --gold-bg: #f7f2e4; --gold-ink: #7d6526; color: #000; }
.rel .kpi { background: #fff; }
/* botão de tema */
.tema-btn { display: inline-flex; align-items: center; gap: 6px; }
.tema-btn svg { width: 16px; height: 16px; }
