/* =====================================================================
   Miftah — Hadith section + bottom bar (Quran | Hadith)
   ===================================================================== */

/* ---------- Bottom bar ---------- */
:root { --tabbar-space: calc(60px + env(safe-area-inset-bottom)); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 32; display: flex; gap: 6px;
  padding: 6px 18px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgb(0 0 0 / .05); }
.tabbar a { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 4px 0 2px; text-decoration: none; color: var(--muted);
  font: 600 .74rem var(--font-ui); letter-spacing: .01em; -webkit-tap-highlight-color: transparent; }
.tabbar .tab-ic { width: 60px; height: 30px; display: grid; place-items: center; border-radius: 999px; transition: background .2s, color .2s; }
.tabbar svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .tab-ic { background: var(--accent-soft); }
.tabbar a:active .tab-ic { transform: scale(.94); }
@media (min-width: 861px) {
  :root { --tabbar-space: 76px; }
  .tabbar { left: 50%; right: auto; bottom: 12px; transform: translateX(-50%); width: 260px; padding: 5px; border: 1px solid var(--line);
    border-radius: 999px; box-shadow: var(--shadow), 0 10px 30px rgb(0 0 0 / .12); width: 380px; }
  .tabbar a { grid-auto-flow: column; justify-content: center; align-items: center; gap: 6px; padding: 0; border-radius: 999px; font-size: .85rem; }
  .tabbar a.on { background: var(--accent-soft); }
  .tabbar a.on .tab-ic { background: none; }
  .tabbar .tab-ic { width: auto; height: 38px; }
}
/* Keep players, toasts and page ends clear of the bar */
body { padding-bottom: calc(110px + var(--tabbar-space)); }
.player { bottom: calc(10px + var(--tabbar-space)); }
.lp { bottom: calc(8px + var(--tabbar-space)) !important; }
body.has-lp:not([data-view="read"]) { padding-bottom: calc(96px + var(--tabbar-space)); }
.toast { bottom: calc(100px + var(--tabbar-space)); }

/* ---------- Layout ---------- */
.hadith { max-width: 860px; margin: 0 auto; padding: 22px clamp(12px, 3vw, 24px); }
.hadith h1 { margin: 0; font-size: 1.7rem; letter-spacing: -.02em; }
.hd-head, .hd-sec-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.hd-title p, .hd-sec-top p { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.hd-lang { grid-template-columns: repeat(3, auto); }
.hd-lang button { font-weight: 600; font-size: .85rem; padding: 7px 12px; }
.hd-lang button[lang] { font-family: "Noto Naskh Arabic", var(--font-ui); }
.hd-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); margin-bottom: 14px; }
.hd-crumbs a { color: var(--accent); text-decoration: none; font-weight: 600; }
.hd-crumbs a:hover { text-decoration: underline; }
.hd-here { color: var(--fg); font-weight: 600; }
.hd-section { margin-top: 26px; }
.hd-sec-head { display: flex; align-items: baseline; justify-content: space-between; }
.hd-sec-head span { color: var(--muted); font-size: .85rem; }
.hd-note { color: var(--muted); font-size: .9rem; line-height: 1.55; margin: 0 0 14px; }
.hd-note.center { text-align: center; padding: 30px 0; }
.hd-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg);
  border-radius: 999px; padding: 8px 16px; font: 600 .85rem var(--font-ui); text-decoration: none; cursor: pointer; }
.hd-btn:hover { border-color: var(--accent); color: var(--accent); }
.hd-credit { margin-top: 36px; text-align: center; color: var(--muted); font-size: .76rem; line-height: 1.5; opacity: .8; }

/* ---------- Search ---------- */
.hd-search { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 6px 6px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.hd-search:focus-within { border-color: var(--accent); }
.hd-search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.hd-search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 16px; padding: 10px 0; color: var(--fg); }
.hd-search-go { border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-fg); font: 600 .9rem var(--font-ui); padding: 10px 16px; cursor: pointer; }
.hd-grader, .hd-filter { font: 500 .88rem var(--font-ui); color: var(--fg); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 12px; max-width: 100%; }
.hd-results { display: grid; gap: 10px; margin-top: 14px; }
.hd-count { color: var(--muted); font-size: .88rem; margin: 0 0 4px; }
.hd-result { display: grid; gap: 8px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  color: var(--fg); text-decoration: none; box-shadow: var(--shadow); transition: border-color .15s; }
.hd-result:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.hd-result-top { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.hd-result-top strong { color: var(--accent); font-size: .92rem; }
.hd-result-top span { color: var(--muted); font-size: .8rem; }
.hd-result-text { line-height: 1.65; font-size: .95rem; }
.hd-result-text.rtl, .hd-saved-snip.rtl { font-family: "Noto Naskh Arabic", var(--font-ui); line-height: 2; text-align: right; }
.hadith[data-lang="urd"] .hd-result-text.rtl, .hadith[data-lang="urd"] .hd-saved-snip.rtl { font-family: "Noto Nastaliq Urdu", "Noto Naskh Arabic", serif; line-height: 2.3; }
.hd-result mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.hd-result .hd-grade { justify-self: start; }
.hd-more { justify-self: center; margin-top: 6px; }
.hd-loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 40px 0; font-size: .92rem; }
.hd-spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: hd-spin .8s linear infinite; }
@keyframes hd-spin { to { transform: rotate(360deg); } }
.hd-error { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- Collections ---------- */
.hd-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.hd-col { position: relative; display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--line); color: var(--fg); text-decoration: none; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.hd-col:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); transform: translateY(-1px); }
.hd-col-text { display: grid; gap: 2px; min-width: 0; }
.hd-col-text strong { font-size: .98rem; }
.hd-col:has(.hd-col-badge) .hd-col-text { padding-right: 52px; }
.hd-col-text span { font-size: .8rem; color: var(--muted); }
.hd-col-badge { position: absolute; top: 10px; right: 12px; font-size: .66rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 3px 8px; }
.hd-art { flex: none; width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; color: #fff; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .12); }
.hd-art-ar { font: 700 15px/1.25 "Amiri Quran", "Amiri", serif; text-align: center; padding: 0 5px; }
.hd-col-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.hd-col-head .hd-art { width: 86px; height: 86px; border-radius: 22px; }
.hd-col-head .hd-art-ar { font-size: 19px; }
.hd-col-head p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

/* ---------- Books (index) ---------- */
.hd-tools { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.hd-filter { flex: 1; min-width: 180px; font-size: 16px; }
.hd-books { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.hd-books li[hidden] { display: none; }
.hd-book { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--line); color: var(--fg); text-decoration: none; transition: border-color .15s; }
.hd-book:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.hd-book-no { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft);
  color: var(--accent); font-weight: 700; font-size: .85rem; font-variant-numeric: tabular-nums; }
.hd-book-text { flex: 1; display: grid; gap: 2px; min-width: 0; }
.hd-book-text strong { font-size: .95rem; }
.hd-book-text span { font-size: .8rem; color: var(--muted); }
.hd-chev svg { width: 18px; height: 18px; color: var(--muted); }

/* ---------- Grade filter ---------- */
.hd-filters { position: sticky; top: 62px; z-index: 4; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 10px 0; margin-bottom: 6px; background: var(--bg); }
.hd-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.hd-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  border-radius: 999px; padding: 7px 12px; font: 600 .84rem var(--font-ui); cursor: pointer; }
.hd-chip b { font-size: .72rem; color: var(--muted); font-weight: 600; }
.hd-chip[aria-checked="true"] { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.hd-chip[aria-checked="true"] b { color: inherit; opacity: .7; }
.hd-chip.sahih[aria-checked="true"] { background: var(--g-sahih); border-color: var(--g-sahih); color: #fff; }
.hd-chip.hasan[aria-checked="true"] { background: var(--g-hasan); border-color: var(--g-hasan); color: #fff; }
.hd-chip.daif[aria-checked="true"] { background: var(--g-daif); border-color: var(--g-daif); color: #fff; }

/* Grade colours */
:root, [data-theme="sepia"] { --g-sahih: #15803d; --g-hasan: #1d4ed8; --g-daif: #b91c1c; }
[data-theme="dark"] { --g-sahih: #22c55e; --g-hasan: #60a5fa; --g-daif: #f87171; }
.hd-grades { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.hd-grade { display: inline-flex; align-items: baseline; gap: 0; font-size: .78rem; border-radius: 999px; padding: 4px 10px;
  border: 1px solid var(--line); color: var(--muted); background: var(--surface-2); }
.hd-grade strong { font-weight: 700; }
.hd-grade.sahih { color: var(--g-sahih); border-color: color-mix(in srgb, var(--g-sahih) 35%, transparent); background: color-mix(in srgb, var(--g-sahih) 10%, var(--surface)); }
.hd-grade.hasan { color: var(--g-hasan); border-color: color-mix(in srgb, var(--g-hasan) 35%, transparent); background: color-mix(in srgb, var(--g-hasan) 10%, var(--surface)); }
.hd-grade.daif { color: var(--g-daif); border-color: color-mix(in srgb, var(--g-daif) 35%, transparent); background: color-mix(in srgb, var(--g-daif) 10%, var(--surface)); }
.hd-grade span { opacity: .85; }

/* ---------- Hadith card ---------- */
.hd-list { display: grid; gap: 14px; }
.hd-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 14px 22px 10px;
  box-shadow: var(--shadow); content-visibility: auto; contain-intrinsic-block-size: auto 380px; min-width: 0; transition: border-color .3s, box-shadow .3s; }
.hd-card[hidden] { display: none; }
.hd-card.focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent), var(--shadow); }
.hd-card.is-bm { border-color: color-mix(in srgb, var(--bm) 45%, var(--line)); }
.hd-top { display: flex; align-items: center; gap: 10px; min-height: 38px; padding-right: 40px; }
.hd-no { flex: none; min-width: 38px; height: 30px; padding: 0 9px; display: grid; place-items: center; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem; font-variant-numeric: tabular-nums; }
.hd-ref { font-size: .8rem; color: var(--muted); min-width: 0; }
.hd-ar { font-family: "Amiri Quran", "Amiri", "Noto Naskh Arabic", serif; font-size: calc(var(--ar-size) * .66); line-height: 2.05; text-align: right;
  margin: 10px 0 12px; color: color-mix(in srgb, var(--fg) 92%, var(--muted)); white-space: pre-line; }
.hd-ar.big { font-size: calc(var(--ar-size) * .8); color: var(--fg); }
.hd-tr { margin: 0; font-size: var(--tr-size); line-height: 1.75; white-space: pre-line; padding-inline-start: 14px;
  border-inline-start: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.hd-tr.rtl { font-family: "Noto Naskh Arabic", var(--font-ui); line-height: 2.1; text-align: right; }
.hd-tr[lang="ur"] { font-family: "Noto Nastaliq Urdu", "Noto Naskh Arabic", serif; line-height: 2.4; }
.hd-narr { font-weight: 700; color: var(--fg); }
.hd-missing { color: var(--muted); font-style: italic; margin: 0; }
.hd-actions { display: flex; justify-content: flex-end; gap: 2px; margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--line); }
.hd-actions .icon-btn { width: 36px; height: 36px; }
.hd-actions svg { width: 18px; height: 18px; }

/* ---------- Saved ---------- */
.hd-saved { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 280px); gap: 10px; overflow-x: auto; padding-bottom: 6px;
  scroll-snap-type: x mandatory; scrollbar-width: none; }
.hd-saved::-webkit-scrollbar { display: none; }
.hd-saved-card { scroll-snap-align: start; display: grid; align-content: start; gap: 4px; padding: 14px 16px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--line); border-top: 3px solid var(--bm); color: var(--fg); text-decoration: none; box-shadow: var(--shadow); }
.hd-saved-card strong { font-size: .92rem; }
.hd-saved-sec { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hd-saved-snip { font-size: .86rem; line-height: 1.55; color: color-mix(in srgb, var(--fg) 85%, var(--muted));
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 4px; }

@media (max-width: 560px) {
  .hadith { padding-top: 16px; }
  .hd-head, .hd-sec-top { align-items: flex-start; }
  .hd-card { padding: 12px 16px 8px; border-radius: 20px; }
  .hd-cols { grid-template-columns: 1fr; }
  .hd-art { width: 56px; height: 56px; border-radius: 14px; }
  .hd-art-ar { font-size: 13px; }
  .hd-search-go { padding: 10px 12px; }
  .hd-filters { top: 58px; }
}
