/* Duty Piracicaba · Painel comercial · tokens de design (tema claro apenas).
   Referência para Jinja2/HTMX. Sem dependências, fontes do sistema. */
:root {
  /* Superfícies: neutros quentes */
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --surface-sunken: #efebe5;
  --border: #e3ddd4;
  --border-strong: #cfc7bb;

  /* Texto */
  --text: #1f1b16;
  --text-2: #4a433b;
  --text-muted: #6b635a;
  --text-inverse: #ffffff;

  /* Acento: verde-petróleo */
  --accent: #0f5f63;
  --accent-hover: #0b4c4f;
  --accent-soft: #e2efef;
  --accent-soft-border: #b9d6d6;
  --focus: #0f5f63;
  --focus-ring: 0 0 0 3px rgba(15, 95, 99, 0.28);

  /* Semânticos */
  --danger: #a3301d;
  --danger-soft: #fbe6e1;
  --danger-border: #eab8ad;
  --success: #1f6b3f;
  --success-soft: #e3f1e7;
  --warning: #7a4b00;
  --warning-soft: #fbefd5;
  --warning-border: #eed39b;

  /* Temperatura do lead (DAT-001) */
  --temp-frio-fg: #2f5f86;   --temp-frio-bg: #e5eef6;
  --temp-morno-fg: #7a4b00;  --temp-morno-bg: #fbefd5;
  --temp-quente-fg: #a3301d; --temp-quente-bg: #fbe4de;

  /* Origem do canal */
  --wa-fg: #1f6b3f;  --wa-bg: #e3f1e7;
  --ig-fg: #8e2a63;  --ig-bg: #f6e4ef;

  /* Estado do atendimento (DAT-002) */
  --st-ia-fg: #0f5f63;       --st-ia-bg: #e2efef;
  --st-wait-fg: #6b3f00;     --st-wait-bg: #f9e3b4;  --st-wait-rule: #d99a1e;
  --st-human-fg: #2b3f73;    --st-human-bg: #e6eaf6;
  --st-closed-fg: #5e574f;   --st-closed-bg: #ece8e2;

  /* Autores da conversa */
  --msg-cliente-bg: #ffffff;  --msg-cliente-border: #e3ddd4;
  --msg-ia-bg: #e2efef;       --msg-ia-border: #b9d6d6;
  --msg-humano-bg: #e6eaf6;   --msg-humano-border: #c3cce6;

  /* Tipografia: fontes do sistema */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;   /* corpo padrão do painel */
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --lh-tight: 1.25;
  --lh-body: 1.45;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;

  /* Espaçamento (base 4) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  /* Raio, sombra, camadas */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(31, 27, 22, 0.06);
  --shadow-2: 0 4px 16px rgba(31, 27, 22, 0.10);
  --shadow-3: 0 12px 40px rgba(31, 27, 22, 0.18);
  --z-nav: 20; --z-toast: 40; --z-modal: 50;

  /* Containers e alvos */
  --sidebar-w: 232px;
  --lead-panel-w: 320px;
  --kanban-col-w: 232px;
  --content-max: 1280px;
  --control-h: 36px;
  --control-h-touch: 44px;
  --bottom-nav-h: 60px;
}

/* Painel comercial: componentes portados de design/prototype/index.html.
   Fora do :root acima, cor só por var(--token) ou color-mix sobre tokens. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: var(--fw-regular) var(--fs-md)/var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 14px; border-radius: var(--radius);
  border: 1px solid transparent; background: none; font-weight: var(--fw-semibold);
  font-size: var(--fs-md); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .12s, border-color .12s;
}
.btn-primary { background: var(--accent); color: var(--text-inverse); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-sunken); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: var(--text-inverse); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.btn-icon { width: var(--control-h); padding: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: var(--fw-semibold); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---------- Campos ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
}
.textarea { height: auto; padding: 9px 12px; resize: vertical; line-height: var(--lh-body); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: var(--focus-ring); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.help { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); font-weight: var(--fw-medium); }
.select-sm { height: 32px; font-size: var(--fs-sm); padding: 0 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; min-height: 22px; padding: 2px 8px;
  border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  line-height: 1.2; white-space: nowrap; vertical-align: middle;
}
.chip-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.o-wa { color: var(--wa-fg); background: var(--wa-bg); }
.o-ig { color: var(--ig-fg); background: var(--ig-bg); }
.t-frio { color: var(--temp-frio-fg); background: var(--temp-frio-bg); }
.t-morno { color: var(--temp-morno-fg); background: var(--temp-morno-bg); }
.t-quente { color: var(--temp-quente-fg); background: var(--temp-quente-bg); }
.s-ia { color: var(--st-ia-fg); background: var(--st-ia-bg); }
.s-aguardando { color: var(--st-wait-fg); background: var(--st-wait-bg); }
.s-humano { color: var(--st-human-fg); background: var(--st-human-bg); }
.s-encerrada { color: var(--st-closed-fg); background: var(--st-closed-bg); }
.chip-neutral { color: var(--text-2); background: var(--surface-sunken); }
.chip-success { color: var(--success); background: var(--success-soft); }
.chip-danger { color: var(--danger); background: var(--danger-soft); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-4); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-8); box-shadow: var(--shadow-1); }
.login-card .brand { margin-bottom: var(--sp-6); }
.login-card h1 { font-size: var(--fs-xl); margin-bottom: 4px; }
.login-card form { display: flex; flex-direction: column; gap: var(--sp-4); margin-top: var(--sp-6); }
.login-foot { margin-top: var(--sp-5); font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- Marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; border-radius: var(--radius); background: var(--accent); color: var(--text-inverse); display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: .02em; flex: none; }
.brand-name { font-weight: var(--fw-semibold); line-height: 1.15; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: var(--sp-4) var(--sp-3); gap: var(--sp-5); }
.sidebar .brand { padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-semibold); padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: var(--radius); color: var(--text-2); text-decoration: none; font-weight: var(--fw-medium); }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: var(--fw-semibold); }
.nav .count { margin-left: auto; min-width: 22px; text-align: center; padding: 1px 7px; border-radius: var(--radius-pill); background: var(--st-wait-bg); color: var(--st-wait-fg); font-size: var(--fs-xs); font-weight: 700; }
.user-box { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 6px 0; border-top: 1px solid var(--border); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-sunken); color: var(--text-2); display: grid; place-items: center; font-size: var(--fs-xs); font-weight: 700; flex: none; }
.user-box .who { min-width: 0; flex: 1; }
.user-box .who strong { display: block; font-size: var(--fs-sm); }
.user-box .who span { font-size: var(--fs-xs); color: var(--text-muted); }
.main { min-width: 0; }
.topbar, .bottom-nav { display: none; }

.page { padding: var(--sp-6) var(--sp-8) var(--sp-10); max-width: var(--content-max); }
.page-wide { max-width: none; padding-left: var(--sp-5); padding-right: var(--sp-5); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-xl); font-weight: var(--fw-semibold); letter-spacing: -.005em; }
.subtitle { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.card-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }

/* ---------- Fila ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-3); overflow-x: auto; scrollbar-width: none; }
.tab { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 9px 10px; font-weight: var(--fw-semibold); color: var(--text-muted); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab .n { font-size: var(--fs-xs); background: var(--surface-sunken); color: var(--text-2); border-radius: var(--radius-pill); padding: 1px 7px; }
.tab .n.warn { background: var(--st-wait-bg); color: var(--st-wait-fg); }
.filters { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); align-items: center; }
.filters .select { width: auto; height: 36px; font-size: var(--fs-sm); }
.search { position: relative; flex: 1 1 220px; max-width: 340px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search .input { height: 36px; padding-left: 34px; font-size: var(--fs-sm); }
.q-cols { grid-template-columns: 112px minmax(0, 1fr) 88px 248px 76px; }
.q-head { display: grid; gap: var(--sp-4); padding: 8px 16px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-muted); border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.q-head span:last-child { text-align: right; }
.q-row { display: grid; gap: var(--sp-4); align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); color: inherit; text-decoration: none; position: relative; }
.q-list .q-row:first-child { border-top: 0; }
.q-row:hover { background: var(--surface-2); }
.q-row.is-waiting { background: color-mix(in srgb, var(--st-wait-bg) 20%, var(--surface)); }
.q-row.is-waiting:hover { background: color-mix(in srgb, var(--st-wait-bg) 40%, var(--surface)); }
.q-row.is-waiting::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--st-wait-rule); }
.q-row.is-closed .q-name { color: var(--text-2); font-weight: var(--fw-medium); }
.q-main { min-width: 0; overflow: hidden; }
.q-name, .q-last { display: block; }
.q-name { font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-last { color: var(--text-muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-last b { color: var(--text-2); font-weight: var(--fw-semibold); }
.q-time { text-align: right; font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.q-time .wait { display: block; color: var(--st-wait-fg); font-weight: 700; font-size: var(--fs-xs); }
.q-chips-m { display: none; }
.q-foot { padding: 10px 16px; font-size: var(--fs-xs); color: var(--text-muted); border-top: 1px solid var(--border); }

/* ---------- Vazio ---------- */
.empty { text-align: center; padding: 64px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 4px; }
.empty-icon .icon { width: 24px; height: 24px; }
.empty h2 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.empty p { color: var(--text-muted); max-width: 440px; }
.empty .btn { margin-top: 6px; }

/* ---------- Conversa ---------- */
.convo { display: flex; flex-direction: column; height: 100vh; }
.convo-head { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); text-decoration: none; font-weight: var(--fw-semibold); font-size: var(--fs-sm); height: 36px; padding: 0 8px 0 4px; border-radius: var(--radius); }
.back:hover { background: var(--surface-sunken); }
.convo-title { min-width: 0; flex: 1 1 260px; }
.convo-title h1 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 3px; font-size: var(--fs-xs); color: var(--text-muted); }
.convo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.state-banner { display: flex; align-items: center; gap: 10px; padding: 10px 20px; font-size: var(--fs-sm); border-bottom: 1px solid var(--border); }
.state-banner .icon { flex: none; }
.state-banner p { flex: 1; min-width: 0; }
.state-banner.aguardando { background: var(--st-wait-bg); color: var(--st-wait-fg); border-color: var(--warning-border); }
.state-banner.ia { background: var(--st-ia-bg); color: var(--st-ia-fg); border-color: var(--accent-soft-border); }
.state-banner.humano { background: var(--st-human-bg); color: var(--st-human-fg); border-color: var(--msg-humano-border); }
.state-banner.encerrada { background: var(--st-closed-bg); color: var(--st-closed-fg); }
.convo-tabs { display: none; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 12px; margin-bottom: 0; }
.convo-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--lead-panel-w); }
.thread-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); }
.thread { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.day-sep { align-self: center; font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-semibold); padding: 2px 0; }
.msg { max-width: min(560px, 80%); display: flex; flex-direction: column; gap: 3px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg-meta { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-muted); }
.msg-meta .author { font-weight: var(--fw-semibold); color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; }
.msg.ia .msg-meta .author { color: var(--st-ia-fg); }
.msg.humano .msg-meta .author { color: var(--st-human-fg); }
.bubble { padding: 9px 12px; border-radius: 12px; border: 1px solid; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.cliente .bubble { background: var(--msg-cliente-bg); border-color: var(--msg-cliente-border); border-top-left-radius: 4px; }
.msg.ia .bubble { background: var(--msg-ia-bg); border-color: var(--msg-ia-border); border-top-right-radius: 4px; }
.msg.humano .bubble { background: var(--msg-humano-bg); border-color: var(--msg-humano-border); border-top-right-radius: 4px; }
.msg.failed .bubble { background: var(--surface); border-color: var(--danger); border-style: dashed; }
.msg-status { font-size: var(--fs-xs); color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.msg-error { font-size: var(--fs-xs); color: var(--danger); font-weight: var(--fw-semibold); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-error .link-btn { color: var(--danger); font-size: var(--fs-xs); }
.msg.sys { display: block; align-self: center; max-width: 92%; text-align: center; font-size: var(--fs-xs); color: var(--text-2); background: var(--surface-sunken); border-radius: var(--radius-pill); padding: 5px 12px; }
.msg.sys b { font-weight: var(--fw-semibold); }
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 20px 14px; }
.composer-alert { display: flex; gap: 8px; align-items: flex-start; background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); border-radius: var(--radius); padding: 8px 12px; font-size: var(--fs-sm); margin-bottom: 10px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 42px; max-height: 160px; resize: none; }
.composer.is-locked textarea { background: var(--surface-sunken); border-color: var(--border); cursor: not-allowed; }
.composer-hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 6px; display: flex; gap: 6px; align-items: center; }

.lead-panel { background: var(--surface); overflow-y: auto; padding: 4px 20px 20px; }
.panel-section { padding: 14px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.panel-section:first-child { border-top: 0; }
.panel-section h2 { font-size: var(--fs-sm); font-weight: var(--fw-semibold); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 6px 10px; margin: 0; font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ai-summary { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: var(--fs-sm); color: var(--text-2); }
.ai-tag { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.sale-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; font-size: var(--fs-sm); display: flex; justify-content: space-between; gap: 8px; }
.sale-item small { display: block; color: var(--text-muted); font-size: var(--fs-xs); }
.muted { color: var(--text-muted); }

/* ---------- Funil ---------- */
.board { display: grid; grid-template-columns: repeat(7, minmax(156px, 1fr)); gap: 8px; overflow-x: auto; align-items: start; padding-bottom: 8px; }
.col { background: var(--surface-sunken); border-radius: var(--radius-lg); padding: 6px; display: flex; flex-direction: column; gap: 6px; min-height: 360px; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 6px 4px; font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.col-head .n { font-size: var(--fs-xs); color: var(--text-muted); background: var(--surface); border-radius: var(--radius-pill); padding: 1px 7px; font-weight: 700; }
.col[data-stage="Venda"] .col-head { color: var(--success); }
.col[data-stage="Perdido"] .col-head { color: var(--text-muted); }
.col-empty { font-size: var(--fs-xs); color: var(--text-muted); text-align: center; padding: 18px 6px; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px; box-shadow: var(--shadow-1); display: flex; flex-direction: column; gap: 7px; }
.kcard.is-waiting { border-left: 3px solid var(--st-wait-rule); }
.kcard-name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--text); text-decoration: none; line-height: 1.25; }
.kcard-name:hover { text-decoration: underline; }
.kcard-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.kcard-foot { font-size: var(--fs-xs); color: var(--text-muted); display: flex; justify-content: space-between; gap: 4px; }
.kcard-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard .select { height: 30px; font-size: var(--fs-xs); padding: 0 6px; }
.col[data-stage="Perdido"] .kcard { opacity: .8; }
.board-hint { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Pós-venda ---------- */
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: var(--sp-6) 0 var(--sp-3); }
.section-title h2 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-semibold); padding: 9px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-top: 1px solid var(--border); vertical-align: top; }
.table tr:first-child td { border-top: 0; }
.table .cell-text { color: var(--text-2); max-width: 360px; }
.table .strong { font-weight: var(--fw-semibold); }
.switch { position: relative; width: 38px; height: 22px; border-radius: var(--radius-pill); border: 0; background: var(--border-strong); cursor: pointer; flex: none; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch-wrap { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--text-2); }
.rule-form { padding: var(--sp-5); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-4); }
.rule-form .full { grid-column: 1 / -1; }
.radio-row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.radio-row label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
.radio-row input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.inline-fields { display: flex; gap: 8px; align-items: center; font-size: var(--fs-sm); }
.inline-fields .input { width: 90px; }
.note { display: flex; gap: 8px; align-items: flex-start; background: var(--warning-soft); color: var(--warning); border: 1px solid var(--warning-border); border-radius: var(--radius); padding: 9px 12px; font-size: var(--fs-sm); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.st-ok { color: var(--success); background: var(--success-soft); }
.st-sched { color: var(--st-human-fg); background: var(--st-human-bg); }
.st-fail { color: var(--danger); background: var(--danger-soft); }

/* ---------- WhatsApp ---------- */
.alert { display: flex; gap: 8px; align-items: flex-start; background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); border-radius: var(--radius); padding: 8px 12px; font-size: var(--fs-sm); }
.alert .icon { margin-top: 2px; }
.wa-qr { display: block; width: 264px; height: auto; max-width: 100%; aspect-ratio: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); image-rendering: pixelated; }

/* ---------- Diálogo ---------- */
dialog { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(540px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow-3); background: var(--surface); color: var(--text); }
dialog::backdrop { background: color-mix(in srgb, var(--text) 45%, transparent); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.dlg-body { padding: 16px 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.dlg-body .full { grid-column: 1 / -1; }
.dlg-foot { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
.money { position: relative; }
.money span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: var(--fs-sm); }
.money .input { padding-left: 34px; }
.readonly-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: var(--fs-sm); }
.consent { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: var(--z-toast); max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--text-inverse); border-radius: var(--radius); padding: 10px 14px; font-size: var(--fs-sm); box-shadow: var(--shadow-2); display: flex; gap: 8px; align-items: center; }
.toast .icon { color: var(--accent-soft-border); }

/* ---------- Tablet: painel do lead vira aba ---------- */
@media (max-width: 1179px) {
  .convo-tabs { display: flex; }
  .convo-body { grid-template-columns: minmax(0, 1fr); }
  .thread-col { border-right: 0; }
  .lead-panel { display: none; }
  .convo.show-lead .lead-panel { display: block; }
  .convo.show-lead .thread-col { display: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 767px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { display: flex; position: sticky; top: 0; z-index: var(--z-nav); align-items: center; justify-content: space-between; gap: 12px; height: 56px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .topbar .brand-mark { width: 28px; height: 28px; font-size: 13px; }
  .topbar-title { font-weight: var(--fw-semibold); font-size: var(--fs-lg); flex: 1; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom-nav-h); background: var(--surface); border-top: 1px solid var(--border); z-index: var(--z-nav); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a, .bottom-nav summary { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: var(--fw-semibold); color: var(--text-muted); text-decoration: none; position: relative; list-style: none; cursor: pointer; min-height: var(--control-h-touch); }
  .bottom-nav summary::-webkit-details-marker { display: none; }
  .bottom-nav a[aria-current="page"] { color: var(--accent); }
  .bottom-nav .count { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--st-wait-rule); color: var(--text-inverse); font-size: 10px; font-weight: 700; border-radius: var(--radius-pill); padding: 0 5px; min-width: 16px; text-align: center; line-height: 16px; }
  .bottom-nav details { flex: 1; display: flex; position: relative; }
  .bottom-nav details summary { width: 100%; }
  .more-menu { position: absolute; right: 8px; bottom: calc(var(--bottom-nav-h) + 8px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); padding: 6px; min-width: 200px; display: flex; flex-direction: column; }
  .more-menu a { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: var(--fs-md); color: var(--text); padding: 0 12px; height: 44px; }
  body[data-view="conversa"] .topbar, body[data-view="conversa"] .bottom-nav { display: none; }

  .btn, .tab, .input, .select { min-height: var(--control-h-touch); }
  .btn-icon { min-width: var(--control-h-touch); }

  .page { padding: var(--sp-4) var(--sp-4) calc(var(--bottom-nav-h) + var(--sp-6)); }
  .page-head h1 { display: none; }
  .page-head .subtitle { margin: 0; }
  .filters .select { flex: 1 1 40%; }
  .search { max-width: none; flex-basis: 100%; }
  .q-head { display: none; }
  .q-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name time" "last last" "chips chips"; gap: 4px 10px; padding: 12px 14px; }
  .q-row > .q-origin, .q-row > .q-temp, .q-row > .q-state { display: none; }
  .q-main { display: contents; }
  .q-name { grid-area: name; }
  .q-last { grid-area: last; }
  .q-time { grid-area: time; }
  .q-time .wait { display: inline; margin-right: 6px; }
  .q-chips-m { grid-area: chips; display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

  .convo { height: 100dvh; }
  .convo-head { padding: 8px 12px 10px; gap: 8px; }
  .back { padding: 0; width: 44px; height: 44px; justify-content: center; }
  .back span { display: none; }
  .convo-title { flex: 1 1 0; }
  .convo-actions { width: 100%; }
  .convo-actions .btn { flex: 1; height: var(--control-h-touch); }
  .state-banner { padding: 8px 12px; font-size: var(--fs-xs); }
  .thread { padding: 14px 12px; }
  .msg { max-width: 88%; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .composer .btn { height: 42px; }
  .lead-panel { padding: 4px 16px 24px; }
  .rule-form { grid-template-columns: minmax(0, 1fr); padding: var(--sp-4); }
  .dlg-body { grid-template-columns: minmax(0, 1fr); }
  .toasts { left: 16px; right: 16px; bottom: calc(var(--bottom-nav-h) + 12px); max-width: none; }
  .login-card { padding: var(--sp-6); }
}
