/* Електронний архів інституту — академічний стриманий стиль, синьо-жовта гама */

:root {
  --blue-900: #0b2f52;
  --blue-700: #134b80;
  --blue-500: #2a6db0;
  --blue-100: #e3edf7;
  --blue-50:  #f3f7fb;
  --yellow-500: #f2c230;
  --yellow-200: #fbe7a6;
  --yellow-100: #fdf4d6;
  --yellow-ink: #6b4f00;   /* жовтий відтінок для тексту — достатній контраст */
  --ink: #1d2733;
  --ink-soft: #4b5869;
  --rule: #d6dee8;
  --paper: #ffffff;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 3px;
}

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

html { -webkit-text-size-adjust: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--blue-50);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
}

a { color: var(--blue-700); text-underline-offset: 2px; }
a:hover { color: var(--blue-900); }

:focus-visible {
  outline: 3px solid var(--yellow-500);
  outline-offset: 2px;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

/* ---------- Шапка ---------- */

.flag-rule {
  height: 6px;
  background: linear-gradient(to right, var(--blue-500) 0 50%, var(--yellow-500) 50% 100%);
}

.masthead {
  background: var(--blue-900);
  color: #fff;
  padding: 28px 0 32px;
  border-bottom: 3px solid var(--yellow-500);
}

.eyebrow {
  margin: 0 0 14px;
  font-size: 14px;
}
.eyebrow a { color: var(--yellow-200); text-decoration: none; }
.masthead h1 a { color: inherit; text-decoration: none; }
.eyebrow a:hover { color: #fff; text-decoration: underline; }

.masthead h1 {
  margin: 0;
  font: 400 clamp(30px, 4vw, 42px)/1.15 var(--serif);
  letter-spacing: 0.01em;
}

.lede {
  max-width: 62ch;
  margin: 12px 0 0;
  color: #cfdbe8;
  font-size: 16px;
}

/* ---------- Макет ---------- */

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 36px;
  padding-top: 32px;
  padding-bottom: 48px;
}

/* ---------- Фільтри ---------- */

.filters { align-self: start; position: sticky; top: 20px; }

.filters form {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--blue-700);
  border-radius: var(--radius);
  padding: 20px;
}

.field { margin: 0 0 16px; padding: 0; border: 0; }

.field label,
.field legend {
  display: block;
  margin-bottom: 5px;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

input, select, button { font: inherit; color: inherit; }

.field input,
.field select {
  width: 100%;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #b9c5d3;
  border-radius: var(--radius);
}
.field input:focus,
.field select:focus { border-color: var(--blue-500); }

.years {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}
.years legend { grid-column: 1 / -1; }
.years span { color: var(--ink-soft); }
.years input { -moz-appearance: textfield; }
.years input::-webkit-inner-spin-button,
.years input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.btn-reset {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--blue-700);
  border-radius: var(--radius);
  color: var(--blue-700);
  cursor: pointer;
}
.btn-reset:hover { background: var(--blue-100); }

/* ---------- Результати ---------- */

.toolbar {
  margin-bottom: 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}

.count {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
}

.sort { font-size: 14px; color: var(--ink-soft); }
.sort select {
  margin-left: 4px;
  padding: 4px 6px;
  border: 1px solid #b9c5d3;
  border-radius: var(--radius);
  background: #fff;
}

/* ---------- Навігація ---------- */

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  font-size: 14px;
  color: var(--ink-soft);
}
.crumbs li + li::before { content: "›"; margin-right: 6px; color: #9aa7b6; }
.crumbs [aria-current] { color: var(--ink); font-weight: 600; }

.crumb-link,
.inline-link {
  padding: 0;
  background: none;
  border: 0;
  color: var(--blue-700);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font: inherit;
}
.crumb-link:hover,
.inline-link:hover { color: var(--blue-900); }

/* ---------- Спільні елементи рівнів ---------- */

.level-label {
  display: block;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--yellow-ink);
  font-variant-numeric: tabular-nums;
}

.meta-line {
  display: block;
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.cipher {
  font-size: 13px;
  font-weight: 700;
  color: var(--blue-900);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 2px;
  background: var(--blue-100);
  color: var(--blue-900);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.tag-more { background: #eef0f3; color: var(--ink-soft); }

/* ---------- 1. Фонди ---------- */

.fonds { list-style: none; margin: 0; padding: 0; }

.fond-card {
  margin-top: 16px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--yellow-500);
  border-radius: var(--radius);
}

.fond-open {
  display: block;
  padding: 18px 24px 4px;
  color: inherit;
  text-decoration: none;
}
.fond-open:hover .fond-title { text-decoration: underline; text-underline-offset: 3px; }

.fond-title {
  display: block;
  margin: 2px 0 4px;
  font: 600 21px/1.3 var(--serif);
  color: var(--blue-900);
}

.fond-desc {
  margin: 6px 24px 18px;
  max-width: 75ch;
}

/* ---------- Шапка фонду / справи ---------- */

.page-head {
  margin-bottom: 24px;
  padding: 22px 26px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--yellow-500);
  border-radius: var(--radius);
}
.page-head--case { border-top-color: var(--blue-500); }

.page-title {
  margin: 4px 0 10px;
  font: 400 clamp(24px, 3vw, 30px)/1.2 var(--serif);
  color: var(--blue-900);
}

.page-sub { margin: -4px 0 12px; font-size: 14px; color: var(--ink-soft); }
.page-desc { margin: 12px 0 0; max-width: 75ch; }

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 20px;
  margin: 14px 0 0;
  font-size: 14px;
}
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; word-break: break-word; }

.case-access {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 16px;
}

.btn-open {
  display: inline-block;
  padding: 7px 14px;
  background: var(--blue-700);
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.btn-open:hover { background: var(--blue-900); color: #fff; }
.btn-open::after { content: " ↗"; color: var(--yellow-500); }

.access-note {
  display: inline-block;
  font-size: 13px;
  color: var(--yellow-ink);
  background: var(--yellow-100);
  padding: 2px 8px;
  border-radius: 2px;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}
.kw {
  padding: 2px 9px;
  background: var(--blue-50);
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-size: 13px;
  color: var(--blue-700);
  cursor: pointer;
}
.kw:hover { background: var(--yellow-100); border-color: var(--yellow-200); color: var(--yellow-ink); }

/* ---------- 2. Справи фонду ---------- */

.opys-head {
  margin: 28px 0 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--blue-100);
  font: 600 17px/1.3 var(--serif);
  color: var(--blue-700);
}

.case-rows {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.case-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 20px;
  align-items: start;
  padding: 14px 20px;
  border-top: 1px solid var(--rule);
}
.case-row:first-child { border-top: 0; }
.case-row:hover { background: var(--blue-50); }

.case-row-main { display: grid; gap: 2px; min-width: 0; }

.case-row-title {
  font: 600 18px/1.35 var(--serif);
  color: var(--blue-900);
  text-decoration: none;
}
.case-row-title:hover { text-decoration: underline; text-underline-offset: 3px; }

.type-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  max-width: 280px;
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
}

/* ---------- 3. Документи справи ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 0;
}
.chip {
  padding: 4px 11px;
  background: #fff;
  border: 1px solid #b9c5d3;
  border-radius: 999px;
  font-size: 13px;
  color: var(--blue-700);
  cursor: pointer;
}
.chip:hover { border-color: var(--blue-500); }
.chip[aria-pressed="true"] { background: var(--blue-700); border-color: var(--blue-700); color: #fff; }

.docs {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-size: 14px;
}
.docs th {
  padding: 9px 12px;
  background: var(--blue-50);
  border-bottom: 2px solid var(--blue-100);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}
.docs td {
  padding: 11px 12px;
  border-top: 1px solid var(--rule);
  vertical-align: top;
}
.docs tbody tr:hover { background: var(--blue-50); }

.doc-n { width: 2.5em; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.doc-main > span { display: block; }
.doc-title { font-weight: 600; color: var(--ink); }
.doc-authors { margin-top: 2px; font-style: italic; color: var(--ink-soft); }
.doc-summary { margin-top: 3px; color: var(--ink); }
.doc-note { margin-top: 3px; font-size: 13px; color: var(--yellow-ink); }
.doc-date, .doc-sheets { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.doc-file { white-space: nowrap; }

.file-link { font-weight: 600; }
.file-link::after { content: " ↗"; }
.file-format {
  margin-left: 8px;
  padding: 0 5px;
  border: 1px solid #b9c5d3;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}
.file-none { font-size: 13px; color: var(--ink-soft); font-style: italic; }

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}
.pager a {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  text-decoration: none;
}
.pager a:hover { border-color: var(--blue-500); }
.pager-next { text-align: right; }
.pager-label { font-size: 13px; font-weight: 600; color: var(--blue-700); }
.pager-title {
  font-size: 14px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Результати пошуку ---------- */

.result-list { list-style: none; margin: 0; padding: 0; }

.result {
  margin-top: 16px;
  padding: 18px 22px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--blue-500);
  border-radius: var(--radius);
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--ink-soft);
}

.result-title {
  font: 600 19px/1.35 var(--serif);
  color: var(--blue-900);
  text-decoration: none;
}
.result-title:hover { text-decoration: underline; text-underline-offset: 3px; }

.result .meta-line { margin-top: 2px; }
.result-hit { margin: 10px 0 0; font-size: 14px; color: var(--yellow-ink); }

.result-docs {
  list-style: none;
  margin: 12px 0 0;
  padding: 10px 14px;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  border-radius: var(--radius);
  font-size: 14px;
}
.result-docs li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 5px 0;
}
.result-docs li + li { border-top: 1px solid var(--blue-100); }
.doc-date-inline { color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums; }

.result-open {
  display: inline-block;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Порожньо / ще ---------- */

.empty {
  margin-top: 24px;
  padding: 20px;
  background: var(--yellow-100);
  border: 1px solid var(--yellow-200);
  border-radius: var(--radius);
}

.btn-more {
  display: block;
  margin: 24px auto 0;
  padding: 9px 24px;
  background: #fff;
  border: 1px solid var(--blue-700);
  border-radius: var(--radius);
  color: var(--blue-700);
  cursor: pointer;
}
.btn-more:hover { background: var(--blue-100); }

/* ---------- Підвал ---------- */

.colophon {
  border-top: 3px solid var(--yellow-500);
  background: var(--blue-900);
  color: #cfdbe8;
  font-size: 14px;
  padding: 18px 0;
}
.colophon p { margin: 4px 0; }

/* ---------- Адаптивність ---------- */

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; gap: 20px; padding-top: 20px; }
  .filters { position: static; }
}

@media (max-width: 640px) {
  .case-row { grid-template-columns: 1fr; }
  .type-summary { justify-content: flex-start; max-width: none; }

  /* Таблиця документів → картки */
  .docs, .docs tbody, .docs tr, .docs td { display: block; width: auto; }
  .docs { border: 0; background: none; }
  .docs thead { display: none; }
  .docs tr {
    position: relative;
    margin-top: 10px;
    padding: 12px 14px 12px 44px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
  }
  .docs td { padding: 0; border: 0; }
  .docs .doc-n { position: absolute; left: 14px; top: 12px; }
  .docs .doc-type, .docs .doc-date, .docs .doc-sheets, .docs .doc-file {
    display: inline-block;
    margin: 8px 12px 0 0;
  }
  .docs .doc-date::before, .docs .doc-sheets::before { content: attr(data-label) ": "; }
  .pager { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .wrap { padding-left: 16px; padding-right: 16px; }
  .page-head, .result { padding: 16px; }
  .fond-open { padding: 16px 16px 4px; }
  .fond-desc { margin: 6px 16px 16px; }
  .case-row { padding: 12px 14px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
}

/* ---------- Друк ---------- */

@media print {
  .filters, .toolbar .sort, .btn-more, .flag-rule, .eyebrow, .chips, .pager, .crumbs { display: none; }
  .layout { display: block; }
  .masthead, .colophon { background: none; color: #000; border: 0; }
  .result, .case-row, .docs tr { break-inside: avoid; }
}
