:root,
:root[data-theme="dark"] {
  --bg: #0b0b0d;
  --surface: #141417;
  --surface-2: #1b1b1f;
  --surface-3: #232328;
  --border: #2a2a30;
  --text: #f3f3f4;
  --muted: #9b9ba4;
  --accent: #ff6a13;
  --accent-hover: #ff8236;
  --accent-soft: rgba(255, 106, 19, 0.14);
  --accent-text: #ffffff;
  --danger: #f05252;
  --ok: #34d399;
  --warn: #f5b942;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #f3f2ef;
  --surface-3: #e9e7e3;
  --border: #e2e0db;
  --text: #151515;
  --muted: #6b6b72;
  --accent: #f05a00;
  --accent-hover: #ff6a13;
  --accent-soft: rgba(240, 90, 0, 0.1);
  --accent-text: #ffffff;
  --danger: #d93636;
  --ok: #0f9f6e;
  --warn: #c98a0b;
  --shadow: 0 10px 30px rgba(20, 20, 20, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 220px; flex: none; display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 18px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.nav, .sidebar-foot { display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot { margin-top: auto; }
.wa-status { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 4px; font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; }
.wa-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.wa-status.on .wa-dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.wa-status.on { color: var(--text); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
  text-decoration: none; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 24px; border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-size: 20px; font-weight: 700; }
h2 { margin: 0; font-size: 18px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 36px; width: 260px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--muted);
}
.search input { border: 0; outline: 0; background: none; width: 100%; color: var(--text); }
.segmented { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.segmented button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface-3); color: var(--text); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: none; }
.btn.danger { background: none; color: var(--danger); border-color: transparent; }
.btn.danger:hover { background: rgba(240, 82, 82, 0.1); }
.icon-btn {
  width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- kanban ---------- */
.board { flex: 1; display: flex; gap: 14px; padding: 18px 24px; overflow-x: auto; overflow-y: hidden; align-items: stretch; }
.col {
  width: 272px; flex: none; display: flex; flex-direction: column; max-height: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 10px 10px 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.col-name { font-weight: 600; font-size: 13px; }
.count { color: var(--muted); font-size: 12px; background: var(--surface-2); padding: 1px 7px; border-radius: 10px; }
.col-head .add { margin-left: auto; }
.col-body { flex: 1; overflow-y: auto; padding: 4px 8px 10px; display: flex; flex-direction: column; gap: 8px; min-height: 80px; border-radius: 0 0 12px 12px; transition: background .15s; }
.col-body.drop-over { background: var(--accent-soft); }
.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 8px; border: 1px dashed var(--border); border-radius: 8px; }
.col-body:has(.card) .empty { display: none; }

.card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  cursor: grab; display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); }
.card.dragging { opacity: .45; cursor: grabbing; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-top strong { font-size: 14px; line-height: 1.3; word-break: break-word; }
.card-sub { color: var(--muted); font-size: 12px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; color: var(--muted); }
.card-meta span { background: var(--surface-3); padding: 1px 7px; border-radius: 10px; }
.badge { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.card-meta .pot-hi { color: var(--ok); }
.card-meta .pot-mid { color: var(--warn); }
.card-next { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 6px; }
.card-next.today { color: var(--warn); font-weight: 600; }
.card-next.late { color: var(--danger); font-weight: 600; }

/* ---------- list ---------- */
.list-wrap { flex: 1; overflow: auto; padding: 18px 24px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.late { color: var(--danger); font-weight: 600; }
td.today { color: var(--warn); font-weight: 600; }
.stage-pill { display: inline-flex; align-items: center; gap: 6px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- dashboard ---------- */
.dash { flex: 1; overflow: auto; padding: 18px 24px 32px; display: flex; flex-direction: column; gap: 18px; }
.dash-toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
label.inline { flex-direction: column; min-width: 160px; }
label.inline select { min-width: 240px; }
.dash-note { margin: -8px 0 0; font-size: 13px; }
.kpi-value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.accent .kpi-value { color: var(--accent); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.panel table { border: 0; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 36px; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; }
.muted { color: var(--muted); }
.late-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.late-item:last-child { border-bottom: 0; }
.late-item:hover strong { color: var(--accent); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center; padding: 20px; z-index: 10; }
.modal {
  width: min(760px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head-actions { display: flex; align-items: center; gap: 8px; }
.modal-body { overflow-y: auto; padding: 8px 20px 16px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.spacer { flex: 1; }
fieldset { border: 0; padding: 0; margin: 16px 0 0; }
fieldset.highlight { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 14px; }
legend { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0; margin-bottom: 10px; }
fieldset.highlight legend { color: var(--accent); float: left; width: 100%; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; clear: both; }
.span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); outline: none; font-size: 14px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.invalid { border-color: var(--danger); }
#genResumo { margin-top: 12px; }
#resumoBox { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
#resumoText { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.history { margin-top: 18px; font-size: 12px; color: var(--muted); }
.history strong { display: block; margin-bottom: 6px; color: var(--text); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.history ol { margin: 0; padding-left: 18px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500;
}
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .app { flex-direction: column; height: auto; min-height: 100vh; }
  .sidebar { width: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .brand-sub { display: none; }
  .nav, .sidebar-foot { flex-direction: row; margin-top: 0; }
  .topbar, .board, .list-wrap, .dash { padding-left: 16px; padding-right: 16px; }
  .search { width: 100%; }
  .board { min-height: 70vh; }
  .panel-grid, .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .bar-row { grid-template-columns: 110px 1fr 30px; }
}

/* tela WhatsApp / piloto automático */
.table-wrap { overflow-x: auto; }
td.wrap { white-space: normal; min-width: 220px; }
.pilot-modes { display: inline-flex; margin-bottom: 10px; }
.pilot-modes button.active[data-pilot="enviar"] { background: var(--accent); color: #fff; }
.pilot-rules { margin: 10px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag-enviado { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.tag-simulado { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tag-erro, .tag-parado { color: #ef4444; border-color: color-mix(in srgb, #ef4444 40%, transparent); }
/* agenda */
.ag-toolbar { align-items: center; }
.ag-label { font-size: 15px; margin-left: 6px; }
.ag-week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 8px; overflow-x: auto; }
.ag-day { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px; min-height: 160px; display: flex; flex-direction: column; gap: 6px; }
.ag-day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ag-day.before { opacity: .7; }
.ag-day-head { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-size: 12px; padding: 0 2px 4px; border-bottom: 1px solid var(--border); }
.ag-day-head strong { font-size: 16px; color: var(--text); }
.ag-day.today .ag-day-head strong { color: var(--accent); }
.ag-item { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 6px 8px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.ag-item.past { border-left-color: var(--muted); opacity: .75; }
.ag-time { font-size: 12px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.ag-item.past .ag-time { color: var(--muted); }
.ag-name { font-size: 13px; font-weight: 600; }
.ag-meta { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.ag-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.ag-task { font-size: 12px; padding: 4px 2px; border-bottom: 0; }
.ag-empty { color: var(--muted); font-size: 12px; text-align: center; padding-top: 12px; }
.btn.small { padding: 3px 8px; font-size: 11px; border-radius: 6px; }
.muted.small { font-size: 11px; }
.late-item .late { color: var(--danger); font-weight: 600; }
.inline-field { display: flex; gap: 6px; }
.inline-field input { flex: 1; }
.inline-field .btn { white-space: nowrap; }
@media (max-width: 860px) { .ag-week { grid-template-columns: 1fr; } .ag-day { min-height: 0; } }
/* etiquetinha de lead do Forms no card */
.card-tags { display: inline-flex; gap: 4px; flex: none; }
.tag-forms { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: var(--accent); color: var(--accent-text); }

/* Dashboard: lista de leads por origem / campanha */
.dash-hint { margin: -6px 0 10px; font-size: 12px; }
tr.group-row td:first-child strong { color: var(--accent); }
tr.group-row.open { background: var(--surface-2); }
tr.group-row td[data-metric]:hover { text-decoration: underline; }
.drill-arrow { color: var(--muted); font-size: 11px; }
.drill { margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.drill-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.drill-head .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: inherit; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip:disabled { opacity: .45; cursor: default; }

/* Agenda: Google Agenda */
.g-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 13px; }
.g-bar .spacer { flex: 1; }
.g-dot { width: 9px; height: 9px; border-radius: 50%; background: #34d399; flex: none; }
.g-dot.off { background: var(--muted); }
.g-dot.err { background: var(--danger); }
.g-cfg ol { margin: 0 0 10px; padding-left: 20px; line-height: 1.7; }
.g-cfg .inline-field input { flex: 1; min-width: 240px; }
.g-chip { display: inline-block; font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 999px; background: #4285f41f; color: #4285f4; border: 1px solid #4285f455; vertical-align: middle; }
.ag-item.gcal { border-style: dashed; }
.ag-item.gcal .ag-name { font-weight: 500; }
.g-link { max-width: 100%; font: inherit; font-size: 11px; padding: 3px 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: inherit; }
.ag-allday { font-size: 11px; padding: 3px 6px; margin-bottom: 6px; border-radius: 6px; background: #4285f41f; color: #4285f4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
