/* ============================================================
   SINDEXUS — Design tokens & base components
   Fintech-clean: Sora (display) + Hanken Grotesk (body) + JetBrains Mono (números)
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --font-display: 'Sora', sans-serif;
  --font-body: 'Hanken Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg: oklch(0.971 0.004 250);
  --surface: #ffffff;
  --surface-2: oklch(0.985 0.003 250);
  --ink: oklch(0.235 0.022 258);
  --ink-2: oklch(0.45 0.018 258);
  --ink-3: oklch(0.60 0.014 258);
  --line: oklch(0.908 0.007 255);
  --line-soft: oklch(0.94 0.005 255);

  --accent: #2549b0;
  --accent-soft: color-mix(in oklch, var(--accent) 9%, white);
  --accent-line: color-mix(in oklch, var(--accent) 28%, white);
  --accent-ink: color-mix(in oklch, var(--accent) 85%, black);

  --ok: oklch(0.55 0.12 155);
  --ok-soft: oklch(0.95 0.025 155);
  --warn: oklch(0.62 0.12 70);
  --warn-soft: oklch(0.96 0.035 85);
  --danger: oklch(0.54 0.17 26);
  --danger-soft: oklch(0.955 0.022 26);
  --info: oklch(0.52 0.13 250);
  --info-soft: oklch(0.955 0.02 250);
  --purple: oklch(0.50 0.14 300);
  --purple-soft: oklch(0.955 0.025 300);
  --neutral-soft: oklch(0.945 0.005 255);

  --sidebar-bg: oklch(0.235 0.035 262);
  --sidebar-ink: oklch(0.88 0.012 255);
  --sidebar-dim: oklch(0.66 0.02 258);

  --r-card: 12px;
  --r-btn: 8px;
  --r-pill: 999px;
  --shadow-card: 0 1px 2px oklch(0.2 0.02 258 / 0.05), 0 1px 3px oklch(0.2 0.02 258 / 0.04);
  --shadow-pop: 0 4px 12px oklch(0.2 0.02 258 / 0.10), 0 12px 32px oklch(0.2 0.02 258 / 0.12);

  --pad-card: 20px;
  --row-h: 52px;
  --fs-body: 14.5px;

  /* Tokens responsivos de página — base (desktop). Caem em <640px (ver media query abaixo). */
  --pad-page: 28px;        /* padding horizontal/topo das páginas (PageHeader, faixas de conteúdo) */
  --pad-page-y: 22px;      /* padding vertical superior das páginas */
  --gap-grid: 18px;        /* gap padrão dos grids de página */
  --gap-kpi: 14px;         /* gap entre KPIs */
}
[data-density="compacto"] {
  --pad-card: 14px;
  --row-h: 42px;
  --fs-body: 13.5px;
}

/* ---------- Breakpoints / tokens responsivos de página ----------
   Mobile-first por sobreposição: preservamos o visual desktop e só
   reduzimos os tokens nas faixas estreitas. */
@media (max-width: 640px) {
  :root {
    --pad-page: 16px;
    --pad-page-y: 16px;
    --gap-grid: 14px;
    --gap-kpi: 10px;
    --pad-card: 16px;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: var(--fs-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-wrap: pretty;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.015em; }
button { font-family: var(--font-body); cursor: pointer; }
input, select, textarea { font-family: var(--font-body); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: oklch(0.85 0.008 255); border-radius: 8px; border: 2.5px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
aside nav::-webkit-scrollbar { width: 0; height: 0; }
aside nav { scrollbar-width: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--r-btn); border: 1px solid transparent;
  font-weight: 600; font-size: 13.5px; padding: 9px 16px;
  transition: filter .12s, background .12s, border-color .12s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { filter: brightness(0.95); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-outline:hover { border-color: var(--ink-3); filter: none; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--neutral-soft); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--ok); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 15px; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); box-shadow: var(--shadow-card);
}
.card-pad { padding: var(--pad-card); }
.card:has(> .table) { overflow-x: auto; }
.card-title { font-size: 14px; font-weight: 600; font-family: var(--font-display); }

/* ---------- Badges / status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-pill); padding: 3.5px 11px;
  font-size: 12px; font-weight: 600; line-height: 1.4; white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill-neutral { background: var(--neutral-soft); color: var(--ink-2); }
.pill-info    { background: var(--info-soft); color: var(--info); }
.pill-warn    { background: var(--warn-soft); color: oklch(0.5 0.12 70); }
.pill-danger  { background: var(--danger-soft); color: var(--danger); }
.pill-success { background: var(--ok-soft); color: var(--ok); }
.pill-purple  { background: var(--purple-soft); color: var(--purple); }
.pill-accent  { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- Inputs ---------- */
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--r-btn);
  background: var(--surface); color: var(--ink);
  padding: 9px 12px; font-size: 14px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 16%, transparent);
}
.textarea { resize: vertical; min-height: 88px; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field-hint { font-size: 12px; color: var(--ink-3); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-3); padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 0 14px; height: var(--row-h); border-bottom: 1px solid var(--line-soft); }
.table tbody tr { transition: background .1s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table .num { font-family: var(--font-mono); font-size: 12.8px; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: none; padding: 10px 14px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tab .count {
  background: var(--neutral-soft); color: var(--ink-2); border-radius: var(--r-pill);
  font-size: 11px; padding: 1px 7px; font-family: var(--font-mono);
}
.tab.active .count { background: var(--accent-soft); color: var(--accent-ink); }

/* ============================================================
   LAYOUT RESPONSIVO — utilitários reusáveis pelos portais
   Mobile-first: as classes preservam o layout desktop e empilham/
   rolam nas faixas estreitas. Substituem grids inline nos portais.
   ============================================================ */

/* Faixa de KPIs: cartões fluidos que quebram linha no mobile. */
.kpi-row { display: flex; flex-wrap: wrap; gap: var(--gap-kpi); }
.kpi-row > * { flex: 1 1 180px; min-width: 0; }

/* Grades de página: viram 1 coluna abaixo de ~720px. */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap-grid); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--gap-grid); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap-grid); }
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr; }
}

/* Detalhe (conteúdo + coluna lateral): empilha abaixo de ~860px. */
.detail-split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap-grid); align-items: start; }
.detail-split.wide { grid-template-columns: minmax(0, 1.5fr) 1fr; }
@media (max-width: 860px) {
  .detail-split, .detail-split.wide { grid-template-columns: 1fr; }
}

/* Container de tabela rolável: mantém a tabela utilizável no mobile. */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > .table { min-width: 560px; }

/* Toolbar/linha de filtros: quebra linha em telas estreitas. */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 600px) {
  /* Busca e selects ocupam a largura toda quando a toolbar quebra. */
  .toolbar > .input-wrap, .toolbar > .input, .toolbar > .select { flex: 1 1 100%; width: 100%; }
}

/* Aba Integrações (superadmin-config) — migrado do CSS injetado via JS para o design system. */
.seg-btn { transition: background .12s ease, color .12s ease; }
.seg-btn:hover { color: var(--ink); }
.integ-row { transition: background .12s ease; }
.integ-row:hover { background: var(--surface-2) !important; }
@media (max-width: 720px) {
  /* Tablet/telas estreitas: provedor cai para a segunda linha; status+ação à direita. */
  .integ-row { flex-wrap: wrap; row-gap: 6px; }
  .integ-row-canal { flex: 1 1 auto; order: 1; }
  .integ-row .pill { order: 2; }
  .integ-row .btn { order: 3; margin-left: auto; }
  .integ-row-prov { flex: 1 1 100%; order: 4; white-space: normal; padding-left: 38px; }
}
@media (max-width: 560px) {
  .integ-topbar [role=group] { width: 100%; }
  .integ-topbar .seg-btn { flex: 1; justify-content: center; }
}

/* ---------- Misc ---------- */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.divider { height: 1px; background: var(--line-soft); border: none; margin: 0; }
.kbd {
  font-family: var(--font-mono); font-size: 11px; background: var(--neutral-soft);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; color: var(--ink-2);
}
.avatar {
  border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-family: var(--font-display); flex: none;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: oklch(0.2 0.02 258 / 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-pop);
  width: min(560px, calc(100vw - 40px)); max-height: min(calc(100vh - 80px), calc(100dvh - 80px));
  display: flex; flex-direction: column; overflow: hidden;
  animation: popIn .18s cubic-bezier(.2,.9,.3,1.2);
}
/* Cabeçalho/corpo/rodapé do modal (estrutura usada pelo componente Modal). */
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); flex: none; }
.modal-body { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; flex: none; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(6px); } }

/* Variante full-screen abaixo de ~600px: ocupa a tela toda, rodapé fixo e safe-area. */
@media (max-width: 600px) {
  .modal-backdrop { align-items: flex-end; }
  .modal {
    width: 100vw !important; max-width: 100vw !important;
    height: 100dvh; max-height: 100dvh;
    border-radius: 0;
    animation: sheetIn .2s cubic-bezier(.2,.9,.3,1.2);
  }
  .modal-foot {
    position: sticky; bottom: 0; background: var(--surface);
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .modal-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
@keyframes sheetIn { from { opacity: 0; transform: translateY(16px); } }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 10px; padding: 11px 18px;
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-pop); z-index: 300;
  display: flex; align-items: center; gap: 9px;
  animation: toastIn .25s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ============================================================
   SHELL MOBILE — drawer off-canvas + topbar (usado pelo PortalShell)
   Abaixo de ~768px a sidebar vira gaveta com backdrop, acionada por
   hambúrguer numa topbar fixa; o main ocupa 100% da largura.
   ============================================================ */
.shell-topbar {
  display: none;
  position: sticky; top: 0; z-index: 70;
  align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.shell-hamburger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--r-btn);
  background: transparent; border: 1px solid var(--line); color: var(--ink); flex: none;
}
.shell-drawer-backdrop {
  position: fixed; inset: 0; background: oklch(0.2 0.02 258 / 0.45);
  z-index: 95; animation: fadeIn .15s ease;
}
/* Modo mobile: a topbar aparece e a sidebar vira gaveta. */
@media (max-width: 768px) {
  .shell-topbar { display: flex; }
  .shell-aside {
    position: fixed !important; top: 0; left: 0; height: 100dvh !important;
    transform: translateX(-100%); transition: transform .22s ease;
    z-index: 100; box-shadow: var(--shadow-pop);
  }
  .shell-aside.open { transform: translateX(0); }
}

/* Helpers de visibilidade por faixa (mobile-first). */
.only-mobile { display: none; }
.only-desktop { display: initial; }
@media (max-width: 768px) {
  .only-mobile { display: initial; }
  .only-desktop { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Superadmin/ops: grids e KPI-rows com colunas fixas (estilo inline) colapsam no mobile.
   !important vence o style inline (display:grid/flex sem flex-wrap/colunas responsivas). */
@media (max-width: 720px) {
  .sa-grid-2, .sa-modgrid { grid-template-columns: 1fr !important; }
  .sa-kpis { flex-wrap: wrap !important; }
  .sa-kpis > * { flex: 1 1 150px !important; min-width: 0 !important; }
  .sa-pad { padding-left: var(--pad-page) !important; padding-right: var(--pad-page) !important; }
}
@media (max-width: 480px) {
  .sa-kpis > * { flex-basis: 100% !important; }
}
