:root {
  --bg: #F4F5F7;
  --surface: #ffffff;
  --text: #17263B;
  --text-light: #526173;
  --muted: #526173;
  --primary: #152941;
  --primary-hover: #1f3b5c;
  --gold: #C3A66D;
  --gold-hover: #d2b985;
  --line: #e3e6eb;
  --border: var(--line);
  --ok: #276449;
  --bad: #a33e38;
  --warn: #855f19;
  --info: #285b91;
  --shadow: 0 7px 24px rgba(21, 41, 65, 0.07);
}
[data-theme="dark"] {
  --bg: #101b2a;
  --surface: #1b2b3e;
  --text: #f0f3f7;
  --text-light: #b5c3d3;
  --muted: #b5c3d3;
  --line: #3a4c61;
  --ok: #80d5a9;
  --bad: #ff9e9c;
  --warn: #f4ca79;
  --info: #a3cfff;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 3px solid #8b6b34; outline-offset: 2px; }
/* Login & Pending Shell */
#login-view, #pending-view {
  position: absolute; inset: 0;
  display: flex; justify-content: center; align-items: center;
  background: var(--bg); z-index: 1000;
}
.login-card {
  background: var(--surface); padding: 32px; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); width: 100%; max-width: 400px;
}
.login-card h2 { margin-top: 0; color: var(--primary); }
[data-theme="dark"] .login-card h2 { color: var(--text); }
.login-logo { display: block; width: 100%; max-width: 300px; height: auto; margin: -28px auto -6px; }
/* App Shell */
aside.drawer {
  width: 260px; flex: 0 0 260px; background: var(--primary); color: #fff;
  display: flex; flex-direction: column; transition: transform 0.3s ease;
  z-index: 100;
}
.brand {
  position: relative; height: 96px; flex: 0 0 96px; overflow: hidden;
  background: #fff; border-bottom: 3px solid var(--gold);
}
.brand-logo { position: absolute; width: 280px; max-width: none; height: auto; left: -24px; top: -35px; }
.nav-scroll { flex: 1; overflow-y: auto; padding: 10px; }
.navgroup {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.11em;
  color: #b4c1d0; padding: 17px 10px 6px; margin-top: 5px;
}
button.nav {
  display: flex; align-items: center; width: 100%; min-height: 42px; padding: 9px 11px;
  background: transparent; border: none; border-left: 3px solid transparent; border-radius: 6px;
  color: #e6edf5; text-align: left; font-size: 13px; cursor: pointer; transition: background 0.2s ease;
}
button.nav:hover { background: rgba(255,255,255,0.09); color: #fff; }
button.nav.active { background: rgba(255,255,255,0.13); color: #fff; border-left-color: var(--gold); font-weight: 650; }
.nav .ico { width: 25px; flex: 0 0 25px; text-align: center; margin-right: 8px; color: var(--gold); }
.content-area { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
#menu-backdrop { display: none; }
header.top {
  min-height: 72px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 10px 28px; flex-shrink: 0; z-index: 50;
}
.top-context { display: flex; align-items: center; min-width: 0; }
.crumb { font-size: 13px; font-weight: 600; line-height: 1.4; }
.crumb .subtle { margin: 0 5px; color: var(--text-light); }
.topright { display: flex; align-items: center; justify-content: flex-end; gap: 14px; min-width: 0; }
.user-display { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-light); }
.company-context { display: flex; flex-direction: column; gap: 3px; min-width: 180px; font-size: 10px; font-weight: 650; color: var(--text-light); }
select.top-select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); font-size: 13px;
}
.menu-toggle { display: none; }
main.workspace { flex: 1; overflow-y: auto; padding: 28px 36px; min-width: 0; }
/* Components */
.heading { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.heading h1 { margin: 0 0 8px 0; font-size: 24px; color: var(--text); }
.heading .subtle { color: var(--text-light); }
.panel, .metric { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel h2 { margin: 0 0 20px 0; font-size: 16px; color: var(--text); border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 15px; }
.metric { margin-bottom: 0; }
.metriclabel, .metricnote { color: var(--text-light); font-size: 12px; }
.metricvalue { color: var(--text); font-size: 23px; font-weight: 700; margin: 7px 0; }
.twocol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.btn { min-height: 38px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; transition: background 0.2s ease, border-color 0.2s ease; }
.btn:hover { border-color: var(--text-light); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
th { padding: 12px 14px; background: var(--bg); color: var(--text-light); font-weight: 650; border-bottom: 1px solid var(--line); }
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.status { display: inline-block; padding: 4px 8px; border-radius: 6px; font-size: 11px; font-weight: 650; text-transform: uppercase; }
.status.ok { background: rgba(39, 100, 73, 0.13); color: var(--ok); }
.status.bad { background: rgba(163, 62, 56, 0.13); color: var(--bad); }
.status.warn { background: rgba(133, 95, 25, 0.14); color: var(--warn); }
.status.info { background: rgba(40, 91, 145, 0.13); color: var(--info); }
input[type="text"], input[type="date"], input[type="month"], input[type="number"], input[type="password"], input[type="email"], select, textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); font-size: 14px;
}
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-light); }
.flex-row { display: flex; flex-wrap: wrap; gap: 15px; }
.flex-row > .btn { align-self: flex-end; }
.subtle { color: var(--text-light); }
.notice, [role="alert"]:not(:empty) { overflow-wrap: anywhere; }
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--primary); color: #fff;
  padding: 12px 24px; border-radius: 6px; font-size: 14px; box-shadow: var(--shadow);
  transform: translateY(100px); opacity: 0; transition: all 0.3s; z-index: 9999;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--bad); }
.skeleton { background: var(--line); border-radius: 4px; height: 20px; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 0.3; } 100% { opacity: 0.6; } }
@media (max-width: 1050px) {
  .user-display { max-width: 130px; }
  main.workspace { padding: 24px; }
}
@media (max-width: 820px) {
  aside.drawer { position: fixed; inset: 0 auto 0 0; height: 100dvh; transform: translateX(-100%); box-shadow: 12px 0 30px rgba(0,0,0,0.18); }
  body.menu-open aside.drawer { transform: translateX(0); }
  body.menu-open #menu-backdrop { display: block; position: fixed; inset: 0; z-index: 90; border: 0; background: rgba(10,25,41,0.58); }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 42px; width: 42px; height: 42px; margin-right: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--primary); font-size: 19px; }
  .user-display { display: none; }
  header.top { padding: 10px 16px; }
  .company-context { min-width: 150px; }
}
@media (max-width: 560px) {
  header.top { align-items: flex-start; flex-direction: column; gap: 8px; }
  .topright { width: 100%; justify-content: space-between; }
  .company-context { flex: 1; }
  main.workspace { padding: 16px; }
  .panel { padding: 16px; }
  .twocol { grid-template-columns: 1fr; }
  .login-card { margin: 16px; padding: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  aside.drawer, .btn, button.nav, .toast { transition: none; }
  .skeleton { animation: none; }
}
/* Etapa 2: telas financeiras e contábeis. Sem alterar o comportamento dos módulos. */
.module-screen { min-width: 0; }
.module-screen > .heading { margin-bottom: 20px; }
.module-screen > .heading p { margin: 0; line-height: 1.5; }
.module-screen .panel h3 { margin: 0 0 16px; color: var(--text); font-size: 17px; }
.module-screen .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 2px 16px; }
.module-screen .checkbox-field { display: flex; align-items: center; gap: 9px; padding-top: 22px; }
.module-screen .checkbox-field input { width: auto; margin: 0; }
.module-screen .checkbox-field label { margin: 0; color: var(--text); }
.module-screen .data-region { min-height: 42px; }
.module-screen .row-actions, .module-screen .upload-controls, .module-screen .transaction-head,
.module-screen .history-row, .module-screen .form-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.module-screen .transaction-head, .module-screen .history-row, .module-screen .form-actions { justify-content: space-between; }
.module-screen .upload-controls input[type="file"] { width: auto; max-width: 100%; }
.module-socios #soc-evidencia-arquivo { display: block; width: 100%; max-width: 100%; min-width: 0; }
.module-screen .transaction-card { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 16px; margin-bottom: 13px; }
.module-screen .transaction-card .subtle { margin-top: 4px; overflow-wrap: anywhere; }
.module-screen .suggestions-table { margin-top: 12px; min-width: 580px; }
.module-screen .history-row { padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.module-screen .stats-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.module-screen .metric.compact { display: flex; align-items: center; gap: 8px; padding: 10px 14px; white-space: nowrap; }
.module-screen .filter-field { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.module-screen .filter-field select { width: auto; max-width: 260px; }
.module-screen .account-badge { text-transform: none; white-space: nowrap; }
.module-screen .account-badge.pending { color: var(--warn); background: rgba(133,95,25,.14); }
.module-screen .report-tabs { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.module-screen .report-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.module-screen .report-filters > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.module-screen .report-filters select { width: auto; max-width: min(100%, 360px); }
.module-screen .notice { padding: 12px 15px; border-radius: 7px; margin-bottom: 15px; line-height: 1.5; }
.module-screen .notice.warn { background: rgba(133,95,25,.12); border: 1px solid rgba(133,95,25,.35); color: var(--warn); }
.module-screen .panel:has(> table), .module-screen .panel:has(> .table),
.module-screen .tablewrap { overflow-x: auto; max-width: 100%; }
.module-screen .panel > table, .module-screen .panel > .table, .module-screen .tablewrap table { min-width: 560px; }
.module-relatorios .panel > table { min-width: 820px; }
.module-relatorios .panel > table th { white-space: nowrap; }
.module-screen .tablewrap table.fiscal-documents-table { min-width: 1120px; }
.fiscal-documents-table th, .fiscal-documents-table td { white-space: nowrap; }
.fiscal-documents-table td:nth-child(4) { font-family: Consolas, monospace; }
.module-screen th, .module-screen td { overflow-wrap: anywhere; }
/* Consultas com dados: rolagem em tela sem alterar a impressão. */
@media screen {
  .module-operacoes #titulos-lista .tablewrap > table { min-width: 1100px; }
  .module-lancamentos > .panel.tablewrap > table { min-width: 920px; }
  .module-operacoes #titulos-lista .tablewrap > table th,
  .module-lancamentos > .panel.tablewrap > table th,
  .module-operacoes #titulos-lista .tablewrap > table td:not(:nth-child(3)),
  .module-lancamentos > .panel.tablewrap > table td:not(:nth-child(2)) { white-space: nowrap; overflow-wrap: normal; }
  .module-operacoes #titulos-lista .tablewrap > table td:nth-child(3),
  .module-lancamentos > .panel.tablewrap > table td:nth-child(2) { min-width: 240px; white-space: normal; overflow-wrap: break-word; }
  .module-relatorios .panel > table { min-width: 1200px !important; /* Sobrepõe o mínimo inline legado somente em tela. */ }
  .module-relatorios .panel > table td { overflow-wrap: normal; }
}
.module-screen .status { white-space: nowrap; }
.module-screen .skeleton { margin-bottom: 8px; }
@media (max-width: 560px) {
  .module-screen .form-grid { grid-template-columns: 1fr; }
  .module-screen .filter-field { margin-left: 0; width: 100%; }
  .module-screen .filter-field select { flex: 1; }
  .module-screen .upload-controls { align-items: stretch; }
  .module-screen .upload-controls .btn { width: 100%; }
}
/* Etapa 3: fechamento mensal, sócios e conferência fiscal. */
.module-fechamento .closing-tabs { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 12px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.module-fechamento .closing-selector { display: flex; align-items: center; gap: 14px 22px; flex-wrap: wrap; }
.module-fechamento .closing-selector select { width: auto; max-width: 100%; }
.module-fechamento .closing-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 12px; margin-bottom: 18px; }
.module-fechamento .closing-metrics .panel { margin: 0; border-top: 3px solid var(--gold); }
.module-fechamento .closing-state.open { background: rgba(39,100,73,.13); color: var(--ok); }
.module-fechamento .closing-state.closed { background: rgba(21,41,65,.14); color: var(--primary); }
.module-fechamento .closing-state.reopened { background: rgba(133,95,25,.17); color: var(--warn); }
.module-fechamento .closing-notice { border-radius: 8px; padding: 16px 18px; margin-bottom: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.module-fechamento .closing-notice.blocking { background: rgba(163,62,56,.11); border: 2px solid var(--bad); color: var(--bad); }
.module-fechamento .closing-notice.warning { background: rgba(133,95,25,.11); border: 1px solid var(--warn); color: var(--warn); }
.module-fechamento .closing-notice ul { margin-bottom: 0; padding-left: 22px; }
.module-fechamento #fechamento-audit-panel { overflow-x: auto; }
.module-socios .reinf-conference { border-top: 3px solid var(--gold); }
.module-socios .reinf-simulation-banner { padding: 12px 15px; border-radius: 7px; border: 1px solid var(--warn); background: rgba(133,95,25,.12); color: var(--warn); font-size: 13px; font-weight: 750; letter-spacing: .02em; }
.module-socios .reinf-cycle { margin-top: 20px; border-left: 3px solid var(--gold); }
.module-socios .reinf-cycle > .form-group { max-width: 480px; }
.module-socios .reinf-cycle input:not([type]) { display: block; width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 14px; }
.module-socios .reinf-step-label { margin: 22px 0 12px; padding: 10px 12px; border-left: 3px solid var(--gold); background: var(--bg); color: var(--primary); font-size: 14px; }
.module-socios .reinf-beneficiary-card, .module-socios .reinf-event-card, .module-socios .reinf-lot-card { box-shadow: none; border-left: 3px solid var(--gold); overflow-wrap: anywhere; }
.module-socios .reinf-beneficiary-card h3, .module-socios .reinf-event-card h5, .module-socios .reinf-lot-card h5 { color: var(--primary); margin-top: 0; }
.module-socios .reinf-lots { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 12px; }
.module-socios .reinf-lots .flex-row, .module-socios .reinf-cycle .btn { margin: 4px 6px 8px 0; }
.module-socios details { border-top: 1px solid var(--line); padding: 10px 0; overflow-wrap: anywhere; }
.module-socios summary { cursor: pointer; color: var(--primary); font-weight: 650; }
.module-socios pre { max-width: 100%; overflow: auto; font-size: 12px; }
.module-socios .lucros-panel { border-top: 3px solid var(--gold); }
.module-socios #lucros-form .form-grid { margin-top: 18px; }
.module-socios #lucros-form input[type='checkbox'] { width: auto; }
.module-socios .lucros-result:empty, .module-socios #lucros-message:empty { display: none; }
.module-socios .lucros-result:not(:empty) { border-left: 3px solid var(--ok); }
.module-socios #lucros-message:not(:empty) { padding: 12px; border-radius: 6px; background: var(--bg); overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .module-fechamento .closing-tabs .btn, .module-fechamento .closing-selector > div { width: 100%; }
  .module-fechamento .closing-selector select { flex: 1; }
  .module-socios .reinf-conference .flex-row > .form-group, .module-socios .reinf-conference .flex-row > .btn { width: 100%; }
  .module-socios .reinf-beneficiary-card { padding: 14px; }
}

/* Conferência XML/OFX: manter valores legíveis sem estreitar as colunas. */
.module-screen .tablewrap table.revenue-check-table { min-width: 1000px; }
.revenue-check-table th:nth-child(n+2):nth-child(-n+4),
.revenue-check-table td:nth-child(n+2):nth-child(-n+4) { white-space: nowrap; overflow-wrap: normal; }
.revenue-check-table th:first-child, .revenue-check-table td:first-child { width: 380px; }
.revenue-check-table th:last-child, .revenue-check-table td:last-child { min-width: 210px; }

.revenue-check-history { min-width: 0; overflow-wrap: anywhere; }
.revenue-check-history input[type="file"] { max-width: 100%; }

.revenue-check-history label { display: block; margin: 10px 0; }
.revenue-check-history input[type="checkbox"] { width: auto; margin-right: 6px; }

.module-carteira .carteira-filters, .module-carteira .carteira-pagination { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.module-carteira .carteira-filters > div { flex: 1 1 180px; min-width: 0; }
.module-carteira .carteira-filters input, .module-carteira .carteira-filters select { width: 100%; }
.module-carteira .carteira-filters input[type="search"] { padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--surface); font: inherit; }
.module-carteira .carteira-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.module-carteira .carteira-stats .panel { margin: 0; }
.module-carteira .carteira-stats > span { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.module-carteira .tablewrap table.carteira-table { min-width: 860px; }
.module-carteira .carteira-table td { vertical-align: top; }
.module-carteira .carteira-detail { overflow-wrap: anywhere; margin-top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
