:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e4e7ef;
  --text: #161a26;
  --muted: #687089;
  --primary: #16a34a;
  --primary-soft: #dcfce7;
  --primary-text: #ffffff;
  --accent: #4f46e5;
  --accent-soft: #e0e7ff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #151b25;
    --surface-2: #1b2230;
    --border: #273042;
    --text: #e7eaf2;
    --muted: #8f99b0;
    --primary: #22c55e;
    --primary-soft: rgba(34, 197, 94, .14);
    --primary-text: #052e14;
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, .15);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .14);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #151b25;
  --surface-2: #1b2230;
  --border: #273042;
  --text: #e7eaf2;
  --muted: #8f99b0;
  --primary: #22c55e;
  --primary-soft: rgba(34, 197, 94, .14);
  --primary-text: #052e14;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, .15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 17px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  display: grid; place-items: center; color: #fff;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: none; color: var(--muted);
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 520; text-align: left; width: 100%;
}
.nav-btn svg { width: 18px; height: 18px; flex: none; }
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.ativo { background: var(--primary-soft); color: var(--primary); }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }

.main { padding: 28px 32px 48px; max-width: 1280px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* Cartões */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.verde { background: var(--primary); }
.dot.azul { background: var(--accent); }
.dot.amarelo { background: var(--warn); }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress > div { height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }

/* Gráfico de barras simples */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-fill { width: 100%; max-width: 42px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; transition: height .4s; }
.bar-label { font-size: 11.5px; color: var(--muted); }
.bar-val { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Status do WhatsApp */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.pill.ok { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.ok::before, .pill.warn::before, .pill.err::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok::before { animation: pulso 2s infinite; }
@keyframes pulso { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.qr-box { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.qr-box img { width: 260px; height: 260px; border-radius: 12px; background: #fff; padding: 10px; border: 1px solid var(--border); }
.qr-box ol { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.qr-box ol li { margin: 4px 0; }

/* Eventos */
.eventos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; max-height: 360px; overflow: auto; }
.eventos li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.eventos li:last-child { border-bottom: 0; }
.eventos time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.eventos .sucesso { color: var(--primary); }
.eventos .erro { color: var(--danger); }
.eventos .aviso { color: var(--warn); }

/* Formulários e botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 560; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 220px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
label.campo { display: flex; flex-direction: column; gap: 6px; font-weight: 560; }
label.campo .dica { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.form-grid { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: 0; }
.switch input { display: none; }
.switch .track { width: 42px; height: 24px; border-radius: 99px; background: var(--border); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* Upload */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.sobre { border-color: var(--primary); background: var(--primary-soft); }
.dropzone svg { width: 40px; height: 40px; color: var(--primary); }
.dropzone strong { display: block; font-size: 15px; margin: 8px 0 4px; }
.lista-arquivos { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow: auto; }
.lista-arquivos li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; font-size: 13px; }
.tipo-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); text-transform: uppercase; }

/* Tabela */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"] { max-width: 300px; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 560; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.tabs button.ativo { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
td .titulo { font-weight: 560; }
td .previa { color: var(--muted); font-size: 12.5px; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 460px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; }
.badge.disp { background: var(--primary-soft); color: var(--primary); }
.badge.entr { background: var(--accent-soft); color: var(--accent); }
.vazio { text-align: center; padding: 40px 10px; color: var(--muted); }
.paginacao { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; flex-wrap: wrap; }

.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ranking li:last-child { border-bottom: 0; }
.ranking .pos { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.ranking .qtd { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

.grupos { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; margin-top: 8px; }
.grupos label { display: flex; gap: 10px; align-items: center; padding: 9px 12px; background: var(--surface-2); border-radius: 8px; cursor: pointer; font-weight: 500; }
.grupos input { width: 16px; height: 16px; accent-color: var(--primary); }

/* Modal e toast */
.modal-fundo { position: fixed; inset: 0; background: rgba(5, 8, 15, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: min(640px, 100%); max-height: 85vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 20px; overflow: auto; white-space: pre-wrap; }
.modal-body img, .modal-body iframe { max-width: 100%; width: 100%; border: 0; border-radius: 8px; }
.modal-body iframe { height: 60vh; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: entra .2s ease-out; }
.toast.erro { background: var(--danger); color: #fff; }
@keyframes entra { from { transform: translateY(8px); opacity: 0; } }

.mobile-bar { display: none; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, var(--primary-soft), transparent 45%), var(--bg); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 18px; }
.login-card .brand { padding: 0; justify-content: center; }
.erro-msg { color: var(--danger); font-size: 13px; min-height: 18px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3-1 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.aberta { transform: none; box-shadow: var(--shadow); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 20px 16px 40px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { max-width: none; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 24px; }
  .qr-box img { width: 100%; height: auto; }
}

textarea::placeholder, input::placeholder { color: var(--muted); opacity: .65; }
@media (max-width: 820px) {
  .page-head > .pill { display: none; }
}

.codigo-pareamento {
  font: 700 40px/1 ui-monospace, Consolas, monospace; letter-spacing: .12em;
  padding: 28px 30px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); user-select: all; white-space: nowrap;
}
.codigo-pareamento span { color: var(--muted); margin: 0 4px; }
.alerta { margin: 16px 0 0; padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); }
@media (max-width: 480px) { .codigo-pareamento { font-size: 30px; padding: 20px; } }
