:root {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --border: #e3e5e2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #0f766e;
  --accent-soft: #e6f3f1;
  --danger: #c03a3a;
  --warn-bg: #fff6e0;
  --fb: #2a78d6;
  --ig: #eb6834;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; }
button, input, select, textarea { font: inherit; }
a { color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 1.3rem; }
.login p { margin: 0; color: var(--text-2); font-size: .9rem; }
.brand-mark { font-size: 2rem; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { font-weight: 700; padding: 4px 10px 18px; line-height: 1.25; }
.sidebar .logo small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.nav-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); }
.nav-btn:hover { background: var(--bg); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-btn .badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: .72rem; padding: 1px 7px; font-weight: 600; }
.sidebar .spacer { flex: 1; }
main { padding: 28px 32px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { margin: 0; font-size: 1.4rem; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: .9rem; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 1rem; }
.card .sub { color: var(--text-2); font-size: .85rem; margin: -6px 0 12px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--text-2); font-size: .82rem; }
.kpi .value { font-size: 1.8rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: .78rem; margin-top: 2px; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #c9ccc7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: grid; gap: 5px; font-size: .88rem; color: var(--text-2); margin-bottom: 14px; }
label.field small { color: var(--muted); }
.toggle { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: .9rem; }
th { color: var(--text-2); font-weight: 500; font-size: .8rem; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; white-space: nowrap; padding: 2px 9px; border-radius: 999px; font-size: .75rem; background: var(--bg); border: 1px solid var(--border); color: var(--text-2); }
.pill.fb::before, .pill.ig::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.pill.fb::before { background: var(--fb); }
.pill.ig::before { background: var(--ig); }
.pill.off { opacity: .55; }
.pill.warn { background: var(--warn-bg); border-color: #f0dca8; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.muted { color: var(--muted); }
.notice { background: var(--warn-bg); border: 1px solid #f0dca8; border-radius: 10px; padding: 12px 14px; font-size: .9rem; margin-bottom: 16px; }

/* checklist */
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checklist li { display: flex; gap: 10px; align-items: center; font-size: .9rem; }
.checklist .dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; flex: none; }
.checklist .ok { background: #dff2e5; color: #1d6b37; }
.checklist .no { background: #f3e3e3; color: var(--danger); }
code { background: var(--bg); padding: 2px 6px; border-radius: 5px; font-size: .85em; word-break: break-all; }

/* conversas */
.convs { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 560px; }
.conv-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.conv-list .search { padding: 10px; border-bottom: 1px solid var(--border); }
.conv-items { overflow-y: auto; max-height: 640px; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; gap: 3px; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--accent-soft); }
.conv-item .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: .9rem; }
.conv-item .top span:last-child { font-weight: 400; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.conv-item .preview { color: var(--text-2); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 560px; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; max-height: 560px; background: #fafbfa; }
.chat-foot { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-foot textarea { min-height: 44px; height: 44px; }
.bubble { max-width: 78%; padding: 9px 13px; border-radius: 14px; white-space: pre-wrap; font-size: .9rem; line-height: 1.4; }
.bubble.user { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.bot { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble.human { align-self: flex-end; background: #e9eefb; border-bottom-right-radius: 4px; }
.bubble .meta { display: block; font-size: .7rem; color: var(--muted); margin-top: 4px; }
.bubble.typing { color: var(--muted); font-style: italic; }
.sim-info { font-size: .8rem; color: var(--text-2); align-self: flex-end; max-width: 78%; display: flex; gap: 6px; flex-wrap: wrap; }

/* gráficos */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: .82rem; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }
.tooltip { position: absolute; pointer-events: none; background: #1d1d1b; color: #fff; padding: 7px 10px; border-radius: 8px; font-size: .78rem; line-height: 1.45; max-width: 240px; transform: translate(-50%, calc(-100% - 10px)); white-space: normal; z-index: 5; display: none; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border-radius: 14px; padding: 22px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 16px; }
.modal .row { justify-content: flex-end; margin-top: 6px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d1d1b; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: .9rem; z-index: 30; }
.toast.err { background: var(--danger); }

/* ---------- telemóvel ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .logo, .sidebar .spacer { display: none; }
  .nav-btn { white-space: nowrap; }
  main { padding: 18px 14px 60px; }
  .convs { grid-template-columns: 1fr; }
  .convs.has-open .conv-list { display: none; }
  .convs:not(.has-open) .chat { display: none; }
  .bubble { max-width: 90%; }
}
@media (min-width: 861px) { .only-mobile { display: none; } }
