:root {
  --navy: #0c335c;
  --blue: #1565b8;
  --gold: #d98200;
  --paper: #eef3f8;
  --card: #ffffff;
  --ink: #1b2838;
  --muted: #5b6b7c;
  --line: #d7e1ec;
  --ok: #157a3f;
  --warn: #b35b00;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(12, 51, 92, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Liberation Sans", Calibri, sans-serif;
  background:
    radial-gradient(1200px 420px at 0 -80px, rgba(21, 101, 184, 0.18), transparent),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 18px 28px;
  background: linear-gradient(90deg, var(--navy), #13487f);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand p { margin: 2px 0 0; color: #cfe3f7; font-size: 13px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 48px;
  border-radius: 8px;
  background: #fff;
  color: var(--navy);
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 13px;
}
.top-actions { display: flex; gap: 10px; }
.site-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.site-nav a {
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.35);
}
.site-nav a:hover { background: rgba(255,255,255,0.12); }
.site-nav a[aria-current="page"] {
  background: var(--gold);
  color: #2b1a00;
  border-color: var(--gold);
}

button, select, input {
  font: inherit;
}
button {
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}
.primary {
  background: var(--gold);
  color: #2b1a00;
  font-weight: 700;
}
.primary:disabled { opacity: 0.65; cursor: wait; }
.ghost {
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
}
.topbar .ghost { color: #fff; border-color: rgba(255,255,255,0.35); }

.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stats article {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--blue);
}
.stats span { color: var(--muted); font-size: 13px; }
.stats strong { display: block; font-size: 28px; margin-top: 4px; }
.stats strong.stat-datetime { font-size: 20px; letter-spacing: -0.02em; }
.stats-acervo { grid-template-columns: repeat(4, 1fr); }
.muted-cell { color: var(--muted); font-size: 13px; }

.panel {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px 12px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.panel h1 { font-size: 18px; margin: 0; }
.panel p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.sync-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 12px 0;
}
.sync-kpis li {
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
}
.sync-kpis em { display: block; font-style: normal; color: var(--muted); font-size: 12px; }
.sync-kpis span { font-size: 20px; font-weight: 700; }
.sync-meta { color: var(--muted); font-size: 13px; text-align: right; }

.progress-track {
  height: 8px;
  background: #dce6f0;
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blue), #3aa0d8);
  transition: width 0.25s ease;
}
.progress-bar.done { background: var(--ok); }
.progress-bar.error { background: var(--danger); }

.download-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 0 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #e8f6ee;
  border: 1px solid #b7e0c5;
}
.download-banner.hidden { display: none; }
.download-banner p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.action-download {
  background: var(--ok);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}
.action-download:disabled { opacity: 0.7; cursor: wait; }

.index-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 0 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #e7f1fb;
  border: 1px solid #b7d3ee;
}
.index-banner.hidden { display: none; }
.index-banner p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.action-index {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}
.action-index:disabled { opacity: 0.7; cursor: wait; }

.log {
  max-height: 180px;
  overflow: auto;
  background: #0f2438;
  color: #d5e8f7;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 8px;
}

.filters { display: flex; gap: 8px; }
.filters input, .filters select, dialog input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  min-width: 180px;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
td.title { font-weight: 600; }
td.title small { display: block; color: var(--muted); font-weight: 400; margin-top: 3px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px !important; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}
.badge.baixado { background: #e4f6ea; color: var(--ok); }
.badge.novo { background: #e7f1fb; color: var(--blue); }
.badge.atualizado { background: #fff3de; color: var(--warn); }
.badge.erro { background: #fde8e6; color: var(--danger); }
.badge.pendente { background: #eef2f6; color: var(--muted); }
.badge.ausente_no_site { background: #f3eef6; color: #6b3f8a; }
.badge.index-src { font-family: ui-monospace, Consolas, monospace; font-size: 0.78rem; text-transform: none; }
.badge.index-src.headers { background: #e8f7f1; color: #0f6b4c; }
.badge.index-src.toc,
.badge.index-src.outlines,
.badge.index-src.names { background: #e7f1fb; color: var(--blue); }
.badge.index-src.none { background: #eef2f6; color: var(--muted); }
.badge.index-src.erro { background: #fde8e6; color: var(--danger); }

.row-actions { display: flex; gap: 8px; }
.row-actions a, .row-actions button, td a {
  font-size: 13px;
  padding: 7px 10px;
  text-decoration: none;
  background: var(--paper);
  color: var(--navy);
  border-radius: 8px;
  display: inline-block;
}

dialog {
  width: min(760px, 94vw);
  border: 0;
  border-radius: 16px;
  padding: 0;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 28, 48, 0.45); }
dialog header, dialog footer, .form-grid { padding: 18px 20px; }
dialog header { border-bottom: 1px solid var(--line); }
dialog h2 { margin: 0 0 6px; }
dialog header p { margin: 0; color: var(--muted); }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.form-grid label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.form-grid .field-hint {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.35;
}
.form-grid select {
  font: inherit;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.form-grid .checkbox {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--line);
}
dialog .ghost { color: var(--navy); border-color: var(--line); }

@media (max-width: 900px) {
  .stats, .sync-kpis, .form-grid, .stats-acervo { grid-template-columns: 1fr 1fr; }
  .topbar, .panel-head, .filters, .download-banner, .index-banner { flex-direction: column; align-items: stretch; }
  .sync-meta { text-align: left; }
}
@media (max-width: 640px) {
  .stats, .sync-kpis, .form-grid, .stats-acervo { grid-template-columns: 1fr; }
}

html:has(body.page-public) {
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}
body.page-public {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}
body.page-public img,
body.page-public svg,
body.page-public video {
  max-width: 100%;
  height: auto;
}
body.page-public .layout {
  flex: 1 0 auto;
  align-content: start;
  width: 100%;
  min-width: 0;
}
body.page-public .topbar {
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  align-items: flex-start;
}
body.page-public .brand {
  min-width: 0;
  gap: 12px;
}
body.page-public .brand > div { min-width: 0; }
body.page-public .brand strong {
  display: block;
  overflow-wrap: anywhere;
}
body.page-public .brand-mark { flex-shrink: 0; }
body.page-public .top-right {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  width: 100%;
}
body.page-public .site-nav {
  flex-wrap: wrap;
  width: 100%;
}
body.page-public .site-nav a {
  min-height: 44px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  touch-action: manipulation;
}
body.page-public .catalog-meta {
  margin: 0;
  color: #cfe3f7;
  font-size: 13px;
}
body.page-public .filters {
  flex-wrap: wrap;
  width: 100%;
  min-width: 0;
}
body.page-public .filters input,
body.page-public .filters select {
  min-width: 0;
  width: 100%;
  min-height: 44px;
}
body.page-public .panel,
body.page-public .panel-head,
body.page-public td.title {
  min-width: 0;
  overflow-wrap: anywhere;
}
body.page-public .online-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ok);
  background: #e4f6ea;
}
body.page-public .table-wrap {
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}
body.page-acervo .panel {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
body.page-acervo .table-wrap {
  margin-inline: -4px;
  padding-inline: 4px;
}
body.page-acervo table {
  min-width: 42rem;
}
body.page-acervo table th:nth-child(2),
body.page-acervo table th:nth-child(3),
body.page-acervo table th:nth-child(4),
body.page-acervo table th:nth-child(5) {
  white-space: nowrap;
}
body.page-acervo .col-date,
body.page-acervo .col-size {
  white-space: nowrap;
  font-size: 13px;
  color: var(--ink);
}
body.page-acervo .col-size {
  color: var(--muted);
}
body.page-acervo .col-status {
  min-width: 7.5rem;
}
body.page-acervo .status-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
body.page-acervo .status-stack .badge {
  white-space: nowrap;
}
body.page-acervo .avail-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
body.page-acervo .avail-on {
  color: var(--ok);
  background: #e4f6ea;
}
body.page-acervo .avail-off {
  color: var(--muted);
  background: #eef2f6;
}

@media (max-width: 720px) {
  body.page-acervo .layout {
    padding-inline: 12px;
  }
  body.page-acervo .stats-acervo {
    grid-template-columns: 1fr 1fr;
  }
  body.page-acervo .stats strong {
    font-size: 22px;
  }
  body.page-acervo .stats strong.stat-datetime {
    font-size: 14px;
    line-height: 1.25;
  }
  body.page-acervo .panel {
    padding: 14px 12px 10px;
    overflow: visible;
  }
  body.page-acervo .panel-head p {
    display: none;
  }
  /* Card rows: readable without forcing page-wide overflow. */
  body.page-acervo .table-wrap {
    margin: 0;
    padding: 0;
    overflow: visible;
  }
  body.page-acervo table {
    min-width: 0;
    width: 100%;
  }
  body.page-acervo thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  body.page-acervo tbody {
    display: grid;
    gap: 10px;
  }
  body.page-acervo tr {
    display: grid;
    gap: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
  }
  body.page-acervo td {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
  }
  body.page-acervo td.empty {
    padding: 20px 8px !important;
    border: 0;
  }
  body.page-acervo td.title {
    padding-bottom: 8px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--line);
  }
  body.page-acervo td.col-date,
  body.page-acervo td.col-size {
    white-space: normal;
    font-size: 13px;
  }
  body.page-acervo td.col-date:nth-child(2)::before {
    content: "Publicado: ";
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  body.page-acervo td.col-date:nth-child(3)::before {
    content: "Atualização: ";
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  body.page-acervo td.col-size::before {
    content: "Tamanho: ";
    color: var(--muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  body.page-acervo .col-status {
    min-width: 0;
  }
  body.page-acervo .status-stack {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
  }
}
body.page-public .site-footer {
  flex-shrink: 0;
  margin-top: auto;
  width: 100%;
  border-top: 1px solid var(--line);
  background: #f7fafc;
}
body.page-public .footer-inner {
  width: min(calc(100% - 32px), 1280px);
  margin-inline: auto;
  padding-block: 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px 16px;
  min-width: 0;
}
body.page-public .footer-copy {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-width: 0;
  overflow-wrap: anywhere;
}
body.page-public .footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
body.page-public .footer-links a {
  display: inline-flex;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  touch-action: manipulation;
}
body.page-public .footer-links a:hover,
body.page-public .footer-links a:focus-visible {
  background: #e7f1fb;
  color: var(--blue);
}

@media (min-width: 721px) {
  body.page-public .topbar {
    flex-wrap: nowrap;
    align-items: center;
    gap: 24px;
    padding: 18px 28px;
  }
  body.page-public .top-right {
    width: auto;
    margin-left: auto;
    align-items: flex-end;
  }
  body.page-public .site-nav {
    width: auto;
    justify-content: flex-end;
  }
  body.page-public .site-nav a {
    flex: 0 0 auto;
    min-height: 0;
    padding: 8px 12px;
  }
  body.page-public .catalog-meta {
    text-align: right;
    max-width: 28rem;
  }
  body.page-public .filters input,
  body.page-public .filters select {
    width: auto;
    min-width: 180px;
    min-height: 0;
  }
  body.page-public .footer-inner {
    width: min(calc(100% - 48px), 1280px);
    padding-block: 18px 24px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}
