:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #dde3ec;
  --text: #1b2430;
  --muted: #6a7789;
  --primary: #2f6df6;
  --primary-hover: #275fdb;
  --own: #17a673;
  --competitor: #d97b2b;
  --danger: #d94a4a;
  --radius: 10px;
  --shadow: 0 4px 18px rgba(27,36,48,.08);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
.muted { color: var(--muted); }
.error-msg { color: var(--danger); font-size: 13px; }
a { color: var(--primary); text-decoration: none; }

/* ---------------- login ---------------- */
.login-body {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #e6eefc, var(--bg));
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 34px 30px; width: min(360px, 92vw);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.login-card h1 { font-size: 20px; margin: 6px 0 0; }
.login-card p { margin: 0 0 8px; }
.login-card input { width: 100%; }
.brand-mark {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #6aa1ff);
  color: #fff; font-weight: 700; font-size: 20px;
  display: grid; place-items: center; letter-spacing: .5px;
}

/* ---------------- inputs / buttons ---------------- */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 14px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,109,246,.12);
}
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
  font-weight: 500; transition: .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---------------- layout ---------------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 22px; height: 58px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 3px rgba(27,36,48,.04);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.topbar .brand .brand-mark { width: 30px; height: 30px; font-size: 13px; border-radius: 8px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav button {
  background: none; border: none; color: var(--muted); padding: 8px 14px;
  cursor: pointer; font-size: 14px; border-radius: 8px; font-weight: 500;
}
.nav button:hover { color: var(--text); background: var(--surface-2); }
.nav button.active { color: var(--primary); background: rgba(47,109,246,.10); }
.spacer { flex: 1; }
.container { padding: 22px; max-width: 1280px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 18px; }

/* ---------------- chips / stats ---------------- */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; min-width: 130px;
  box-shadow: var(--shadow);
}
.stat .val { font-size: 22px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12px; }

/* ---------------- filter bar ---------------- */
.filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filters .field { display: flex; flex-direction: column; }
.filters .actions { grid-column: 1 / -1; display: flex; gap: 8px; }

/* ---------------- table ---------------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; white-space: nowrap; }
thead th {
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface-2); font-size: 12px;
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.price { font-weight: 600; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge.own { background: rgba(23,166,115,.14); color: #0f875b; }
.badge.competitor { background: rgba(217,123,43,.14); color: #b5641d; }

/* ---------------- cards (concorrentes) ---------------- */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card.own { border-left: 3px solid var(--own); }
.card.competitor { border-left: 3px solid var(--competitor); }
.card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card .offices { margin: 10px 0; display: flex; flex-direction: column; gap: 4px; }
.office-tag {
  font-size: 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; display: flex; justify-content: space-between;
}
.office-tag code { color: var(--muted); }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------------- modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(27,36,48,.42);
  display: none; place-items: center; z-index: 50; padding: 20px;
}
.modal-backdrop.open { display: grid; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: min(560px, 96vw);
  box-shadow: 0 12px 40px rgba(27,36,48,.20); max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; }
.form-row { margin-bottom: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.office-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.office-row input { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.chips-select { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-size: 13px; user-select: none;
}
.chip.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.locked { cursor: default; background: var(--surface-2); border-color: var(--border); color: var(--muted); }

/* ---------------- misc ---------------- */
.pagination { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 12px; }
.page-size-lbl { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.page-size-lbl select { padding: 5px 8px; font-size: 13px; }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; border: 1px solid var(--text);
  padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow);
  z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
/* ---------------- multiselect dropdown ---------------- */
.multiselect { position: relative; max-width: 320px; }
.multiselect-toggle {
  width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 32px 9px 11px; font-size: 14px; cursor: pointer;
  position: relative;
}
.multiselect-toggle::after {
  content: '▾'; position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%); color: var(--muted);
}
.multiselect-toggle:hover { border-color: var(--primary); }
.multiselect-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 6px; max-height: 240px;
  overflow-y: auto;
}
.multiselect-menu label {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  border-radius: 6px; cursor: pointer; color: var(--text); font-size: 14px; margin: 0;
}
.multiselect-menu label:hover { background: var(--surface-2); }
.multiselect-menu input[type=checkbox] { width: auto; margin: 0; }

.search-results { border: 1px solid var(--border); border-radius: 8px; margin-top: 6px; max-height: 180px; overflow-y: auto; background: var(--surface); }
.search-item { padding: 8px 11px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.search-item:hover { background: var(--surface-2); }

/* ---------------- menu com submenu ---------------- */
.menu { position: relative; }
.menu-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.menu-btn:hover { border-color: var(--primary); }
.menu .caret { color: var(--muted); font-size: 11px; margin-left: 2px; }
.menu-dropdown {
  position: absolute; top: 100%; left: 0; margin-top: 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 6px; min-width: 180px; z-index: 40; display: none; flex-direction: column;
}
/* ponte invisivel: cobre o vao entre o botao e o menu para o hover nao cair */
.menu-dropdown::before {
  content: ''; position: absolute; top: -6px; left: 0; right: 0; height: 6px;
}
.menu:hover .menu-dropdown { display: flex; }
.menu-dropdown button {
  background: none; border: none; color: var(--muted); text-align: left;
  padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.menu-dropdown button:hover { background: var(--surface-2); color: var(--text); }
.menu-dropdown button.active { color: var(--primary); background: rgba(47,109,246,.10); }

/* ---------------- detalhe da venda ---------------- */
.det-hero {
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.det-addr { font-size: 20px; font-weight: 700; }
.det-price { text-align: right; }
.det-price-val { font-size: 26px; font-weight: 700; color: var(--own); }
.det-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; margin-top: 16px;
}
.det-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.det-lbl { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.det-val { font-weight: 500; word-break: break-word; }
.det-h { margin: 22px 0 10px; font-size: 15px; }
/* ficha RESO: quebrar linha no conteudo em vez de scroll horizontal */
#det-raw td { white-space: normal; word-break: break-word; vertical-align: top; }
#det-raw td:first-child { color: var(--muted); }
