:root {
  --green: #173f2c;
  --green-dark: #0d2f20;
  --green-light: #2d6047;
  --paper: #f3eee2;
  --card: #fffdf8;
  --line: #d3c6a7;
  --muted: #667067;
  --shadow: 0 2px 10px rgba(26, 39, 29, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: #233325;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.5;
}

.site-shell {
  margin: 0;
  box-shadow: 0 2px 10px rgba(26, 39, 29, 0.14);
}

.site-header {
  min-height: 250px;
  display: flex;
  align-items: center;
  background:
    linear-gradient(rgba(16, 65, 43, .34), rgba(8, 45, 29, .58)),
    url("tabularium_header_green_bg.jpg") center 53% / cover no-repeat;
  border-bottom: 1px solid rgba(228, 206, 142, .55);
}

.site-brand {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(22px, 4vw, 52px);
  padding: 30px 18px;
  color: #fff9e7;
  text-decoration: none;
}

.site-brand:hover { text-decoration: none; }

.site-logo-wrap {
  width: clamp(165px, 18vw, 225px);
  height: clamp(165px, 18vw, 225px);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 248, 222, .72);
  border-radius: 50%;
  background: rgba(253, 248, 233, .92);
  box-shadow: 0 5px 24px rgba(0,0,0,.24);
}

.site-logo {
  width: 84%;
  height: 84%;
  object-fit: cover;
  border-radius: 50%;
  mix-blend-mode: multiply;
}

.site-heading { display: block; text-shadow: 0 2px 5px rgba(0,0,0,.42); }

.site-title {
  display: block;
  color: #fff6d9;
  font-size: clamp(3.3rem, 8vw, 6.8rem);
  font-weight: 500;
  letter-spacing: .08em;
  line-height: .95;
}

.site-subtitle {
  display: block;
  margin-top: 18px;
  color: #fff8e5;
  font-size: clamp(1.2rem, 2.5vw, 2rem);
}

.site-subtitle-latin {
  display: block;
  margin-top: 5px;
  color: #f5ecd2;
  font-size: clamp(1.05rem, 2vw, 1.55rem);
  font-style: italic;
  letter-spacing: .02em;
}

.site-nav {
  background: linear-gradient(90deg, #0a3826, #0e4a31 50%, #0a3826);
  border-bottom: 1px solid #c99b2e;
}

.site-nav-inner {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  display: flex;
  justify-content: center;
}

.site-nav a {
  position: relative;
  display: inline-block;
  padding: 14px 28px 13px;
  color: #fff8e5;
  font-weight: 700;
}

.site-nav a:hover { text-decoration: none; background: rgba(255,255,255,.05); }
.site-nav a.active::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 0;
  height: 3px;
  background: #d3a52e;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 18px 40px;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(45, 96, 71, .35);
  outline-offset: 2px;
}

.card {
  margin: 0 0 16px;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); }

.search-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 16px 22px;
}

.field { margin: 0; }

.year-search {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
}

.year-search .input-wrap { min-width: 0; }
.field-error { margin: 6px 0 0; color: #8b1e1e; font-size: .92rem; }
.field label { display: block; margin-bottom: 6px; font-weight: 700; }
.input-wrap { position: relative; }

input[type="search"], select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #bfb18f;
  border-radius: 6px;
  background: #fff;
  color: #233325;
  font: inherit;
  font-size: 1rem;
}

input[type="search"] { padding-right: 42px; }
input[type="search"]::-webkit-search-cancel-button { display: none; }

.clear-field {
  position: absolute;
  top: 50%;
  right: 8px;
  display: none;
  width: 30px;
  height: 30px;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #596359;
  font-size: 24px;
  line-height: 1;
}

.clear-field:hover { background: #eee9dc; color: #233325; }
.input-wrap.has-value .clear-field { display: block; }

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

button, .button {
  display: inline-block;
  min-height: 44px;
  padding: 10px 20px;
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
}

button:hover, .button:hover { background: var(--green-light); text-decoration: none; }
.button-secondary { background: #6c675a; }
.button-secondary:hover { background: #575247; }

.contact-action {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.contact-action .button {
  text-align: center;
}

.site-footer {
  padding: 18px 20px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-size: .92rem;
}

.catalog-stats {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid #e1d8c3;
  color: var(--muted);
  font-size: .98rem;
}

.results-summary { margin: 4px 2px 14px; }

.result-card h2 {
  margin: 0 0 8px;
  color: var(--green-dark);
  font-size: 1.35rem;
  line-height: 1.28;
}

.result-title a {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  max-height: 3.46rem;
  line-height: 1.28;
  color: #222;
  text-decoration: none;
}

.result-title a:hover {
  color: #6b4b2a;
  text-decoration: underline;
}

.result-author { margin: 0 0 6px; font-weight: 700; }
.result-meta { line-height: 1.6; }
.result-location {
  margin: 14px 0 0;
  padding-top: 10px;
  border-top: 1px solid #e5ddca;
  color: var(--muted);
}

.detail-heading { margin-top: 0; color: var(--green-dark); }
.back-link { display: inline-block; margin-bottom: 14px; }
.detail-table { width: 100%; border-collapse: collapse; }
.detail-table tr { border-bottom: 1px solid #e8e0ce; }
.detail-table tr:last-child { border-bottom: 0; }
.detail-table th {
  width: 220px;
  padding: 9px 20px 9px 0;
  text-align: left;
  vertical-align: top;
}
.detail-table td { padding: 9px 0; vertical-align: top; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  main { padding: 12px 10px 28px; }
  .site-header { min-height: 190px; }
  .site-brand { width: calc(100% - 20px); gap: 14px; padding: 24px 10px; }
  .site-logo-wrap { width: 108px; height: 108px; border-width: 1px; }
  .site-title { font-size: clamp(2rem, 10vw, 3.15rem); letter-spacing: .04em; }
  .site-subtitle { margin-top: 8px; font-size: .98rem; line-height: 1.25; }
  .site-subtitle-latin { margin-top: 4px; font-size: .88rem; line-height: 1.25; }
  .site-nav-inner { width: calc(100% - 20px); }
  .site-nav a { padding: 12px 22px 11px; }
  .search-grid { grid-template-columns: 1fr; }
  .year-search { grid-template-columns: 1fr; }
  .card { padding: 17px; }
  .detail-table, .detail-table tbody, .detail-table tr, .detail-table th, .detail-table td { display: block; width: 100%; }
  .detail-table th { padding: 10px 0 2px; }
  .detail-table td { padding: 0 0 10px; }
}

/* Bibliograafilise kirje detailvaade */
.detail-page { max-width: 980px; margin: 0 auto; }
.detail-title-block {
  margin: 0 0 18px;
  padding: 18px 22px;
  border-left: 5px solid var(--green);
  background: rgba(255, 253, 248, .72);
}
.detail-heading {
  margin: 0;
  color: var(--green-dark);
  font-size: clamp(1.65rem, 3vw, 2.4rem);
  line-height: 1.2;
}
.detail-author { margin: 9px 0 0; font-size: 1.12rem; font-weight: 700; }
.detail-section { padding: 0; overflow: hidden; }
.section-heading {
  margin: 0;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #e9e2cf;
  color: var(--green-dark);
  font-size: 1.25rem;
}
.detail-list { margin: 0; }
.detail-list > div {
  display: grid;
  grid-template-columns: minmax(170px, 230px) minmax(0, 1fr);
  border-bottom: 1px solid #e8e0ce;
}
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt {
  padding: 11px 18px;
  background: rgba(243, 238, 226, .45);
  font-weight: 700;
}
.detail-list dd {
  min-width: 0;
  margin: 0;
  padding: 11px 18px;
  overflow-wrap: anywhere;
}
.copy-section { border-color: #b5a579; }
.copy-section .section-heading {
  background: var(--green);
  color: #fff8e5;
}
.inventory-badge {
  display: inline-block;
  padding: 5px 11px;
  border: 1px solid #b58a26;
  border-radius: 5px;
  background: #fff6d8;
  color: var(--green-dark);
  font-weight: 700;
  letter-spacing: .02em;
}

@media (max-width: 760px) {
  .detail-title-block { padding: 14px 16px; }
  .detail-list > div { display: block; }
  .detail-list dt { padding: 10px 16px 2px; background: transparent; }
  .detail-list dd { padding: 0 16px 10px; }
}

/* Kontaktvorm ja kirje veast teatamine */
.contact-page { max-width: 780px; margin: 0 auto; }
.contact-card h1 { margin-top: 0; color: var(--green-dark); }
.contact-field { margin-top: 18px; }
.contact-field label { display: block; margin-bottom: 6px; }
.contact-field input[type="email"],
.contact-field input[type="text"],
.contact-field textarea {
  box-sizing: border-box;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #bfb18f;
  border-radius: 6px;
  background: #fff;
  color: #233325;
  font: inherit;
}
.contact-field textarea { resize: vertical; }
.contact-field input:focus,
.contact-field textarea:focus {
  border-color: var(--green);
  outline: 2px solid rgba(43, 83, 50, .16);
}
.help-text { margin: 6px 0 0; color: var(--muted); font-size: .92rem; }
.form-errors {
  margin: 16px 0;
  padding: 10px 12px;
  border-left: 4px solid #8b1e1e;
  background: #f8e7e7;
}
.success-card { text-align: center; }
.success-card .actions { justify-content: center; }
.record-report { margin-top: 18px; text-align: right; }
