/* ── Variables ────────────────────────────────────────────────────────── */
:root {
  --bg:          #f5f4f0;
  --surface:     #ffffff;
  --surface-2:   #f0ede8;
  --border:      #e0dbd3;
  --text:        #1a1714;
  --text-muted:  #7a736a;
  --accent:      #2b5daa;
  --accent-dark: #1e4280;
  --accent-light:#e8eef8;
  --danger:      #c0392b;
  --radius:      6px;
  --radius-lg:   12px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:   0 4px 12px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg:   0 12px 40px rgba(0,0,0,.15);
  --font-sans:   'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display:'Georgia', 'Times New Roman', serif;
  --transition:  160ms ease;
  --header-h:    64px;
}

/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Header ───────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 2rem;
  gap: 2rem;
}

.site-logo {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: normal;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: .02em;
}
.site-logo span { color: var(--accent); }

.site-nav {
  display: flex;
  gap: .25rem;
  align-items: center;
}

.nav-link {
  padding: .4rem .85rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: var(--accent-light);
  color: var(--accent);
  text-decoration: none;
}

.header-spacer { flex: 1; }

/* ── Page Wrapper ─────────────────────────────────────────────────────── */
.page-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: normal;
  color: var(--text);
  margin-bottom: .35rem;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: .92rem;
  margin-bottom: 2rem;
}

/* ── Search Bar ───────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: .5rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .4rem .4rem .4rem 1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.search-bar input[type="text"] {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1rem;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
}

.search-bar input::placeholder { color: var(--text-muted); }

/* ── Filter Panel ─────────────────────────────────────────────────────── */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: flex-end;
  box-shadow: var(--shadow-sm);
}

.filter-group { display: flex; flex-direction: column; gap: .35rem; min-width: 140px; }
.filter-group label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

.filter-group select,
.filter-group input[type="number"],
.filter-group input[type="text"] {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .45rem .75rem;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  font-family: var(--font-sans);
  transition: border-color var(--transition);
}
.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  font-family: var(--font-sans);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); box-shadow: var(--shadow-sm); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

/* ── Category Grid (Index) ───────────────────────────────────────────── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.category-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  text-decoration: none;
  color: var(--text);
}
.category-card .cat-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.category-card .cat-count {
  font-size: .85rem;
  color: var(--text-muted);
}
.cat-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-light);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.1rem;
  margin-bottom: .25rem;
}

/* ── Results Header ───────────────────────────────────────────────────── */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.results-count { font-size: .9rem; color: var(--text-muted); }
.results-count strong { color: var(--text); }

/* ── Cards Grid ───────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.archive-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
}
.archive-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.card-thumb-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 2rem;
}

.card-body {
  padding: .85rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.card-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: .78rem;
  color: var(--text-muted);
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: .4rem;
}

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-image  { background: #e8f4ec; color: #2d7a45; }
.badge-pdf    { background: #fdecea; color: #c0392b; }
.badge-other  { background: var(--surface-2); color: var(--text-muted); }

/* ── Empty State ──────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  grid-column: 1 / -1;
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: .4; }
.empty-state p { font-size: 1rem; }

/* ── Pagination ───────────────────────────────────────────────────────── */
.pagination {
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}
.pagination-list {
  display: flex;
  list-style: none;
  gap: .3rem;
  flex-wrap: wrap;
  justify-content: center;
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 .5rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
a.page-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}
.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.page-btn.disabled {
  opacity: .35;
  cursor: default;
  pointer-events: none;
}
.page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  color: var(--text-muted);
}
.pagination-info {
  font-size: .82rem;
  color: var(--text-muted);
}

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,8,6,.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 1000px;
  height: 82vh;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  transform: translateY(16px) scale(.98);
  transition: transform 220ms ease;
  overflow: hidden;
}
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-shrink: 0;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: normal;
  color: var(--text);
  line-height: 1.35;
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: .1rem .3rem;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  display: flex;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.modal-media {
  width: 45%;
  flex-shrink: 0;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.modal-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.modal-media iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.modal-media .no-media {
  color: #888;
  font-size: .9rem;
  text-align: center;
  padding: 2rem;
}

.modal-details {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.detail-row {
  display: flex;
  gap: .75rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--surface-2);
  align-items: baseline;
  flex-wrap: wrap;
}
.detail-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  min-width: 110px;
  flex-shrink: 0;
}
.detail-value {
  font-size: .9rem;
  color: var(--text);
  flex: 1;
  word-break: break-word;
}

.ocr-toggle {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.ocr-toggle summary {
  cursor: pointer;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
}
.ocr-toggle summary::before { content: '▶ '; font-size: .7rem; }
.ocr-toggle[open] summary::before { content: '▼ '; }
.ocr-text-content {
  margin-top: .75rem;
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}

.modal-footer {
  padding: .85rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  flex-shrink: 0;
  background: var(--surface);
}

/* ── Breadcrumb ───────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { opacity: .4; }
.breadcrumb .current { color: var(--text); }

/* ── Stats Bar ────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem 1rem;
  font-size: .82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.stat-chip strong { color: var(--text); font-size: .95rem; }

/* ── Footer ───────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 2rem;
  text-align: center;
  font-size: .8rem;
  color: var(--text-muted);
  background: var(--surface);
  margin-top: 4rem;
}

/* ── DB Error ─────────────────────────────────────────────────────────── */
.db-error {
  background: #fdecea;
  border: 1px solid #f5c6c2;
  color: #922;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1rem;
  font-size: .9rem;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .site-header { padding: 0 1rem; gap: 1rem; }
  .page-wrapper { padding: 1.25rem 1rem 3rem; }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .filter-panel { flex-direction: column; }
  .filter-group { min-width: unset; width: 100%; }

  /* Modal: full-screen bottom sheet on mobile */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
    overflow: hidden;
    justify-content: flex-start !important;
  }

  .modal {
    width: 100vw;
    max-width: 100vw;
    height: 95dvh;
    max-height: 95dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
    overflow: hidden;        /* hard clip - nothing escapes horizontally */
  }

  .modal-overlay.open .modal {
    transform: translateY(0);
  }

  /* Single vertical scroll, no horizontal */
  .modal-body {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* Media panel: fixed height, full width */
  .modal-media {
    width: 100%;
    min-width: 0;
    height: 260px;
    flex-shrink: 0;
  }

  /* Details: natural height, no inner scroll, fully contained */
  .modal-details {
    overflow-y: visible;
    overflow-x: hidden;
    flex: none;
    padding: 1rem;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Prevent long unbroken strings from forcing width */
  .detail-row {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
  }

  .detail-label {
    min-width: 0;
    flex-shrink: 0;
  }

  .detail-value {
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
    max-width: 100%;
  }

  /* Compact header on mobile */
  .modal-header {
    padding: .85rem 1rem;
  }
  .modal-title {
    font-size: 1rem;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  /* Footer stacks buttons */
  .modal-footer {
    padding: .75rem 1rem;
    flex-wrap: wrap;
    gap: .5rem;
  }
  .modal-footer .btn {
    flex: 1;
    justify-content: center;
  }
}

/* ── PDF Search Hint ──────────────────────────────────────────────────── */
.pdf-search-hint {
  font-size: .8rem;
  color: var(--text-muted);
  background: var(--accent-light);
  border: 1px solid #c5d8f5;
  border-radius: var(--radius);
  padding: .35rem .75rem;
  flex: 1;
  display: flex;
  align-items: center;
  gap: .35rem;
}
.pdf-search-hint kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .1rem .35rem;
  font-size: .75rem;
  font-family: monospace;
  color: var(--text);
}
.pdf-search-hint strong {
  color: var(--accent-dark);
}

/* ── Share Button ─────────────────────────────────────────────────────── */
#modalShareBtn {
  transition: background var(--transition), color var(--transition);
}
#modalShareBtn:hover {
  background: var(--accent-light);
  color: var(--accent);
}
