/* ============================================================
   Idazluma — Euskal Dokumentu Bilaketa Sistema
   Proyecto colaborativo, no oficial. Simple parchment-style
   archival look.
   ============================================================ */

:root {
  --bg:           #faf7f0;
  --surface:      #ffffff;
  --border:       #d6c99a;
  --border-light: #e8e0c8;
  --accent:       #5c3d10;
  --accent-hover: #7a5218;
  --accent-faint: #f5ede0;
  --text:         #2a1f0e;
  --text-muted:   #7a6140;
  --danger:       #8b2020;
  --radius:       5px;
  --shadow:       0 1px 4px rgba(0,0,0,0.08);
}

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

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: var(--accent);
  color: #fff;
  padding: 1.1rem 2rem;
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
  border-bottom: 3px solid #3d2509;
}
header h1 {
  font-size: 1.45rem;
  font-weight: normal;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
header p {
  font-size: 0.82rem;
  opacity: 0.72;
  font-family: sans-serif;
  letter-spacing: 0.03em;
}

/* ── Language switcher ── */
.lang-switcher {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.lang-switcher a {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-family: sans-serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: rgba(255,255,255,0.65);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 3px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.lang-switcher a:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-color: rgba(255,255,255,0.5);
}
.lang-switcher a.active {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border-color: rgba(255,255,255,0.7);
  pointer-events: none;
}

/* ── Main ── */
main {
  flex: 1;
  max-width: 980px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

/* ── Search card ── */
.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}
.search-card h2 {
  font-size: 0.72rem;
  font-family: sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 1.1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.8rem 1.1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}
.form-group label {
  font-size: 0.72rem;
  font-family: sans-serif;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.form-group input,
.form-group select {
  padding: 0.42rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: Georgia, serif;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 3px rgba(92,61,16,0.12);
}
.form-group input::placeholder { color: #bba876; }

.form-actions {
  margin-top: 1.1rem;
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

/* ── Buttons ── */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1.3rem;
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: sans-serif;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
button:hover, .btn:hover     { background: var(--accent-hover); }
button.secondary             {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
button.secondary:hover       { background: var(--accent-faint); }

/* ── HTMX loading ── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text-muted); font-size: 0.85rem; font-family: sans-serif; }
.spinner {
  width: 1rem; height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Results header ── */
.results-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.results-header h2 {
  font-size: 0.72rem;
  font-family: sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}
.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-family: sans-serif;
  font-weight: 600;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
}

.trimmed-notice {
  font-size: 0.82rem;
  font-family: sans-serif;
  color: var(--accent);
  background: var(--accent-faint);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.9rem;
  margin-bottom: 1rem;
}

/* ── Record cards ── */
.record-list { display: flex; flex-direction: column; gap: 0.9rem; }

.record-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  transition: border-left-color 0.15s;
}
.record-card:hover { border-left-color: var(--accent); }

.record-title {
  font-size: 1rem;
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 0.2rem;
  line-height: 1.4;
}
.record-description {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: sans-serif;
  margin-bottom: 0.4rem;
  line-height: 1.4;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.2rem;
  font-size: 0.78rem;
  font-family: sans-serif;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.record-meta span { white-space: nowrap; }
.record-meta a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--text-muted);
}
.record-meta a:hover { color: var(--accent); border-bottom-color: var(--accent); }

.record-detail {
  font-size: 0.85rem;
  margin-top: 0.35rem;
  color: var(--text);
  line-height: 1.5;
}
.record-detail .label {
  font-size: 0.72rem;
  font-family: sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-right: 0.4rem;
}

.record-images {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.record-images a {
  font-size: 0.75rem;
  font-family: sans-serif;
  color: var(--accent-hover);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.5rem;
  background: var(--accent-faint);
  transition: background 0.12s;
}
.record-images a:hover { background: var(--border-light); }

/* ── No results / empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-family: sans-serif;
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty-state .icon { font-size: 2rem; margin-bottom: 0.5rem; }

/* ── Error ── */
.error-box {
  background: #fff8f8;
  border: 1px solid #e8c0c0;
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  color: var(--danger);
  font-family: sans-serif;
}
.error-box .error-title {
  font-weight: 700;
  margin-bottom: 0.35rem;
  font-size: 0.95rem;
}

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border-light);
  padding: 1.2rem 2rem;
  text-align: center;
  font-size: 0.78rem;
  font-family: sans-serif;
  color: var(--text-muted);
  margin-top: auto;
}

/* ── Search help ── */
details.search-help {
  margin-top: 1rem;
  font-family: sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
}
details.search-help summary {
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
details.search-help summary::before { content: "▶"; font-size: 0.65rem; transition: transform 0.15s; }
details[open].search-help summary::before { transform: rotate(90deg); }
details.search-help .help-body {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1.5rem;
}
@media (max-width: 600px) { details.search-help .help-body { grid-template-columns: 1fr; } }
.help-section h4 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.help-section ul { padding-left: 1.1rem; line-height: 1.9; }
.help-section code {
  font-family: monospace;
  background: var(--accent-faint);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85em;
  color: var(--accent);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 18, 5, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 1.75rem 2rem;
  max-width: 460px;
  width: 100%;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  line-height: 1;
}
.modal-close:hover { background: var(--accent-faint); color: var(--accent); }
.modal h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 0.35rem;
}
.modal-img-ref {
  font-size: 0.78rem;
  font-family: monospace;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 0.3rem 0.6rem;
  margin-bottom: 1rem;
  word-break: break-all;
}
.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: sans-serif;
  margin-bottom: 1rem;
  line-height: 1.5;
}
.modal .form-group { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1.25rem; }
.modal-actions .btn-pay {
  flex: 1;
  justify-content: center;
  background: #635bff; /* Stripe purple */
  border-color: transparent;
}
.modal-actions .btn-pay:hover { background: #4f48cc; }
.modal-actions .btn-pay.disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ── Modal thumbnail ── */
.modal-thumb-area {
  margin-bottom: 1rem;
  text-align: center;
  min-height: 2rem;
}
.modal-thumb-area img {
  max-width: 100%;
  max-height: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  object-fit: contain;
  display: block;
  margin: 0 auto;
}
.modal-thumb-loading {
  font-size: 0.78rem;
  font-family: sans-serif;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0;
}

/* ── Modal success state ── */
.modal-success {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}
.modal-success .success-icon { font-size: 2.2rem; }
.modal-success p {
  font-family: sans-serif;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  line-height: 1.5;
}

/* ── Record actions (Ver ficha button) ── */
.record-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.ficha-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.9rem;
  background: var(--accent-faint);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-family: sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ficha-btn:hover {
  background: var(--border-light);
  border-color: var(--accent);
}

/* ── Ficha modal ── */
.ficha-modal { max-width: 560px; }
.ficha-modal h3 {
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 1rem;
  line-height: 1.4;
  padding-right: 1.5rem;
}
.ficha-fields {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}
.ficha-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-light);
}
.ficha-row:last-child { border-bottom: none; }
.ficha-row:nth-child(even) { background: var(--bg); }
.ficha-row dt {
  font-size: 0.72rem;
  font-family: sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 5.5rem;
  flex-shrink: 0;
}
.ficha-row dd {
  font-size: 0.88rem;
  color: var(--text);
  font-family: Georgia, serif;
  line-height: 1.5;
}
.ficha-row dd a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--border);
}
.ficha-row dd a:hover { border-bottom-color: var(--accent); }

/* ── Image buttons ── */
.img-btn {
  font-size: 0.75rem;
  font-family: sans-serif;
  color: var(--accent-hover);
  background: var(--accent-faint);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
  transition: background 0.12s;
}
.img-btn:hover { background: var(--border-light); }

.img-undigitized {
  font-size: 0.75rem;
  font-family: sans-serif;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  header { flex-wrap: wrap; gap: 0.25rem 0.6rem; padding: 1rem; }
  header h1 { flex: 0 0 auto; }
  header p  { flex: 1 1 100%; order: 3; }
  .lang-switcher { margin-left: auto; }
  main   { margin: 1rem auto; padding: 0 1rem; }
  .form-grid { grid-template-columns: 1fr; }
}

/* Contribution message */
.modal-contribution-msg {
  font-size: 0.9rem;
  color: #5c3d10;
  background: #fef9ec;
  border-left: 3px solid #c8922a;
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  border-radius: 0 4px 4px 0;
  line-height: 1.5;
}

/* Pay / free buttons row */
.modal-actions-pay {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.modal-actions-pay .btn-pay {
  font-size: 1.05rem;
  padding: 0.75rem 1rem;
  text-align: center;
}
.btn-free {
  background: none;
  border: 1px solid #aaa;
  color: #555;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-free:hover:not(.disabled) { background: #f0ebe3; }
.btn-free.disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ── Header record count ── */
.header-count {
  font-size: 0.75rem;
  opacity: 0.85;
  font-family: sans-serif;
  letter-spacing: 0.02em;
  flex: 1 1 100%;
}
.header-count #record-count {
  font-weight: bold;
  font-size: 0.9rem;
}

/* ── Ficha page ── */
.ficha-page, .imagen-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 0;
}
.ficha-nav {
  margin-bottom: 1.2rem;
}
.ficha-page-title {
  font-size: 1.2rem;
  color: var(--accent);
  margin-bottom: 1rem;
}
.ficha-images {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.ficha-tag {
  display: inline-block;
  background: #f0ebe3;
  border: 1px solid #d4c9b5;
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  font-size: 0.82rem;
  margin: 0.1rem 0.1rem 0.1rem 0;
}
