/* =========================================================
   KHALWATI SITE SHELL R5 — 2026-09-27
   Unified identity, no-flash library, Safari-safe controls.
   One public header/footer across the whole website.
   ========================================================= */
:root{--kh-shell-bg:#fbf6e9;--kh-shell-card:#fffdf8;--kh-shell-deep:#073f34;--kh-shell-green:#0a684e;--kh-shell-line:rgba(190,151,67,.28)}
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
body{min-height:100vh;display:flex;flex-direction:column}
body>main{flex:1 0 auto;min-width:0}
.site-header{position:sticky!important;top:0!important;z-index:70!important;padding:max(7px,env(safe-area-inset-top)) 0 0!important;background:linear-gradient(180deg,rgba(251,246,233,.985),rgba(251,246,233,.925))!important;border:0!important;-webkit-backdrop-filter:blur(16px)!important;backdrop-filter:blur(16px)!important}
.site-header .header-inner,.home-refined .site-header .header-inner{width:min(1240px,calc(100% - 28px))!important;height:64px!important;min-height:64px!important;margin:0 auto 7px!important;padding:0 13px!important;display:flex!important;align-items:center!important;justify-content:space-between!important;gap:14px!important;border:1px solid var(--kh-shell-line)!important;border-radius:18px!important;background:rgba(255,253,248,.965)!important;box-shadow:0 8px 24px rgba(56,41,10,.055)!important}
.site-header .kh-brand,.site-header .brand{display:inline-flex!important;align-items:center!important;gap:9px!important;min-width:0!important;flex:0 1 auto!important;color:var(--kh-shell-deep)!important;text-decoration:none!important}
.site-header .kh-brand-mark{width:40px;height:40px;flex:0 0 40px;display:grid;place-items:center}
.site-header .kh-brand img,.site-header .brand img,.home-refined .site-header .brand img{width:40px!important;height:40px!important;display:block!important;object-fit:contain!important;flex:0 0 40px!important}
.site-header .kh-brand-copy{display:flex;align-items:center;min-width:0}
.site-header .kh-brand-copy strong,.site-header .brand strong{margin:0!important;color:var(--kh-shell-deep)!important;font-size:.96rem!important;line-height:1.35!important;font-weight:800!important;white-space:nowrap!important}
.site-header .kh-brand-copy small{display:none!important}
.site-header .nav-links,.home-refined .site-header .nav-links{display:flex!important;flex:1 1 auto!important;align-items:center!important;justify-content:center!important;gap:1px!important;min-width:0!important}
.site-header .nav-links a,.home-refined .site-header .nav-links a{min-height:40px!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;padding:0 9px!important;border-radius:11px!important;color:#315247!important;font-size:.84rem!important;font-weight:750!important;line-height:1.25!important;white-space:nowrap!important;text-decoration:none!important;transition:background-color .16s ease,color .16s ease!important}
.site-header .nav-links a:hover,.site-header .nav-links a:focus-visible{background:#f2ecdc!important;color:var(--kh-shell-deep)!important}
.site-header .nav-links a[aria-current="page"]{background:#e8f1e9!important;color:var(--kh-shell-green)!important}
.site-header .header-actions,.home-refined .site-header .header-actions{display:flex!important;align-items:center!important;justify-content:flex-end!important;gap:7px!important;flex:0 0 auto!important}
.site-header .icon-btn{width:44px!important;min-width:44px!important;height:44px!important;min-height:44px!important;padding:0!important;border:1px solid #ded1b2!important;border-radius:12px!important;background:#fffdf8!important;color:var(--kh-shell-deep)!important;box-shadow:none!important}
.site-header .mobile-menu{display:none!important}
.site-header .mobile-menu svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round}

/* Shared footer */
.site-footer{flex:0 0 auto!important;margin-top:28px!important;padding:18px 0 max(18px,env(safe-area-inset-bottom))!important;border-top:1px solid rgba(201,154,55,.22)!important;background:rgba(255,253,248,.72)!important;color:#66766f!important}
.site-footer .footer-inner{width:min(1240px,calc(100% - 28px))!important;min-height:48px!important;margin:0 auto!important;display:grid!important;grid-template-columns:minmax(0,1fr) auto auto!important;align-items:center!important;gap:20px!important}
.footer-brand{display:inline-flex;align-items:center;gap:9px;min-width:0;color:var(--kh-shell-deep)!important;font-weight:800;text-decoration:none!important}
.footer-brand img{width:34px;height:34px;object-fit:contain;flex:0 0 34px}
.footer-brand span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.site-footer .footer-links{display:flex!important;align-items:center!important;justify-content:center!important;gap:4px!important;flex-wrap:wrap!important;margin:0!important}
.site-footer .footer-links a{padding:7px 9px;border-radius:9px;color:#48675d!important;font-weight:700;text-decoration:none!important}
.site-footer .footer-links a:hover,.site-footer .footer-links a:focus-visible{background:#f2ecdc;color:var(--kh-shell-deep)!important}
.footer-copy{white-space:nowrap;color:#877c68;font-size:.82rem}

/* Privacy page keeps its readable content width while shell stays full-width. */
.privacy-content{width:min(900px,calc(100% - 32px))!important;margin:0 auto!important}

@media(max-width:1100px){
  .site-header .nav-links,.home-refined .site-header .nav-links{display:none!important}
  .site-header .mobile-menu,.home-refined .site-header .mobile-menu{display:inline-flex!important}
}
@media(max-width:700px){
  .site-header{padding-top:max(5px,env(safe-area-inset-top))!important}
  .site-header .header-inner,.home-refined .site-header .header-inner{width:calc(100% - 18px)!important;height:58px!important;min-height:58px!important;margin-bottom:6px!important;padding:0 10px!important;border-radius:15px!important;gap:8px!important}
  .site-header .kh-brand-mark{width:34px;height:34px;flex-basis:34px}
  .site-header .kh-brand img,.site-header .brand img,.home-refined .site-header .brand img{width:34px!important;height:34px!important;flex-basis:34px!important}
  .site-header .kh-brand-copy strong,.site-header .brand strong{max-width:min(66vw,270px)!important;font-size:.88rem!important;overflow:hidden!important;text-overflow:ellipsis!important}
  .site-header .icon-btn{width:44px!important;min-width:44px!important;height:44px!important;min-height:44px!important}
  .site-footer{margin-top:22px!important;padding-top:16px!important}
  .site-footer .footer-inner{width:calc(100% - 24px)!important;grid-template-columns:1fr!important;justify-items:center!important;gap:8px!important;text-align:center!important}
  .footer-brand{max-width:100%;justify-content:center}
  .site-footer .footer-links{gap:1px!important}
  .site-footer .footer-links a{padding:7px 6px;font-size:.82rem}
}
@media(max-width:390px){
  .site-header .kh-brand-copy strong,.site-header .brand strong{max-width:220px!important;font-size:.83rem!important}
  .footer-brand span{font-size:.87rem}
}
@media(prefers-reduced-motion:reduce){.site-header .nav-links a{transition:none!important}}

/* Library preference card is present in HTML before async sync, so there is no layout flash. */
.kh-lib-pref{width:100%;min-height:74px;box-sizing:border-box;display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:13px;margin:14px 0 18px;padding:12px 15px;border:1px solid rgba(194,153,67,.34);border-radius:18px;background:linear-gradient(180deg,#fffdf9 0%,#fcf8ee 100%);box-shadow:0 7px 20px rgba(44,65,53,.045);color:#173f34;cursor:pointer;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:rgba(7,88,61,.08)}
.kh-lib-pref-input{position:absolute!important;width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0 0 0 0)!important;clip-path:inset(50%)!important;white-space:nowrap!important}
.kh-lib-pref-icon{width:44px;height:44px;display:inline-flex;align-items:center;justify-content:center;border-radius:13px;background:#f5ecd5;color:#9a7019;flex:0 0 44px}.kh-lib-pref-icon svg{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.kh-lib-pref-copy{min-width:0;display:block;text-align:right;direction:rtl}.kh-lib-pref-copy strong{display:block;margin:0 0 2px;color:#123d31;font-size:.98rem;line-height:1.45;font-weight:800}.kh-lib-pref-copy small{display:block;color:#817965;font-size:.79rem;line-height:1.55}
.kh-lib-switch{position:relative;width:48px;height:28px;display:inline-block;flex:0 0 48px;border-radius:999px;background:#d8d2c4;box-shadow:inset 0 0 0 1px rgba(39,63,52,.08);transition:background-color .16s ease}.kh-lib-switch::after{content:"";position:absolute;top:4px;left:4px;width:20px;height:20px;border-radius:50%;background:#fff;box-shadow:0 2px 7px rgba(31,52,42,.22);transition:transform .16s ease}.kh-lib-pref-input:checked~.kh-lib-switch{background:#0b6a4c}.kh-lib-pref-input:checked~.kh-lib-switch::after{transform:translateX(20px)}.kh-lib-pref-input:focus-visible~.kh-lib-switch{outline:3px solid rgba(18,112,78,.20);outline-offset:3px}
@media(max-width:600px){.kh-lib-pref{min-height:68px;grid-template-columns:40px minmax(0,1fr) 46px;gap:10px;margin:10px 0 14px;padding:11px 12px;border-radius:16px}.kh-lib-pref-icon{width:40px;height:40px;flex-basis:40px;border-radius:12px}.kh-lib-pref-copy strong{font-size:.92rem}.kh-lib-pref-copy small{font-size:.74rem}.kh-lib-switch{width:46px;height:27px;flex-basis:46px}.kh-lib-switch::after{width:19px;height:19px}.kh-lib-pref-input:checked~.kh-lib-switch::after{transform:translateX(19px)}}
@media(prefers-reduced-motion:reduce){.kh-lib-switch,.kh-lib-switch::after{transition:none}}

/* Static styles used by library-auto-sync: no style injection after first paint. */
.kh-cover-placeholder{width:100%;height:100%;min-height:220px;display:grid;place-items:center;text-align:center;padding:16px;background:#f5edd9;color:#074a3e;font-weight:800;border-radius:inherit}
.books-grid[data-khalwati-live="1"] .book-card{cursor:pointer}
.library-tools.kh-filters-only{justify-content:center}

/* R6 Audio navigation */
.site-header .kh-audio-link>span,.drawer .kh-audio-link>span{display:inline-block;margin-inline-end:4px;font-size:.92em;line-height:1;color:#a87717}


/* R6c: dynamic library first-paint guard. */
.books-grid:not([data-khalwati-live]){position:relative;min-height:240px}
.books-grid:not([data-khalwati-live])>.book-card{opacity:0;visibility:hidden;pointer-events:none}
.books-grid:not([data-khalwati-live])::before{content:"جاري تحديث المكتبة…";position:absolute;inset:18px 0 auto;min-height:118px;display:grid;place-items:center;border:1px solid #ead8aa;border-radius:18px;background:linear-gradient(100deg,#fffdf8 30%,#f7efd9 50%,#fffdf8 70%);background-size:220% 100%;color:#0a5b48;font-weight:800;animation:khLibraryLoading 1.25s linear infinite;z-index:2}
.books-grid[data-khalwati-live]::before{display:none}
.book-cover-wrap{position:relative;overflow:hidden;background:#f4efe4}
.book-cover-wrap.kh-cover-loading::after{content:"";position:absolute;inset:0;background:linear-gradient(105deg,#f2ead8 25%,#fffaf0 45%,#f2ead8 65%);background-size:220% 100%;animation:khLibraryLoading 1.15s linear infinite}
.book-cover-wrap img.kh-cover-img-loading{opacity:0}
.book-cover-wrap img{transition:opacity .16s ease}
@keyframes khLibraryLoading{to{background-position:-220% 0}}
@media (prefers-reduced-motion:reduce){.books-grid:not([data-khalwati-live])::before,.book-cover-wrap.kh-cover-loading::after{animation:none}}
@media(max-width:640px){.books-grid:not([data-khalwati-live]){min-height:190px}.books-grid:not([data-khalwati-live])::before{min-height:96px;font-size:.92rem}}
