:root,
:root[data-theme="paper"] {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-recessed: #f1efe9;
  --row-hover: #faf9f6;
  --fg: #181816;
  --muted: #68655e;
  --border: #e5e2da;
  --border-strong: #cfcbc0;
  --accent: #b84a27;
  --accent-hover: #9c3c1e;
  --accent-soft: #f9ebe6;
  --accent-tint: rgba(184, 74, 39, 0.14);
  --focus-ring: rgba(184, 74, 39, 0.22);
  --ink-action: #181816;
  --ink-action-fg: #ffffff;
  --ink-action-hover: #2d2d29;
  --success: #1b6e3f;
  --success-soft: #eaf5ee;
  --warn: #9a5b08;
  --warn-soft: #fdf5e4;
  --warn-border: #e5c687;
  --danger: #b42318;
  --danger-soft: #fef2f2;
  --danger-border: #f3b8b4;
  --sig-line: #b8b3a8;
  --code-bg: rgba(24, 24, 22, 0.06);
  --backdrop: rgba(24, 24, 22, 0.5);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
}

:root[data-theme="dark"] {
  --bg: #111110;
  --surface: #181816;
  --surface-recessed: #22221f;
  --row-hover: #1f1f1c;
  --fg: #eeede8;
  --muted: #9b9890;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --accent: #e07652;
  --accent-hover: #eb8a68;
  --accent-soft: rgba(224, 118, 82, 0.15);
  --accent-tint: rgba(224, 118, 82, 0.2);
  --focus-ring: rgba(224, 118, 82, 0.28);
  --ink-action: #eeede8;
  --ink-action-fg: #111110;
  --ink-action-hover: #d8d6cf;
  --success: #4ade80;
  --success-soft: rgba(34, 197, 94, 0.14);
  --warn: #f5b942;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --warn-border: rgba(245, 185, 66, 0.35);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --danger-border: rgba(248, 113, 113, 0.38);
  --sig-line: rgba(255, 255, 255, 0.25);
  --code-bg: rgba(255, 255, 255, 0.08);
  --backdrop: rgba(0, 0, 0, 0.72);
  color-scheme: dark;
}

:root[data-theme="blue"] {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-recessed: #e8eef7;
  --row-hover: #f7faff;
  --fg: #132033;
  --muted: #55657d;
  --border: #dde4ef;
  --border-strong: #c3cedf;
  --accent: #1b5ec7;
  --accent-hover: #154ca3;
  --accent-soft: #e9f1fd;
  --accent-tint: rgba(27, 94, 199, 0.14);
  --focus-ring: rgba(27, 94, 199, 0.22);
  --ink-action: #132033;
  --ink-action-fg: #ffffff;
  --ink-action-hover: #213452;
  --success: #166e46;
  --success-soft: #e7f6ee;
  --warn: #9a5b08;
  --warn-soft: #fdf4e3;
  --warn-border: #e5c687;
  --danger: #b42318;
  --danger-soft: #fef2f2;
  --danger-border: #f3b8b4;
  --sig-line: #aeb9ca;
  --code-bg: rgba(19, 32, 51, 0.06);
  --backdrop: rgba(19, 32, 51, 0.5);
}

:root[data-theme="sage"] {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-recessed: #e9ede7;
  --row-hover: #f7f9f6;
  --fg: #15211a;
  --muted: #5a6960;
  --border: #dde3da;
  --border-strong: #c3ccc0;
  --accent: #216e4e;
  --accent-hover: #19563c;
  --accent-soft: #e8f3ed;
  --accent-tint: rgba(33, 110, 78, 0.14);
  --focus-ring: rgba(33, 110, 78, 0.22);
  --ink-action: #15211a;
  --ink-action-fg: #ffffff;
  --ink-action-hover: #24362c;
  --success: #1b6e3f;
  --success-soft: #eaf5ee;
  --warn: #9a5b08;
  --warn-soft: #fdf5e4;
  --warn-border: #e5c687;
  --danger: #b42318;
  --danger-soft: #fef2f2;
  --danger-border: #f3b8b4;
  --sig-line: #adb8b0;
  --code-bg: rgba(21, 33, 26, 0.06);
  --backdrop: rgba(21, 33, 26, 0.5);
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

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

/* Layout principal: sidebar + workspace */
.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--fg);
}

.sync-row {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  flex-shrink: 0;
}

.sync-dot.online {
  background: var(--success);
}

.sync-dot.error {
  background: var(--danger);
}

.sidebar-section {
  padding: 16px 12px;
  flex: 1;
}

.sidebar-label {
  padding: 0 8px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.region-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.region-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.region-item:hover {
  background: var(--surface-recessed);
}

.region-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.region-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.region-count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
}

.region-item.active .region-count {
  background: var(--accent-tint);
  color: var(--accent);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.theme-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.theme-label {
  padding: 0;
}

.theme-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.theme-btn:hover {
  background: var(--surface-recessed);
  color: var(--fg);
}

.theme-btn.active {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--fg);
}

.theme-swatch {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
}

.swatch-paper { background: #b84a27; }
.swatch-dark { background: #181816; }
.swatch-blue { background: #1b5ec7; }
.swatch-sage { background: #216e4e; }

.sidebar-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
}

.sidebar-link:hover {
  color: var(--fg);
  text-decoration: underline;
}

/* Workspace */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.summary-item strong,
.summary-btn strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--fg);
}

.summary-sep {
  width: 1px;
  height: 12px;
  background: var(--border-strong);
}

.summary-beneficiados {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-recessed);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 12px;
}

.summary-beneficiados strong {
  color: var(--accent);
  font-weight: 600;
}

.beneficiados-breakdown {
  color: var(--muted);
  font-size: 11.5px;
  margin-left: 2px;
}

.beneficiados-info {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.beneficiados-info strong {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
}

table tfoot {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--surface-recessed);
  border-top: 2px solid var(--border-strong);
  font-weight: 600;
  font-size: 12px;
}

table tfoot td {
  padding: 8px 10px;
  color: var(--fg);
  border-right: 1px solid var(--border);
}

table tfoot td:last-child {
  border-right: none;
}

.summary-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 6px;
  margin: -2px -6px;
  border: none;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.summary-btn:hover {
  background: var(--surface-recessed);
  color: var(--fg);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
}

.dot-ok { background: var(--success); }
.dot-warn { background: #d97706; }
.dot-danger { background: var(--danger); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-primary {
  background: var(--ink-action);
  color: var(--ink-action-fg);
}

.btn-primary:hover {
  background: var(--ink-action-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-recessed);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.inline-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* Conteúdo principal */
.main-content {
  padding: 18px 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Barra de busca e filtros */
.controls-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.search-box {
  position: relative;
  flex: 1 1 320px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  color: var(--muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 34px 0 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 13.5px;
}

.search-box input:focus {
  outline: 2px solid var(--focus-ring);
  border-color: var(--accent);
  background: var(--surface);
}

.clear-input-btn {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.clear-input-btn:hover {
  background: var(--surface-recessed);
  color: var(--fg);
}

.search-match-info {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
}

.columns-trigger-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.signature-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
}

.signature-switch input,
.col-check input {
  accent-color: var(--accent);
  cursor: pointer;
}

.filters-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  align-items: end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.filter-field select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font-family: inherit;
  font-size: 12.5px;
}

.filter-field select:focus {
  outline: 2px solid var(--focus-ring);
  border-color: var(--accent);
}

.btn-link-clear {
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  padding: 0 4px;
  justify-self: start;
}

.btn-link-clear:hover {
  color: var(--fg);
  text-decoration: underline;
}

/* Gaveta de checkboxes de colunas */
.columns-drawer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.columns-drawer-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.columns-drawer-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-btn {
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.preset-btn:hover {
  background: var(--surface-recessed);
  border-color: var(--border-strong);
}

.column-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 6px 12px;
}

.col-check {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
}

.col-check:hover {
  background: var(--bg);
}

/* Estado de loading / erro */
.state-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 13px;
}

.state-banner.error {
  justify-content: space-between;
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Superfície da tabela */
.table-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  color: var(--muted);
}

.table-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.swatch-red {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
}

.swatch-missing {
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
}

thead th.sortable:hover {
  color: var(--fg);
}

.sort-arrow {
  margin-left: 4px;
  color: var(--accent);
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tbody tr:hover td {
  background: var(--row-hover);
}

td.col-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}

td.col-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  white-space: nowrap;
}

.cell-red {
  background: var(--danger-soft) !important;
  color: var(--danger);
  font-weight: 500;
}

.cell-red-inner {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.red-mark {
  font-weight: 600;
}

.cell-missing {
  color: var(--warn);
}

.missing-label {
  display: inline-block;
  font-size: 11.5px;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 1px 6px;
  border-radius: 4px;
}

.cell-dup {
  background: var(--warn-soft) !important;
}

.dup-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 4px;
  background: var(--warn);
  color: #1c1917;
  vertical-align: middle;
}

.region-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg);
  background: var(--surface-recessed);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.match-badge {
  display: inline-block;
  margin-left: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

.signature-col {
  min-width: 190px;
}

.signature-line {
  border-bottom: 1px solid var(--sig-line);
  height: 18px;
  width: 100%;
}

/* Status / Botão de Pendências */
.issue-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.issue-btn.has-red {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.issue-btn:hover {
  filter: brightness(0.96);
}

.ok-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--success);
  white-space: nowrap;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-kicker {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 2px;
}

.modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.modal-subtitle {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.modal-close {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-recessed);
  color: var(--fg);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-section {
  border-radius: var(--radius-md);
  padding: 12px 14px;
  border: 1px solid var(--border);
}

.modal-section.red-section {
  background: var(--danger-soft);
  border-color: var(--danger-border);
}

.modal-section.missing-section {
  background: var(--warn-soft);
  border-color: var(--warn-border);
}

.modal-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal-section.red-section h4 {
  color: var(--danger);
}

.modal-section.missing-section h4 {
  color: var(--warn);
}

.modal-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.modal-list code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* Responsivo */
@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .region-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .region-item {
    width: auto;
  }

  .topbar {
    position: static;
  }
}

/* Impressão */
.print-only-header {
  display: none;
}

body.print-measuring .no-print,
body.print-measuring .match-badge,
body.print-measuring .icon {
  display: none !important;
}

body.print-measuring .table-wrapper {
  overflow: visible !important;
}

body.print-measuring table {
  width: auto !important;
  table-layout: auto !important;
  border-collapse: collapse !important;
}

body.print-measuring thead th,
body.print-measuring tbody td {
  white-space: nowrap !important;
  padding: 0.32em 0.45em !important;
  font-size: inherit !important;
  line-height: 1.25 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

body.print-measuring .signature-col {
  min-width: 11.5em !important;
  width: 13em !important;
}

@page {
  size: A4 landscape;
  margin: 7mm;
}

@media print {
  :root,
  :root[data-theme="dark"],
  :root[data-theme="blue"],
  :root[data-theme="sage"] {
    color-scheme: light;
  }

  body {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 9pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .no-print,
  tfoot,
  #tableFoot {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .main-content,
  .table-surface,
  .table-wrapper {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: #ffffff !important;
  }

  .print-only-header {
    display: block;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1.5px solid #000000;
  }

  .print-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
  }

  .print-only-header h1 {
    margin: 0;
    font-size: 12.5pt;
    color: #000000 !important;
  }

  .print-only-header p {
    margin: 1px 0 0;
    font-size: 8.5pt;
    color: #222222 !important;
  }

  .print-meta {
    text-align: right;
    font-size: 8pt;
    color: #222222 !important;
    white-space: nowrap;
  }

  table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: auto;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    font-size: var(--print-font-size, 8pt);
  }

  thead {
    display: table-header-group;
  }

  tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  thead th,
  tbody td,
  tbody tr:last-child td {
    border-top: none !important;
    border-left: none !important;
    border-right: 1px solid #222222 !important;
    border-bottom: 1px solid #222222 !important;
    padding: 0.38em 0.45em;
    background: #ffffff !important;
    color: #000000 !important;
    white-space: nowrap !important;
    font-size: inherit !important;
    font-weight: 400 !important;
    line-height: 1.25;
    text-transform: none;
    letter-spacing: 0;
    text-decoration: none !important;
  }

  thead th {
    border-top: 1px solid #222222 !important;
    background: #efefef !important;
    font-weight: 500 !important;
  }

  thead th:first-child,
  tbody td:first-child,
  tbody tr:last-child td:first-child {
    border-left: 1px solid #222222 !important;
  }

  tbody tr td.cell-red,
  tbody tr:nth-child(even) td,
  tbody tr:nth-child(even) td.cell-red {
    background: #ffffff !important;
    color: #000000 !important;
    font-weight: 400 !important;
    text-decoration: none !important;
  }

  .cell-red-inner,
  .red-mark,
  .missing-label,
  .region-tag {
    color: #000000 !important;
    background: transparent !important;
    padding: 0 !important;
    font-size: inherit !important;
    font-weight: 400 !important;
    text-decoration: none !important;
  }

  .match-badge,
  .icon,
  .signature-line {
    display: none !important;
  }

  .signature-col {
    min-width: 11.5em;
    width: 13em;
  }
}


/* ---------------- Formulário de Cadastro Local ---------------- */

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-section-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-group-title {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field.span-2 {
  grid-column: span 2;
}

@media (max-width: 720px) {
  .form-field.span-2 {
    grid-column: span 1;
  }
}

.form-field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.form-field input,
.form-field select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
}

.form-field input:focus,
.form-field select:focus {
  outline: 2px solid var(--focus-ring);
  border-color: var(--accent);
  background: var(--surface);
}

.field-hint {
  font-size: 11px;
  font-weight: 500;
}

.field-hint.ok {
  color: var(--ok);
}

.field-hint.err {
  color: var(--danger);
}

.field-hint.warn {
  color: var(--warn);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.form-actions-left,
.form-actions-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.local-files-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--fg-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.local-files-box code {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-mini {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}

.btn-mini:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-mini.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.toast-banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 13px;
  font-weight: 500;
}

.toast-banner.warn {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
}

.form-legend {
  font-size: 12px;
  color: var(--muted);
}

.req-star {
  color: var(--danger);
  font-weight: 700;
}

.opt-tag {
  font-weight: 400;
  font-size: 10.5px;
  opacity: 0.75;
}

/* ---------------- Login e Sessão ---------------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-brand {
  font-size: 19px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.login-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-submit {
  width: 100%;
  height: 38px;
  justify-content: center;
  margin-top: 4px;
}

.login-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
}

.login-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.user-session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
}

.user-session-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-session-name {
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-session-role {
  font-size: 11px;
  color: var(--muted);
}

.btn-logout {
  height: 26px;
  padding: 0 9px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}
