/* Painel SMS — tema claro e escuro (segue o sistema). Sem fontes nem arquivos de fora (CSP). */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --sidebar: #ffffff;
  --text: #161a22;
  --text-2: #3b4250;
  --muted: #6b7280;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --ok: #047857;
  --ok-bg: #e7f6ef;
  --warn: #92400e;
  --warn-bg: #fdf3e1;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info: #334155;
  --info-bg: #eef1f5;
  --bubble: #e9ecf1;
  --bubble-text: #161a22;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 12px;
  --radius-sm: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1b2029;
    --sidebar: #12151b;
    --text: #e8eaef;
    --text-2: #c3c8d2;
    --muted: #8b93a1;
    --border: #262c36;
    --border-strong: #343b47;
    --accent: #7c83ff;
    --accent-hover: #939aff;
    --accent-soft: #1f2340;
    --accent-text: #0b0d12;
    --ok: #5fd3a0;
    --ok-bg: #11291f;
    --warn: #f3c46b;
    --warn-bg: #2d2412;
    --bad: #ff8b80;
    --bad-bg: #351a18;
    --info: #b8c2d4;
    --info-bg: #1e2430;
    --bubble: #262c36;
    --bubble-text: #e8eaef;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- marca ---------- */

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
}
.brand-lg { font-size: 17px; margin-bottom: 28px; }
.brand-lg .brand-mark { width: 36px; height: 36px; border-radius: 10px; }

/* ---------- entrada ---------- */

.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }

/* ---------- estrutura ---------- */

.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100%;
  /* fundo da coluna do menu até o fim da página */
  background: linear-gradient(90deg, var(--sidebar) 0 239px, var(--border) 239px 240px, transparent 240px);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.sidebar .brand { padding: 4px 8px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button[aria-selected=true] { background: var(--accent-soft); color: var(--accent); }
.nav svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
}
.avatar {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  text-transform: uppercase;
}
.account-name { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.account-name .muted { white-space: nowrap; }
.account-name #who-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { padding: 32px 36px 56px; min-width: 0; max-width: 1180px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 22px; }
.page-head p { margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }

/* ---------- cartões ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); }
.result-card { margin-top: 16px; }
.pad { padding: 0 18px; }
.msg.pad:empty { display: none; }
.msg.pad { padding-top: 12px; padding-bottom: 12px; margin: 0; }

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ---------- formulários ---------- */

label { display: block; font-weight: 600; margin: 18px 0 6px; font-size: 13px; color: var(--text-2); }
form > label:first-of-type { margin-top: 0; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text-2); }

input[type=text], input[type=tel], input[type=password], input[type=datetime-local], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 1em; }
.hint.warn { color: var(--warn); }

/* ---------- botões ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.block { width: 100%; margin-top: 22px; }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { background: var(--bad-bg); border-color: var(--bad); }
.btn.danger:disabled { color: var(--muted); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-solid:hover { filter: brightness(1.08); }

button.link { border: 0; background: none; color: inherit; padding: 0; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.actions { margin-top: 22px; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- avisos ---------- */

.msg { min-height: 1.5em; margin-top: 12px; color: var(--muted); }
.msg.error { color: var(--bad); }

.banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin: -4px 0 18px;
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
}

.result {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--info-bg);
  color: var(--info);
}
.result.error { background: var(--bad-bg); color: var(--bad); }
.result p { margin: 0 0 8px; }
.result p:last-child { margin-bottom: 0; }
.result ul { margin: 6px 0 8px; padding-left: 20px; }
.result .row { margin-top: 10px; }
.result-card.result { margin-top: 16px; }

.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .4s; border-radius: 999px; }

/* ---------- prévia ---------- */

.preview-card { position: sticky; top: 24px; }
.phone {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface-2);
  padding: 14px 14px 22px;
  min-height: 240px;
}
.phone-top { display: flex; justify-content: center; margin-bottom: 18px; }
.phone-dot { width: 56px; height: 6px; border-radius: 999px; background: var(--border-strong); }
.bubble {
  max-width: 90%;
  width: fit-content;
  padding: 10px 13px;
  border-radius: 16px 16px 16px 4px;
  background: var(--bubble);
  color: var(--bubble-text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}
.bubble:empty::before { content: "Sua mensagem aparece aqui."; color: var(--muted); }
.preview-card .hint { margin-top: 12px; }

/* ---------- importar lista ---------- */

.label-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 18px 0 6px; }
.label-row label { margin: 0; }
#bulk-import-result { margin-top: 10px; font-size: 13px; }
.howto {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
}
.howto summary { cursor: pointer; padding: 8px 12px; font-weight: 600; color: var(--accent); }
.howto ul { margin: 0; padding: 0 14px 10px 30px; }
.howto li { margin: 4px 0; }

/* ---------- clientes ---------- */

.nowrap-row { flex-wrap: nowrap; }
.nowrap-row input { flex: 1; min-width: 0; }
#client-form label.check { margin-top: 14px; }
.keybox {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}
.keybox-title { margin-bottom: 8px; }
.keybox code {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  user-select: all;
}
.keybox .hint { margin: 8px 0 12px; }
td code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); }
tr.off td { opacity: .6; }

/* ---------- números ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }
.stat-value.bad { color: var(--bad); }

/* ---------- tabelas ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.msgcell { max-width: 340px; overflow-wrap: anywhere; color: var(--text-2); }
td.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.right, td.right { text-align: right; }
td.right .row { justify-content: flex-end; flex-wrap: nowrap; }
th.sel, td.sel { width: 40px; padding-right: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--info-bg);
  color: var(--info);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.sub { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- confirmação e avisos flutuantes ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 12, 16, .5);
  z-index: 20;
}
.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow-lg);
}
.modal-box h2 { font-size: 17px; margin-bottom: 8px; }
.modal-box p { color: var(--text-2); }

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
  max-width: calc(100vw - 40px);
}
.toast {
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- telas menores ---------- */

@media (max-width: 1080px) {
  .grid-2 { grid-template-columns: 1fr; }
  .preview-card { position: static; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: none; }
  .sidebar { min-width: 0; }
  .sidebar {
    height: auto;
    z-index: 10;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar .brand { padding: 0; }
  .account { margin: 0 0 0 auto; padding: 0; border: 0; }
  .account-name { display: none; }
  .nav {
    order: 3;
    flex-direction: row;
    width: 100%;
    overflow-x: auto;
    gap: 4px;
    scrollbar-width: none;
  }
  .nav button { width: auto; flex: none; padding: 7px 10px; }
  .content { padding: 20px 16px 48px; }
  .nowrap-row { flex-wrap: wrap; }
  .nowrap-row .btn { width: 100%; }
}

@media (max-width: 600px) {
  .card { padding: 16px; }
  .login-card { padding: 24px; }
  .stats { gap: 10px; }
  .stat-value { font-size: 20px; }
  /* Tabela vira lista empilhada no celular */
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { padding: 12px 16px; border-bottom: 1px solid var(--border); position: relative; }
  td { border: 0; padding: 2px 0; }
  td.msgcell { max-width: none; }
  td:empty { display: none; }
  td.sel { position: absolute; right: 16px; top: 14px; width: auto; }
  td.right { text-align: left; margin-top: 8px; }
  td.right .row { justify-content: flex-start; }
  td.num { text-align: left; }
  tbody tr:hover td { background: none; }
}

/* ---------- Últimos envios: busca, filtros e carga automática ---------- */
.filters { margin-bottom: 12px; }
.filters input[type=search], .filters select {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.filters input[type=search] { flex: 1 1 180px; max-width: 260px; }
.filters select { flex: 0 1 210px; max-width: 100%; cursor: pointer; }
.filters select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.small-text { font-size: 13px; }
#hist-foot { justify-content: center; }

@media (max-width: 640px) {
  .filters input[type=search], .filters select { flex: 1 1 100%; max-width: none; }
}

/* ---------- Operadora ---------- */
.filters.tight { margin-bottom: 0; }
.filters input[type=date] {
  padding: 6px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  color-scheme: light dark;
}
label.inline { display: inline; margin: 0; font-weight: 500; font-size: 13px; color: var(--muted); }
#prov-msg:empty { display: none; }
#prov-msg { margin: 0 0 14px; }
[data-panel="provider"] .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 640px; }
@media (max-width: 600px) {
  [data-panel="provider"] .stats { grid-template-columns: 1fr; }
}
