/**
 * PGFN Platform UI — estilos compartilhados entre módulos.
 * Fonte de verdade visual: sidebar, listas (Nome/Extensão/Tamanho/Ações),
 * botões Visualizar/Download, modal de visualização, filtros e responsivo.
 * Módulos devem carregar /platform/platform.css e só acrescentar CSS específico.
 */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root,
[data-theme='light'] {
  --font-sans: 'Lato', system-ui, -apple-system, sans-serif;

  --color-primary: #0b1d3a;
  --color-primary-dark: #152a4d;
  --color-accent: #2c4f8e;
  --color-accent-soft: #d7e1f1;
  --color-accent-muted: #a7b7d6;
  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-surface-elevated: #e7ebf2;
  --color-border: #c2c8d6;
  --color-text: #333a48;
  --color-text-muted: #6d88c1;
  --color-heading: #152a4d;
  --color-on-primary: #f8f6ee;
  --color-nav-hover-bg: #d7e1f1;
  --color-nav-hover-text: #0b1d3a;
  --color-nav-active-bg: #0b1d3a;
  --color-nav-active-text: #f8f6ee;
  --color-link: #2c4f8e;
  --color-link-visited: #6d88c1;
  --color-link-hover: #0b1d3a;
  --color-danger: #c0392b;
  --color-danger-bg: #fdf2f2;
  --color-danger-border: #f5c6cb;
  --color-success: #27ae60;
  --color-success-bg: #e8f6f0;
  --color-success-border: #a9dfbf;
  --color-success-text: #1e8449;
  --color-warning: #d68910;
  --color-download: #d4b06a;
  --color-download-hover: #b8944e;
  --color-download-text: #0b1d3a;
  --color-overlay: rgba(11, 29, 58, 0.45);
  --color-loading-overlay: rgba(244, 246, 251, 0.88);
  --focus-ring: rgba(44, 79, 142, 0.18);
  --sidebar-width: 280px;
  --header-height: 80px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(11, 29, 58, 0.08);
  --modal-pad-x: 1.5rem;
}

[data-theme='dark'] {
  --color-primary: #142b52;
  --color-primary-dark: #0a1026;
  --color-accent: #5d7ea8;
  --color-accent-soft: #254a7a;
  --color-accent-muted: #6d88c1;
  --color-bg: #0a1026;
  --color-surface: #142b52;
  --color-surface-elevated: #254a7a;
  --color-border: #5d7ea8;
  --color-text: #f8f6ee;
  --color-text-muted: #a7b7d6;
  --color-heading: #f8f6ee;
  --color-on-primary: #f8f6ee;
  --color-nav-hover-bg: #254a7a;
  --color-nav-hover-text: #f8f6ee;
  --color-nav-active-bg: #5d7ea8;
  --color-nav-active-text: #f8f6ee;
  --color-link: #a7b7d6;
  --color-link-visited: #5d7ea8;
  --color-link-hover: #f0d79a;
  --color-danger: #e74c3c;
  --color-danger-bg: rgba(192, 57, 43, 0.22);
  --color-danger-border: rgba(231, 76, 60, 0.45);
  --color-success: #27ae60;
  --color-success-bg: rgba(39, 174, 96, 0.18);
  --color-success-border: rgba(39, 174, 96, 0.4);
  --color-success-text: #7dcea0;
  --color-warning: #d4b06a;
  --color-download: #d4b06a;
  --color-download-hover: #f0d79a;
  --color-download-text: #0a1026;
  --color-overlay: rgba(10, 16, 38, 0.72);
  --color-loading-overlay: rgba(10, 16, 38, 0.88);
  --focus-ring: rgba(93, 126, 168, 0.35);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

html {
  color-scheme: light;
}

html[data-theme='dark'] {
  color-scheme: dark;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 28px;
  font-weight: 400;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

a {
  color: var(--color-link);
  font-weight: 500;
}

a:visited {
  color: var(--color-link-visited);
}

a:hover,
a:active {
  color: var(--color-link-hover);
}

/* Nav/sidebar: não herdar a:hover global (apagava o texto no dark). */
.module-nav-item:visited,
.sidebar-item:visited,
.ano-btn:visited {
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: 1rem 2rem;
  box-shadow: var(--shadow);
  min-height: var(--header-height);
}

.header-content {
  min-width: 0;
  flex: 1;
}

.header h1 {
  font-size: 32px;
  line-height: 44px;
  font-weight: 700;
  color: var(--color-on-primary);
}

.subtitle {
  font-size: 14px;
  line-height: 20px;
  font-weight: 400;
  opacity: 0.9;
  margin-top: 0.15rem;
  color: var(--color-on-primary);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border: 1px solid rgba(248, 246, 238, 0.35);
  border-radius: var(--radius);
  background: rgba(248, 246, 238, 0.08);
  color: var(--color-on-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
  background: rgba(248, 246, 238, 0.18);
  border-color: rgba(248, 246, 238, 0.55);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-download);
  outline-offset: 2px;
}

.theme-toggle-icon {
  display: none;
  width: 1.25rem;
  height: 1.25rem;
}

html[data-theme='light'] .theme-toggle-icon--moon,
html:not([data-theme]) .theme-toggle-icon--moon {
  display: block;
}

html[data-theme='dark'] .theme-toggle-icon--sun {
  display: block;
}

/* Layout */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  overflow-y: auto;
}

.module-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.module-nav-item {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.module-nav-item:hover {
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
}

.module-nav-item.active,
.module-nav-item.active:hover,
.module-nav-item.active:visited {
  background: var(--color-nav-active-bg);
  color: var(--color-nav-active-text);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sidebar-count,
.anos-count,
.trimestres-count {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.sidebar-list,
.anos-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
}

.sidebar-item,
.ano-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-item:hover,
.ano-btn:hover {
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
}

.sidebar-item.active,
.ano-btn.active,
.sidebar-item.active:hover,
.ano-btn.active:hover {
  background: var(--color-nav-active-bg);
  color: var(--color-nav-active-text);
}

.sidebar-item:focus-visible,
.ano-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.sidebar h2 {
  font-size: 14px;
  line-height: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-accent);
  margin-bottom: 0.75rem;
}

.sidebar-head h2 {
  margin-bottom: 0;
}

.year-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.year-chip {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.year-chip:hover {
  border-color: var(--color-accent);
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
}

.year-chip.active,
.year-chip.active:hover {
  background: var(--color-nav-active-bg);
  border-color: var(--color-nav-active-bg);
  color: var(--color-nav-active-text);
}

.year-chip:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.trimestres-count {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.trimestres-nav {
  display: block;
}

.trimestres-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.year-group {
  display: flex;
  flex-direction: column;
}

.year-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.year-toggle:hover {
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
}

.year-toggle:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.year-label {
  flex: 1;
}

.year-count {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.year-toggle[aria-expanded="true"] .year-count {
  background: var(--color-accent-soft);
  color: var(--color-heading);
}

.chevron {
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex-shrink: 0;
}

.year-toggle[aria-expanded="true"] .chevron {
  transform: rotate(45deg);
}

.year-panel[hidden] {
  display: none !important;
}

.year-panel,
.trimestres-flat {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0 0 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.trimestre-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 1.25rem;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.875rem;
  color: var(--color-text);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.trimestre-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.trimestre-item:hover {
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
}

.trimestre-item.active,
.trimestre-item.active:hover {
  background: var(--color-nav-active-bg);
  color: var(--color-nav-active-text);
}

.placeholder {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Main */
.main {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 240px;
  color: var(--color-text-muted);
  font-size: 1rem;
  text-align: center;
}

.error-state {
  border: 1px solid var(--color-danger-border);
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.main-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.main-header h2 {
  font-size: 24px;
  line-height: 32px;
  font-weight: 700;
  color: var(--color-heading);
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Table */
.table-container {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--color-surface-elevated);
}

th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-surface);
}

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

tr:hover td {
  background: var(--color-accent-soft);
}

td.actions-cell {
  background: var(--color-surface);
}

tr:hover td.actions-cell {
  background: var(--color-accent-soft);
}

.file-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  min-width: 0;
}

.file-name {
  font-weight: 500;
  color: var(--color-text);
  word-break: break-word;
}

.file-url-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.file-url-toggle:hover,
.file-url-toggle[aria-expanded='true'] {
  color: var(--color-nav-hover-text);
  border-color: var(--color-accent-muted);
  background: var(--color-nav-hover-bg);
}

.file-url-icon {
  flex-shrink: 0;
}

.file-url {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--color-text-muted);
  word-break: break-all;
  line-height: 1.35;
  max-width: 100%;
}

.file-url.is-collapsed {
  display: none;
}

.file-ext {
  font-size: 0.9rem;
  color: var(--color-text);
  text-transform: uppercase;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4rem 0.875rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, color 0.15s, border-color 0.15s;
}

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

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-on-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
  border-color: var(--color-border);
}

.btn-download {
  background: var(--color-download);
  color: var(--color-download-text);
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-download:hover {
  background: var(--color-download-hover);
  color: var(--color-download-text);
}

/**
 * Ações de linha — padrão DataJud (fonte de verdade).
 * Markup canônico (NÃO usar display:flex no <td> — quebra a tabela):
 *   <td class="actions-cell">
 *     <div class="actions">
 *       <button class="btn btn-secondary btn-sm">Visualizar</button>
 *       <a class="btn btn-download btn-sm">Download</a>
 *     </div>
 *   </td>
 */
div.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 0.3rem;
  width: 5.5rem;
  min-width: 5.5rem;
  max-width: 5.5rem;
  box-sizing: border-box;
  margin: 0 auto;
}

div.actions > .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  min-height: 1.85rem;
  height: 1.85rem;
  padding: 0 0.45rem;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  border-width: 1px;
  border-style: solid;
  border-radius: var(--radius);
}

div.actions > .btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}

div.actions > .btn-secondary:hover:not(:disabled) {
  background: var(--color-nav-hover-bg);
  color: var(--color-nav-hover-text);
  border-color: var(--color-border);
}

div.actions > .btn-download {
  background: var(--color-download);
  color: var(--color-download-text);
  border-color: var(--color-download);
}

div.actions > .btn-download:hover:not(:disabled) {
  background: var(--color-download-hover);
  color: var(--color-download-text);
  border-color: var(--color-download-hover);
}

div.actions > a.btn-download:link,
div.actions > a.btn-download:visited,
div.actions > a.btn-download:hover,
div.actions > a.btn-download:active {
  color: var(--color-download-text);
  text-decoration: none;
}

td.actions-cell,
th.col-acoes {
  width: 6.25rem;
  min-width: 6.25rem;
  max-width: 6.25rem;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
  vertical-align: middle;
  text-align: center;
}

/* Evita legado td.actions com flex (estraga layout da tabela). */
td.actions {
  display: table-cell;
  width: 6.25rem;
  min-width: 6.25rem;
  max-width: 6.25rem;
  vertical-align: middle;
  text-align: center;
}

/* Modal / Viewer */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-overlay);
  backdrop-filter: blur(2px);
}

.viewer-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1280px;
  height: 100%;
  max-height: 100vh;
  margin: 0 auto;
  background: var(--color-surface);
  box-shadow: 0 24px 48px rgba(10, 16, 38, 0.28);
  overflow: hidden;
  color: var(--color-text);
}

@media (min-width: 769px) {
  .viewer-modal {
    padding: 1.25rem;
    align-items: center;
  }

  .viewer-shell {
    height: 92vh;
    max-height: 92vh;
    border-radius: 12px;
  }
}

/* Header */
.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem var(--modal-pad-x);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
  min-height: 56px;
}

.viewer-header-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
}

.viewer-back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.viewer-back:hover {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}

.viewer-titles {
  min-width: 0;
}

.viewer-header h3,
.viewer-titles h3 {
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  color: var(--color-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-subtitle {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.1rem;
}

.viewer-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.viewer-link-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-download-text);
  background: var(--color-download);
  border: 1px solid transparent;
  text-decoration: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.viewer-link-action:hover,
.viewer-link-action:visited:hover {
  background: var(--color-download-hover);
  color: var(--color-download-text);
}

.viewer-link-action:visited {
  color: var(--color-download-text);
}

.viewer-link-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.viewer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.viewer-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* Entries list */
.viewer-entries {
  flex: 1;
  overflow: auto;
  padding: 0 var(--modal-pad-x);
}

.viewer-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Toolbar & filters */
.viewer-toolbar {
  flex-shrink: 0;
  padding: 0.85rem var(--modal-pad-x) 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.viewer-toolbar-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

/* Compat: módulos que ainda usam barra de busca (ex.: Editais) */
.viewer-search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.viewer-search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.viewer-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

.viewer-search-input {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.25rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.viewer-search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.viewer-filters-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.viewer-filters-toggle:hover,
.viewer-filters-toggle[aria-expanded="true"] {
  background: var(--color-bg);
  border-color: var(--color-border);
}

.viewer-filters-toggle[aria-expanded="true"] {
  color: var(--color-heading);
}

.viewer-filters-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--color-accent);
  color: var(--color-on-primary);
  font-size: 0.65rem;
  font-weight: 600;
}

/* Filters panel */
.viewer-filters {
  display: flex;
  flex-direction: column;
  padding-bottom: 0.75rem;
}

/* Datepicker padrão plataforma: DD/MM/YYYY */
.date-field {
  position: relative;
  display: flex;
  align-items: center;
}

.date-field input[type='text'] {
  width: 100%;
  padding-right: 2.25rem;
}

.date-picker-btn {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  z-index: 1;
  pointer-events: none;
}

.date-native {
  position: absolute;
  right: 0.15rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  opacity: 0.011;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.date-native::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  opacity: 0;
}

.viewer-filters-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  margin-bottom: 0.65rem;
}

.viewer-filters-rows {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.viewer-filters-row {
  display: grid;
  gap: 0.75rem 1rem;
  align-items: start;
}

.viewer-filters-row-selects {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.viewer-filters-row-ranges {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.viewer-filters-row-actions {
  grid-template-columns: 1fr;
}

.viewer-filter {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.viewer-filter label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  line-height: 1.25;
}

.viewer-filter select,
.viewer-filter input,
.viewer-valor-range input {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--color-text);
  background: var(--color-surface);
  width: 100%;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.viewer-filter select:focus,
.viewer-filter input:focus,
.viewer-valor-range input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.viewer-filter select:disabled,
.viewer-valor-range input:disabled {
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.viewer-valor-range {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem;
}

.viewer-valor-range input {
  min-width: 0;
}

.viewer-valor-sep {
  color: var(--color-text-muted);
  font-size: 0.7rem;
  flex-shrink: 0;
  text-align: center;
}

.viewer-filter-valor .viewer-valor-range {
  min-height: 2.25rem;
}

.viewer-filter-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
  font-size: 0.72rem !important;
  font-weight: 500 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--color-text) !important;
  cursor: pointer;
}

.viewer-filter-check input {
  width: auto;
  margin: 0;
}

.viewer-filters-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  min-width: 0;
}

.viewer-filters-actions .viewer-btn-apply,
.viewer-filters-actions .btn-ghost {
  display: inline-flex;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 5.5rem;
  white-space: nowrap;
}

/* Desktop: painel de filtros sempre visível; botão "Filtros" some */
@media (min-width: 1024px) {
  #btn-toggle-filtros {
    display: none;
  }

  #filters-panel.hidden {
    display: flex !important;
    flex-direction: column;
  }

  .viewer-toolbar-top {
    margin-bottom: 0.5rem;
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1023px) {
  .viewer-filters-row-selects {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .viewer-filters-row-ranges {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.viewer-btn-apply {
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.viewer-notice {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  padding: 0.5rem 0 0.75rem;
  line-height: 1.35;
  border-top: 1px solid var(--color-border);
  margin-top: 0.25rem;
}

/* Body & table */
.viewer-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background: var(--color-bg);
  padding: 0 var(--modal-pad-x);
}

/**
 * Frame de detalhe (Lista / ADEs / DataJud): scroll + loading,
 * sem quebrar o shell tabular (.viewer-body).
 */
.viewer-detail-frame,
.ade-viewer-frame,
.datajud-viewer-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg);
}

.viewer-modal .viewer-content {
  min-height: 0;
  overflow: hidden;
}

.detalhe-body {
  padding-top: 0.75rem;
  padding-bottom: 1.25rem;
}

/* Cards de seção dentro do modal de detalhe */
.viewer-section,
.natureza-block,
.ade-corpo-block,
.dj-section {
  margin: 0 0 1rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-surface);
}

.viewer-section-head,
.natureza-head,
.ade-corpo-head,
.dj-section-head {
  padding: 0.65rem 1rem;
  background: var(--color-surface-elevated);
  border-bottom: 1px solid var(--color-border);
}

.viewer-section-head h4,
.natureza-head h4,
.ade-corpo-head h4,
.dj-section-head h4 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-heading);
}

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--color-loading-overlay);
  z-index: 2;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.viewer-table-area {
  height: 100%;
  overflow: auto;
  /* Garante respiro mesmo se o body não tiver pad (modais legados). */
  box-sizing: border-box;
}

.viewer-table-area > .viewer-empty,
.viewer-table-area > .viewer-error,
.viewer-table-area > .viewer-loading {
  padding-left: 0;
  padding-right: 0;
}

.viewer-table-scroll {
  min-width: 100%;
}

.viewer-table-area table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  background: var(--color-surface);
  color: var(--color-text);
}

.viewer-table-area thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface-elevated);
}

.viewer-table-area th {
  padding: 0.55rem 0.85rem;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

/* Dados Abertos: ordenação via botão interno — o pad fica no .viewer-th-btn */
.viewer-table-area th:has(.viewer-th-btn) {
  padding: 0;
}

.viewer-th-sortable {
  vertical-align: bottom;
}

.viewer-th-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.viewer-th-btn:hover {
  background: var(--color-accent-soft);
  color: var(--color-text);
}

.viewer-th-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-sort-icon {
  flex-shrink: 0;
  font-size: 0.62rem;
  opacity: 0.35;
}

.viewer-sort-icon.is-active {
  opacity: 1;
  color: var(--color-accent);
}

.viewer-table-area td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-text);
  background: var(--color-surface);
}

.viewer-table-area tbody tr:hover td {
  background: var(--color-accent-soft);
}

.viewer-table-area .xml-content,
.viewer-table-area .txt-content {
  padding: 1rem;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-all;
}

.viewer-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 120px;
  padding: 2rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.viewer-error {
  padding: 1.5rem;
  color: var(--color-danger);
  font-size: 0.875rem;
}

/* Footer */
.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem var(--modal-pad-x);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.viewer-count {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.viewer-pagination {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.viewer-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.viewer-page-btn:hover:not(:disabled) {
  background: var(--color-bg);
  border-color: var(--color-border);
}

.viewer-page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.viewer-page-info {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  padding: 0 0.35rem;
  white-space: nowrap;
}

/* Entries inside viewer */
.entries-intro {
  padding: 1rem 0 0.5rem;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.45;
}

.entries-table-wrap {
  padding: 0 0 1rem;
}

.entries-intro strong {
  color: var(--color-heading);
  font-weight: 600;
}

.tipo-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.tipo-badge.supported {
  background: var(--color-success-bg);
  border-color: var(--color-success-border);
  color: var(--color-success-text);
}

.tipo-badge.unsupported {
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
  color: var(--color-danger);
}

/* Legacy modal aliases (main list table etc.) */
.modal-content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  width: 95vw;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

/* Qualquer modal da plataforma: padding lateral mínimo no conteúdo. */
.modal .modal-content:not(.viewer-shell),
.modal .modal-body,
.modal .detalhe-body {
  padding-left: var(--modal-pad-x);
  padding-right: var(--modal-pad-x);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
}

.btn-close:hover {
  color: var(--color-text);
}

.btn-download-subtle {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-download-subtle:hover {
  color: var(--color-download-text);
  border-color: var(--color-download);
  background: var(--color-download-hover);
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-loading-overlay);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--color-text);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--color-danger);
  color: var(--color-on-primary);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 3000;
  max-width: 420px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.toast.success {
  background: var(--color-success);
}

.toast.warning {
  background: var(--color-warning);
  color: var(--color-download-text);
}

.toast.info {
  background: var(--color-accent);
}

.toast.toast-error,
.toast.error {
  background: var(--color-danger);
}

.fidelity-notice {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  background: var(--color-accent-soft);
  border: 1px solid var(--color-accent-muted);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

/* Viewer responsive */
@media (max-width: 768px) {
  :root {
    --modal-pad-x: 1rem;
  }

  .viewer-header {
    padding: 0.65rem var(--modal-pad-x);
  }

  .viewer-back span {
    display: none;
  }

  .viewer-link-action span,
  .viewer-link-action {
    font-size: 0;
    padding: 0.35rem;
    gap: 0;
  }

  .viewer-link-action svg {
    width: 16px;
    height: 16px;
  }

  .viewer-toolbar {
    padding: 0.65rem var(--modal-pad-x) 0;
  }

  .viewer-toolbar-top,
  .viewer-search-bar {
    flex-wrap: nowrap;
  }

  .viewer-search-wrap {
    flex: 1;
  }

  .viewer-filters-toggle {
    flex-shrink: 0;
  }

  .viewer-filters-rows {
    gap: 0.85rem;
  }

  .viewer-filters-row-selects,
  .viewer-filters-row-ranges,
  .viewer-filters-row {
    grid-template-columns: 1fr;
    gap: 0.85rem;
    align-items: stretch;
  }

  .viewer-filter {
    gap: 0.4rem;
  }

  .viewer-filters-actions {
    justify-content: stretch;
    padding-top: 0.15rem;
  }

  .viewer-filters-actions .viewer-btn-apply,
  .viewer-filters-actions .btn-ghost {
    flex: 1;
  }

  .viewer-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.55rem var(--modal-pad-x);
  }

  .viewer-pagination {
    justify-content: center;
  }

  .viewer-count {
    text-align: center;
  }

  .entries-intro {
    padding: 0.75rem 0;
  }

  .entries-table-wrap {
    padding: 0 0 0.75rem;
  }
}

@media (max-width: 480px) {
  .viewer-header h3,
  .viewer-titles h3 {
    font-size: 0.82rem;
    max-width: 52vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chevron,
  .year-chip,
  .trimestre-item,
  .year-toggle {
    transition: none;
  }
}

/* Filtros de sidebar (padrão plataforma) */
.filters-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0 0.15rem 1rem;
}

.filters-form label {
  font-size: 12px;
  line-height: 18px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.filters-form select,
.filters-form input,
.filters-form input[type='text'] {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filters-form select:focus,
.filters-form input:focus,
.filters-form input[type='text']:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.filters-form select:disabled,
.filters-form input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  background: var(--color-surface-elevated);
  color: var(--color-text-muted);
}

.filters-form ::placeholder {
  color: var(--color-text-muted);
  opacity: 0.85;
}

.filters-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    padding: 0.85rem 1rem;
  }

  .header h1 {
    font-size: 24px;
    line-height: 32px;
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .main {
    padding: 1rem;
  }
}
