:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --ink: #17201a;
  --muted: #667063;
  --line: #dce3d6;
  --primary: #147a5c;
  --primary-2: #0e5944;
  --accent: #c0832b;
  --danger: #b84a4a;
  --warning: #b7791f;
  --radius: 8px;
  --shadow: 0 18px 50px rgba(31, 42, 35, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--primary);
  color: white;
  min-height: 36px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: var(--primary-2); }
button.small { min-height: 30px; padding: 0 10px; font-size: 12px; }
button.ghost, .ghost {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}
button.ghost:hover, .ghost:hover { background: #e4eadf; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 10px 11px;
  outline: 0;
}

textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20, 122, 92, .12); }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(rgba(20, 122, 92, .08), rgba(20, 122, 92, .08)),
    url("https://images.unsplash.com/photo-1600607687939-ce8a6c25118c?auto=format&fit=crop&w=1600&q=80") center/cover;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, .95);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 14px;
  padding: 30px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: white;
  font-weight: 900;
}

.login-panel h1 { margin: 0; font-size: 30px; letter-spacing: 0; }
.login-panel p { margin: -8px 0 4px; color: var(--muted); line-height: 1.5; }
.login-panel small { color: var(--muted); text-align: center; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  overflow: hidden;
}

.sidebar {
  background: #17201a;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 18px;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.side-brand strong { display: block; }
.side-brand span { display: block; color: rgba(255,255,255,.58); font-size: 12px; margin-top: 2px; }

.nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: rgba(255,255,255,.74);
  border-radius: 7px;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,.10);
  color: white;
}

.side-card {
  margin-top: auto;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: 14px;
}

.side-card span { color: #d9b36e; font-weight: 800; font-size: 12px; text-transform: uppercase; }
.side-card p { margin: 8px 0 0; color: rgba(255,255,255,.72); font-size: 13px; line-height: 1.45; }

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  min-height: 72px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  gap: 16px;
}

.topbar h2 { margin: 0; font-size: 23px; letter-spacing: 0; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.view {
  display: none;
  overflow: auto;
  padding: 18px 22px 28px;
}

.view.active {
  display: grid;
  gap: 16px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
}

.metric, .panel, .property-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(23, 32, 26, .04);
}

.metric { padding: 15px; }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { display: block; margin-top: 8px; font-size: 26px; letter-spacing: 0; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.panel { padding: 16px; min-width: 0; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head.flat { margin: 0 0 7px; }
.panel h3, .property-card h3 { margin: 0; font-size: 16px; letter-spacing: 0; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 190px auto auto;
  gap: 10px;
  align-items: center;
}

.view-toggle {
  display: flex;
  min-height: 36px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.view-toggle button {
  min-height: 28px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.view-toggle button:hover,
.view-toggle button.active {
  color: white;
  background: var(--primary);
}

.file-button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
}
.file-button input { display: none; }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: #f8faf6; }
td strong { display: block; margin-bottom: 4px; }
td span { display: block; color: var(--muted); font-size: 12px; line-height: 1.45; }
.empty-row { text-align: center; color: var(--muted); padding: 30px; }

.status {
  display: inline-block;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}
.status.quente { background: #dff3e9; color: #116348; }
.status.morno { background: #fff0cf; color: #89590b; }
.status.frio { background: #e8edf2; color: #52606d; }
.status.sem-resposta { background: #f2e7e7; color: #8d3e3e; }
.status.visita { background: #e6f3ff; color: #1f5f8f; }
.status.perdido { background: #f6dddd; color: #903131; }
.status.disponivel { background: #dff3e9; color: #116348; }
.status.reservado { background: #fff0cf; color: #89590b; }
.status.vendido { background: #f2e7e7; color: #8d3e3e; }

.pipeline-wrap {
  display: grid;
  grid-template-columns: repeat(6, minmax(240px, 1fr));
  gap: 12px;
  align-items: start;
  overflow-x: auto;
  padding-bottom: 8px;
}

.pipeline-column {
  min-height: 520px;
  background: #f8faf6;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pipeline-column:hover {
  border-color: rgba(20, 122, 92, .45);
}

.pipeline-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.pipeline-head h3 {
  margin: 0;
  font-size: 15px;
}

.pipeline-head span,
.pipeline-total {
  color: var(--muted);
  font-size: 12px;
}

.pipeline-head strong {
  min-width: 28px;
  min-height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--primary);
}

.pipeline-total {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.pipeline-cards {
  display: grid;
  gap: 9px;
}

.pipeline-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  box-shadow: 0 1px 0 rgba(23, 32, 26, .04);
  cursor: grab;
}

.pipeline-card:active {
  cursor: grabbing;
}

.pipeline-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.pipeline-card-top strong {
  line-height: 1.25;
}

.pipeline-card p {
  margin: 8px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.pipeline-facts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}

.pipeline-facts span,
.pipeline-note {
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 7px;
  font-size: 12px;
  line-height: 1.35;
}

.pipeline-note {
  margin-top: 8px;
  background: #fff8ea;
  color: #785118;
}

.pipeline-actions {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
  margin-top: 9px;
}

.pipeline-actions select {
  min-height: 30px;
  padding: 5px 7px;
  font-size: 12px;
}

.pipeline-empty {
  min-height: 90px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.funnel, .bars { display: grid; gap: 10px; }
.funnel-row, .bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 34px;
  gap: 10px;
  align-items: center;
}
.funnel-row span, .bar-row span { color: var(--muted); font-size: 13px; text-transform: capitalize; }
.funnel-row div, .bar-row div { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.funnel-row i, .bar-row i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.funnel-row strong, .bar-row strong { text-align: right; }

.lead-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.lead-mini {
  min-height: 86px;
  display: grid;
  align-content: start;
  text-align: left;
  gap: 5px;
  background: #f8faf6;
  border: 1px solid var(--line);
  color: var(--ink);
}
.lead-mini:hover { background: var(--surface-2); }
.lead-mini span, .lead-mini small { color: var(--muted); }

.chat-layout {
  min-height: calc(100vh - 126px);
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 14px;
}

.chat-list, .chat-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-list { overflow-y: auto; }
.chat-person {
  width: 100%;
  min-height: 72px;
  display: grid;
  gap: 4px;
  text-align: left;
  color: var(--ink);
  background: white;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
}
.chat-person:hover, .chat-person.active { background: #f1f6ee; }
.chat-person span, .chat-person small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-panel { display: flex; flex-direction: column; min-width: 0; }
.chat-active { display: flex; flex: 1; min-height: 0; flex-direction: column; }
.chat-header {
  min-height: 74px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.chat-header h3 { margin: 0; }
.chat-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.chat-actions { display: flex; gap: 8px; }

.messages {
  flex: 1;
  min-height: 380px;
  overflow: auto;
  padding: 18px;
  background: #edf4eb;
}
.msg {
  max-width: 68%;
  width: fit-content;
  margin-bottom: 10px;
  padding: 10px 12px 6px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.msg.ia, .msg.human { margin-left: auto; background: #d8f0df; }
.msg.system { margin-inline: auto; background: rgba(23, 32, 26, .08); color: var(--muted); max-width: 80%; }
.msg p { margin: 0; line-height: 1.45; }
.msg span { display: block; margin-top: 4px; text-align: right; color: var(--muted); font-size: 11px; }
.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.property-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(240px, 1fr));
  gap: 14px;
}

.property-card { overflow: hidden; }
.property-media {
  height: 126px;
  background:
    linear-gradient(rgba(20, 122, 92, .08), rgba(20, 122, 92, .08)),
    url("https://images.unsplash.com/photo-1600566753190-17f0baa2a6c3?auto=format&fit=crop&w=900&q=80") center/cover;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  padding: 12px;
}
.property-media span {
  background: rgba(255,255,255,.92);
  border-radius: 999px;
  padding: 5px 9px;
  font-weight: 900;
}
.property-body { padding: 14px; }
.property-body p { margin: 8px 0; color: var(--muted); line-height: 1.45; }
.property-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.property-facts span {
  background: var(--surface-2);
  border-radius: 7px;
  padding: 8px;
  font-size: 12px;
  font-weight: 800;
}

.automation-list { display: grid; gap: 10px; }
.automation {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #f8faf6;
}
.automation span { color: var(--muted); font-size: 13px; }

.recommendation-box {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.recommendation-box article {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #f8faf6;
}
.recommendation-box span, .recommendation-box small { color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 26, .54);
}

.modal-box {
  width: min(720px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 14px;
}
.modal-box.large { width: min(980px, 100%); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  background: #17201a;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  .metrics, .property-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .lead-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; gap: 10px; }
  .nav { grid-template-columns: repeat(4, 1fr); }
  .side-card { display: none; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .toolbar { grid-template-columns: 1fr; }
  .pipeline-wrap { grid-template-columns: 1fr; overflow-x: visible; }
  .pipeline-column { min-height: auto; }
  .metrics, .property-grid, .lead-strip, .form-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; }
  .chat-list { max-height: 220px; }
  .composer { grid-template-columns: 1fr; }
  .msg { max-width: 88%; }
}
