@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,500;12..96,700&family=Figtree:wght@400;500;600&display=swap');

:root {
  --bg: #EEF1F4;
  --panel: #FFFFFF;
  --ink: #1B2533;
  --muted: #5D6B7E;
  --line: #D8DEE6;
  --rail: #1E2A38;
  --rail-ink: #C9D3DF;
  --ai: #3048E8;
  --ai-soft: #E5E9FF;
  --human: #C77A12;
  --human-soft: #FFF1DC;
  --won: #22865A;
  --lost: #9AA5B4;
  --danger: #C2392B;
  --lead-bubble: #F1F4F8;
  --radius-lg: 14px;
  --radius-sm: 8px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Figtree', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141A22; --panel: #1C2430; --ink: #E6EBF2; --muted: #93A0B2; --line: #2C3644;
    --rail: #0F141B; --ai-soft: #232C55; --human-soft: #3A2C17; --lead-bubble: #252F3D;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--body); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 26px; } h2 { font-size: 19px; } h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--ai); }
:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- estrutura ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-family: var(--display); font-size: 21px; color: #fff; padding: 0 10px 18px; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; border-radius: 50%; background: conic-gradient(var(--ai) 0 75%, #8FA0FF 75%); }
.nav-btn { background: none; border: 0; text-align: left; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--rail-ink); cursor: pointer; display: flex; justify-content: space-between; }
.nav-btn:hover { background: rgba(255,255,255,.06); }
.nav-btn[aria-current="page"] { background: rgba(255,255,255,.1); color: #fff; }
.badge { background: var(--human); color: #fff; border-radius: 99px; font-size: 12px; padding: 0 7px; font-weight: 600; }
.rail-foot { margin-top: auto; font-size: 13px; padding: 10px; display: grid; gap: 6px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--lost); }
.dot.on { background: #4ADE80; }

main { padding: 26px 30px 60px; min-width: 0; }
.topline { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- piloto ---------- */
.pilot { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius-lg); background: var(--ai); color: #fff; margin-bottom: 22px; }
.pilot.off { background: var(--panel); color: var(--ink); border: 1px dashed var(--line); }
.pilot-pulse { width: 12px; height: 12px; border-radius: 50%; background: #fff; flex: none; animation: pulse 2s infinite; }
.pilot.off .pilot-pulse { background: var(--lost); animation: none; }
.pilot p { margin: 0; flex: 1; }
.pilot strong { font-family: var(--display); font-size: 17px; display: block; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.6); } 70% { box-shadow: 0 0 0 10px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }
@media (prefers-reduced-motion: reduce) { .pilot-pulse { animation: none; } }

/* ---------- botões ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ai); border-color: var(--ai); color: #fff; }
.btn.warn { background: var(--human); border-color: var(--human); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.pilot .btn { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.35); color: #fff; }
.pilot.off .btn { background: var(--ai); border-color: var(--ai); }

/* ---------- números ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 26px; }
.stat { background: var(--panel); padding: 14px 16px; }
.stat b { font-family: var(--display); font-size: 28px; display: block; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }

/* ---------- funil ---------- */
.board { display: grid; grid-template-columns: repeat(6, minmax(210px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { min-width: 0; }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 8px; border-bottom: 3px solid var(--line); margin-bottom: 10px; }
.col-head h3 { font-size: 15px; }
.col-head span { color: var(--muted); font-size: 13px; }
.col[data-stage="ganho"] .col-head { border-color: var(--won); }
.col[data-stage="qualificado"] .col-head, .col[data-stage="proposta"] .col-head { border-color: var(--ai); }
.cards { display: grid; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; text-align: left; width: 100%; display: grid; gap: 4px; }
.card:hover { border-color: var(--muted); }
.card.human { border-left: 4px solid var(--human); }
.card.pending { border-left: 4px solid var(--ai); }
.card-name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.card-last { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 12px; border-radius: 99px; padding: 1px 8px; background: var(--lead-bubble); color: var(--muted); }
.tag.human { background: var(--human-soft); color: var(--human); font-weight: 600; }
.tag.ai { background: var(--ai-soft); color: var(--ai); }
.score { font-family: var(--display); font-size: 13px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 10px 4px; }

/* ---------- lista / atividade ---------- */
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row small { color: var(--muted); }
.search { padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); min-width: 220px; }

/* ---------- painel do lead ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(15, 20, 27, .45); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(980px, 100vw); background: var(--bg); z-index: 11; display: grid; grid-template-columns: 1fr 320px; box-shadow: -10px 0 40px rgba(0,0,0,.2); }
.thread-wrap { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.thread-head { padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.thread { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: var(--lead-bubble); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--ai-soft); }
.msg.humano { background: var(--human-soft); }
.msg.nota { align-self: center; background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; max-width: 90%; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.msg-meta .err { color: var(--danger); }
.msg-subject { font-weight: 600; font-size: 13px; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 16px; display: grid; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.composer textarea { width: 100%; min-height: 64px; resize: vertical; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--bg); }
.composer input, .composer select { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 8px; background: var(--bg); }
.side { overflow-y: auto; padding: 20px; display: grid; gap: 18px; align-content: start; }
.side section { display: grid; gap: 8px; }
.side h3 { font-size: 14px; color: var(--muted); font-family: var(--body); font-weight: 600; }
.handoff { background: var(--human-soft); border: 1px solid var(--human); border-radius: var(--radius-sm); padding: 12px; display: grid; gap: 8px; }
.handoff p { margin: 0; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.meter { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ai); }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input[type="checkbox"] { width: 38px; height: 22px; appearance: none; background: var(--line); border-radius: 99px; position: relative; cursor: pointer; flex: none; }
.switch input[type="checkbox"]::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input[type="checkbox"]:checked { background: var(--ai); }
.switch input[type="checkbox"]:checked::after { left: 19px; }
.activity-mini { font-size: 12.5px; color: var(--muted); display: grid; gap: 4px; max-height: 200px; overflow-y: auto; }

/* ---------- formulários ---------- */
.form { display: grid; gap: 14px; max-width: 760px; }
.form label { display: grid; gap: 5px; font-weight: 500; }
.form label small { font-weight: 400; color: var(--muted); }
.form input, .form textarea, .form select { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; background: var(--panel); }
.form textarea { min-height: 84px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px 18px; display: grid; gap: 14px; background: var(--panel); }
legend { font-family: var(--display); font-weight: 700; padding: 0 6px; font-size: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
code { background: var(--lead-bubble); padding: 1px 5px; border-radius: 4px; font-size: 13px; word-break: break-all; }

dialog { border: 0; border-radius: var(--radius-lg); padding: 22px; width: min(520px, 94vw); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(15, 20, 27, .5); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); padding: 28px; border-radius: var(--radius-lg); width: min(360px, 100%); display: grid; gap: 14px; border: 1px solid var(--line); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 50; }
.warnbar { background: var(--human-soft); color: var(--ink); border: 1px solid var(--human); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail { flex-direction: row; flex-wrap: wrap; padding: 10px 16px; align-items: center; }
  .brand { padding: 0 10px 0 0; }
  .rail-foot { display: none; }
  main { padding: 18px 16px 60px; }
  .drawer { grid-template-columns: 1fr; overflow-y: auto; }
  .thread-wrap { border-right: 0; min-height: 80vh; }
  .form-grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(6, 78vw); }
}

.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 42px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); flex: none; cursor: pointer; }
.color-row input:not([type="color"]) { flex: 1; min-width: 0; }
.preview-bar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn { border: 0; background: var(--panel); padding: 7px 14px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed="true"] { background: var(--ai-soft); color: var(--ai); }
.preview-frame { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; display: flex; justify-content: center; }
.preview-frame iframe { width: 100%; height: 680px; border: 0; background: #fff; border-radius: 6px; transition: width .2s; }
.badge-muted { background: rgba(255,255,255,.18); }
.filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filters select { width: 100%; }
.kv-sep { grid-column: 1 / -1; border-top: 1px solid var(--line); margin: 4px 0; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } }
