/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* ---- Ícones de linha usados fora da sidebar (badges, banners, títulos) ---- */
.icon-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-inline svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.icon-badge svg {
  width: 22px;
  height: 22px;
}

.btn-primary {
  background: var(--gradient-brand);
  color: var(--text-inverse);
  box-shadow: var(--shadow-neon-brand-sm);
}

.btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: var(--shadow-neon-brand);
}

.btn-ghost {
  background: transparent;
  color: var(--text-body);
  border-color: var(--border-subtle);
}

.btn-ghost:hover {
  background: var(--overlay-soft);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.btn-danger:hover {
  filter: brightness(1.15);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--fs-xs);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Visualmente igual a :disabled, mas continua clicável — usado quando o clique precisa
   disparar feedback (toast) explicando por que a ação está bloqueada, em vez de simplesmente
   não fazer nada (o que o atributo disabled nativo faz, sem chance de explicar o motivo). */
.btn-soft-disabled {
  opacity: 0.5;
}

.btn-soft-disabled:hover {
  filter: none;
  box-shadow: var(--shadow-neon-brand-sm);
}

/* ---- Icon quick-action buttons ---- */
.icon-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: var(--space-3);
}

.icon-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-card-raised);
  color: var(--text-body);
  cursor: pointer;
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease;
}

.icon-action:hover {
  border-color: var(--color-primary-600);
  background: var(--surface-card);
  transform: translateY(-2px);
}

.icon-action .icon-badge {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-brand);
  color: #fff;
  font-size: 16px;
}

/* ---- Page title row (usado no admin e no portal) ---- */
.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.page-title-row p {
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ---- Cards ---- */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.card-tight {
  padding: var(--space-4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.card-clickable {
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.card-clickable:hover {
  box-shadow: var(--shadow-glow), var(--shadow-neon-brand-sm);
  border-color: var(--color-primary-700);
  transform: translateY(-2px);
}

/* ---- Grid helpers ---- */
.grid {
  display: grid;
  gap: var(--space-5);
}

.grid-cards {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.grid-kpi {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

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

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---- Avatars ---- */
.avatar-square {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--gradient-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-sm);
  flex-shrink: 0;
}

/* ---- Status pill ---- */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill[data-status="aguardando_base"] {
  background: var(--overlay-mid);
  color: var(--text-muted);
}

.status-pill[data-status="base_importada"] {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.status-pill[data-status="em_classificacao"] {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.status-pill[data-status="em_analise"] {
  background: rgba(251, 90, 46, 0.16);
  color: var(--color-primary-bright);
}

.status-pill[data-status="fechamento_realizado"] {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.status-pill[data-status="publicado"] {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* ---- Badges (roles / small labels) ---- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: var(--overlay-mid);
  color: var(--text-body);
}

.badge-primary {
  background: rgba(251, 90, 46, 0.16);
  color: var(--color-primary-bright);
}

/* ---- KPI tiles ---- */
.kpi-tile {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}

.kpi-label {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  letter-spacing: 0.01em;
}

.kpi-delta {
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-top: var(--space-1);
}

.kpi-delta.up {
  color: var(--color-success);
}

.kpi-delta.down {
  color: var(--color-neon);
}

.kpi-sparkline {
  margin-top: var(--space-3);
  display: block;
  width: 100%;
  height: 32px;
}

.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
}

.kpi-icon svg {
  width: 18px;
  height: 18px;
}

/* ---- Donut (rosca) com legenda ---- */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-wrap: wrap;
}

.donut-legend {
  flex: 1;
  min-width: 160px;
}

.donut-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: var(--fs-sm);
}

.donut-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.donut-legend-label {
  flex: 1;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.donut-legend-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.donut-segment {
  transition: filter 0.15s ease, opacity 0.15s ease;
}

.donut-segment:hover {
  filter: brightness(1.2);
}

.donut-wrap:has(.donut-segment:hover) .donut-segment:not(:hover) {
  opacity: 0.35;
}

.radial-hoverable {
  cursor: pointer;
}

.radial-hoverable:hover svg circle:last-child {
  filter: brightness(1.3) !important;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  font-size: var(--fs-sm);
}

.table th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--surface-card-raised);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr.total-row td {
  font-weight: 700;
  background: var(--surface-card-raised);
}

.table tr.total-row-strong td {
  font-weight: 700;
  background: rgba(251, 90, 46, 0.1);
  color: var(--color-primary-300);
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table tbody tr:hover {
  background: var(--overlay-faint);
}

/* ---- Open items list (contas a receber / pagar) ---- */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-sm);
}

.list-row:last-child {
  border-bottom: none;
}

.list-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.list-row-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-row-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  flex-shrink: 0;
}

/* ---- Sidebar / Topbar shell ---- */
#app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface-sidebar);
  color: var(--color-gray-700);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-3);
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border-subtle);
  transition: width 0.18s ease;
}

.sidebar-collapse-btn {
  position: absolute;
  top: 26px;
  right: -12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-card-raised);
  border: 1px solid var(--border-subtle);
  color: var(--color-gray-500);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  z-index: 6;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-collapse-btn:hover {
  border-color: var(--color-neon);
  color: var(--text-body);
  box-shadow: var(--shadow-neon-sm);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-6);
  color: var(--text-body);
  white-space: nowrap;
}

.sidebar-brand-textwrap {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  overflow: hidden;
}

.sidebar-brand-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-subtitle {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--color-gray-600);
  transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-link-icon svg {
  width: 17px;
  height: 17px;
  display: block;
}

.sidebar-link:hover .sidebar-link-icon,
.sidebar-link.active .sidebar-link-icon {
  color: currentColor;
}

.sidebar-link-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Sidebar retraída ---- */
body.sidebar-collapsed .sidebar {
  width: 76px;
}

body.sidebar-collapsed .sidebar .sidebar-link-text,
body.sidebar-collapsed .sidebar .sidebar-section-label,
body.sidebar-collapsed .sidebar-brand-textwrap {
  display: none;
}

body.sidebar-collapsed .sidebar .sidebar-link-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: var(--overlay-soft);
}

body.sidebar-collapsed .sidebar .sidebar-link-icon svg {
  width: 16px;
  height: 16px;
}

body.sidebar-collapsed .sidebar .sidebar-link.active .sidebar-link-icon {
  background: var(--overlay-strong);
}

body.sidebar-collapsed .sidebar .sidebar-link {
  justify-content: center;
  padding: 8px 4px;
}

body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar-brand-logo {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: block;
  filter: drop-shadow(var(--shadow-neon-brand-sm));
}

.sidebar-section-label {
  font-family: var(--font-display);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--color-gray-600);
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-gray-700);
  cursor: pointer;
}

.sidebar-link:hover {
  background: var(--surface-sidebar-active);
  color: var(--text-body);
}

.sidebar-link.active {
  background: var(--gradient-brand);
  color: var(--text-inverse);
  box-shadow: var(--shadow-neon-brand-sm);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-7);
  background: var(--surface-page);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 5;
}

/* ---- Seletor de competência (topbar admin e portal) ---- */
.competencia-picker {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.competencia-picker select {
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-body);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.competencia-picker select:hover {
  background: var(--overlay-soft);
  border-color: var(--border-strong);
}

.competencia-picker select option {
  color: var(--text-body);
  background: var(--surface-card);
  font-weight: 500;
}

.content {
  padding: var(--space-7);
  flex: 1;
}

.content-narrow {
  max-width: 960px;
}

/* ---- Alternador de tema (topbar) ---- */
.theme-toggle-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: var(--surface-card-raised);
  color: var(--text-body);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.theme-toggle-btn:hover {
  border-color: var(--color-neon);
  box-shadow: var(--shadow-neon-sm);
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* ---- Session pill (topbar) ---- */
.session-pill {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 6px 8px 6px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  cursor: pointer;
}

.session-pill:hover {
  border-color: var(--border-strong);
}

.session-pill .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
}

.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text-body);
}

.tab.active {
  color: var(--color-primary-bright);
  border-bottom-color: var(--color-primary);
}

/* ---- Forms ---- */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-family: var(--font-display);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-card-raised);
  color: var(--text-body);
}

.form-field input::placeholder,
.form-field textarea::placeholder {
  color: var(--text-muted);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--color-primary-bright);
  box-shadow: 0 0 0 3px rgba(251, 54, 2, 0.16), var(--shadow-neon-brand-sm);
}

.form-field textarea {
  resize: vertical;
  min-height: 90px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

/* Grade de lançamento manual por categoria (DRE) — usa auto-fill (não auto-fit) para que a
   largura das colunas fique igual em todas as linhas, mesmo quando uma delas tem poucos itens
   (ex.: 3 categorias de receita vs. 9 de dedução); sem isso a linha com menos itens esticava e
   ficava com colunas bem mais largas que as outras. Rótulos longos são truncados numa linha só
   (com title= mostrando o nome completo) para as caixas de valor ficarem sempre alinhadas. */
.form-grid-manual {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}

.form-grid-manual .form-field label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Modal / toast ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: var(--space-5);
}

.modal {
  background: var(--surface-card-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.toast-stack {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 60;
}

.toast {
  background: var(--surface-card-raised);
  border: 1px solid var(--border-strong);
  color: var(--text-body);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-md);
  animation: toast-in 0.15s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: var(--space-9) var(--space-5);
  color: var(--text-muted);
}

/* ---- Radar ---- */
.radar-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-sm);
}

.radar-item:last-child {
  border-bottom: none;
}

.radar-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
}

.radar-dot.green {
  background: var(--color-success);
  box-shadow: 0 0 8px rgba(47, 216, 138, 0.6);
}

.radar-dot.yellow {
  background: var(--color-warning);
  box-shadow: 0 0 8px rgba(250, 178, 25, 0.6);
}

.radar-dot.red {
  background: var(--color-neon);
  box-shadow: var(--shadow-neon-sm);
}

/* ---- Filter bar ---- */
.filter-bar {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
  align-items: center;
}

.filter-bar select,
.filter-bar input {
  font-size: var(--fs-sm);
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-card-raised);
  color: var(--text-body);
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-field input {
  width: 100%;
  padding-left: 34px;
}

.search-field::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-muted);
  border-radius: 50%;
  box-shadow: 5px 5px 0 -3px var(--text-muted);
}

/* ---- Ranking bars (maiores despesas, composição) ---- */
.bar-row {
  display: grid;
  grid-template-columns: 200px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.bar-track {
  height: 20px;
  background: var(--surface-card-raised);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--gradient-brand);
  border-radius: 4px;
  box-shadow: var(--shadow-neon-brand-sm);
}

.bar-label {
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-value {
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* ---- Barra de progresso (indicadores da Visão Geral) ---- */
.progress-row {
  margin-bottom: var(--space-4);
}

.progress-row:last-child {
  margin-bottom: 0;
}

.progress-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}

.progress-row-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-body);
}

.progress-row-value {
  font-size: var(--fs-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--overlay-mid);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--gradient-brand);
}

/* ---- Linha de pendência (título + subtítulo + valor + badge), usada na Visão Geral ---- */
.pendencia-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.pendencia-row:last-child {
  border-bottom: none;
}

.pendencia-row-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pendencia-row-icon svg {
  width: 16px;
  height: 16px;
}

.pendencia-row-main {
  flex: 1;
  min-width: 0;
}

.pendencia-row-title {
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pendencia-row-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pendencia-row-end {
  text-align: right;
  flex-shrink: 0;
}

.pendencia-row-value {
  font-weight: 600;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.pendencia-row-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 3px;
  white-space: nowrap;
}

/* ---- Seletor de período (Mensal / Trimestral / Anual) ---- */
.chart-toggle {
  display: inline-flex;
  background: var(--overlay-mid);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.chart-toggle button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 5px 12px;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.chart-toggle button.active {
  background: var(--surface-card-raised);
  color: var(--text-body);
  box-shadow: var(--shadow-neon-sm);
}

/* ---- Anel radial (KPI de margem) ---- */
.kpi-radial-wrap {
  margin-top: var(--space-3);
  display: flex;
  justify-content: center;
}

/* ---- Tooltip de gráfico (sparkline, fluxo de caixa, evolução da margem) ---- */
.chart-hit {
  cursor: pointer;
}

.chart-tooltip {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  pointer-events: none;
  background: var(--surface-card-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-xs);
  color: var(--text-body);
  box-shadow: var(--shadow-md), var(--shadow-neon-brand-sm);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  white-space: nowrap;
  line-height: 1.6;
}

.chart-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip .tip-title {
  display: block;
  font-weight: 700;
  color: var(--text-body);
  margin-bottom: 3px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border-subtle);
}

.chart-tooltip .tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-tooltip .tip-row strong {
  margin-left: auto;
  padding-left: 10px;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip .tip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

/* ---- Ambient glow background (auth screens, hero) ---- */
.glow-backdrop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}

.glow-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
}

.glow-blob.b1 {
  width: 480px;
  height: 480px;
  background: var(--glow-1);
  top: -120px;
  left: -80px;
}

.glow-blob.b2 {
  width: 420px;
  height: 420px;
  background: var(--glow-2);
  bottom: -140px;
  left: 20%;
}

.glow-blob.b3 {
  width: 460px;
  height: 460px;
  background: var(--glow-3);
  bottom: -160px;
  right: -100px;
}

/* ---- Odin AI (assistente do portal do cliente) ---- */
.odin-ai-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-neon-brand-sm), var(--shadow-md);
  z-index: 1000;
  transition: transform 0.15s ease;
}

.odin-ai-bubble:hover {
  transform: scale(1.06);
}

.odin-ai-bubble svg {
  width: 26px;
  height: 26px;
}

.odin-ai-panel {
  position: fixed;
  right: 24px;
  bottom: 92px;
  width: 360px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}

.odin-ai-header {
  background: var(--gradient-brand);
  color: #fff;
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.odin-ai-header-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  letter-spacing: 0.01em;
}

.odin-ai-header-title svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.odin-ai-header-sub {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 400;
  opacity: 0.85;
}

.odin-ai-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  display: flex;
  opacity: 0.85;
}

.odin-ai-close:hover {
  opacity: 1;
}

.odin-ai-close svg {
  width: 18px;
  height: 18px;
}

.odin-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.odin-ai-msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  line-height: 1.45;
  white-space: pre-wrap;
}

.odin-ai-msg-bot {
  align-self: flex-start;
  background: var(--overlay-mid);
  color: var(--text-body);
  border-bottom-left-radius: 4px;
}

.odin-ai-msg-user {
  align-self: flex-end;
  background: var(--gradient-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.odin-ai-suggestions {
  padding: 0 var(--space-4) var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.odin-ai-suggestion-btn {
  font-size: var(--fs-xs);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-body);
  cursor: pointer;
  font-family: inherit;
}

.odin-ai-suggestion-btn:hover {
  background: var(--overlay-soft);
}

.odin-ai-input-row {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.odin-ai-input-row input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: var(--fs-sm);
  padding: 9px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-card-raised);
  color: var(--text-body);
}

.odin-ai-input-row button {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--gradient-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.odin-ai-input-row button svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 480px) {
  .odin-ai-panel {
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
  }

  .odin-ai-bubble {
    right: 16px;
    bottom: 16px;
  }
}

/* ==========================================================================
   Responsivo — mobile/tablet retrato. A sidebar vira uma gaveta (fixed,
   off-canvas) aberta pelo botão de menu no topbar em vez de ficar fixa ao
   lado do conteúdo; tudo que era grade de 2-3 colunas empilha em 1 coluna.
   Um único breakpoint cobre celular e tablet retrato — não há necessidade
   de um layout intermediário nesta fase.
   ========================================================================== */

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-body);
  cursor: pointer;
}

.mobile-menu-btn svg {
  width: 18px;
  height: 18px;
}

/* Fundo escurecido atrás da gaveta — cobre o conteúdo inteiro e fecha a gaveta ao ser tocado.
   Só existe visualmente abaixo do breakpoint mobile (ver media query); em telas largas fica
   sempre display:none, então não atrapalha nada mesmo estando sempre no DOM. */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 38;
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }

  /* O botão de retrair/expandir desktop não faz sentido na gaveta mobile — quem abre/fecha é
     sempre o botão de menu do topbar + o fundo escurecido. */
  .sidebar-collapse-btn {
    display: none;
  }

  #app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 264px;
    max-width: 82vw;
    height: 100vh;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 40;
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  body.mobile-nav-open .sidebar-backdrop {
    display: block;
  }

  /* A gaveta mobile sempre abre "expandida" (com texto), mesmo que o usuário tenha deixado a
     sidebar retraída (ícones só) da última vez que usou em desktop — os dois estados são
     independentes por design (um é lido de localStorage, o outro nunca persiste). */
  body.sidebar-collapsed .sidebar {
    width: 264px !important;
  }

  body.sidebar-collapsed .sidebar .sidebar-link-text,
  body.sidebar-collapsed .sidebar .sidebar-section-label,
  body.sidebar-collapsed .sidebar-brand-textwrap,
  body.sidebar-collapsed .sidebar .portal-client-name {
    display: block !important;
  }

  body.sidebar-collapsed .sidebar .sidebar-link-icon {
    width: 20px !important;
    height: 20px !important;
    background: none !important;
  }

  body.sidebar-collapsed .sidebar .sidebar-link-icon svg {
    width: 17px !important;
    height: 17px !important;
  }

  body.sidebar-collapsed .sidebar .sidebar-link {
    justify-content: flex-start !important;
    padding: 10px var(--space-3) !important;
  }

  body.sidebar-collapsed .sidebar-brand,
  body.sidebar-collapsed .sidebar .portal-client-brand {
    justify-content: flex-start !important;
    padding-left: var(--space-3) !important;
    padding-right: var(--space-3) !important;
  }

  .main-col {
    width: 100%;
    min-width: 0;
  }

  .topbar {
    height: auto;
    min-height: var(--topbar-height);
    padding: var(--space-3) var(--space-4);
    flex-wrap: wrap;
    row-gap: var(--space-3);
  }

  .content {
    padding: var(--space-4);
  }

  /* Toda grade ad-hoc (2 ou 3 colunas via style="grid-template-columns:...") empilha em 1
     coluna — cobre KPIs, gráficos lado a lado, cards de cliente, formulários de categoria,
     bases de importação, etc. sem precisar editar cada página individualmente.
     minmax(0, 1fr) — não só "1fr" — porque uma coluna "1fr" sozinha não encolhe abaixo da
     largura mínima do conteúdo (tabelas, gráficos), o que estourava a tela pro lado. */
  .grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .client-detail-header {
    flex-wrap: wrap;
  }

  .page-title-row h2 {
    font-size: var(--fs-lg);
  }

  .modal {
    padding: var(--space-5);
  }

  /* .list-row (contas a receber/pagar, categorias) tem selects com min-width fixo
     (220px/200px) lado a lado — não cabe em 375px. Empilha cada div-filho em uma
     linha própria e deixa os selects ocuparem a largura toda. */
  .list-row {
    flex-wrap: wrap;
  }

  .list-row > div {
    flex: 1 1 100%;
    min-width: 0;
  }

  .list-row select {
    width: 100%;
    min-width: 0 !important;
  }

  /* Banner "Vendo como [cliente]" (modo impersonation) tem padding largo de desktop e
     flex-wrap:nowrap inline — o texto ficava espremido contra o botão "Voltar para o Admin".
     Deixa o texto quebrar em 2 linhas e o botão cair pra linha de baixo em telas estreitas. */
  .impersonation-banner {
    padding: var(--space-2) var(--space-3) !important;
    flex-wrap: wrap !important;
    white-space: normal !important;
  }

  .impersonation-banner span {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  .impersonation-banner button {
    margin-left: 0 !important;
  }
}

@media (max-width: 480px) {
  /* Nome + cargo de quem está logado cabem bem em tablet; no celular, o cargo já é redundante
     (aparece nos outros lugares do app) e sobra pouco espaço no topbar quebrado em duas linhas. */
  .session-role-label {
    display: none;
  }
}
