:root {
  --bg: #f1f5f4;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e2e8e6;
  --text: #0f1f1c;
  --text-2: #4b5d59;
  --muted: #7a8c88;
  --accent: #0f766e;
  --accent-2: #0d9488;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --chat-bg: #efeae2;
  --in-bubble: #ffffff;
  --out-bubble: #d9fdd3;
  --note-bubble: #fff4c2;
  --sidebar: #0f2e2a;
  --sidebar-text: #a7c4bf;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1412;
    --surface: #111d1b;
    --surface-2: #162522;
    --border: #233532;
    --text: #e3eeeb;
    --text-2: #a9bcb8;
    --muted: #7b908c;
    --accent: #2dd4bf;
    --accent-2: #14b8a6;
    --accent-soft: #134e48;
    --chat-bg: #0d1715;
    --in-bubble: #1c2b28;
    --out-bubble: #11463f;
    --note-bubble: #3d3515;
    --sidebar: #08100f;
    --sidebar-text: #8fb0aa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #0b1412; --surface: #111d1b; --surface-2: #162522; --border: #233532; --text: #e3eeeb; --text-2: #a9bcb8;
  --muted: #7b908c; --accent: #2dd4bf; --accent-2: #14b8a6; --accent-soft: #134e48; --chat-bg: #0d1715; --in-bubble: #1c2b28;
  --out-bubble: #11463f; --note-bubble: #3d3515; --sidebar: #08100f; --sidebar-text: #8fb0aa; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 12px; font-size: 15px; }
h4 { margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 6px; color: var(--text-2); }
hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.center { text-align: center; }
.right { text-align: right; }
.ic { flex-shrink: 0; vertical-align: middle; }
.loading, .empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.loading.full { padding-top: 40vh; }
.empty.big { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.empty.big .ic { opacity: 0.35; }

/* ---------- Controles ---------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
input[type='checkbox'], input[type='radio'] { width: auto; accent-color: var(--accent); }
input[type='color'] { padding: 2px; height: 38px; width: 64px; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; color: var(--text-2); }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
fieldset { border: 1px solid var(--border); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
legend { font-size: 13px; color: var(--text-2); padding: 0 4px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme='dark'] .btn.primary { color: #04201c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .btn.primary { color: #04201c; } }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger, .btn.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost.danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row label { flex: 1; }
.row .grow { flex: 3; }
.search { flex-direction: row; align-items: center; gap: 0; position: relative; flex: 1; }
.search .ic { position: absolute; left: 10px; color: var(--muted); }
.search input { padding-left: 32px; }
.alert { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.chip {
  --c: #64748b; display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; line-height: 1;
  padding: 3px 7px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent); white-space: nowrap;
}
.chip.ai { --c: #7c3aed; }
.chip.bot { --c: #0284c7; }
.chip.user { --c: var(--text-2); }
.chip.toggle { cursor: pointer; opacity: 0.5; font-size: 12px; padding: 5px 9px; }
.chip.toggle.on { opacity: 1; box-shadow: inset 0 0 0 1px var(--c); }
.dot { --c: #94a3b8; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: 8px; }
.badge { background: var(--ok); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; min-width: 20px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; }
.avatar {
  --s: 40px; --h: 170; position: relative; flex-shrink: 0; width: var(--s); height: var(--s); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; overflow: hidden; font-weight: 700;
  font-size: calc(var(--s) * 0.38); color: hsl(var(--h) 45% 30%); background: hsl(var(--h) 55% 86%);
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.st { font-weight: 600; }
.st-pending { color: var(--warn); }
.st-open { color: var(--ok); }
.st-ai { color: #7c3aed; }
.st-bot { color: #0284c7; }
.st-closed { color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); }
.scroll-x { overflow-x: auto; scrollbar-width: none; }
.tab {
  background: none; border: 0; font: inherit; font-weight: 600; color: var(--muted); padding: 10px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; display: inline-flex; gap: 6px; align-items: center;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count:empty { display: none; }
.tab .count { font-size: 11px; background: var(--surface-2); color: var(--text-2); border-radius: 99px; padding: 1px 7px; }
.tab.active .count { background: var(--accent-soft); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); font: inherit; padding: 6px 12px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- Toast / modal ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; transition: opacity 0.4s, transform 0.4s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal-wrap { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); display: flex; align-items: center; justify-content: center; z-index: 900; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 460px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { max-width: 760px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px 20px; }
.modal header h3 { margin: 0; }
.modal-body { padding: 4px 20px 12px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.preview-img { max-width: 100%; max-height: 50vh; border-radius: 8px; object-fit: contain; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, var(--sidebar), var(--accent)); }
.login-card { background: var(--surface); width: 100%; max-width: 380px; border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: -8px 0 0; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }

/* ---------- Shell ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { width: 64px; background: var(--sidebar); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 8px; flex-shrink: 0; }
.brand { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a { position: relative; width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--sidebar-text); }
.nav a span { display: none; }
.nav a:hover { background: rgb(255 255 255 / 0.07); color: #fff; }
.nav a.active { background: rgb(255 255 255 / 0.12); color: #fff; }
.nav .badge { position: absolute; top: 2px; right: 0; background: var(--warn); }
.side-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wa-dot { color: var(--sidebar-text); display: flex; }
.wa-dot.ok { color: #4ade80; }
.wa-dot.bad { color: #f87171; }
.me-btn { border: 0; background: none; padding: 0; cursor: pointer; border-radius: 50%; }
/* min-height: 0 deixa a área principal rolar sozinha (sem isso, no celular o conteúdo passava por baixo do menu) */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wa-banner { background: var(--danger); color: #fff; padding: 6px 16px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.wa-banner a { color: #fff; font-weight: 700; }
main { flex: 1; min-height: 0; overflow: auto; }
body.offline .content::before { content: 'Sem conexão com o servidor — reconectando…'; background: var(--warn); color: #fff; padding: 4px 16px; font-size: 12px; }

/* ---------- Páginas ---------- */
.page { padding: 20px 24px; max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.page-head .row { flex-wrap: wrap; }
.page-head .search { min-width: 240px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card.pad { padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head p { margin: 0; max-width: 800px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .pre { white-space: pre-wrap; max-width: 600px; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--surface-2); }
.table tr.inactive td { opacity: 0.5; }
.cell-user { display: inline-flex; align-items: center; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .span2, .form-grid h3, .form-grid > .check { grid-column: span 2; }
.form-grid h3 { margin: 4px 0 0; }
.hours { display: flex; flex-direction: column; gap: 6px; }
.hour-row { display: flex; align-items: center; gap: 8px; }
.hour-row label { width: 110px; }
.hour-row input[type='time'] { width: 120px; }
.preview-wa { background: var(--chat-bg); border-radius: 8px; padding: 10px; }
.bubble-prev { background: var(--out-bubble); border-radius: 8px; padding: 8px 10px; max-width: 420px; margin-top: 6px; }
.tag-grid { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px; }
.tag-item { display: flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 4px 4px 10px; }
.wa-status { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.wa-status.ok { color: var(--ok); }
.wa-status.bad { color: var(--danger); }
.qr { width: 264px; height: 264px; background: #fff; padding: 8px; border-radius: 12px; image-rendering: pixelated; }
.paircode { font: 700 32px ui-monospace, monospace; letter-spacing: 4px; padding: 16px; }
.card.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 300px; color: var(--ok); }
.card.center p, .card.center h3 { color: var(--text); }
details summary { cursor: pointer; color: var(--text-2); }
.contact-detail { display: flex; gap: 14px; align-items: center; }
.notes { white-space: pre-wrap; background: var(--surface-2); padding: 10px; border-radius: 8px; }

/* Relatórios */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 26px; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat-sub { font-size: 12px; color: var(--muted); }
.bars { display: flex; align-items: stretch; gap: 2px; height: 180px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; cursor: default; outline: none; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--border); }
.bar { width: 100%; max-width: 28px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; transition: opacity 0.15s; }
.bar-col:hover .bar, .bar-col:focus .bar { opacity: 0.75; }
.bar-label { font-size: 11px; color: var(--muted); height: 14px; white-space: nowrap; }
.axis-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart-tip { position: fixed; z-index: 50; background: var(--text); color: var(--surface); font-size: 12px; padding: 5px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; }

/* ---------- Tela de atendimento ---------- */
.chat-screen { display: grid; grid-template-columns: var(--list-w, 360px) 1fr; height: 100%; }
.chat-screen.info-open { grid-template-columns: var(--list-w, 360px) 1fr 300px; }
.chat-screen.resizing { user-select: none; cursor: col-resize; }
.list-pane { position: relative; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); min-height: 0; min-width: 0; }
.resizer { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 5; touch-action: none; }
.resizer:hover, .chat-screen.resizing .resizer { background: linear-gradient(to right, transparent 3px, var(--accent) 3px, var(--accent) 5px, transparent 5px); }
.tabs.wrap { flex-wrap: wrap; }
.st-chip.st-pending { --c: var(--warn); }
.st-chip.st-open { --c: var(--ok); }
.st-chip.st-ai { --c: #7c3aed; }
.st-chip.st-bot { --c: #0284c7; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 6px; }
.list-pane .tabs { padding: 0 6px; }
.list-pane .tab { padding: 10px 8px; font-size: 13px; }
.list-filters { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); }
.list-filters select { width: 120px; flex-shrink: 0; }
.ticket-list { flex: 1; overflow-y: auto; }
.ticket {
  display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: none; font: inherit; color: inherit;
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.ticket:hover { background: var(--surface-2); }
.ticket.active { background: var(--accent-soft); }
.t-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.t-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.t-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-row time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.t-last { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-sub { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.wait { font-size: 11px; color: var(--warn); display: inline-flex; align-items: center; gap: 2px; font-weight: 600; }

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.head-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.head-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-main .muted { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-actions { display: flex; gap: 2px; align-items: center; }
.head-actions .btn { margin-right: 6px; }
.messages { flex: 1; overflow-y: auto; padding: 12px 6% 8px; display: flex; flex-direction: column; gap: 2px; }
.more { text-align: center; font-size: 12px; color: var(--muted); padding: 6px; }
.day-sep, .ticket-sep { text-align: center; margin: 10px 0 6px; }
.day-sep span, .ticket-sep span { background: var(--surface); color: var(--text-2); font-size: 12px; padding: 4px 10px; border-radius: 8px; box-shadow: 0 1px 1px rgb(0 0 0 / 0.08); }
.ticket-sep span { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.evt { align-self: center; font-size: 12px; color: var(--text-2); background: color-mix(in srgb, var(--surface) 80%, transparent); padding: 3px 10px; border-radius: 8px; margin: 4px 0; text-align: center; max-width: 80%; }
.evt.reaction { background: none; }
.msg { display: flex; margin: 1px 0; }
.msg.out { justify-content: flex-end; }
.msg.note { justify-content: center; }
.bubble {
  position: relative; max-width: min(75%, 560px); padding: 6px 9px 18px; border-radius: 8px; background: var(--in-bubble);
  box-shadow: 0 1px 1px rgb(0 0 0 / 0.08); word-wrap: break-word; overflow-wrap: anywhere; min-width: 80px;
}
.msg.out .bubble { background: var(--out-bubble); }
.msg.note .bubble { background: var(--note-bubble); max-width: 85%; }
.bubble.bare { background: none !important; box-shadow: none; }
.who { display: flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.msg.ai .who { color: #7c3aed; }
.msg.bot .who, .msg.phone .who { color: #0284c7; }
.msg.note .who { color: var(--warn); }
.txt { white-space: normal; }
.txt.transcript { font-style: italic; color: var(--text-2); border-left: 2px solid var(--border); padding-left: 6px; margin-top: 4px; }
.meta { position: absolute; right: 8px; bottom: 3px; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.tick { display: inline-flex; }
.tick.read { color: #0ea5e9; }
.tick.fail { color: var(--danger); }
.reply-btn { position: absolute; top: 2px; right: -32px; border: 0; background: var(--surface); color: var(--muted); border-radius: 50%; width: 26px; height: 26px; display: none; align-items: center; justify-content: center; cursor: pointer; box-shadow: var(--shadow); }
.msg.out .reply-btn { right: auto; left: -32px; }
.msg:hover .reply-btn { display: inline-flex; }
.quote { border-left: 3px solid var(--accent); background: rgb(0 0 0 / 0.05); padding: 4px 8px; border-radius: 4px; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.media-img img { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; }
.sticker { width: 140px; height: 140px; object-fit: contain; }
.media-video { max-width: 100%; max-height: 320px; border-radius: 6px; }
audio { width: 280px; max-width: 100%; height: 40px; }
.doc { display: flex; align-items: center; gap: 8px; padding: 8px; background: rgb(0 0 0 / 0.05); border-radius: 6px; color: var(--text); text-decoration: none; min-width: 200px; }
.doc span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-wait { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }

.composer-wrap { background: var(--surface); border-top: 1px solid var(--border); position: relative; }
.composer-locked, .composer-hint { padding: 8px 14px; color: var(--muted); font-size: 12px; text-align: center; }
.composer-locked { padding: 16px; font-size: 14px; }
.composer-hint { background: var(--surface-2); }
.composer { padding: 6px 10px 10px; }
.composer.note-mode { background: var(--note-bubble); }
.composer .mode { display: flex; gap: 4px; margin-bottom: 6px; }
.composer .mode button { border: 0; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); padding: 3px 8px; border-radius: 6px; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.composer .mode button.on { background: var(--accent-soft); color: var(--accent); }
.composer.note-mode .mode button.on { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer-row textarea { resize: none; max-height: 180px; border-radius: 20px; padding: 9px 14px; line-height: 1.4; }
.icon-btn.send { background: var(--accent); color: #fff; border-radius: 50%; }
.icon-btn.recording { color: #fff; background: var(--danger); border-radius: 50%; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
.quoting { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--surface-2); border-left: 3px solid var(--accent); font-size: 12px; color: var(--text-2); }
.qr-pop { position: absolute; bottom: 100%; left: 10px; right: 10px; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); z-index: 5; }
.qr-pop button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none; font: inherit; color: inherit; text-align: left; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.qr-pop button span { color: var(--muted); font-size: 12px; }
.qr-pop button.sel, .qr-pop button:hover { background: var(--accent-soft); }
.qr-empty { padding: 12px; color: var(--muted); }

.info-pane { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; display: none; }
.chat-screen.info-open .info-pane { display: block; }
.info-head { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 16px 12px; text-align: center; position: relative; }
.info-head .icon-btn { position: absolute; right: 8px; top: 8px; }
.info-form { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 16px; border-bottom: 1px solid var(--border); }
.info-form .btn { align-self: flex-start; }
.info-sec { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.info-sec p { margin: 0; white-space: pre-wrap; }
.tag-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.hist .muted { display: block; font-size: 12px; }
.mobile-only { display: none; }

/* Chaves liga/desliga */
label.switch { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; color: var(--text); cursor: pointer; }
label.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
label.switch span { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--border); flex-shrink: 0; transition: background 0.15s; }
label.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: transform 0.15s; }
label.switch input:checked + span { background: var(--accent); }
label.switch input:checked + span::after { transform: translateX(16px); }
label.switch input:focus-visible + span { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
label.switch.big span { width: 48px; height: 28px; }
label.switch.big span::after { width: 22px; height: 22px; }
label.switch.big input:checked + span::after { transform: translateX(20px); }
label.switch.big b { font-size: 16px; }
.master { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; }
.master.off { border-color: var(--border); background: var(--surface-2); }
.master p { margin: 8px 0 0; }
.bot-part { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.bot-part:disabled { opacity: 0.55; }
.auto-msg { display: flex; flex-direction: column; gap: 6px; }
.auto-msg.off textarea { opacity: 0.5; }

/* Conexões */
.conn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; padding: 16px; }
.conn-card { --c: #0f766e; border: 1px solid var(--border); border-top: 3px solid var(--c); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.conn-top { display: flex; align-items: center; gap: 4px; }
.conn-top b { flex: 1; font-size: 15px; }
.conn-state { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.conn-state.ok { color: var(--ok); }
.conn-state.bad { color: var(--danger); }
.conn-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.qr-box { display: flex; flex-direction: column; align-items: center; min-height: 290px; justify-content: center; }
.ok-big { color: var(--ok); }
.ok-big p { color: var(--text); }
.chip.conn .ic { opacity: 0.8; }

/* ---------- SaaS ---------- */
.top-banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 7px 16px; font-size: 13px; }
.top-banner a { font-weight: 700; color: inherit; }
.top-banner.support { background: #7c3aed; color: #fff; }
.top-banner.support .btn { margin-left: auto; }
.top-banner.trial { background: var(--accent-soft); color: var(--accent); }
.top-banner.late { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.status-pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.status-pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.status-pill.trial { background: var(--accent-soft); color: var(--accent); }
.status-pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.status-pill.bad { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.limit { display: block; margin-top: 4px; color: var(--text-2); font-weight: 600; }
.limit.full { color: var(--warn); }
.login-card.wide { max-width: 480px; }
.login-logo.danger { background: var(--danger); }
.login-logo.sm { width: 34px; height: 34px; border-radius: 9px; display: inline-flex; }
.inv-list { display: flex; flex-direction: column; gap: 8px; }
.inv { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.inv > div { display: flex; flex-direction: column; }
.plan-now { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.plan-now b { font-size: 20px; }
.price { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.price small { font-size: 13px; font-weight: 500; color: var(--muted); }
.usage { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 4px; }
.webhook-box { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; }
.webhook-box code { word-break: break-all; }
.btn.big { padding: 13px 22px; font-size: 16px; }

/* Cadastro */
.signup { min-height: 100%; background: linear-gradient(180deg, var(--accent-soft), var(--bg) 340px); }
.signup-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; max-width: 1100px; margin: 0 auto; }
.brand-row { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand-row .login-logo { color: #fff; align-items: center; justify-content: center; }
.signup-body { max-width: 1100px; margin: 0 auto; padding: 8px 24px 60px; display: flex; flex-direction: column; gap: 28px; }
.signup-body h1 { font-size: 30px; margin: 10px 0 6px; }
.signup-body h2 { font-size: 18px; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; }
.signup-body section > p { margin: 0 0 12px; }
.step { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
.signup-body .form-grid { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.pick-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.pick-grid.plans { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.pick { position: relative; cursor: pointer; display: block; color: var(--text); font-weight: 400; }
.pick input { position: absolute; opacity: 0; }
.pick-box { position: relative; display: flex; flex-direction: column; gap: 6px; height: 100%; padding: 16px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); transition: border-color 0.15s, box-shadow 0.15s; }
.pick-box small { color: var(--muted); font-size: 12.5px; }
.pick-box .emoji { font-size: 26px; }
.pick-box ul { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.pick-box li { display: flex; gap: 6px; align-items: center; }
.pick:hover .pick-box { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.pick input:checked + .pick-box { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.pick input:focus-visible + .pick-box { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.pick-box.current { border-color: var(--accent); }
.ribbon { position: absolute; top: -10px; right: 12px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
:root[data-theme='dark'] .ribbon, :root[data-theme='dark'] .step { color: #04201c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .ribbon, :root:not([data-theme='light']) .step { color: #04201c; } }
@media (max-width: 800px) {
  .signup-body h1 { font-size: 24px; }
  .signup-head, .signup-body { padding-left: 16px; padding-right: 16px; }
  .top-banner.support .btn { margin-left: 0; }
}

/* ---------- Agenda ---------- */
.agenda { display: flex; flex-direction: column; height: 100%; }
.agenda-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 20px 8px; }
.agenda-head .row { gap: 6px; }
.agenda-head h2 { margin-right: 8px; }
.ag-cals { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 20px 8px; }
.ag-body { flex: 1; overflow: auto; padding: 0 20px 20px; min-height: 0; }
.cal-grid { display: grid; grid-template-columns: 56px repeat(var(--cols), minmax(110px, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); position: relative; }
.cal-corner, .cal-colhead { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--border); }
.cal-colhead { padding: 8px 6px; text-align: center; font-weight: 700; font-size: 13px; border-left: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-colhead.today { color: var(--accent); }
.cal-hours { grid-column: 1; }
.cal-hour { height: var(--hour); font-size: 11px; color: var(--muted); text-align: right; padding: 0 6px; transform: translateY(-7px); }
.cal-col { position: relative; border-left: 1px solid var(--border); cursor: copy;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), var(--border) calc(var(--hour) - 1px), var(--border) var(--hour)); }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.cal-now::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.appt { --c: #0f766e; position: absolute; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; overflow: hidden; text-align: left;
  font: inherit; font-size: 12px; line-height: 1.25; padding: 3px 6px; border-radius: 6px; cursor: pointer; color: var(--text);
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border: 0; border-left: 3px solid var(--c); }
.appt:hover { background: color-mix(in srgb, var(--c) 28%, var(--surface)); }
.appt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.appt span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.appt.st-confirmed b::after { content: ' ✓'; color: var(--ok); }
.appt.st-reschedule { border-left-style: dashed; }
.appt.st-done, .appt.st-no_show { opacity: 0.55; }
.ag-list { display: flex; flex-direction: column; gap: 6px; max-width: 760px; }
.ag-item { --c: #0f766e; display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--c); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.ag-item:hover { background: var(--surface-2); }
.ag-time { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 46px; }
.ag-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.slot { font: inherit; font-size: 13px; font-variant-numeric: tabular-nums; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.slot:hover { border-color: var(--accent); }
.slot.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.other-time { flex-direction: row; align-items: center; gap: 4px; font-weight: 400; }
.other-time input { width: auto; padding: 4px 6px; }
.contact-pick .picked { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.bk-results { display: flex; flex-direction: column; margin: 4px 0 8px; }
.bk-results button { text-align: left; border: 0; border-bottom: 1px solid var(--border); background: none; font: inherit; color: inherit; padding: 7px 4px; cursor: pointer; }
.bk-results button:hover { background: var(--surface-2); }
.appt-detail { border-left: 4px solid var(--c); padding-left: 12px; }
.appt-detail p { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row.wrap { flex-wrap: wrap; }
.hist.pad { padding: 12px 16px; }
.hist li .icon-btn { width: 26px; height: 26px; vertical-align: middle; }
@media (max-width: 800px) {
  .agenda-head, .ag-cals { padding-left: 12px; padding-right: 12px; }
  .ag-body { padding: 0 8px 12px; }
  .cal-grid { grid-template-columns: 44px repeat(var(--cols), minmax(88px, 1fr)); }
  .hour-row { flex-wrap: wrap; }
}

/* Editor do site */
.site-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 4; margin-bottom: 12px; }
.site-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.site-url { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.site-stats { margin-bottom: 12px; }
.editor { display: flex; flex-direction: column; gap: 10px; }
.ed-sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ed-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.ed-sec > summary::-webkit-details-marker { display: none; }
.ed-sec > summary::before { content: '▸'; color: var(--muted); transition: transform 0.15s; }
.ed-sec[open] > summary::before { transform: rotate(90deg); }
.ed-sec > summary b { flex: 1; }
.ed-vis { font-size: 12px; color: var(--muted); }
.ed-vis.on { color: var(--ok); font-weight: 600; }
.ed-body { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--border); padding-top: 14px; }
.ed-body h4 { margin: 6px 0 0; }
.form-grid.three { grid-template-columns: 1fr 2fr auto; align-items: end; }
.form-grid.three > .check { grid-column: auto; padding-bottom: 10px; white-space: nowrap; }
.editor { padding-bottom: 40px; }
.img-field { display: flex; flex-direction: column; gap: 6px; }
.img-label { font-size: 13px; font-weight: 500; color: var(--text-2); display: flex; flex-direction: column; }
.img-label small { font-weight: 400; color: var(--muted); }
.img-box { width: 220px; max-width: 100%; aspect-ratio: 16 / 10; border: 1px dashed var(--border); border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: var(--surface-2); }
.img-box img { width: 100%; height: 100%; object-fit: contain; }
.list-ed { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); }
.list-fields { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.list-actions { display: flex; flex-direction: column; gap: 2px; }
.list-actions [data-move] .ic { transform: rotate(90deg); }
.list-ed > .btn { align-self: flex-start; }
.slug-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 400; color: var(--text); }
.slug-row input { width: 220px; flex: 0 1 220px; }
@media (max-width: 800px) { .form-grid.three { grid-template-columns: 1fr; } .site-head { position: static; } }

/* Escolha do modelo de IA */
.model-pick { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.model-opt { position: relative; display: block; cursor: pointer; font-weight: 400; color: var(--text); }
.model-opt > input[type='radio'] { position: absolute; opacity: 0; }
.model-box { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border: 2px solid var(--border); border-radius: 10px; background: var(--surface); }
.model-opt:hover .model-box { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.model-opt > input:checked + .model-box { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.model-opt > input:focus-visible + .model-box { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.model-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.model-top b { font-size: 14px; margin-right: 4px; }
.model-meta { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.model-best { font-size: 13px; }
.model-box input[name='model_other'] { margin: 4px 0; }

/* Simulador de IA */
.sim { background: var(--chat-bg); border-radius: 8px; padding: 12px; height: 380px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.sim .bubble { padding-bottom: 6px; }
.sim-trace { align-self: stretch; font: 11px/1.4 ui-monospace, Consolas, monospace; color: var(--text-2); background: color-mix(in srgb, var(--surface) 75%, transparent);
  border-left: 3px solid var(--warn); padding: 4px 8px; border-radius: 4px; white-space: pre-wrap; word-break: break-word; }

/* ---------- Responsivo ---------- */
@media (max-width: 1200px) {
  .chat-screen.info-open { grid-template-columns: var(--list-w, 320px) 1fr; }
  .chat-screen.info-open .info-pane { position: fixed; right: 0; top: 0; bottom: 0; width: 320px; z-index: 20; box-shadow: var(--shadow); }
  /* painel do contato por cima da tela: só com uma conversa aberta (senão cobria a lista inteira no celular) */
  .chat-screen.info-open:not(.show-chat) .info-pane { display: none; }
  .info-head .mobile-only { display: inline-flex; }
}
@media (max-width: 800px) {
  .app { flex-direction: column-reverse; }
  .sidebar { width: 100%; height: 56px; flex-direction: row; padding: 0 8px; justify-content: space-around; }
  .brand { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .side-bottom { flex-direction: row; }
  .chat-screen, .chat-screen.info-open { grid-template-columns: 1fr; }
  .resizer { display: none; }
  .chat-pane { display: none; }
  .chat-screen.show-chat .list-pane { display: none; }
  .chat-screen.show-chat .chat-pane { display: flex; }
  .chat-screen.info-open .info-pane { width: 100%; }
  .mobile-only { display: inline-flex; }
  .messages { padding: 10px 8px; }
  .bubble { max-width: 85%; }
  .reply-btn { display: none !important; }
  .head-actions .btn { padding: 5px 8px; margin-right: 0; }
  .page { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2, .form-grid h3, .form-grid > .check { grid-column: span 1; }
  .page-head .search { min-width: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
}
