:root {
  --bg: #FBF7F4;
  --bg-elevated: #FFFFFF;
  --surface: #F4ECE6;
  --surface-hover: #EDE2DA;
  --border: #E4D6CC;
  --text: #2B1A1D;
  --text-muted: #7A6660;
  --accent: #7B2D3E;
  --accent-strong: #601F2D;
  --accent-contrast: #FFFFFF;
  --accent-soft: #F3E1E4;
  /* Estágios do funil como rampa ordinal (um só matiz, claro→escuro = mais perto de fechar);
     "Perdido" é a cor de status crítica — validado com scripts/validate_palette.js da skill dataviz. */
  --stage-prospeccao: #6DA7EC;
  --stage-prospeccao-soft: rgba(109,167,236,0.14);
  --stage-negociacao: #2A78D6;
  --stage-negociacao-soft: rgba(42,120,214,0.14);
  --stage-fechado: #184F95;
  --stage-fechado-soft: rgba(24,79,149,0.14);
  --stage-perdido: #D03B3B;
  --stage-perdido-soft: rgba(208,59,59,0.14);
  --shadow: 0 1px 2px rgba(30,15,15,0.07), 0 10px 26px rgba(30,15,15,0.08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1C1416; --bg-elevated: #241A1D; --surface: #2B1F22; --surface-hover: #33262A; --border: #3A2A2E;
    --text: #F3E9E6; --text-muted: #B7A29C;
    --accent: #D46A80; --accent-strong: #C85570; --accent-contrast: #1C1416; --accent-soft: rgba(212,106,128,0.16);
    --stage-prospeccao: #9EC5F4; --stage-prospeccao-soft: rgba(158,197,244,0.18);
    --stage-negociacao: #6DA7EC; --stage-negociacao-soft: rgba(109,167,236,0.20);
    --stage-fechado: #3987E5; --stage-fechado-soft: rgba(57,135,229,0.22);
    --stage-perdido: #E36B6B; --stage-perdido-soft: rgba(227,107,107,0.20);
    --shadow: 0 1px 2px rgba(0,0,0,0.5), 0 14px 30px rgba(0,0,0,0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #1C1416; --bg-elevated: #241A1D; --surface: #2B1F22; --surface-hover: #33262A; --border: #3A2A2E;
  --text: #F3E9E6; --text-muted: #B7A29C;
  --accent: #D46A80; --accent-strong: #C85570; --accent-contrast: #1C1416; --accent-soft: rgba(212,106,128,0.16);
  --stage-prospeccao: #9EC5F4; --stage-prospeccao-soft: rgba(158,197,244,0.18);
  --stage-negociacao: #6DA7EC; --stage-negociacao-soft: rgba(109,167,236,0.20);
  --stage-fechado: #3987E5; --stage-fechado-soft: rgba(57,135,229,0.22);
  --stage-perdido: #E36B6B; --stage-perdido-soft: rgba(227,107,107,0.20);
  --shadow: 0 1px 2px rgba(0,0,0,0.5), 0 14px 30px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; margin: 0; letter-spacing: -0.01em; }
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
code { background: var(--surface); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* ---------- auth pages ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 34px; width: 100%; max-width: 400px;
}
.auth-brand { font-size: 21px; font-weight: 700; }
.auth-brand span { color: var(--accent); display: block; font-size: 14px; font-family: 'Manrope', sans-serif; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; margin-top: 2px; }
.auth-sub { font-size: 13.5px; color: var(--text-muted); margin-top: 10px; margin-bottom: 22px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-note { font-size: 12px; color: var(--text-muted); margin-top: 14px; line-height: 1.5; }

.alert { background: var(--stage-perdido-soft); color: var(--stage-perdido); border: 1px solid var(--stage-perdido); border-radius: 9px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 16px; }
.alert-info { background: var(--stage-prospeccao-soft); color: var(--stage-prospeccao); border-color: var(--stage-prospeccao); }
.alert-success { background: var(--stage-fechado-soft); color: var(--stage-fechado); border-color: var(--stage-fechado); }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; padding-block: 28px 20px; border-bottom: 1px solid var(--border); }
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.brand { font-size: 22px; font-weight: 700; }
.brand span { color: var(--accent); }
.tagline { font-size: 13.5px; color: var(--text-muted); margin-top: 4px; max-width: 42ch; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-muted); }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px; min-width: 116px; }
.stat-label { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 17px; font-weight: 600; margin-top: 2px; }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding-block: 22px; }
.toolbar-fields { display: flex; gap: 10px; flex-wrap: wrap; flex: 1 1 320px; }

input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text); background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-input { flex: 1 1 220px; min-width: 0; }
.stage-filter { min-width: 160px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 9px; font-weight: 700; font-size: 14px; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface); }
.btn-small { height: 32px; padding: 0 12px; font-size: 13px; }

/* ---------- dashboard: meta + funil ---------- */
.dashboard { display: flex; flex-direction: column; gap: 16px; padding-block: 22px 6px; }

.meta-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.meta-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.meta-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-family: 'Manrope', sans-serif; font-weight: 700; }
.meta-value { font-size: 26px; font-weight: 700; font-family: 'Fraunces', Georgia, serif; margin-top: 4px; }
.meta-value .meta-pct { color: var(--accent); }

.meter-track { position: relative; height: 12px; border-radius: 999px; background: var(--accent-soft); margin-top: 16px; overflow: hidden; }
.meter-fill { position: absolute; inset: 0; width: 0%; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }
.meta-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 13px; color: var(--text-muted); flex-wrap: wrap; }
.meta-foot .mono { color: var(--text); font-weight: 600; }

.metas-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.projeto-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.projeto-nome { font-family: 'Fraunces', Georgia, serif; font-size: 15.5px; font-weight: 700; }
.projeto-meta-valor { font-size: 12.5px; color: var(--text-muted); }
.projeto-meta-valor .mono { color: var(--text); font-weight: 600; }
.projeto-meta-valor .meta-pct { color: var(--accent); font-weight: 700; }
.projeto-card .meter-track { margin-top: 0; height: 9px; }
.projeto-foot { font-size: 12px; color: var(--text-muted); min-height: 16px; }
.projeto-foot .mono { color: var(--text); font-weight: 600; }
.projeto-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 2px; padding-top: 10px; border-top: 1px solid var(--border); }
.projeto-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.projeto-stat-value { font-size: 13px; font-weight: 700; margin-top: 2px; }

.funnel-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.funnel-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.funnel-head h2 { font-size: 17px; }
.funnel-sub { font-size: 12.5px; color: var(--text-muted); }
.funnel { display: flex; flex-direction: column; gap: 12px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 96px; align-items: center; gap: 12px; }
.funnel-row-label { font-size: 13.5px; font-weight: 700; }
.funnel-row-count { font-size: 11.5px; color: var(--text-muted); font-weight: 500; }
.funnel-track { height: 22px; border-radius: 6px; background: var(--surface); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 6px 0 0 6px; min-width: 2px; }
.funnel-row-value { font-size: 13.5px; font-weight: 700; text-align: right; }

@media (max-width: 720px) {
  .metas-grid { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 96px 1fr 78px; }
}

.list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-elevated); margin-bottom: 40px; }
.client-header, .client-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 14px; align-items: center; padding: 14px 18px; }
.client-header { background: var(--surface); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.client-row { border-top: 1px solid var(--border); }
.client-row:hover { background: var(--surface); }
.client-name { font-weight: 700; }
.client-company { font-size: 13px; color: var(--text-muted); margin-top: 1px; }
.project-badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 10.5px; font-weight: 700; border: 1px solid var(--border); color: var(--text-muted); background: var(--surface); margin-top: 5px; }
.client-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elevated); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); }
.icon-btn:hover { background: var(--surface); color: var(--text); }

.detail { grid-column: 1 / -1; background: var(--surface); border-top: 1px solid var(--border); padding: 18px; margin: 0 -18px -14px -18px; display: none; }
.detail.open { display: block; }
.detail-grid { display: flex; gap: 28px; flex-wrap: wrap; }
.detail-col { flex: 1 1 260px; }
.detail-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 10px; }
.timeline { display: flex; flex-direction: column; gap: 10px; max-height: 220px; overflow-y: auto; padding-right: 4px; }
.timeline-item { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.timeline-date { font-size: 11.5px; color: var(--text-muted); margin-bottom: 3px; }
.timeline-text { font-size: 13.5px; line-height: 1.5; }
.empty-note { font-size: 13px; color: var(--text-muted); }
.interacao-form { display: flex; flex-direction: column; gap: 8px; }
.interacao-form textarea { min-height: 64px; resize: vertical; }

.empty-state { padding: 56px 20px; text-align: center; color: var(--text-muted); }
.empty-state h3 { color: var(--text); font-size: 18px; margin-bottom: 8px; }

.banner { background: var(--stage-negociacao-soft); border: 1px solid var(--stage-negociacao); color: var(--text); border-radius: 9px; padding: 10px 14px; font-size: 13px; margin-top: 6px; margin-bottom: 6px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(20,10,10,0.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; }
.modal { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; padding: 26px; }
.modal h2 { font-size: 19px; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); font-family: 'Manrope', sans-serif; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow); z-index: 30; }

@media (max-width: 720px) {
  .client-header { display: none; }
  .client-row { grid-template-columns: 1fr; row-gap: 6px; }
  .client-row .cell { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
  .client-row .cell::before { content: attr(data-label); font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
  .row-actions { justify-content: flex-start; margin-top: 4px; }
  .detail { margin: 0 -18px -14px -18px; }
  .topbar-right { align-items: flex-start; }
}

[hidden] { display: none !important; }
