/* AutoDM — visual claro, sóbrio, inspirado nos apps da Apple.
   Fundo cinza-claro, superfícies brancas, contornos finos escuros, ícones em linha. */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --outline: rgba(29, 29, 31, 0.22);   /* contorno fino dos quadros */
  --divider: rgba(29, 29, 31, 0.10);
  --ink: #1d1d1f;                      /* traço dos ícones e botões principais */
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.08);
  --ok: #248a3d; --ok-bg: #e8f5ec;
  --warn: #a05a00; --warn-bg: #fdf3e2;
  --err: #d70015; --err-bg: #fdecee;
  --radius: 14px;
  --radius-sm: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: -0.006em; }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 14px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: var(--err); min-height: 1em; }
.ic { flex: 0 0 auto; display: inline-block; vertical-align: middle; }

/* ---------- Estrutura ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 22px 14px;
  display: flex; flex-direction: column; gap: 22px;
  background: rgba(255, 255, 255, 0.72); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--outline);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand.big { font-size: 26px; justify-content: center; }
.logo { width: 30px; height: 30px; border: 1px solid var(--ink); border-radius: 9px; display: grid; place-items: center; color: var(--ink); background: var(--surface); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); font-size: 14px; }
nav a:hover { background: rgba(0, 0, 0, 0.04); text-decoration: none; }
nav a .ic { color: var(--ink); }
nav a.active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--outline); font-weight: 600; }
nav a.active .ic { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.sidebar-foot .btn { justify-content: flex-start; padding-left: 8px; color: var(--muted); }
.tpl { display: flex; flex-direction: column; gap: 10px; }
.tpl .tpl-ic { width: 36px; height: 36px; border: 1px solid var(--ink); border-radius: 10px; display: grid; place-items: center; color: var(--ink); }
.tpl p { margin: 0; flex: 1; }
.tpl .btn { align-self: flex-start; }
.account-badge { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 7px; padding: 0 6px; }
.account-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.account-badge .dot.off { background: var(--faint); }
.main { padding: 34px 40px 60px; max-width: 1220px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 26px; }

/* ---------- Superfícies ---------- */
.card { background: var(--surface); border: 1px solid var(--outline); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, 1fr); } .g2 { grid-template-columns: 1fr 1fr; }
.stack > * + * { margin-top: 14px; }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.stat .n { font-size: 30px; font-weight: 600; letter-spacing: -0.03em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.hero { padding: 30px; background: var(--surface); }
.hero h1 { font-size: 34px; }
.hero p { color: var(--muted); font-size: 16px; max-width: 560px; }

/* ---------- Botões ---------- */
.btn {
  border: 1px solid var(--outline); background: var(--surface); color: var(--text);
  padding: 8px 16px; border-radius: 980px; cursor: pointer; font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.05); border-color: transparent; }
.btn.danger { color: var(--err); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.white { background: var(--surface); color: var(--ink); }

/* Controle segmentado (filtros e períodos) */
.seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--outline); border-radius: 10px; background: rgba(118, 118, 128, 0.08); }
.seg .btn { border: 0; background: transparent; border-radius: 8px; padding: 5px 14px; font-size: 13px; }
.seg .btn.primary { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .1); }

/* ---------- Formulários ---------- */
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  border: 1px solid var(--outline); border-radius: var(--radius-sm); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 113, 227, .15); }
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
label { display: block; font-weight: 500; margin: 16px 0 6px; font-size: 13px; }
label .muted { font-weight: 400; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row > .shrink { flex: 0 0 auto; }

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--divider); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td { font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 980px; font-size: 12px; font-weight: 500; border: 1px solid var(--outline); color: var(--text); background: var(--surface); }
.pill.replied, .pill.on { border-color: transparent; background: var(--ok-bg); color: var(--ok); }
.pill.error { border-color: transparent; background: var(--err-bg); color: var(--err); }
.pill.skipped { border-color: transparent; background: var(--warn-bg); color: var(--warn); }
.pill.ignored { color: var(--muted); }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }

/* Interruptor (estilo iOS) */
.switch { position: relative; width: 44px; height: 26px; flex: 0 0 auto; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: rgba(120, 120, 128, .2); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; background: #fff; border-radius: 50%; box-shadow: 0 2px 4px rgba(0, 0, 0, .2), 0 0 0 .5px rgba(0, 0, 0, .04); transition: .2s; }
.switch input:checked + span { background: #34c759; }
.switch input:checked + span::after { transform: translateX(18px); }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.step { border: 1px solid var(--outline); border-radius: 12px; padding: 16px; margin-top: 12px; background: var(--surface-2); }
.step-head { display: flex; justify-content: space-between; align-items: center; }
.tag { border: 1px solid var(--ink); color: var(--ink); font-weight: 600; font-size: 11px; padding: 2px 8px; border-radius: 6px; letter-spacing: .02em; }
.btn-row { display: grid; grid-template-columns: 150px 1fr 1fr auto; gap: 8px; margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; }
.media { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--outline); cursor: pointer; aspect-ratio: 1; background: #ececf0; }
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.media.sel::after { content: "✓"; position: absolute; top: 5px; right: 5px; background: var(--accent); color: #fff; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; }

.phone { background: var(--surface); border: 1px solid var(--outline); border-radius: 28px; padding: 18px; position: sticky; top: 24px; }
.phone .who { font-weight: 600; padding-bottom: 12px; border-bottom: 1px solid var(--divider); margin-bottom: 12px; text-align: center; }
.bubble { background: #e9e9eb; border-radius: 18px; padding: 9px 13px; margin: 6px 0; max-width: 88%; white-space: pre-wrap; line-height: 1.4; width: fit-content; }
.bubble.me { background: var(--accent); color: #fff; margin-left: auto; }
.bubble .b { display: block; text-align: center; margin-top: 8px; padding: 7px; background: var(--surface); color: var(--accent); border-radius: 10px; font-weight: 500; border: 1px solid var(--divider); }
.bubble .meta { font-size: 11px; opacity: .6; margin-top: 3px; }
.context { font-size: 11px; color: var(--faint); text-align: center; margin-top: 12px; }

.copy { display: flex; gap: 8px; } .copy input { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; background: var(--surface-2); }
.check { display: flex; gap: 10px; align-items: center; margin: 14px 0 4px; font-weight: 400; font-size: 14px; }
.check input { width: auto; accent-color: var(--accent); }

/* ---------- Login / toast ---------- */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 360px; display: flex; flex-direction: column; gap: 14px; text-align: center; padding: 30px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: rgba(29, 29, 31, .92); backdrop-filter: blur(10px); color: #fff; padding: 11px 18px; border-radius: 980px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); max-width: 460px; font-size: 13px; z-index: 50; }
.toast.err { background: var(--err); }

/* ---------- Gráficos ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.bars > div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.bars i { display: block; width: 100%; max-width: 26px; background: #48484a; border-radius: 5px 5px 2px 2px; min-height: 2px; }
.bars span { font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.bars.two .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; }
.bars.two .pair i { flex: 1; }
.bars.two .pair { justify-content: center; }
.bars.two .pair i { max-width: 12px; }
.bars.two .pair i.c1 { background: #d2d2d7; } .bars.two .pair i.c2 { background: #48484a; }
.legend i.c1 { background: #d2d2d7; } .legend i.c2 { background: #48484a; }
.top-posts { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.tp { color: inherit; display: flex; flex-direction: column; gap: 6px; }
.tp:hover { text-decoration: none; }

/* ---------- Conversas ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 14px; align-items: start; }
.inbox-list { padding: 6px; max-height: 72vh; overflow: auto; }
.conv { padding: 11px 12px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.conv + .conv { margin-top: 2px; }
.conv:hover { background: rgba(0, 0, 0, .035); }
.conv.sel { background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(0, 113, 227, .25); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-thread .who { font-weight: 600; padding-bottom: 12px; border-bottom: 1px solid var(--divider); margin-bottom: 8px; }
.msgs { max-height: 56vh; overflow: auto; display: flex; flex-direction: column; padding: 4px 2px; }
.inbox-thread .bubble { max-width: 75%; }
.event { display: inline-flex; align-items: center; gap: 6px; }
.notice { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); font-size: 12px; margin-top: 12px; }

/* Diagnóstico */
.diag { background: var(--surface-2); color: var(--text); border: 1px solid var(--outline); padding: 14px; border-radius: 10px; font: 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace; overflow: auto; max-height: 320px; white-space: pre-wrap; margin-top: 12px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--outline); }
  nav { flex-direction: row; flex-wrap: wrap; }
  .g4, .g2, .editor, .inbox { grid-template-columns: 1fr; }
  .main { padding: 20px; }
}
