:root {
  color-scheme: light;
  --md-primary: #2563eb;
  --md-primary-strong: #1d4ed8;
  --md-primary-container: #dbeafe;
  --md-on-primary: #ffffff;
  --md-secondary: #475569;
  --md-secondary-container: #e2e8f0;
  --md-tertiary: #7c3aed;
  --md-success: #059669;
  --md-error: #dc2626;
  --md-surface: #ffffff;
  --md-surface-container-low: #f8fafc;
  --md-surface-container: #f1f5f9;
  --md-surface-container-high: #e8eef6;
  --md-background: #f6f8fc;
  --md-outline: #d6deea;
  --md-outline-variant: #e5ebf3;
  --md-on-surface: #111827;
  --md-on-surface-variant: #64748b;
  --md-inverse-surface: #0f172a;
  --md-inverse-surface-2: #172033;
  --md-shadow-1: 0 1px 2px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .06);
  --md-shadow-2: 0 4px 10px rgba(15, 23, 42, .08), 0 2px 5px rgba(15, 23, 42, .05);
  --md-shadow-3: 0 12px 28px rgba(15, 23, 42, .10), 0 4px 12px rgba(15, 23, 42, .06);
  --md-radius-xs: 8px;
  --md-radius-sm: 12px;
  --md-radius-md: 16px;
  --md-radius-lg: 24px;
  --md-radius-xl: 28px;
  --bg: var(--md-background);
  --paper: var(--md-surface);
  --paper-soft: var(--md-surface-container-low);
  --ink: var(--md-on-surface);
  --muted: var(--md-on-surface-variant);
  --line: var(--md-outline-variant);
  --gold: var(--md-primary);
  --gold-2: #38bdf8;
  --green: var(--md-success);
  --red: var(--md-error);
  --shadow: var(--md-shadow-2);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  color: var(--ink);
  font-family: Manrope, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 92% 0%, rgba(37, 99, 235, .12), transparent 34%),
    linear-gradient(180deg, #fbfdff 0%, var(--md-background) 55%, #eef4fb 100%);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .20);
  outline-offset: 2px;
}

.sidebar {
  width: 288px;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--md-inverse-surface) 0%, #111827 100%);
  color: white;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  border-right: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--md-radius-md);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #38bdf8, var(--md-primary) 58%, var(--md-tertiary));
  color: white;
  font-weight: 900;
  letter-spacing: -.6px;
  box-shadow: 0 12px 30px rgba(37,99,235,.34);
}
.brand strong { display:block; font-size: 15px; letter-spacing: -.2px; }
.brand span, .sidebar-card p { color: rgba(255,255,255,.64); font-size: 12px; line-height: 1.55; }
nav { display: grid; gap: 4px; }
.nav-item {
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  background: transparent;
  color: rgba(255,255,255,.72);
  font-size: 13px;
  font-weight: 760;
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.nav-icon {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: rgba(255,255,255,.82);
  background: rgba(255,255,255,.07);
  font-size: 14px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.nav-item.active, .nav-item:hover {
  background: rgba(219, 234, 254, .14);
  color: white;
}
.nav-item.active .nav-icon, .nav-item:hover .nav-icon {
  background: linear-gradient(135deg, #38bdf8, var(--md-primary));
  color: white;
  transform: scale(1.04);
}
.nav-item.active::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #38bdf8;
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
}
.sidebar-card {
  margin-top: auto;
  border: 1px solid rgba(148,163,184,.18);
  border-radius: var(--md-radius-lg);
  padding: 18px;
  background: rgba(15, 23, 42, .72);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.sidebar-card h3 {
  margin: 8px 0;
  font-family: "Plus Jakarta Sans", Manrope, sans-serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.65px;
}
.health-dot { display:flex; align-items:center; gap:8px; margin-top:14px; color:rgba(255,255,255,.80); font-size:12px; font-weight:850; }
.health-dot span { width:8px; height:8px; border-radius:50%; background:#22c55e; box-shadow:0 0 0 5px rgba(34,197,94,.12); }

.app { flex: 1; padding: 32px; overflow-x: hidden; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  padding: 20px 22px;
  border: 1px solid rgba(226,232,240,.86);
  border-radius: var(--md-radius-xl);
  background: rgba(255,255,255,.78);
  box-shadow: var(--md-shadow-1);
  backdrop-filter: blur(12px);
}
h1 {
  font-family: "Plus Jakarta Sans", Manrope, sans-serif;
  font-size: 36px;
  margin: 4px 0 0;
  letter-spacing: -1.08px;
  font-weight: 800;
}
h2 { margin: 0; letter-spacing: -.58px; font-size: 22px; font-weight: 820; }
h3 { letter-spacing: -.38px; }
.eyebrow { color: var(--md-primary); text-transform: uppercase; font-size: 10px; font-weight: 900; letter-spacing: 1.7px; }
.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.primary, .secondary, .ghost, .link, .pill-btn {
  min-height: 40px;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 850;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
}
.primary {
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-shadow-2);
}
.primary:hover { background: var(--md-primary-strong); box-shadow: var(--md-shadow-3); transform: translateY(-1px); }
.secondary { background: var(--md-primary-container); color: #174ea6; border: 1px solid #bfdbfe; }
.secondary:hover { background: #cfe3ff; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--md-outline); }
.ghost:hover { background: var(--md-surface-container); }
.link { background: transparent; color: var(--md-primary); min-height: auto; padding: 6px 0; border-radius: var(--md-radius-xs); }
.small { min-height: 34px; padding: 0 13px; }
.hidden { display: none !important; }
.session-pill {
  display:inline-flex;
  align-items:center;
  min-height:38px;
  padding:0 13px;
  border-radius:999px;
  background: var(--md-primary-container);
  color:#174ea6;
  font-size:12px;
  font-weight:900;
  border:1px solid #bfdbfe;
}

.view { display: none; animation: fade .16s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity:0; transform: translateY(3px);} to {opacity:1; transform:none;} }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(170px,1fr)); gap: 14px; margin-bottom: 16px; }
.metric, .panel, .kanban-column {
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(226,232,240,.95);
  border-radius: var(--md-radius-lg);
  box-shadow: var(--md-shadow-1);
}
.metric {
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: box-shadow .16s ease, transform .16s ease;
}
.metric:hover { box-shadow: var(--md-shadow-2); transform: translateY(-1px); }
.metric::after {
  content: "";
  position: absolute;
  right: -26px;
  top: -34px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: rgba(37,99,235,.08);
}
.metric span { color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .75px; }
.metric strong { display: block; margin-top: 10px; font-size: 34px; letter-spacing: -1.2px; font-weight: 850; }
.grid.two { display: grid; grid-template-columns: 1.2fr .9fr; gap: 16px; }
.panel { padding: 22px; }
.admin-wide { grid-column: 1 / -1; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dark-panel {
  background: linear-gradient(145deg, var(--md-inverse-surface), var(--md-inverse-surface-2));
  color: white;
  overflow: hidden;
  position: relative;
  border-color: rgba(255,255,255,.10);
  box-shadow: var(--md-shadow-3);
}
.dark-panel p { color: rgba(226,232,240,.76); line-height: 1.65; }
.automation-preview { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 10px; margin-top: 22px; align-items: center; }
.automation-preview div:not(:nth-child(even)) {
  border: 1px solid rgba(255,255,255,.10);
  padding: 13px;
  border-radius: var(--md-radius-md);
  background: rgba(255,255,255,.055);
  font-size: 12px;
  font-weight: 850;
}

.lead-list { display: grid; gap: 10px; }
.lead-row, .lead-card {
  border: 1px solid var(--line);
  border-radius: var(--md-radius-md);
  padding: 14px;
  background: var(--paper-soft);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.lead-row:hover, .lead-card:hover { border-color: #cbd5e1; background: white; box-shadow: var(--md-shadow-1); }
.lead-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.as-button { width: 100%; text-align: left; color: inherit; }
.lead-row b, .lead-card b { display:block; }
.muted, .lead-row span, .lead-card p { color: var(--muted); font-size: 13px; line-height: 1.45; }
.badge {
  display:inline-flex;
  align-items:center;
  min-height: 24px;
  border-radius:999px;
  padding:0 10px;
  font-size:10px;
  font-weight:900;
  background:var(--md-primary-container);
  color:#1e40af;
  text-transform: uppercase;
  letter-spacing: .35px;
  white-space: nowrap;
}
.score { color: var(--green); font-weight: 900; }

.kanban-toolbar { display:flex; justify-content:space-between; align-items:end; gap:16px; margin-bottom:18px; }
.kanban-toolbar p { margin: 6px 0 0; color: var(--muted); }
.kanban { display: grid; grid-template-columns: repeat(7, 286px); gap: 12px; overflow-x: auto; padding: 3px 3px 18px; }
.kanban-column { padding: 12px; min-height: 610px; box-shadow: none; background: rgba(248,250,252,.88); }
.column-head { display:flex; justify-content:space-between; align-items:center; margin-bottom: 12px; }
.column-head h3 { margin:0; font-size: 12px; text-transform: uppercase; letter-spacing: .65px; }
.count { background: var(--md-inverse-surface); color:white; padding: 3px 8px; border-radius: 99px; font-size: 11px; }
.card-stack { display:grid; gap:9px; min-height: 520px; }
.lead-card { cursor: grab; box-shadow: none; }
.lead-card.dragging { opacity:.55; }
.card-top { display:flex; justify-content:space-between; gap:10px; }
.card-actions { display:flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.pill-btn { min-height: 32px; background: var(--md-secondary-container); color:#334155; padding:0 11px; font-size: 11px; box-shadow:none; }
.pill-btn:hover { background:#dbeafe; color:#174ea6; }
.pill-btn.danger { background:#fee2e2; color:#991b1b; }
.pill-btn.danger:hover { background:#fecaca; color:#7f1d1d; }
.row-actions { display:flex; gap:6px; align-items:center; justify-content:flex-end; flex-wrap:wrap; }

.search { width: min(360px, 100%); }
.table-wrap { overflow:auto; border-radius: var(--md-radius-md); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 820px; background:white; }
th { text-align:left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .9px; background: var(--md-surface-container-low); }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #f8fafc; }

.property-grid, .broker-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr)); gap: 12px; }
.property-card, .broker-card {
  border: 1px solid var(--line);
  border-radius: var(--md-radius-lg);
  padding: 17px;
  background: var(--paper-soft);
  transition: box-shadow .15s ease, transform .15s ease, background .15s ease;
}
.property-card:hover, .broker-card:hover { background:white; box-shadow:var(--md-shadow-2); transform:translateY(-1px); }
.property-card h3, .broker-card h3 { margin: 10px 0 6px; }
.price { font-size: 22px; font-weight: 900; letter-spacing: -.5px; }

.automation-list, .message-log, .stage-list, .visit-timeline, .settings-form, .tenant-list, .team-list, .service-lead-list { display:grid; gap: 12px; margin-top: 16px; }
.auto-item, .message-item, .stage-item, .detail-card, .visit-item, .tenant-item, .team-item, .service-lead-item {
  border:1px solid var(--line);
  border-radius:var(--md-radius-lg);
  padding:15px;
  background:var(--paper-soft);
}
.stage-item, .visit-item, .tenant-item, .team-item, .service-lead-item { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.service-lead-item { align-items:flex-start; }
.service-lead-top { display:flex; align-items:center; gap:10px; margin-bottom:4px; }
.service-lead-item p { margin:4px 0; }
.service-lead-item small { color:var(--muted); font-size:11px; }
.stage-item span { width:29px; height:29px; border-radius:50%; display:grid; place-items:center; background:var(--md-primary); color:white; font-size:12px; font-weight:900; }
.inline-form { display:flex; gap:10px; margin-top:16px; }
.inline-form input { flex:1; }
.message-panel { margin-top:16px; }
.message-item strong { display:block; margin-bottom: 5px; }
.detail-grid { display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap:12px; }
.detail-card.wide { margin-top:12px; }
.detail-card h3 { margin: 8px 0; }
.big { font-size: 40px; display:block; }
.chat-thread { display:grid; gap:10px; max-height:360px; overflow:auto; padding:8px; border-radius:var(--md-radius-md); background:white; border:1px solid var(--line); }
.chat-bubble { max-width:76%; padding:12px 14px; border-radius:18px; border:1px solid var(--line); background:var(--paper-soft); }
.chat-bubble p { margin:6px 0 0; color:var(--ink); line-height:1.5; white-space:pre-wrap; }
.chat-bubble.lead { justify-self:start; background:#fff; }
.chat-bubble.assistant { justify-self:end; background:#dbeafe; border-color:#bfdbfe; }
.chat-bubble.human { justify-self:end; background:#dcfce7; border-color:#bbf7d0; }
.chat-bubble.system { justify-self:center; max-width:88%; background:#f1f5f9; }
.chat-meta { display:flex; justify-content:space-between; gap:10px; color:var(--muted); font-size:11px; }
.chat-meta b { color:var(--ink); }
.notes-list { display:grid; gap:9px; margin:8px 0 12px; }
.note-item { border:1px solid var(--line); border-radius:var(--md-radius-md); background:white; padding:12px; }
.note-item span { display:block; color:var(--muted); font-size:11px; margin:3px 0 8px; }
.note-item p { margin:0; white-space:pre-wrap; line-height:1.5; }
.note-form { display:grid; grid-template-columns:1fr auto; gap:10px; align-items:end; }
.note-form textarea { min-height:72px; }

input, select, textarea {
  border:1px solid var(--md-outline);
  border-radius: var(--md-radius-sm);
  padding: 12px 13px;
  background:white;
  outline-color: var(--md-primary);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:hover, select:hover, textarea:hover { border-color:#bac7d8; }
input:focus, select:focus, textarea:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 4px rgba(37,99,235,.10);
}
textarea { min-height: 92px; resize: vertical; }
label { display:grid; gap:7px; font-weight:850; font-size: 12px; color:#334155; text-transform: uppercase; letter-spacing: .35px; }
menu { display:flex; justify-content:flex-end; gap:10px; padding:0; margin:20px 0 0; }

.login-overlay { position:fixed; inset:0; z-index:20; display:grid; place-items:center; padding:24px; background:rgba(15,23,42,.72); backdrop-filter: blur(5px); }
.login-card { width:min(420px, 100%); display:grid; gap:14px; background:white; border-radius:var(--md-radius-xl); padding:28px; box-shadow:0 30px 90px rgba(2,6,23,.32); }
.login-card .compact { color:var(--ink); margin-bottom:8px; }
.login-card h2 { font-size:28px; }
.form-error { color:var(--red); min-height:20px; margin:0; font-size:13px; font-weight:800; }
.modal { width: min(780px, calc(100vw - 24px)); border:0; border-radius: var(--md-radius-xl); padding:0; box-shadow: 0 26px 90px rgba(15,23,42,.28); background: var(--paper); }
.detail-modal { width: min(1120px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15,23,42,.56); backdrop-filter: blur(2px); }
.modal form { padding: 24px; }
.modal-body { padding:24px; }
.modal-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:18px; }
.icon { width:38px; height:38px; border-radius:50%; background:var(--md-primary-container); font-size:22px; color:#174ea6; display:grid; place-items:center; }
.form-grid { display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px; }
.brand-preview { min-height: 330px; display:flex; flex-direction:column; justify-content:center; }
input[type="color"] { min-height: 45px; padding: 4px; }

@media (max-width: 980px) {
  body { display:block; }
  .sidebar { position:relative; width:auto; min-height:auto; }
  nav { grid-template-columns: repeat(2,1fr); }
  .metrics, .grid.two { grid-template-columns: 1fr; }
  .topbar { align-items:flex-start; flex-direction: column; }
  h1 { font-size: 33px; }
}
@media (max-width: 620px) {
  .form-grid, .metrics, .detail-grid { grid-template-columns:1fr; }
  .app{padding:18px;}
  .inline-form, .visit-item{flex-direction:column; align-items:flex-start;}
  .top-actions { width:100%; flex-wrap: wrap; }
  .automation-preview { grid-template-columns:1fr; }
  .automation-preview div:nth-child(even) { display:none; }
  .note-form { grid-template-columns:1fr; }
  .chat-bubble { max-width:92%; }
}

.soft-separator { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.check-row { display:flex; align-items:center; gap:10px; text-transform:none; letter-spacing:0; font-size:13px; }
.check-row input { width:auto; }

/* Atendimento humano (central de conversas) */
.chat-container {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 190px);
  min-height: 520px;
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(226,232,240,.95);
  border-radius: var(--md-radius-lg);
  box-shadow: var(--md-shadow-1);
  overflow: hidden;
}
.chat-sidebar { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; display: grid; gap: 8px; align-content: start; background: var(--md-surface-container-low); }
.chat-lead-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 13px; border-radius: var(--md-radius-md); background: white; border: 1px solid var(--line); transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
.chat-lead-item:hover { border-color: #cbd5e1; box-shadow: var(--md-shadow-1); }
.chat-lead-item.active { border-color: var(--md-primary); background: var(--md-primary-container); }
.chat-lead-item b { display: block; font-size: 14px; }
.chat-lead-item span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.chat-lead-state { font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .35px; color: #174ea6; white-space: nowrap; }
.chat-lead-state.paused { color: #b45309; }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.chat-header h3 { margin: 0; font-size: 18px; }
.chat-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; background: linear-gradient(180deg, #fbfdff, var(--md-background)); }
.chat-empty { color: var(--muted); font-size: 14px; text-align: center; margin-top: 40px; }
.chat-input-row { padding: 14px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; background: white; }
.chat-input-row input { flex: 1; }
@media (max-width: 900px) {
  .chat-container { grid-template-columns: 1fr; height: auto; }
  .chat-sidebar { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-messages { min-height: 320px; }
}
