/* ==========================================================================
   Ahadees — modern responsive RTL stylesheet
   ========================================================================== */

/* Self-hosted fonts. font-display:swap → text shows immediately in a fallback,
   then swaps to the web font once it arrives (non-blocking). */
@font-face {
  font-family: "Jameel Noori";
  src: url("/assets/fonts/Jameel_Noori.v1.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  /* Jameel Noori renders small; scale its glyphs up. This only affects the
     web font (not the fallback), so text grows once the font has loaded. */
  size-adjust: 118%;
}
@font-face {
  font-family: "Amiri";
  src: url("/assets/fonts/Amiri-Regular.v1.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1b19;
  --ink-soft: #55524c;
  --muted: #8a8680;
  --line: #e5e2db;
  --brand: #0f6b4f;
  --brand-ink: #0b4d39;
  --brand-soft: #e3f0ea;
  --accent: #b8892b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.05);
  --wrap: 960px;
  --ur: "Jameel Noori", "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif;
  --ar: "Amiri", "Noto Naskh Arabic", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

/* Dark palette (shared by OS-preference and the explicit "dark" choice). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #14150f; --surface: #1d1e17; --surface-2: #23241c;
    --ink: #ecebe4; --ink-soft: #c3c1b6; --muted: #8f8d81;
    --line: #33342a; --brand: #4fbf95; --brand-ink: #7fd4b3;
    --brand-soft: #17352a; --accent: #d8ab54;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
/* Explicit user choice wins over the OS preference. Light needs no var
   overrides — it inherits the :root defaults; it only re-asserts the scheme. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  --bg: #14150f; --surface: #1d1e17; --surface-2: #23241c;
  --ink: #ecebe4; --ink-soft: #c3c1b6; --muted: #8f8d81;
  --line: #33342a; --brand: #4fbf95; --brand-ink: #7fd4b3;
  --brand-soft: #17352a; --accent: #d8ab54;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: 16px;
}
img { max-width: 100%; height: auto; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 16px; }
.ur { font-family: var(--ur); line-height: 2.1; }
.muted { color: var(--muted); }
.skip-link { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link:focus { position: fixed; inset-block-start: 8px; inset-inline-start: 8px; width: auto; height: auto; clip: auto; background: var(--surface); padding: 8px 12px; z-index: 20; border-radius: 8px; }

/* ---- Header / nav ------------------------------------------------------ */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
/* Header bar uses LTR ordering (logo left, controls right) even though the
   site content is RTL. */
.header-inner { display: flex; direction: ltr; align-items: center; gap: 12px; padding-block: 10px; }
.brand { display: inline-flex; align-items: center; margin-inline-end: auto; }
.brand-logo { display: block; height: 44px; width: auto; }
.brand-logo--dark { display: none; }
/* Swap logo variant with the theme (mirrors the palette logic). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .brand-logo--light { display: none; }
  :root:not([data-theme]) .brand-logo--dark { display: block; }
}
:root[data-theme="dark"]  .brand-logo--light { display: none; }
:root[data-theme="dark"]  .brand-logo--dark  { display: block; }
:root[data-theme="light"] .brand-logo--light { display: block; }
:root[data-theme="light"] .brand-logo--dark  { display: none; }

.search-mini { display: flex; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.search-mini input { border: 0; background: transparent; padding: 4px 16px; color: var(--ink); min-width: 0; width: 20rem; font: inherit; }
.search-mini input:focus { outline: none; }
.search-mini button { border: 0; background: transparent; padding: 3px 12px; cursor: pointer; font-size: .95rem; }

.theme-toggle { border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 1.05rem; line-height: 1; border-radius: 9px; padding: 7px 11px; cursor: pointer; }
.theme-toggle:hover { border-color: var(--brand); }
.theme-toggle .theme-icon { display: inline-block; }

.nav-toggle { display: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 1.2rem; border-radius: 9px; padding: 4px 12px; cursor: pointer; }

.main-nav { border-top: 1px solid var(--line); background: var(--surface-2); }
.main-nav ul {
  list-style: none; display: flex; direction: ltr; flex-wrap: nowrap; justify-content: center;
  gap: 2px; margin: 0; padding: 4px 0;
  overflow-x: auto; -ms-overflow-style: none; scrollbar-width: none;
}
.main-nav ul::-webkit-scrollbar { display: none; }
.main-nav li { white-space: nowrap; }
.main-nav a { display: block; padding: 6px 9px; border-radius: 8px; color: var(--ink-soft); font-size: .8rem; }
.main-nav a:hover { background: var(--brand-soft); text-decoration: none; }
.main-nav li.active a { color: var(--brand-ink); font-weight: 600; background: var(--brand-soft); }

/* ---- Layout blocks ----------------------------------------------------- */
main { padding-block: 22px 48px; min-height: 60vh; }
.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--ink-soft); }
.breadcrumb span { margin-inline: 4px; }
/* Left-aligned breadcrumb (LTR), for group/category pages. */
.breadcrumb-ltr { direction: ltr; display: flex; flex-wrap: wrap; align-items: center; gap: 5px; justify-content: flex-start; }
.breadcrumb-ltr span { margin: 0; }

.hero { padding: 8px 0 0; }
#categories.block { margin-top: 10px; }
.hero h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.6rem); color: var(--brand-ink); }
.hero .lead { color: var(--ink-soft); margin: 6px 0 0; }

.block { margin-top: 30px; scroll-margin-top: 110px; }
.block-title { font-size: 1.15rem; margin: 0 0 14px; padding-bottom: 8px; border-bottom: 2px solid var(--brand-soft); }
.block-title .ur { font-size: 1.1rem; color: var(--muted); }

.card-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.card-grid-compact { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.card a {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; box-shadow: var(--shadow); height: 100%;
  transition: border-color .15s, transform .15s;
}
.card a:hover { text-decoration: none; border-color: var(--brand); transform: translateY(-1px); }
.card-en-name { font-weight: 600; color: var(--ink); }
.card-ur { font-family: var(--ur); font-weight: 600; color: var(--brand-ink); font-size: 1.4rem; line-height: 1.9; }
.card-count { background: var(--brand-soft); color: var(--brand-ink); border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 600; flex: none; }

/* Numbered groups — cards with a title and a count strip; max 5 per row. */
.group-grid { list-style: none; margin: 0; padding: 0; display: grid; direction: ltr; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .group-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .group-grid { grid-template-columns: repeat(5, 1fr); } }
.gcard {
  display: flex; flex-direction: column; justify-content: space-between; height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden; transition: border-color .15s, transform .15s;
}
.gcard:hover { text-decoration: none; border-color: var(--brand); transform: translateY(-2px); }
.gcard-title { padding: 16px 12px 14px; font-weight: 600; color: var(--brand-ink); text-align: center; }
.gcard-strip { background: var(--bg); border-top: 1px solid var(--line); padding: 6px 10px; font-size: .72rem; color: var(--muted); text-align: center; }

/* ---- Lists ------------------------------------------------------------- */
.page-title { font-size: clamp(1.4rem, 4vw, 2rem); margin: 0 0 18px; color: var(--brand-ink); }
.page-title .ur { font-size: .9em; color: var(--muted); }
/* English on the left, Urdu on the right, on one line. */
.page-title--split { display: flex; direction: ltr; justify-content: space-between; align-items: baseline; gap: 6px 20px; flex-wrap: wrap; }
.page-title--split .pt-ur { font-family: var(--ur); font-weight: 400; color: var(--muted); font-size: .78em; line-height: 1.8; }

.hadees-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.hadees-list a { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.hadees-list a:hover { text-decoration: none; border-color: var(--brand); }
.h-id { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; min-width: 3.2em; }
.h-title { flex: 1; color: var(--ink); font-size: 1.05rem; }
.h-title.ur { font-size: 1.4rem; line-height: 1.95; }
.badge { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; padding: 3px 9px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.badge-text { background: var(--brand-soft); color: var(--brand-ink); }
.badge-image { background: #f0e7d3; color: #8a6a1f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme]) .badge-image { background: #3a3220; color: #d8ab54; } }
:root[data-theme="dark"] .badge-image { background: #3a3220; color: #d8ab54; }

/* ---- Single hadees ----------------------------------------------------- */
.hadees { --card-pad: clamp(16px, 4vw, 34px); --ts: 1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--card-pad); overflow: hidden; }

/* Merged card header/footer strips (full-bleed to the card edges). */
.card-strip { display: flex; direction: ltr; align-items: center; gap: 12px; margin-inline: calc(-1 * var(--card-pad)); padding: 9px var(--card-pad); background: var(--bg); }
.card-strip .breadcrumb { margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 0; }
.card-strip .breadcrumb span { margin: 0; }
.card-strip-top { margin-top: calc(-1 * var(--card-pad)); margin-bottom: var(--card-pad); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; justify-content: space-between; }
.card-strip-bottom { margin-top: var(--card-pad); margin-bottom: calc(-1 * var(--card-pad)); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); justify-content: space-between; }

/* Text-size control */
.text-size { display: flex; align-items: center; gap: 4px; flex: none; }
.ts-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); border-radius: 7px; padding: 3px 9px; min-width: 30px; cursor: pointer; font: inherit; font-size: .82rem; line-height: 1.4; }
.ts-btn:hover { border-color: var(--brand); color: var(--brand-ink); }
.ts-reset { font-weight: 700; }

/* Prev/next in the bottom strip */
.strip-nav { border: 1px solid var(--line); background: var(--surface); color: var(--brand-ink); border-radius: 999px; padding: 6px 14px; font-size: .85rem; font-weight: 600; }
.strip-nav:hover { border-color: var(--brand); text-decoration: none; }
.hadees-head { margin-bottom: 14px; text-align: center; }
.hadees-head .page-title { margin: 0; }

.hadees-text { display: grid; gap: 20px; }
.ht-hadith { display: grid; gap: 12px; }
.ht-urdu, .ht-arabic { display: flow-root; }
.ht-block { border-radius: var(--radius-sm); }
.ht-arabic { font-family: var(--ar); font-size: calc(1.7rem * var(--ts, 1)); line-height: 2.4; text-align: justify; padding: 18px 20px; background: var(--surface-2); border: 1px solid var(--line); }
.ht-source { color: var(--muted); font-size: .72em; float: left; margin-top: .4em; }
.ht-urdu { font-size: calc(1.5rem * var(--ts, 1)); text-align: justify; padding: 6px 2px; }
.ht-note { background: var(--brand-soft); padding: 16px 20px; font-size: calc(1.4rem * var(--ts, 1)); text-align: justify; }
.ht-note-title { font-family: var(--ur); color: var(--brand-ink); margin: 0 0 6px; font-size: calc(1.3rem * var(--ts, 1)); }
/* English translation + original-image panels read left-to-right. */
.ht-translation, .ht-original { border-top: 1px dashed var(--line); padding-top: 12px; direction: ltr; text-align: left; }
.ht-translation summary, .ht-original summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.ht-en { margin-top: 10px; color: var(--ink-soft); font-size: calc(1rem * var(--ts, 1)); }

.hadees-image { margin: 0; text-align: center; }
.hadees-image img { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; padding: 8px; }
.hadees-image figcaption { margin-top: 10px; font-size: .85rem; }

.tag-row { display: flex; direction: ltr; justify-content: flex-start; flex-wrap: wrap; gap: 6px 14px; margin-top: 24px; }
.tag { font-size: .9rem; color: var(--brand); font-weight: 500; }
.tag:hover { text-decoration: underline; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; }
.pager a { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; color: var(--ink); }
.pager a:hover { border-color: var(--brand); text-decoration: none; }

/* ---- Search ------------------------------------------------------------ */
.search-full { display: flex; gap: 8px; margin-bottom: 18px; }
.search-full input { flex: 1; padding: 12px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; }
.search-full button, .btn { display: inline-block; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 10px 18px; cursor: pointer; font: inherit; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-ink); text-decoration: none; }
.btn-warn { background: #b5401f; border-color: #b5401f; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .85rem; }
.empty { padding: 30px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---- Footer ------------------------------------------------------------ */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding-block: 14px; margin-top: 30px; }
.footer-nav ul { list-style: none; margin: 0; padding: 0; display: flex; direction: ltr; flex-wrap: wrap; justify-content: center; gap: 2px 4px; }
.footer-nav a { display: block; padding: 6px 12px; border-radius: 8px; color: var(--ink-soft); font-size: .9rem; }
.footer-nav a:hover { background: var(--brand-soft); color: var(--brand-ink); text-decoration: none; }

/* ---- Admin ------------------------------------------------------------- */
body.admin { background: var(--bg); }
.admin-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px; position: sticky; top: 0; z-index: 10; }
.admin-bar a { color: var(--ink-soft); }
.admin-progress { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; font-size: .85rem; color: var(--muted); }
.meter { display: inline-block; width: 120px; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--brand); }
.admin-wrap, .admin-filters { max-width: 1100px; margin-inline: auto; padding-inline: 16px; }
.admin-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-block: 16px; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); color: var(--ink-soft); font-size: .88rem; }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.admin-filters input[type=search] { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
.admin-table { width: 100%; border-collapse: collapse; max-width: 1100px; margin: 0 auto; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.admin-table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.admin-pager { display: flex; gap: 16px; align-items: center; justify-content: center; padding: 20px; }

.admin-login { max-width: 340px; margin: 8vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.admin-login h1 { margin-top: 0; }
.admin-login label { display: block; margin-bottom: 14px; font-size: .9rem; }
.admin-login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink); font: inherit; margin-top: 4px; }
.alert { padding: 10px 14px; border-radius: 8px; margin: 12px 0; }
.alert-error { background: #fbe4de; color: #8a2b12; }
.alert-ok { background: var(--brand-soft); color: var(--brand-ink); }

.admin-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; max-width: 1200px; margin: 20px auto; padding-inline: 16px; align-items: start; }
.edit-image { position: sticky; top: 70px; }
.edit-image img { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; padding: 8px; width: 100%; }
.edit-form { display: grid; gap: 14px; }
.edit-form label { display: grid; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.edit-form .hint { font-weight: 400; color: var(--muted); }
.edit-form input, .edit-form textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; }
.edit-form textarea { resize: vertical; }
.fa-urdu { font-family: var(--ur); font-size: 1.3rem; line-height: 2.2; }
.fa-arabic { font-family: var(--ar); font-size: 1.3rem; line-height: 2.2; }
.edit-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.edit-tags { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 14px; margin: 0; }
.edit-tags legend { font-size: .85rem; font-weight: 600; color: var(--ink-soft); padding: 0 6px; }
.tag-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.tag-check { display: flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 400; color: var(--ink); }
.tag-check input { width: auto; margin: 0; }
.tag-check .ur { font-family: var(--ur); color: var(--muted); font-size: 1.1rem; }

/* ---- Responsive -------------------------------------------------------- */
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .main-nav { display: none; }
  .main-nav.open { display: block; }
  .main-nav ul { flex-direction: column; }
  .search-mini input { width: 6rem; }
  .admin-edit { grid-template-columns: 1fr; }
  .edit-image { position: static; }
}
