:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16191d;
  --text-muted: #5d6673;
  --border: #e1e4e9;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --danger-bg: #ffebe9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1c222b;
    --text: #e6edf3;
    --text-muted: #8d96a0;
    --border: #2a313c;
    --accent: #4493f8;
    --accent-text: #0e1116;
    --ok: #3fb950;
    --warn: #d29922;
    --danger: #f85149;
    --danger-bg: #3d1214;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c222b;
  --text: #e6edf3;
  --text-muted: #8d96a0;
  --border: #2a313c;
  --accent: #4493f8;
  --accent-text: #0e1116;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --danger-bg: #3d1214;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

button, input { font: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 600; cursor: pointer;
}
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }

.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer;
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.brand h1 { font-size: 17px; margin: 0; line-height: 1.2; }
.brand small { color: var(--text-muted); font-size: 13px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.input {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
.login-card .btn { width: 100%; margin-top: 6px; }
.alert {
  display: none; margin-bottom: 14px; padding: 10px 12px; border-radius: 10px;
  background: var(--danger-bg); color: var(--danger); font-size: 14px;
}
.alert.show { display: block; }
.alert.sucesso { background: var(--surface-2); color: var(--ok); }
.login-foot { margin-top: 18px; text-align: center; color: var(--text-muted); font-size: 12px; }

/* ---------- App ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { margin: 0; }
.topbar-actions { display: flex; gap: 8px; }
.nav {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: none; padding: 7px 12px; border-radius: 999px;
  color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 500;
}
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.nav a.disabled { opacity: .5; pointer-events: none; }
main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
.page-title { font-size: 22px; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); margin: 0 0 20px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card h2 { font-size: 14px; margin: 0 0 12px; color: var(--text-muted); font-weight: 600; }
.stat { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--text-muted); font-size: 13px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list .meta { color: var(--text-muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.section { margin-top: 20px; }
.muted { color: var(--text-muted); }

/* ---------- Conciliação + chat ---------- */
.pequeno { font-size: 13px; }
.btn-pequeno { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.secao-titulo { font-size: 17px; margin: 20px 0 4px; }
.grid-compacta { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grid-compacta .card { padding: 10px 12px; }
.grid-compacta .stat { font-size: 22px; }
.st-sugerido .stat { color: var(--warn); }
.st-pendente .stat { color: var(--danger); }
.st-conciliado .stat { color: var(--ok); }
.concil { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .concil { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; max-width: 1280px; }
  .concil-chat { position: sticky; top: 76px; }
}
.fila { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.fila-item { display: grid; gap: 6px; }
.fila-linha { display: flex; justify-content: space-between; gap: 12px; }
.fila-nome { font-weight: 600; overflow-wrap: anywhere; }
.fila-acoes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.motivo { margin: 0; color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.meta { color: var(--text-muted); font-size: 13px; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }
.concil-chat { display: flex; flex-direction: column; gap: 10px; }
.chat-topo { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-topo h2 { margin: 0; }
.chat-msgs { display: flex; flex-direction: column; gap: 8px; max-height: 60dvh; min-height: 160px; overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-user { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg-assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; white-space: normal; }
.msg-sistema { align-self: center; font-size: 13px; color: var(--text-muted); }
.msg.pensando { color: var(--text-muted); font-style: italic; }
.md p { margin: 0 0 6px; }
.md p:last-child { margin-bottom: 0; }
.md ul { margin: 4px 0 6px; padding-left: 18px; }
.md code { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 13px; }
.acao { align-self: stretch; border: 1px dashed var(--accent); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.acao-aplicada { border-style: solid; border-color: var(--ok); }
.acao-descartada { opacity: .6; border-color: var(--border); }
.acao-erro { border-color: var(--danger); }
.acao-resumo { font-weight: 600; font-size: 14px; }
.chat-contexto { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 6px 10px; font-size: 13px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-input { min-height: 44px; padding: 10px 12px; resize: vertical; }
