/* ============================================================
   SisRating (Aureon) — app.css
   ============================================================
   Estilos do projeto. Consome variáveis de tokens.css.
   Convenção: BEM-like + utility complementar.
   Compatível com Alpine CSP build (zero JS inline aqui).
   ============================================================ */

/* ---------- Reset enxuto ---------- */
*, *::before, *::after { box-sizing: border-box; }

/* F4 — x-cloak: esconder elementos Alpine antes de hidratar */
[x-cloak] { display: none !important; }

html { font-size: 16px; color-scheme: light; }
select option { background: #ffffff; color: var(--text-body); }
body {
  margin: 0;
  padding: 0;
  background: var(--surface-page);
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html, body { overflow-x: hidden; }
body { min-height: 100vh; min-height: 100svh; }

h1, h2, h3, h4 { margin: 0; }

img, svg { display: block; max-width: 100%; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
}

a {
  color: var(--text-link);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Números financeiros — sempre tabular pra alinhar coluna R$ */
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.col-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--text-sm); }
.is-numeric { font-variant-numeric: tabular-nums; text-align: right; }

/* Utility spacing rápido */
.mt-4 { margin-top: var(--space-4); }

/* ============================================================
   LAYOUT — app shell + header + container
   ============================================================ */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100svh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-height);
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-subtle);
}
.app-header__inner {
  max-width: var(--container-max);
  margin: 0 auto;
  height: 100%;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

/* Brand: "[Au] SisRating" no header (ver também .brand-mark utility em tokens) */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  font-size: var(--text-md);
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  border-radius: var(--radius-pill);
  letter-spacing: 0;
}
.brand__name {
  letter-spacing: -0.005em;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

/* brand-mark utility (texto-pílula reutilizável em telas vazias / login) */
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wider);
  color: var(--text-primary);
}
.brand-name {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: -0.005em;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}
.app-nav__link {
  position: relative;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-body);
  padding: var(--space-2) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--motion-fast) var(--ease-out);
}
.app-nav__link:hover { color: var(--text-primary); text-decoration: none; }
.app-nav__link.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--brand);
}
.app-nav__link:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

.app-header__spacer { flex: 1; }

/* Sino + dot de notificação */
.bell-wrap { position: relative; }
.bell {
  position: relative;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--text-body);
  background: transparent;
  border: 0;
}
.bell:hover { background: var(--surface-subtle); color: var(--text-primary); }
.bell:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.bell__dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 8px; height: 8px;
  background: var(--danger-500);
  border-radius: var(--radius-pill);
  border: 2px solid var(--surface-card);
  box-sizing: content-box;
}

.bell-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
  z-index: var(--z-dropdown);
}
.bell-popover__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  margin: 0 0 var(--space-2) 0;
}
.bell-popover__item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--text-body);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
}
.bell-popover__item:last-child { border-bottom: 0; }
.bell-popover__item:hover { background: var(--surface-subtle); color: var(--text-primary); text-decoration: none; }
.bell-popover__dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

/* Ícone de ação no header (admin, refresh) */
.app-header__icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--text-body);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.app-header__icon-btn:hover { background: var(--surface-subtle); color: var(--text-primary); }
.app-header__icon-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* User chip */
.user-chip-wrap { position: relative; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius);
  border: 1px solid var(--border-default);
  background: var(--surface-card);
  color: var(--text-body);
  font-size: var(--text-base);
}
.user-chip:hover { background: var(--surface-subtle); }
.user-chip__avatar {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-weight: var(--weight-semibold);
  font-size: var(--text-xs);
  border-radius: var(--radius-pill);
}
.user-chip__name-text {
  font-size: var(--text-sm);
  color: var(--text-body);
  font-weight: var(--weight-medium);
}
.user-chip__caret { transition: transform var(--motion-fast) var(--ease-out); }
.user-chip__caret.is-open { transform: rotate(180deg); }
.user-chip__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  list-style: none;
  margin: 0;
  padding: var(--space-1);
  z-index: var(--z-dropdown);
}
.user-chip__menuitem {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--text-body);
  font-size: var(--text-base);
  text-decoration: none;
}
.user-chip__menuitem:hover { background: var(--surface-subtle); color: var(--text-primary); text-decoration: none; }

/* Tenant chip (super_admin / apoio_aureon — troca de parceiro) */
.tenant-chip-wrap { position: relative; }
.tenant-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border-default);
  background: var(--surface-card);
  color: var(--text-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.tenant-chip:hover { background: var(--surface-subtle); color: var(--text-primary); }
.tenant-chip:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.tenant-chip__label { color: var(--text-secondary); font-weight: var(--weight-regular); }

.container {
  max-width: var(--container-max);
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6) var(--space-8);
  flex: 1;
}

.page-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}
.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

/* ============================================================
   BOTÕES
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  border: 1px solid transparent;
  transition: background var(--motion-fast) var(--ease-out),
              border-color var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}
.btn--primary {
  background: var(--brand);
  color: var(--text-on-brand);
  font-weight: var(--weight-semibold);
}
.btn--primary:hover { background: var(--brand-hover); }
.btn--primary:disabled,
.btn--primary[aria-disabled="true"] {
  background: var(--neutral-200);
  color: var(--text-disabled);
  cursor: not-allowed;
}
.btn--ghost {
  background: transparent;
  color: var(--text-body);
  border-color: var(--border-default);
}
.btn--ghost:hover { background: var(--surface-subtle); color: var(--text-primary); }
.btn--danger {
  background: var(--danger-500);
  color: #fff;
}
.btn--danger:hover { background: var(--danger-600); }
.btn--danger-soft {
  background: var(--surface-card);
  color: var(--danger-700);
  border-color: var(--danger-100);
}
.btn--danger-soft:hover {
  background: var(--danger-50);
  border-color: var(--danger-500);
  color: var(--danger-700);
}
.btn--small { height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--full { width: 100%; }

/* Botão-ícone: 32px desktop, 44px mobile (M2 audit) */
.btn--icon {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: var(--radius);
  color: var(--text-body);
  background: transparent;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn--icon:hover { background: var(--surface-subtle); color: var(--text-primary); }
.btn--icon:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
@media (max-width: 767px) {
  /* M2 audit — touch target ≥44px em mobile */
  .btn--icon { width: 44px; height: 44px; }
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}
.btn--ghost:disabled,
.btn--ghost[aria-disabled="true"] {
  background: transparent;
  color: var(--text-disabled);
  border-color: var(--border-subtle);
}

/* ============================================================
   INPUTS / FIELDS
   ============================================================ */
.field { display: block; margin-bottom: var(--space-4); }
.field__label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-body);
  margin-bottom: var(--space-1);
}
.field__hint {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}
.field__error {
  display: block;
  font-size: var(--text-sm);
  color: var(--danger-700);
  margin-top: var(--space-1);
}

.input, .select, .textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  background: var(--surface-card);
  color: var(--text-body);
  font-size: var(--text-base);
  transition: border-color var(--motion-fast) var(--ease-out),
              box-shadow var(--motion-fast) var(--ease-out);
}
.textarea {
  height: auto;
  min-height: 80px;
  padding: var(--space-2) var(--space-3);
  resize: vertical;
  line-height: var(--leading-normal);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}
.input--error, .select--error, .textarea--error {
  border-color: var(--danger-500);
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-inset);
  cursor: not-allowed;
}

/* radio inline (label + checkbox/radio numa linha) */
.radio-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-base);
  color: var(--text-body);
  cursor: pointer;
  user-select: none;
}
.radio-inline input {
  width: 16px; height: 16px;
  accent-color: var(--brand);
  cursor: pointer;
}

/* Search input com ícone à esquerda */
.input-search-wrap {
  position: relative;
}
.input-search-wrap__icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.input-search-wrap .input,
.input-search-wrap input {
  padding-left: calc(var(--space-3) + 24px);
}

/* ============================================================
   GRIDS / LAYOUT HELPERS
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.flex-row { display: flex; align-items: center; gap: var(--space-3); }
.flex-row--wrap { flex-wrap: wrap; }

/* ============================================================
   CARDS / KPIs
   ============================================================ */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}
.card__head {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.card__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}
.card__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}
.card__body { padding: var(--space-4) var(--space-6); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
@media (max-width: 1023px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 639px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi {
  background: var(--kpi-neutral-bg);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out),
              transform var(--motion-fast) var(--ease-out);
  text-align: left;
  width: 100%;
}
.kpi:hover { border-color: var(--border-strong); }
.kpi:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}
.kpi--brand    { background: var(--kpi-brand-bg);    border-color: var(--indigo-200); }
.kpi--brand .kpi__number { color: var(--kpi-brand-fg); }
.kpi--positive { background: var(--kpi-positive-bg); border-color: var(--success-100); }
.kpi--positive .kpi__number { color: var(--kpi-positive-fg); }
.kpi--warning  { background: var(--kpi-warning-bg);  border-color: var(--warning-100); }
.kpi--warning .kpi__number { color: var(--kpi-warning-fg); }
.kpi--danger   { background: var(--kpi-danger-bg);   border-color: var(--danger-100); }
.kpi--danger .kpi__number { color: var(--kpi-danger-fg); }

.kpi__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}
.kpi__number {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-tight);
}
.kpi__meta {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}
.kpi__warn {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--warning-700);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-medium);
}

/* ============================================================
   CHIPS / BADGES — status de parcela (a_vencer/cobrado/pago/atrasado/renegociado/cancelado)
   ============================================================
   O JS gera classes "chip chip--<intent>" via statusChip().
   Mantenho aliases por status nominal (chip--a-vencer etc.) caso
   algum HTML futuro use diretamente.
   ============================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-sm);
  background: var(--status-neutral-bg);
  color: var(--status-neutral-fg);
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip svg { width: 12px; height: 12px; }
.chip__dot {
  width: 6px; height: 6px;
  border-radius: var(--radius-pill);
  background: var(--status-neutral-dot);
  flex-shrink: 0;
  display: inline-block;
}

/* Por intenção semântica (usadas pelo statusChip() em recebiveis.js) */
.chip--neutral   { background: var(--status-neutral-bg); color: var(--status-neutral-fg); }
.chip--neutral .chip__dot   { background: var(--status-neutral-dot); }
.chip--success   { background: var(--status-success-bg); color: var(--status-success-fg); }
.chip--success .chip__dot   { background: var(--status-success-dot); }
.chip--warning   { background: var(--status-warning-bg); color: var(--status-warning-fg); }
.chip--warning .chip__dot   { background: var(--status-warning-dot); }
.chip--danger    { background: var(--status-danger-bg);  color: var(--status-danger-fg); }
.chip--danger .chip__dot    { background: var(--status-danger-dot); }
.chip--info      { background: var(--status-info-bg);    color: var(--status-info-fg); }
.chip--info .chip__dot      { background: var(--status-info-dot); }
.chip--muted     { background: var(--status-muted-bg);   color: var(--status-muted-fg); border-color: var(--border-subtle); }
.chip--muted .chip__dot     { background: var(--status-muted-dot); }

/* Por status nominal (alias direto pro nome do status — useful em HTML estático) */
.chip--a-vencer    { background: var(--status-neutral-bg); color: var(--status-neutral-fg); }
.chip--a-vencer .chip__dot    { background: var(--status-neutral-dot); }
.chip--cobrado     { background: var(--status-warning-bg); color: var(--status-warning-fg); }
.chip--cobrado .chip__dot     { background: var(--status-warning-dot); }
.chip--pago        { background: var(--status-success-bg); color: var(--status-success-fg); }
.chip--pago .chip__dot        { background: var(--status-success-dot); }
.chip--atrasado    { background: var(--status-danger-bg);  color: var(--status-danger-fg); }
.chip--atrasado .chip__dot    { background: var(--status-danger-dot); }
.chip--renegociado { background: var(--status-info-bg);    color: var(--status-info-fg); }
.chip--renegociado .chip__dot { background: var(--status-info-dot); }
.chip--cancelado   { background: var(--status-muted-bg);   color: var(--status-muted-fg); border-color: var(--border-subtle); }
.chip--cancelado .chip__dot   { background: var(--status-muted-dot); }

/* ============================================================
   TABELA
   ============================================================ */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-card);
}
.table thead th {
  background: var(--surface-subtle);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
.table thead th.is-action,
.table tbody td.is-action { text-align: right; white-space: nowrap; }

.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-base);
  color: var(--text-body);
  vertical-align: middle;
}
.table tbody tr {
  transition: background var(--motion-fast) var(--ease-out);
}
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover { background: var(--surface-subtle); }
.table tbody tr:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: -2px;
}

/* Estados visuais de linha (recebíveis) */
.table tbody tr.is-paid { opacity: 0.7; }
.table tbody tr.is-paid:hover { opacity: 1; }
.table tbody tr.is-late { box-shadow: inset 3px 0 0 var(--danger-500); }

.table-wrap {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* Paginação */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.pagination__controls { display: flex; gap: var(--space-1); align-items: center; }
.pagination__btn {
  min-width: 32px; height: 32px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  color: var(--text-body);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.pagination__btn:hover { background: var(--surface-subtle); }
.pagination__btn.is-active {
  background: var(--brand);
  color: var(--text-on-brand);
  border-color: var(--brand);
  font-weight: var(--weight-semibold);
}
.pagination__btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   FILTROS / FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default);
  background: var(--surface-card);
  color: var(--text-body);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  height: 36px;
  white-space: nowrap;
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
}
.filter-chip:hover { border-color: var(--border-strong); }
.filter-chip.is-active {
  background: var(--brand-soft);
  color: var(--brand-soft-text);
  border-color: var(--brand);
}
.filter-chip:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.filter-chip svg { width: 12px; height: 12px; }
.filter-chip__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: var(--space-1);
  min-width: 22px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: var(--weight-semibold);
  background: var(--neutral-200);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.filter-chip.is-active .filter-chip__count {
  background: var(--brand-soft);
  color: var(--brand-deep);
}

/* select usado como filter-chip nativo (Período) */
select.filter-chip {
  padding-right: var(--space-6);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
                    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* ============================================================
   TABS (admin, auditoria)
   ============================================================ */
.tabs {
  display: flex;
  gap: var(--space-4);
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  position: relative;
  padding: var(--space-3) 0;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-body);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  background: transparent;
  border-left: 0; border-right: 0; border-top: 0;
  white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--brand);
}
.tab:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ============================================================
   DRAWER + OVERLAY + MODAL
   ============================================================ */
.overlay {
  position: fixed; inset: 0;
  background: oklch(22% 0.030 270 / 0.45);
  z-index: var(--z-overlay);
  animation: fade-in var(--motion-base) var(--ease-out);
}

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--drawer-width);
  max-width: 100vw;
  background: var(--surface-card);
  box-shadow: var(--shadow-drawer);
  z-index: var(--z-drawer);
  display: flex; flex-direction: column;
  transform: translateX(0);
  animation: slide-in-right var(--motion-slow) var(--ease-out);
}
.drawer--wide { width: var(--drawer-width-wide); }

.drawer__head {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  flex-shrink: 0;
}
.drawer__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}
.drawer__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}
.drawer__body { flex: 1; overflow-y: auto; padding: var(--space-6); }
.drawer__foot {
  padding: var(--space-3) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-card);
  display: flex; justify-content: flex-end; gap: var(--space-3);
  flex-shrink: 0;
}

/* Seção dentro do drawer (Dados pessoais / Vendas / Histórico …) */
.drawer__section {
  padding-bottom: var(--space-5);
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.drawer__section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
  margin-bottom: 0;
}
.drawer__section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  margin: 0 0 var(--space-3) 0;
}

/* Drag handle — só visível em mobile (M1 audit, bottom-sheet) */
.drag-handle {
  display: none;
  width: 40px;
  height: 4px;
  background: var(--neutral-300);
  border-radius: var(--radius-pill);
  margin: 12px auto;
  flex-shrink: 0;
}

/* ----- M1 audit: drawer-right vira bottom-sheet em mobile ----- */
@media (max-width: 767px) {
  .drawer {
    /* Vira bottom-sheet */
    right: auto !important;
    left: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 92vh !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0 !important;
    box-shadow: var(--shadow-sheet) !important;
    transform: translateY(100%);
    animation: slide-up-sheet var(--motion-sheet) var(--ease-out) forwards;
  }
  .drawer.is-open { transform: translateY(0); }

  /* drag-handle só aparece em mobile, no topo do drawer-virou-sheet */
  .drawer .drag-handle { display: block; }
}
@media (min-width: 768px) {
  .drawer .drag-handle { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer { animation-duration: 0.01ms !important; }
}

/* @keyframes do drawer + sheet + pop-in */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in-right { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slide-up-sheet { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes pop-in-sm { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* ============================================================
   SOMA-PREVIEW (form Nova venda + Renegociar)
   ============================================================
   Caixa que mostra soma das parcelas em tempo real. Alinha à
   direita, fonte mono, fundo neutral-100, padding 12px, radius-md.
   Documentada no design-spec §4.3.
   ============================================================ */
.soma-preview {
  background: var(--neutral-100);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--text-body);
  text-align: right;
  transition: background var(--motion-base) var(--ease-out),
              border-color var(--motion-base) var(--ease-out);
}
.soma-preview__line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 2px 0;
}
.soma-preview__line--total {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-default);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  font-size: var(--text-md);
}
.soma-preview__ok {
  color: var(--success-700);
  font-weight: var(--weight-semibold);
}
.soma-preview__err {
  color: var(--danger-700);
  font-weight: var(--weight-semibold);
}

/* ============================================================
   TOASTS
   ============================================================ */
.toast-stack {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex; flex-direction: column-reverse; gap: var(--space-2);
  max-width: 380px;
}
.toast {
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  color: var(--text-body);
  display: flex; gap: var(--space-2); align-items: flex-start;
  animation: slide-up var(--motion-base) var(--ease-out);
}
.toast--success { border-left-color: var(--success-500); }
.toast--error   { border-left-color: var(--danger-500); }
.toast--info    { border-left-color: var(--info-500); }
.toast--warning { border-left-color: var(--warning-500); }
.toast__text { flex: 1; }
.toast__action {
  background: transparent;
  color: var(--text-link);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: 0 var(--space-2);
  margin-left: var(--space-1);
}
.toast__action:hover { text-decoration: underline; }
.toast__close { margin-left: auto; color: var(--text-tertiary); }
.toast__close:hover { color: var(--text-primary); }
@keyframes slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   SKELETON SHIMMER
   ============================================================ */
.skeleton {
  display: block;
  background: linear-gradient(90deg, var(--neutral-100) 0%, var(--neutral-200) 50%, var(--neutral-100) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  border-radius: var(--radius-sm);
  height: 14px;
}
.skeleton-row { height: 36px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--neutral-100); }
}

/* ============================================================
   EMPTY STATE / ERROR STATE
   ============================================================ */
.state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-secondary);
}
.state__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--surface-subtle);
  color: var(--text-secondary);
}
.state__title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.state__sub {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}
.state--error .state__icon { background: var(--danger-50); color: var(--danger-700); }
.state--error .state__title { color: var(--danger-700); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-4);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
  padding: var(--space-8);
}
.login-brand { text-align: center; margin-bottom: var(--space-6); }
.login-brand__mark {
  display: inline-flex;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
  border-radius: var(--radius-pill);
  margin-bottom: var(--space-3);
  letter-spacing: 0;
}
.login-brand__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}
.login-brand__sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}
.login-form { margin: 0; }
.login-foot {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--space-6);
}

/* ============================================================
   LISTAS COMPACTAS DO DASHBOARD
   ============================================================ */
.list-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
}
.list-row:last-child { border-bottom: 0; }
.list-row__main { color: var(--text-primary); font-weight: var(--weight-medium); }
.list-row__sub  { color: var(--text-secondary); font-size: var(--text-xs); margin-top: 2px; }
.list-row__meta { color: var(--text-secondary); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

.ranking-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-base);
}
.ranking-row:last-child { border-bottom: 0; }
.ranking-row__pos {
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  width: 24px;
  font-variant-numeric: tabular-nums;
}
.ranking-row__name { color: var(--text-body); flex: 1; }
.ranking-row__count {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.ranking-row__value {
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

/* ============================================================
   CARD-LIST (mobile fallback de tabelas — admin, compradores)
   ============================================================ */
.card-list-mobile { display: none; }
.card-list { display: flex; flex-direction: column; gap: var(--space-2); }

.list-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-card);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
}
.list-card:hover { border-color: var(--border-strong); background: var(--surface-subtle); }
.list-card:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.list-card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}
.list-card__name {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}
.list-card__value {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.list-card__meta {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin: 2px 0 0;
}
.list-card__foot {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-2);
  flex-wrap: wrap;
}

/* ============================================================
   ERROR BANNER (login + drawers)
   ============================================================ */
.error-banner {
  display: flex; align-items: flex-start; gap: var(--space-2);
  background: var(--danger-50);
  color: var(--danger-700);
  border: 1px solid var(--danger-100);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  margin: var(--space-2) 0;
}

/* ============================================================
   HEADER MOBILE — hambúrguer + drawer-nav (≤767px)
   ============================================================ */
.app-nav-toggle {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-body);
  background: transparent;
  border: 0;
  flex-shrink: 0;
}
.app-nav-toggle:hover { background: var(--surface-subtle); color: var(--text-primary); }
.app-nav-toggle:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* drawer-from-left que segura a nav vertical no mobile */
.nav-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--surface-card);
  box-shadow: var(--shadow-drawer);
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  animation: slide-in-left var(--motion-base) var(--ease-out);
}
.nav-drawer__head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-shrink: 0;
}
.nav-drawer__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}
.nav-drawer__close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-body);
  background: transparent;
  border: 0;
}
.nav-drawer__close:hover { background: var(--surface-subtle); color: var(--text-primary); }
.nav-drawer__list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
  display: flex;
  flex-direction: column;
}
.nav-drawer__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-body);
  border-left: 3px solid transparent;
  text-decoration: none;
}
.nav-drawer__link:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
  text-decoration: none;
}
.nav-drawer__link.is-active {
  color: var(--text-primary);
  border-left-color: var(--brand);
  background: var(--brand-soft);
}
.nav-drawer__divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-2) var(--space-5);
}

/* C2 audit — nav-drawer hidden em desktop (defensive) */
@media (min-width: 768px) {
  .nav-drawer { display: none !important; }
}

@media (max-width: 767px) {
  .app-nav-toggle { display: inline-flex; }
  .app-nav { display: none !important; }
  .app-header__inner {
    padding: 0 var(--space-3);
    gap: var(--space-2);
    height: var(--header-height-mobile);
  }
  .app-header { height: var(--header-height-mobile); }
  .brand__name {
    /* impede quebra em 2 linhas em 360px */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
  }
  /* user-chip mostra só inicial em mobile */
  .user-chip__name-text { display: none; }
  /* tenant-chip vira só o valor em mobile */
  .tenant-chip__label { display: none; }

  /* card-list-mobile: vira block, tabela some quando contém .card-list-mobile irmão */
  .card-list-mobile { display: block; }
  .card-list-mobile + .table-wrap,
  .table-wrap + .card-list-mobile { display: block; }

  .container { padding: var(--space-4); }
  .page-title-row { flex-direction: column; align-items: flex-start; gap: var(--space-1); margin-bottom: var(--space-6); }
  .page-title { font-size: var(--text-xl); }

  .card__head { padding: var(--space-3) var(--space-4); }
  .card__body { padding: var(--space-3) var(--space-4); }
}

/* Header tablet (768-1023px) — compactar nav */
@media (min-width: 768px) and (max-width: 1023px) {
  .app-header__inner {
    gap: var(--space-3);
    padding: 0 var(--space-4);
  }
  .app-nav { gap: var(--space-4); }
  .app-nav__link {
    white-space: nowrap;
    font-size: var(--text-sm);
  }
  .brand__name {
    font-size: var(--text-base);
    white-space: nowrap;
  }
  /* user-chip mostra só inicial em tablet */
  .user-chip__name-text { display: none; }
}

/* ============================================================
   FOOTER — versão do sistema
   ============================================================ */
.app-footer {
  margin-top: var(--space-8);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-subtle);
  color: var(--text-tertiary);
  font-size: var(--text-xs);
}
.app-footer__inner {
  max-width: var(--container-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-align: center;
  flex-wrap: wrap;
}
.app-footer__sep { color: var(--border-default); }
.app-footer__version { font-variant-numeric: tabular-nums; }

/* ============================================================
   AJUSTES FINOS — mobile final
   ============================================================ */
@media (max-width: 480px) {
  .filter-bar { gap: var(--space-1); }
  .filter-chip { font-size: var(--text-xs); padding: var(--space-1) var(--space-2); height: 32px; }

  .modal,
  .drawer__head { gap: var(--space-2); }
  .drawer__head { padding: var(--space-3) var(--space-4); }
  .drawer__body { padding: var(--space-4); }
  .drawer__foot { padding: var(--space-3) var(--space-4); }
  .drawer__foot .btn { min-height: 44px; flex: 1; }
}
