@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #f6f2e9;
  --surface: #ffffff;
  --ink: #22271f;
  --ink-dim: #6f7566;
  --forest: #1f3b32;
  --forest-dim: #2c4d42;
  --brass: #b3854f;
  --brass-light: #e3c9a0;
  --border: #e4ddcb;
  --danger: #a8452c;
  --warn: #96702c;
  --warn-bg: #f7ecd8;
  --success: #3c6b49;
  --success-bg: #e6efe4;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: 'Inter', sans-serif; font-size: 15px; }
a { color: var(--forest); text-decoration: none; }
h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; margin: 0 0 6px; color: var(--forest); }

/* ---- Header ---- */
.site-header { background: var(--forest); padding: 14px 0; }
.site-header-inner {
  max-width: 1160px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
}
.site-brand { display: flex; align-items: center; gap: 10px; color: #f3ede0; font-family: 'Fraunces', serif; font-weight: 600; font-size: 17px; }
.site-brand-mark { background: var(--brass); color: var(--forest); width: 30px; height: 30px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 13px; }

.site-search { display: flex; flex-grow: 1; max-width: 440px; }
.search-input-wrap { position: relative; flex-grow: 1; }
.search-input-wrap input {
  width: 100%; padding: 9px 30px 9px 12px; border: none; border-radius: 4px 0 0 4px;
  font-family: 'Inter', sans-serif; font-size: 13.5px;
}
.search-clear-x {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  color: var(--ink-dim); font-size: 17px; line-height: 1; width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.search-clear-x:hover { background: #ece7d8; color: var(--ink); }
.site-search button {
  padding: 9px 16px; border: none; border-radius: 0 4px 4px 0; background: var(--brass);
  color: var(--forest); font-weight: 600; font-size: 13px; cursor: pointer; flex-shrink: 0;
}

.site-nav { display: flex; align-items: center; gap: 18px; margin-inline-start: auto; }
.site-nav a { color: rgba(243,237,224,0.85); font-size: 13.5px; font-weight: 500; }
.site-nav a:hover { color: #fff; }
.site-nav-user { color: var(--brass-light); font-size: 13px; }
.btn-pill { background: var(--brass); color: var(--forest) !important; padding: 7px 14px; border-radius: 100px; font-weight: 600 !important; }

.lang-switch select {
  background: transparent; color: rgba(243,237,224,0.85); border: 1px solid rgba(243,237,224,0.3);
  border-radius: 4px; padding: 5px 8px; font-size: 12px; font-family: 'Inter', sans-serif;
}
.lang-switch select option { color: #111; }

/* ---- Main ---- */
.site-main { max-width: 1160px; margin: 0 auto; padding: 30px 24px 60px; min-height: 60vh; }

.hero { margin-bottom: 28px; }
.hero p { color: var(--ink-dim); font-size: 15px; max-width: 560px; }

.home-layout { display: grid; grid-template-columns: 240px 1fr; gap: 32px; align-items: start; }
.home-layout > div:last-child { min-width: 0; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 34px 0 14px; }
.section-heading:first-child { margin-top: 0; }
.section-heading h2 { font-size: 18px; }

/* ---- Book grid (home / related) ---- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px; }
.book-card { display: block; }
.book-card .cover {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 5px;
  border: 1px solid var(--border); background: #ece7d8; margin-bottom: 8px;
}
.book-card .cover-placeholder {
  width: 100%; aspect-ratio: 2/3; border-radius: 5px; border: 1px solid var(--border);
  background: linear-gradient(135deg, #ece7d8, #e1dac5); margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center; color: var(--ink-dim);
  font-family: 'Fraunces', serif; font-size: 12px; text-align: center; padding: 10px;
}
.book-card .card-title { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.3; }
.book-card .card-author { font-size: 11.5px; color: var(--ink-dim); margin-top: 2px; }
.book-card .card-languages { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.book-card .card-author a, .book-card .card-languages a { color: inherit; text-decoration: none; }
.book-card .card-author a:hover, .book-card .card-languages a:hover { text-decoration: underline; }

/* ---- Author row (home) ---- */
.author-row-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 18px; }
.author-card { text-align: center; }
.author-card .photo {
  width: 76px; height: 76px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border);
  background: #ece7d8; margin: 0 auto 8px;
}
.author-card .photo-placeholder {
  width: 76px; height: 76px; border-radius: 50%; background: linear-gradient(135deg, #ece7d8, #e1dac5);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 8px; font-family: 'Fraunces', serif;
  color: var(--ink-dim); font-size: 20px;
}
.author-card .name { font-size: 12.5px; font-weight: 600; }

/* ---- Search / results list ---- */
.search-layout { display: grid; grid-template-columns: 240px 1fr; gap: 32px; align-items: start; }
.search-layout > div:last-child { min-width: 0; }

.filters-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; position: sticky; top: 20px;
}
.filters-panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-dim); margin-bottom: 14px; }
.filters-panel .field { margin-bottom: 14px; }
.filters-panel label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-dim); margin-bottom: 5px; }
.filters-panel select, .filters-panel input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; font-family: 'Inter', sans-serif;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.filters-panel select:focus, .filters-panel input:focus {
  outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(179,133,79,0.15);
}
.filters-panel .year-row { display: flex; gap: 8px; }

/* ---- Type-ahead combo (category / author filters) ---- */
.combo-wrap { position: relative; }
.combo-search { padding-right: 30px !important; cursor: text; }
.combo-clear {
  position: absolute; right: 7px; top: 7px; width: 21px; height: 21px; border: none; background: none;
  color: var(--ink-dim); font-size: 17px; line-height: 1; cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; transition: background 0.12s ease, color 0.12s ease;
}
.combo-clear:hover { background: #ece7d8; color: var(--danger); }

.combo-options {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 6px; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  max-height: 248px; overflow-y: auto; padding: 6px;
  box-shadow: 0 14px 32px rgba(34,39,31,0.14), 0 2px 8px rgba(34,39,31,0.06);
}

.combo-option {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; font-size: 13px; color: var(--ink); cursor: pointer;
  border-radius: 5px; transition: background 0.1s ease;
}
.combo-option:hover, .combo-option.active { background: var(--bg); }
.combo-option + .combo-option { margin-top: 1px; }

/* The "All categories" / "All authors" reset option, always first */
.combo-option-all {
  font-style: italic; color: var(--ink-dim);
  border-bottom: 1px solid var(--border); border-radius: 5px 5px 0 0; margin-bottom: 4px; padding-bottom: 9px;
}

/* The option matching whatever filter is currently applied */
.combo-option.is-selected { background: var(--warn-bg); }
.combo-option.is-selected .combo-option-label { font-weight: 600; color: var(--forest); }
.combo-option.is-selected .combo-option-label::before { content: "✓ "; color: var(--brass); font-weight: 700; }

.combo-option-label { flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.combo-count {
  flex-shrink: 0; display: inline-block; min-width: 15px; text-align: center;
  font-weight: 700; font-size: 11px; letter-spacing: 0.01em;
  background: var(--brass-light); color: var(--forest-dim);
  padding: 2px 9px; border-radius: 999px; line-height: 1.6;
}
.combo-option:hover .combo-count, .combo-option.active .combo-count {
  background: var(--brass); color: #fff;
}

.combo-empty { padding: 12px 10px; font-size: 12.5px; color: var(--ink-dim); text-align: center; font-style: italic; }

.combo-more {
  display: block; text-align: center; padding: 9px 10px; margin-top: 2px;
  font-size: 12.5px; font-weight: 600; color: var(--forest); text-decoration: none;
  border-top: 1px solid var(--border); border-radius: 0 0 5px 5px;
}
.combo-more:hover { background: var(--bg); text-decoration: underline; }

/* [hidden] ties in specificity with any of the explicit `display`
   rules above (.combo-option, .combo-clear, .combo-more each set
   their own display: flex/block) — and since these rules load after
   the browser's default stylesheet, the tie goes to them, silently
   overriding [hidden]. This makes the JS-driven hide/show (filtering,
   the clear button, "show more") actually take effect. */
.combo-option[hidden], .combo-clear[hidden], .combo-more[hidden] { display: none !important; }

.results-count { color: var(--ink-dim); font-size: 13px; margin-bottom: 16px; }

.result-row { display: flex; gap: 16px; padding: 18px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.result-row:first-child { padding-top: 0; }
.result-row > div:last-child { min-width: 0; flex: 1 1 200px; }
.result-row .cover, .result-row .cover-placeholder {
  width: 80px; flex-shrink: 0; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--border); background: #ece7d8;
}
.result-row .cover-placeholder { display: flex; align-items: center; justify-content: center; color: var(--ink-dim); font-family: 'Fraunces', serif; font-size: 11px; text-align: center; padding: 6px; }
.result-row .result-title { font-size: 16.5px; margin-bottom: 3px; }
.result-row .result-title a { color: var(--forest); }
.result-meta { font-size: 12.5px; color: var(--ink-dim); margin-bottom: 8px; }
.result-meta a { color: var(--ink-dim); text-decoration: underline; text-decoration-color: var(--border); }
.result-meta a:hover { color: var(--forest); text-decoration-color: var(--brass); }
.result-excerpt { font-size: 13.5px; color: var(--ink); line-height: 1.5; }
.result-languages { font-size: 12px; color: var(--ink-dim); margin-top: 6px; }
.result-languages a { color: inherit; text-decoration: none; }
.result-languages a:hover { text-decoration: underline; }
.result-badges { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 100px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-neutral { background: #ece7d8; color: var(--ink-dim); }

/* ---- Book detail page ---- */
.detail-layout { display: grid; grid-template-columns: 220px 1fr; gap: 36px; }
.detail-layout > div:last-child { min-width: 0; }
.detail-cover { width: 100%; border-radius: 6px; border: 1px solid var(--border); }
.detail-cover-placeholder {
  width: 100%; aspect-ratio: 2/3; border-radius: 6px; border: 1px solid var(--border);
  background: linear-gradient(135deg, #ece7d8, #e1dac5); display: flex; align-items: center; justify-content: center;
  color: var(--ink-dim); font-family: 'Fraunces', serif; padding: 20px; text-align: center;
}
.detail-title { font-size: 26px; margin-bottom: 6px; }
.detail-authors { font-size: 15px; color: var(--ink-dim); margin-bottom: 4px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.detail-authors a { color: var(--forest); font-weight: 500; }
.author-chip { display: inline-flex; align-items: center; gap: 6px; }
.author-chip img, .author-chip .ph {
  width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); background: #ece7d8;
}
.author-chip .ph { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--ink-dim); font-family: 'Fraunces', serif; }

.language-editions { margin: 10px 0 18px; font-size: 13px; color: var(--ink-dim); }
.language-editions .lang-badge {
  display: inline-block; padding: 4px 11px; border-radius: 100px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); margin-inline-end: 6px; color: var(--ink);
}
.language-editions .lang-badge.current { background: var(--forest); color: #fff; border-color: var(--forest); }

.detail-actions { display: flex; gap: 10px; margin: 20px 0; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; padding: 10px 18px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--forest); color: #fff; }
.btn-primary:hover { background: var(--forest-dim); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-outline:hover { border-color: var(--forest); color: var(--forest); }
.btn-locked { background: var(--warn-bg); color: var(--warn); cursor: default; }
.btn-favorite { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-favorite.active { background: var(--brass-light); border-color: var(--brass); color: var(--forest-dim); }

.notify-btn {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 5px 11px; border-radius: 100px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-dim);
  cursor: pointer;
}
.notify-btn.active { background: var(--success-bg); border-color: #cfe2cc; color: var(--success); }

.detail-meta-table { font-size: 13.5px; margin: 20px 0; }
.detail-meta-table tr td { padding: 5px 0; }
.detail-meta-table tr td:first-child { color: var(--ink-dim); width: 130px; }
.detail-meta-table a { text-decoration: underline; text-decoration-color: var(--border); }

.detail-description { font-size: 14.5px; line-height: 1.7; margin: 20px 0; max-width: 640px; }

.share-row { display: flex; align-items: center; gap: 10px; margin: 24px 0; }
.share-row .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-dim); }
.share-btn {
  width: 34px; height: 34px; border-radius: 100px; background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--forest);
}
.share-btn:hover { border-color: var(--brass); }

/* ---- Auth forms ---- */
.auth-card {
  max-width: 420px; margin: 20px auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 30px 32px;
}
.auth-card h1 { font-size: 21px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.auth-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; font-family: 'Inter', sans-serif;
}
.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 6px; }
.auth-card .switch-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--ink-dim); }
.auth-card .checkbox-row { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; margin-bottom: 16px; }
.auth-card .checkbox-row input { width: auto; margin-top: 3px; }
.auth-card .form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.captcha-box { background: #faf7f0; border: 1px solid var(--border); border-radius: 4px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.captcha-box strong { font-family: 'Fraunces', serif; }

.flash { padding: 11px 16px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 20px; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: var(--success); border-color: #cfe2cc; }
.flash-error { background: #f6e6e1; color: var(--danger); border-color: #ecd2ca; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-dim); font-size: 13.5px; }

.legal-page { max-width: 680px; font-size: 14px; line-height: 1.7; }
.legal-page h2 { font-size: 16px; margin-top: 24px; }

/* ---- Footer ---- */
.site-footer { border-top: 1px solid var(--border); margin-top: 40px; }
.site-footer-inner { max-width: 1160px; margin: 0 auto; padding: 20px 24px; font-size: 12.5px; color: var(--ink-dim); display: flex; gap: 10px; flex-wrap: wrap; }
.site-footer-sep { color: var(--border); }

@media (max-width: 780px) {
  .search-layout, .detail-layout, .home-layout { grid-template-columns: 1fr; }
  .filters-panel { position: static; }
  .site-search { order: 3; max-width: 100%; }
  .auth-card .form-row-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .site-header-inner { gap: 12px; }
  .site-nav { gap: 12px; margin-inline-start: 0; flex-wrap: wrap; }
  .site-main { padding: 20px 16px 40px; }
  .detail-title { font-size: 22px; }
  .hero h1 { font-size: 26px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
  .author-row-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
  .result-row .cover, .result-row .cover-placeholder { width: 64px; }
  .auth-card { padding: 24px 20px; }
  .detail-meta-table tr td:first-child { width: 105px; }
}

@media (max-width: 420px) {
  .site-brand { font-size: 15px; }
  .site-brand-mark { width: 26px; height: 26px; font-size: 11px; }
  .detail-actions .btn, .share-row, .notify-btn { font-size: 12.5px; }
  .result-row { gap: 12px; }
  .result-row .cover, .result-row .cover-placeholder { width: 56px; }
  .combo-options { left: -1px; right: -1px; }
}

/* ---- Author profile ---- */
.author-profile { display: flex; gap: 28px; align-items: flex-start; margin-bottom: 30px; }
.author-profile-photo {
  width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border);
  background: #ece7d8; flex-shrink: 0;
}
.author-profile-photo-placeholder {
  width: 120px; height: 120px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #ece7d8, #e1dac5); display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-size: 42px; color: var(--ink-dim);
}
.author-profile-body { flex-grow: 1; min-width: 0; }
.author-profile-body h1 { font-size: 25px; margin-bottom: 4px; }
.author-profile-accreditations { font-size: 14px; color: var(--ink-dim); margin-bottom: 8px; }
.author-profile-orcid { font-size: 13px; margin-bottom: 14px; }
.author-profile-orcid a { display: inline-flex; align-items: center; gap: 6px; color: var(--forest); font-weight: 500; }
.author-profile-orcid a:hover { text-decoration: underline; }
.author-profile-bio { font-size: 14.5px; line-height: 1.65; color: var(--ink); max-width: 640px; margin: 0 0 16px; }

@media (max-width: 560px) {
  .author-profile { flex-direction: column; align-items: center; text-align: center; }
  .author-profile-bio { max-width: 100%; }
}

/* ============================================================
   RTL support (Arabic UI language)
   ============================================================
   Flexbox and Grid both follow the page's writing direction by
   default, so most of this site's layout (header nav, the sidebar/
   content split on search & home, share-row, detail-actions, etc.)
   already mirrors correctly under dir="rtl" with zero extra CSS.
   Only a handful of things that use PHYSICAL left/right positioning
   (rather than direction-aware "start/end") need an explicit RTL
   counterpart — that's everything below.
   ============================================================ */

[dir="rtl"] .search-input-wrap input {
  padding: 9px 12px 9px 30px;
  border-radius: 0 4px 4px 0;
}
[dir="rtl"] .search-clear-x { right: auto; left: 8px; }
[dir="rtl"] .site-search button { border-radius: 4px 0 0 4px; }

[dir="rtl"] .combo-search { padding-right: 12px !important; padding-left: 30px !important; }
[dir="rtl"] .combo-clear { right: auto; left: 7px; }

/* A book's own text direction follows ITS language, not the site's —
   see the .book-rtl-text wrapper used in book.php / search.php /
   index.php for a specific title's title/summary/description. This
   is independent of [dir="rtl"] above, which only covers the site
   chrome itself when the visitor's UI language is Arabic. */
.book-rtl-text { direction: rtl; text-align: right; unicode-bidi: isolate; }
