/* ============================================================================
   Portal de Contabilidade · Intense — extensões compartilhadas do portal.
   Dono: slot base-ui (ADR-0013). Acrescenta ao app.css do DS; NÃO redefine tokens.
   Regra (contrato §8.2): só var(--token). Nenhum valor de cor literal aqui.
   Cada bloco abaixo está listado no STATUS.md do slot base-ui.
   ========================================================================== */

/* ── base: atributo hidden vence o display dos componentes ───────────────── */
[hidden] { display: none !important; }

/* ── .sr-only — texto só para leitor de tela ─────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* ── .skip-link — pular para o conteúdo (teclado) ────────────────────────── */
.skip-link {
  position: fixed; top: var(--gap-sm); left: var(--gap-sm); z-index: 120;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--accent); color: var(--bg); font-weight: 600; font-size: var(--fs-sm);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* ── movimento reduzido (REVISAO-DESIGN §2, item 10) ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}

/* ── .truncate em célula e em flex ───────────────────────────────────────── */
.row > .truncate, .row-between > .truncate, .grow.truncate { min-width: 0; }
.tbl td.truncate-cell { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================================
   SHELL — ajustes sobre o DS
   ========================================================================== */

/* páginas sem sessão (404 de anônimo): sem sidebar, uma coluna */
.app-public { grid-template-columns: minmax(0, 1fr); }
.public-brand { display: flex; justify-content: center; padding: var(--gap-lg) var(--gap-md) 0; }
.public-brand img { width: 168px; height: auto; }

.sidebar-head .brand img { width: auto; }
.sidebar-nav a.nav-item { text-decoration: none; }
/* contém o .sr-only (position:absolute) dentro da rolagem da faixa horizontal */
.nav-item { position: relative; }
.nav-item .nav-count[data-zero="1"] { opacity: .7; }

.user-chip { cursor: default; }
.user-chip:hover { background: none; }
.user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; text-align: left; }
.user-name { font-size: var(--fs-sm); font-weight: 500; line-height: 1.3; }
.user-role { font-size: var(--fs-meta); color: var(--muted); line-height: 1.3; }
.user-text .user-name, .user-text .user-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-logout { margin: 0; flex: none; }

.avatar-sm { width: 24px; height: 24px; font-size: 9px; }

.topbar .crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb a:hover { color: var(--fg); }
.topbar .crumb .sep { margin: 0 6px; color: var(--surface-4); }
.topbar .crumb [aria-current="page"] { color: var(--fg); font-weight: 600; }
.topbar .demo-flag { white-space: nowrap; }

/* ── busca global + lista suspensa ───────────────────────────────────────── */
.search-form { position: relative; display: flex; flex: 1; min-width: 260px; max-width: 380px; margin: 0; }
.search-form .search { min-width: 0; max-width: none; width: 100%; }
.search-pop {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); max-height: min(60vh, 440px); overflow-y: auto;
}
.search-pop:empty { display: none; }
.search-opt {
  display: flex; align-items: center; justify-content: space-between; gap: var(--gap-sm);
  min-height: 44px; padding: 8px var(--gap-md); border-bottom: 1px solid var(--border-soft);
  font-size: var(--fs-sm);
}
.search-opt:last-child { border-bottom: 0; }
.search-opt:hover, .search-opt:focus-visible, .search-opt[aria-selected="true"] { background: var(--surface-4); }
.search-opt .nm { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-opt .sub { display: block; font-family: var(--font-mono); font-size: var(--fs-meta); color: var(--muted); font-weight: 400; }
.search-opt .badge { flex: none; }
.search-empty { padding: var(--gap-md); font-size: var(--fs-sm); color: var(--muted); }
.search-empty a { color: var(--gold-lit); font-weight: 500; }
.search-empty a:hover { text-decoration: underline; }

/* ============================================================================
   ESTADO DE CARREGAMENTO HTMX (includeIndicatorStyles = false)
   O conteúdo atual permanece; só esmaece com atraso (sem piscar).
   ========================================================================== */
[aria-busy="true"]:not(.btn):not(button):not(input):not(form):not(body) {
  opacity: .62; cursor: progress; transition: opacity .15s .15s;
}
.btn.htmx-request, .btn[aria-busy="true"], button.htmx-request, button[aria-busy="true"] {
  pointer-events: none; opacity: .72;
}
.btn.htmx-request::after, .btn[aria-busy="true"]::after {
  content: ''; width: 13px; height: 13px; flex: none; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: portal-spin .7s linear infinite;
}
@keyframes portal-spin { to { transform: rotate(360deg); } }

/* ============================================================================
   .bar-w-N — largura da barra de progresso (0–100) sem `style=""`: a CSP
   (default-src 'self') bloqueia atributo style inline. Usado por {% progress_bar %}.
   ========================================================================== */
.bar > i.bar-w-0 { width: 0%; }
.bar > i.bar-w-1 { width: 1%; }
.bar > i.bar-w-2 { width: 2%; }
.bar > i.bar-w-3 { width: 3%; }
.bar > i.bar-w-4 { width: 4%; }
.bar > i.bar-w-5 { width: 5%; }
.bar > i.bar-w-6 { width: 6%; }
.bar > i.bar-w-7 { width: 7%; }
.bar > i.bar-w-8 { width: 8%; }
.bar > i.bar-w-9 { width: 9%; }
.bar > i.bar-w-10 { width: 10%; }
.bar > i.bar-w-11 { width: 11%; }
.bar > i.bar-w-12 { width: 12%; }
.bar > i.bar-w-13 { width: 13%; }
.bar > i.bar-w-14 { width: 14%; }
.bar > i.bar-w-15 { width: 15%; }
.bar > i.bar-w-16 { width: 16%; }
.bar > i.bar-w-17 { width: 17%; }
.bar > i.bar-w-18 { width: 18%; }
.bar > i.bar-w-19 { width: 19%; }
.bar > i.bar-w-20 { width: 20%; }
.bar > i.bar-w-21 { width: 21%; }
.bar > i.bar-w-22 { width: 22%; }
.bar > i.bar-w-23 { width: 23%; }
.bar > i.bar-w-24 { width: 24%; }
.bar > i.bar-w-25 { width: 25%; }
.bar > i.bar-w-26 { width: 26%; }
.bar > i.bar-w-27 { width: 27%; }
.bar > i.bar-w-28 { width: 28%; }
.bar > i.bar-w-29 { width: 29%; }
.bar > i.bar-w-30 { width: 30%; }
.bar > i.bar-w-31 { width: 31%; }
.bar > i.bar-w-32 { width: 32%; }
.bar > i.bar-w-33 { width: 33%; }
.bar > i.bar-w-34 { width: 34%; }
.bar > i.bar-w-35 { width: 35%; }
.bar > i.bar-w-36 { width: 36%; }
.bar > i.bar-w-37 { width: 37%; }
.bar > i.bar-w-38 { width: 38%; }
.bar > i.bar-w-39 { width: 39%; }
.bar > i.bar-w-40 { width: 40%; }
.bar > i.bar-w-41 { width: 41%; }
.bar > i.bar-w-42 { width: 42%; }
.bar > i.bar-w-43 { width: 43%; }
.bar > i.bar-w-44 { width: 44%; }
.bar > i.bar-w-45 { width: 45%; }
.bar > i.bar-w-46 { width: 46%; }
.bar > i.bar-w-47 { width: 47%; }
.bar > i.bar-w-48 { width: 48%; }
.bar > i.bar-w-49 { width: 49%; }
.bar > i.bar-w-50 { width: 50%; }
.bar > i.bar-w-51 { width: 51%; }
.bar > i.bar-w-52 { width: 52%; }
.bar > i.bar-w-53 { width: 53%; }
.bar > i.bar-w-54 { width: 54%; }
.bar > i.bar-w-55 { width: 55%; }
.bar > i.bar-w-56 { width: 56%; }
.bar > i.bar-w-57 { width: 57%; }
.bar > i.bar-w-58 { width: 58%; }
.bar > i.bar-w-59 { width: 59%; }
.bar > i.bar-w-60 { width: 60%; }
.bar > i.bar-w-61 { width: 61%; }
.bar > i.bar-w-62 { width: 62%; }
.bar > i.bar-w-63 { width: 63%; }
.bar > i.bar-w-64 { width: 64%; }
.bar > i.bar-w-65 { width: 65%; }
.bar > i.bar-w-66 { width: 66%; }
.bar > i.bar-w-67 { width: 67%; }
.bar > i.bar-w-68 { width: 68%; }
.bar > i.bar-w-69 { width: 69%; }
.bar > i.bar-w-70 { width: 70%; }
.bar > i.bar-w-71 { width: 71%; }
.bar > i.bar-w-72 { width: 72%; }
.bar > i.bar-w-73 { width: 73%; }
.bar > i.bar-w-74 { width: 74%; }
.bar > i.bar-w-75 { width: 75%; }
.bar > i.bar-w-76 { width: 76%; }
.bar > i.bar-w-77 { width: 77%; }
.bar > i.bar-w-78 { width: 78%; }
.bar > i.bar-w-79 { width: 79%; }
.bar > i.bar-w-80 { width: 80%; }
.bar > i.bar-w-81 { width: 81%; }
.bar > i.bar-w-82 { width: 82%; }
.bar > i.bar-w-83 { width: 83%; }
.bar > i.bar-w-84 { width: 84%; }
.bar > i.bar-w-85 { width: 85%; }
.bar > i.bar-w-86 { width: 86%; }
.bar > i.bar-w-87 { width: 87%; }
.bar > i.bar-w-88 { width: 88%; }
.bar > i.bar-w-89 { width: 89%; }
.bar > i.bar-w-90 { width: 90%; }
.bar > i.bar-w-91 { width: 91%; }
.bar > i.bar-w-92 { width: 92%; }
.bar > i.bar-w-93 { width: 93%; }
.bar > i.bar-w-94 { width: 94%; }
.bar > i.bar-w-95 { width: 95%; }
.bar > i.bar-w-96 { width: 96%; }
.bar > i.bar-w-97 { width: 97%; }
.bar > i.bar-w-98 { width: 98%; }
.bar > i.bar-w-99 { width: 99%; }
.bar > i.bar-w-100 { width: 100%; }

/* ============================================================================
   TOASTS — níveis ok / info / warn / danger (app.css só traz o `.toast` base)
   ========================================================================== */
.toast-host { pointer-events: none; max-width: calc(100vw - 2 * var(--gap-md)); }
.toast {
  pointer-events: auto; border-left: 3px solid var(--ok);
  width: max-content; max-width: min(440px, 100%);
}
.toast .toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .toast-x { width: 24px; height: 24px; margin: -4px -6px -4px 4px; flex: none; }
.toast .toast-x svg { width: 12px; height: 12px; color: var(--muted); }
.toast .toast-x:hover svg { color: var(--fg); }
.toast-info { border-left-color: var(--info); }
.toast-info > svg { color: var(--info); }
.toast-warn { border-left-color: var(--warn); }
.toast-warn > svg { color: var(--warn); }
.toast-danger { border-left-color: var(--danger); }
.toast-danger > svg { color: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@media (max-width: 600px) {
  .toast-host { left: var(--gap-md); right: var(--gap-md); bottom: var(--gap-md); align-items: stretch; }
  .toast { width: auto; max-width: none; }
}

/* ── bloqueio de rolagem com modal/gaveta aberta ─────────────────────────── */
body.has-overlay { overflow: hidden; }

/* ── gaveta: fechada fica fora da árvore de acessibilidade (R19) ─────────── */
.drawer { visibility: hidden; transition: transform .22s cubic-bezier(.32, .72, 0, 1), visibility 0s linear .22s; }
.drawer.is-open { visibility: visible; transition-delay: 0s, 0s; }

/* ============================================================================
   MENSAGENS EM LINHA — .notice (erro de formulário, bloqueio, sessão expirada)
   ========================================================================== */
.notice {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); font-size: var(--fs-sm);
}
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.notice-danger { background: var(--danger-soft); border-color: color-mix(in oklch, var(--danger) 38%, transparent); }
.notice-danger svg { color: var(--danger); }
.notice-warn { background: var(--warn-soft); border-color: color-mix(in oklch, var(--warn) 38%, transparent); }
.notice-warn svg { color: var(--warn); }
.notice-info { background: var(--info-soft); border-color: color-mix(in oklch, var(--info) 38%, transparent); }
.notice-info svg { color: var(--info); }

/* erro de campo (contrato §7.3 — `.field-error` sempre visível quando renderizado) */
.field-error { font-size: 11px; color: var(--danger); margin: 0; }

/* ============================================================================
   LOGIN
   ========================================================================== */
.auth-logo-narrow { display: none; width: 168px; height: auto; margin: 0 0 var(--gap-lg); }
.auth-narrow-only { display: none; text-align: center; }
.auth-form { gap: 18px; }
.auth-form .field-pass { position: relative; }
.auth-form .field-pass .input { padding-right: 46px; }
.auth-form .field-pass .btn-icon { position: absolute; right: 4px; top: 4px; width: 36px; height: 36px; }
.auth-form .field-pass .btn-icon { display: grid; place-items: center; }
.btn-icon [data-ico] { display: grid; place-items: center; }
.btn-icon [data-ico="off"] { display: none; }
.btn-icon[aria-pressed="true"] [data-ico="on"] { display: none; }
.btn-icon[aria-pressed="true"] [data-ico="off"] { display: grid; }
.btn-icon [data-ico] svg { width: 18px; height: 18px; }
.auth-form h1 { margin: 0; }
.auth-form .lead-sm { font-size: var(--fs-sm); color: var(--muted); margin-top: 6px; }
.auth-aside .auth-points { padding: 0; margin: var(--gap-lg) 0 0; list-style: none; }
.auth-aside .eyebrow { margin-bottom: 14px; }
@media (max-width: 1080px) {
  .auth-logo-narrow { display: block; }
  .auth-narrow-only { display: block; }
  .auth-main { align-content: center; }
}

/* ============================================================================
   ERROS 403 / 404 / 500 e card de erro HTMX
   ========================================================================== */
.errpage { min-height: 56vh; display: grid; place-items: center; padding: var(--gap-lg) var(--gap-md); }
.errpage-full { min-height: 100vh; }
.errpage-card { width: min(480px, 100%); text-align: center; }
.errpage-card .err-code {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--gold-lit); margin: 0 0 var(--gap-sm);
}
.errpage-card h1 { font-size: var(--fs-h2); margin-bottom: var(--gap-sm); }
.errpage-card p { color: var(--muted); font-size: var(--fs-body); }
.errpage-card .btn { margin-top: var(--gap-lg); }
.errpage-card .errpage-logo { width: 168px; height: auto; margin: 0 auto var(--gap-xl); }

.error-card { text-align: center; padding: var(--gap-lg) var(--gap-md); color: var(--muted); }
.error-card svg { width: 28px; height: 28px; margin: 0 auto var(--gap-sm); color: var(--warn); }
.error-card h3 { color: var(--fg); font-size: var(--fs-body); margin-bottom: 4px; }
.error-card p { font-size: var(--fs-sm); }
.error-card .btn { margin-top: var(--gap-md); }

/* ── .empty com ação ─────────────────────────────────────────────────────── */
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--gap-sm); margin-top: var(--gap-md); }

/* ============================================================================
   .dl — lista de definição (rótulo / valor), usada nas fichas
   ========================================================================== */
.dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 11px 20px; font-size: var(--fs-sm); }
.dl dt { color: var(--muted); font-size: var(--fs-meta); white-space: nowrap; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dl dd { margin-bottom: var(--gap-sm); }
}

/* ============================================================================
   SELEÇÃO DE LINHAS e .bulkbar (barra de ações em lote)
   ========================================================================== */
.bulkbar { padding: 10px var(--gap-md); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.bulkbar-in { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--gap-sm); }
.bulkbar .meta b { color: var(--fg); font-family: var(--font-mono); }
.bulkbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* checkbox real (<input type=checkbox>) dentro do `.checkbox` do DS */
.checkbox { position: relative; }
.checkbox > input[type="checkbox"] {
  position: absolute; opacity: 0; width: 18px; height: 18px; margin: 1px 0 0; cursor: inherit;
}
.checkbox > input:checked + .box { background: var(--accent); border-color: var(--accent); }
.checkbox > input:checked + .box svg { opacity: 1; }
.checkbox > input:indeterminate + .box { border-color: var(--accent); }
.checkbox > input:indeterminate + .box::after {
  content: ''; width: 8px; height: 2px; border-radius: 2px; background: var(--accent);
}
.checkbox > input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.checkbox > input:disabled + .box, .checkbox.is-lock .box { opacity: .55; }
.checkbox > input:disabled, .checkbox.is-lock { cursor: not-allowed; }
/* alvo de toque ≥ 44 px dentro de tabela */
.checkbox.is-cell { min-width: 44px; min-height: 44px; align-items: center; justify-content: center; padding: 0; }

/* ============================================================================
   .perm — matriz de permissões (Perfis e auditoria)
   ========================================================================== */
.perm th.c, .perm td.c { text-align: center; width: 112px; }
.perm td.c .checkbox { justify-content: center; padding: 0; display: inline-flex; }
.perm td.c .checkbox.is-lock { cursor: not-allowed; opacity: .55; }
.perm tr.grp td {
  background: var(--bg); font-family: var(--font-mono); font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); padding-top: 14px; padding-bottom: 6px;
}
.perm tbody tr.grp:hover { background: transparent; }
.perm th .ph { display: block; font-family: var(--font-body); font-size: 12px; letter-spacing: 0; text-transform: none; color: var(--fg); font-weight: 600; }
.perm .sens { color: var(--warn); font-family: var(--font-mono); font-size: 10px; margin-left: 6px; }

/* ============================================================================
   RESPONSIVO do shell (≤ 1080 px: a sidebar vira faixa horizontal)
   Os breakpoints são os do app.css (1240 / 1080 / 900); só se acrescenta 600.
   ========================================================================== */
@media (max-width: 1080px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { overflow: visible; min-width: 0; }
  .sidebar-nav { overflow-x: auto; min-width: 0; scrollbar-width: thin; }
  .nav-item { white-space: nowrap; min-height: 44px; width: auto; }
  .nav-group { flex: none; }
  .sidebar-foot { padding: 8px var(--gap-sm); }
  .user-chip { width: auto; padding: 2px; }
  .user-text { display: none; }
}
@media (max-width: 600px) {
  /* faixa de navegação em duas linhas: marca + usuário em cima, menu rolável embaixo */
  .sidebar { flex-wrap: wrap; }
  .sidebar-head { order: 1; }
  .sidebar-foot { order: 2; margin-left: auto; border-left: 0; }
  .sidebar-nav { order: 3; flex: 1 0 100%; border-top: 1px solid var(--border-soft); }
  .topbar { padding: 0 var(--gap-md); gap: var(--gap-sm); }
  .topbar .grow { display: none; }
  .topbar .crumb { flex: 0 1 auto; max-width: 42%; }
  .search-form { min-width: 0; flex: 1 1 120px; max-width: none; }
  .topbar .crumb .crumb-extra { display: none; }
  .topbar .demo-flag { font-size: 9px; padding: 2px 6px; }
}

/* G2 — promovido do slot carteira (e do cofre standalone em 360 px):
   chips largos quebram de linha em vez de empurrar a página. */
.chipset { flex-wrap: wrap; max-width: 100%; }

/* G2 — nas tabelas da carteira a marca lateral vai só na primeira célula (o DS pinta todas as
   células da linha). Atrasado = vermelho; em entrada = azul; atrasado e em entrada: vence o atraso. */
.ct-tbl tr.is-late td, .ct-tbl tr.is-flag td { box-shadow: none; }
.ct-tbl tr.ct-entrada > td:first-child { box-shadow: inset 3px 0 0 var(--info); }
.ct-tbl tr.is-late > td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.ct-tbl tr.is-flag:not(.is-late):not(.ct-entrada) > td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
