/* ------------------------------------------------------------------
   ui-600 — camada final de layout (v6.0.2)

   DESCOBERTA QUE MOTIVOU ESTA VERSÃO
   As folhas system-400 a system-570 prendem 663 regras ao seletor
   `body.ui-system`. Mas `ui-system` não é um nome de camada: é a classe
   do TEMA "seguir o sistema". Quem usa o tema Claro ou Escuro fica sem
   essas 663 regras, das quais cerca de 90% é estrutura pura (layout,
   tamanho de ícone, altura de controle) e não tem relação com cor.

   O resultado, na prática: no tema Claro a barra de histórico perde o
   flex e os botões caem em duas ou três linhas, e 108 ícones perdem
   `fill:none; stroke:currentColor` e viram manchas pretas.

   Esta camada reescreve as regras estruturais SEM depender do tema.
   A especificidade é elevada com `html body` e com a repetição da
   classe, para vencer o `!important` das camadas anteriores em
   qualquer tema, sem precisar duplicar as 663 regras.
   ------------------------------------------------------------------ */

/* ==================================================================
   1. ÍCONES — contorno em vez de mancha preta
   Atinge apenas SVG sem atributo `fill`, que são exatamente os ícones
   de traço. Quem tem `fill` próprio (marca, gráficos) não é tocado,
   e `fill` declarado no próprio <path> continua valendo.
   ================================================================== */
html body .topbar svg:not([fill]),
html body .sidebar svg:not([fill]),
html body .menu-btn svg:not([fill]),
html body .history-button svg:not([fill]),
html body .notification-item svg:not([fill]),
html body .notifications-panel svg:not([fill]),
html body .analytics-view svg:not([fill]),
html body .btn svg:not([fill]),
html body .nav-group-toggle svg:not([fill]),
html body .profile-row svg:not([fill]) {
  fill: none !important;
  stroke: currentColor !important;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==================================================================
   2. BARRA DE HISTÓRICO — voltar, avançar e recentes em uma linha só
   Sem o flex, os botões viram inline-block e quebram a linha.
   ================================================================== */
html body .topbar .topbar-history,
html body nav.topbar-history {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: 2px !important;
  flex: none !important;
  width: auto !important;
  max-width: none !important;
}
html body .topbar-history .history-recent {
  display: flex !important;
  align-items: center !important;
  position: relative !important;
  flex: none !important;
}
html body .topbar-history .history-button.history-button {
  display: inline-grid !important;
  place-items: center !important;
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  cursor: pointer !important;
}
html body .topbar-history .history-button svg {
  width: 18px !important;
  height: 18px !important;
}
html body .topbar-history .history-button[disabled] { opacity: .4 !important; cursor: default !important; }

/* ==================================================================
   3. MENU LATERAL — a lista de navegação é quem rola
   Antes, <nav> era um grid com flex:0 1 auto: ao ficar mais alto que a
   tela, a caixa encolhia mas o conteúdo transbordava e os últimos itens
   passavam por cima do bloco do usuário.
   ================================================================== */
html body .sidebar {
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}
html body .sidebar > .logo,
html body .sidebar > .profile-switcher,
html body .sidebar > .sidebar-collapse-toggle,
html body .sidebar > .nav-tools,
html body .sidebar > .nav-toolbar,
html body .sidebar > .user {
  flex: 0 0 auto !important;
}
html body .sidebar nav {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 6px !important;
}
html body .sidebar nav::-webkit-scrollbar { width: 8px; }
html body .sidebar nav::-webkit-scrollbar-thumb { background: #d9d9e3; border-radius: 99px; }
html body .sidebar nav::-webkit-scrollbar-track { background: transparent; }

html body .sidebar .user {
  position: relative !important;
  z-index: 1 !important;
  margin-top: 0 !important;
  border-top: 1px solid var(--line, #e3e3eb) !important;
  background: var(--surface, #fff) !important;
  padding: 12px 8px max(12px, env(safe-area-inset-bottom)) !important;
  align-items: center !important;
}
html body .sidebar .user > div { min-width: 0 !important; }
html body .sidebar .user strong {
  display: block !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

/* ==================================================================
   4. MARCA x BOTÃO DE RECOLHER
   O botão é absoluto no canto superior direito e o nome passava por
   baixo dele. Em vez de cortar o nome, ele quebra em duas linhas.
   ================================================================== */
html body .sidebar .logo { padding-right: 44px !important; min-width: 0 !important; align-items: flex-start !important; }
html body .sidebar .brand-copy { min-width: 0 !important; overflow: hidden !important; }
html body .sidebar .brand-copy strong {
  display: block !important;
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  line-height: 1.25 !important;
  text-overflow: clip !important;
}
html body .sidebar .brand-copy small { display: block !important; overflow-wrap: anywhere !important; line-height: 1.3 !important; }
html body.sidebar-mode-compact .sidebar .logo { padding-right: 8px !important; }

/* ==================================================================
   5. TABELAS EM MODO CARTÃO (celular)
   system-530 e system-540 montam a linha em DUAS colunas e o
   system-550 em UMA. Com as duas ativas abaixo de 700 px, cada célula
   ficava com ~93 px e o rótulo sozinho consumia tudo, sobrando 0 px
   para o valor: era isso que cortava contrato, saldo e parcelas.
   ================================================================== */
html body .table-wrap table td,
html body .table-wrap table td:before,
html body .table-wrap table th { overflow-wrap: anywhere !important; word-break: normal !important; }
html body .table-wrap { max-width: 100% !important; }

@media (max-width: 900px) {
  html body table.mobile-card-table.mobile-card-table tbody tr {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }
  /* O responsive-140 ainda manda a última célula para a coluna 2 e a
     linha 1, o que criava uma segunda coluna implícita. */
  html body table.mobile-card-table.mobile-card-table tbody tr > td,
  html body table.mobile-card-table.mobile-card-table tbody tr > td:first-child,
  html body table.mobile-card-table.mobile-card-table tbody tr > td:last-child {
    grid-column: 1 !important;
    grid-row: auto !important;
  }
  html body table.mobile-card-table.mobile-card-table tbody tr > td {
    display: grid !important;
    grid-template-columns: minmax(84px, 34%) minmax(0, 1fr) !important;
    gap: 10px !important;
    align-items: baseline !important;
    width: auto !important;
    text-align: left !important;
  }
  html body table.mobile-card-table.mobile-card-table tbody tr > td.right,
  html body table.mobile-card-table.mobile-card-table tbody tr > td.amount { text-align: left !important; }
  html body table.mobile-card-table.mobile-card-table tbody tr > td[colspan],
  html body table.mobile-card-table.mobile-card-table tbody tr > td.description { grid-template-columns: 1fr !important; }
}

/* ==================================================================
   6. ÁREAS CLICÁVEIS
   "Sair" tinha 17x13 px e os grupos do menu 27 px de altura.
   ================================================================== */
html body .link-button,
html body summary.link-button {
  display: inline-flex !important;
  align-items: center !important;
  min-height: 24px !important;
}
html body .nav-group-toggle.nav-group-toggle { min-height: 32px !important; height: auto !important; }
html body .nav-tools button { min-width: 32px !important; min-height: 32px !important; }
html body .analytics-switch button { min-height: 30px !important; padding-inline: 10px !important; }
html body .analytics-expand,
html body .sidebar-collapse-toggle { min-width: 32px !important; min-height: 32px !important; }
html body .nav-move-buttons button { min-width: 32px !important; }

@media (pointer: coarse), (max-width: 900px) {
  html body .link-button,
  html body summary.link-button { min-height: 40px !important; }
  html body .nav-group-toggle.nav-group-toggle { min-height: 40px !important; }
  html body .nav-tools button { min-width: 40px !important; min-height: 40px !important; }
  html body .analytics-switch button { min-height: 36px !important; padding-inline: 12px !important; }
  html body .analytics-expand,
  html body .sidebar-collapse-toggle { min-width: 40px !important; min-height: 40px !important; }
  html body .nav-move-buttons button { min-width: 44px !important; min-height: 44px !important; }
  html body .topbar-history .history-button.history-button { width: 42px !important; min-width: 42px !important; height: 42px !important; }
  /* `:not(#_)` eleva a especificidade sem depender de ID nenhum. É
     necessário porque regras como `.profile-switcher select` fixam
     `height:30px!important` e venceriam um seletor sem classe. */
  html body select:not(#_),
  html body input:not([type=checkbox]):not([type=radio]):not(#_),
  html body textarea:not(#_),
  html body .btn:not(#_),
  html body a.btn:not(#_),
  html body button.btn:not(#_) {
    min-height: 40px !important;
    height: auto !important;
  }
  html body .btn:not(#_),
  html body a.btn:not(#_),
  html body button.btn:not(#_) {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* Rótulo longo não pode ser espremido a ponto de cortar o texto. */
html body .btn { flex: none; }
html body .panel-head .form-actions .btn,
html body .form-actions .btn { min-width: fit-content !important; }

/* ==================================================================
   7. FAIXAS QUE ROLAM NA HORIZONTAL
   Havia conteúdo além da borda sem nenhum sinal de que a faixa rola.
   ================================================================== */
html body .settings-tabs,
html body .analytics-stats,
html body .nav-chips,
html body .tab-strip {
  overflow-x: auto !important;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
html body .settings-tabs::-webkit-scrollbar,
html body .analytics-stats::-webkit-scrollbar,
html body .nav-chips::-webkit-scrollbar,
html body .tab-strip::-webkit-scrollbar { height: 0; }
@media (max-width: 900px) {
  html body .settings-tabs,
  html body .analytics-stats,
  html body .nav-chips,
  html body .tab-strip {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
    padding-right: 14px !important;
  }
}

/* ==================================================================
   8. SEM ROLAGEM HORIZONTAL DA PÁGINA, em nenhuma largura
   ================================================================== */
html, body { max-width: 100% !important; overflow-x: hidden !important; }
html body .main { min-width: 0 !important; }
html body .panel,
html body .kpi,
html body .profile-row { min-width: 0 !important; }
html body .panel code,
html body .hash,
html body .context-note code { overflow-wrap: anywhere !important; }

/* ==================================================================
   9. BARRA SUPERIOR em telas estreitas
   Com os controles em tamanho de toque, menu + histórico + título +
   ações não cabem lado a lado. Em vez de esconder funções, a barra
   passa a ocupar duas linhas.
   ================================================================== */
@media (max-width: 720px) {
  html body .topbar:not(#_) {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 8px !important;
    row-gap: 6px !important;
  }
  html body .topbar:not(#_) > .menu-btn { order: 1 !important; flex: none !important; }
  html body .topbar:not(#_) > .topbar-history { order: 2 !important; flex: none !important; }
  html body .topbar:not(#_) > .topbar-actions {
    order: 3 !important;
    flex: 1 1 auto !important;
    justify-content: flex-end !important;
    min-width: 0 !important;
  }
  html body .topbar:not(#_) > .topbar-title { order: 4 !important; flex: 1 1 100% !important; min-width: 0 !important; }
  html body .topbar:not(#_) > .topbar-title h1 { font-size: 20px !important; line-height: 1.2 !important; overflow-wrap: anywhere !important; }
}

/* ==================================================================
   10. MENU FORA DA TELA (celular)
   ================================================================== */
@media (max-width: 1100px) {
  html body .sidebar { height: 100dvh !important; max-height: 100dvh !important; padding-bottom: 0 !important; }
  html body.menu-open { overflow: hidden !important; }
}

/* Respeita quem pediu menos movimento. */
@media (prefers-reduced-motion: reduce) {
  html body .sidebar,
  html body .sidebar nav { scroll-behavior: auto !important; }
}
