.file-viewer {
  margin: 0 0 30px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  scroll-margin-top: 76px;
}

.file-viewer[hidden] { display: none; }

.file-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.file-viewer-head h2 {
  margin: 0;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.file-viewer-kicker {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.file-viewer-actions,
.file-list-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.file-viewer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}

.file-viewer-close:hover,
.file-viewer-close:focus-visible,
.file-item-open:hover,
.file-item-open:focus-visible {
  color: var(--accent-dark);
}

.file-viewer-close:focus-visible,
.file-item-open:focus-visible,
.file-sheet-tab:focus-visible,
.file-download:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.file-download {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff !important;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.file-download:hover { filter: brightness(0.92); }

.file-download-small {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 0.78rem;
}

.file-sheet-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 0 12px;
  padding: 4px 2px 8px;
}

.file-sheet-tabs[hidden] { display: none; }

.file-sheet-tab {
  flex: 0 0 auto;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-soft);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.file-sheet-tab:hover { border-color: var(--accent); }

.file-sheet-tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.file-viewer-content {
  min-height: 80px;
  color: var(--text);
}

.file-table-wrap {
  max-height: 68vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
}

.file-data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  line-height: 1.4;
}

.file-data-table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-data-table th,
.file-data-table td {
  max-width: 360px;
  padding: 8px 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.file-data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 700;
}

.file-data-table tr:nth-child(even) td { background: var(--bg-soft); }
.file-data-table tr:last-child td { border-bottom: 0; }
.file-data-table tr > :last-child { border-right: 0; }

.file-paragraphs {
  max-height: 68vh;
  overflow-y: auto;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
}

.file-paragraphs p {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 0.94rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.file-paragraphs p:last-child { margin-bottom: 0; }

.file-viewer-empty {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 9px;
  color: var(--text-muted);
  background: var(--bg-soft);
}

.file-list li { align-items: center; }
.file-list .nm { flex: 1 1 360px; }

.file-item-open {
  display: inline;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

@media (max-width: 680px) {
  .file-viewer { padding: 16px; }
  .file-viewer-head { flex-direction: column; }
  .file-viewer-actions { width: 100%; justify-content: space-between; }
  .file-list .nm { flex-basis: 100%; }
  .file-list .sz { margin-right: auto; }
  .file-list-actions { flex-wrap: wrap; }
  .file-data-table th,
  .file-data-table td { max-width: 260px; padding: 7px 8px; }
}
