/* ================= مكتبة آفاق — التصميم العام ================= */
:root {
  /* هوية آفاق: الأحمر والأبيض */
  --ivory: #FAF9F7;
  --paper: #FFFFFF;
  --beige: #F3F1EE;
  --beige-2: #E4E1DC;
  --brand: #E31E24;
  --brand-d: #C2161C;
  --brand-soft: #FDECEC;
  --brown: #E31E24;
  --ink: #1F1D1B;
  --muted: #6F6A64;
  --line: #E9E6E1;
  --danger: #B3261E;
  --danger-soft: #FBE9E7;
  --radius: 14px;
  --cut: 14px; /* الزاوية المقصوصة من الشعار */
  --gap-y: 40px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --font-body: "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font-display: "Cairo", "IBM Plex Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: pageIn .45s var(--ease) both;
  transition: opacity .18s ease;
}
body.leaving { opacity: 0; }
main { flex: 1; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

img { max-width: 100%; display: block; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; }
.container { width: min(1120px, 100% - 32px); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 6px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- الشريط العلوي ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 76px; }
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
/* علامة الشعار: مستطيل أحمر بزاوية مقصوصة أسفل اليمين، والاسم بالأبيض */
.brand-mark {
  width: 50px; height: 58px; flex: none;
  background: var(--brand); color: #fff;
  clip-path: polygon(0 0, 100% 0, 100% 82%, 82% 100%, 0 100%);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 0 4px 8px; overflow: hidden;
  font-family: var(--font-display); font-weight: 800; font-size: 13px; line-height: 1.1; text-align: center;
}
.brand-mark .wm-1, .brand-mark .wm-2 { display: block; }
.brand-mark .wm-2 { font-size: 15px; }
.brand-mark.has-logo { background: transparent; clip-path: none; padding: 0; width: auto; max-width: 70px; }
.brand-mark img { width: auto; height: 100%; object-fit: contain; }
.brand-name { font-family: var(--font-display); font-size: 22px; font-weight: 800; line-height: 1.2; display: block; }
.brand-sub { font-size: 12.5px; color: var(--muted); line-height: 1.2; display: block; margin-top: 2px; }

.cart-link {
  position: relative; display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 50%;
  text-decoration: none; color: var(--ink);
  transition: background .2s;
}
.cart-link:hover { background: var(--beige); }
.cart-badge {
  position: absolute; top: 3px; left: 1px;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--brown); color: #fff;
  font-size: 12px; font-weight: 600; line-height: 20px; text-align: center;
  transform: scale(0); transition: transform .25s var(--ease);
}
.cart-badge.show { transform: scale(1); }
.cart-badge.bump { animation: bump .45s var(--ease); }
@keyframes bump { 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

.preview-banner {
  background: var(--brown); color: #fff; text-align: center;
  font-size: 13.5px; padding: 6px 16px;
}
.preview-banner a { color: #fff; font-weight: 600; margin-inline-start: 8px; }

/* ---------- العنوان الرئيسي ---------- */
.hero { padding: 64px 0 40px; text-align: center; }
.hero h1 { font-family: var(--font-display); font-weight: 800; font-size: clamp(30px, 5.2vw, 48px); line-height: 1.45; }
.hero p { margin: 6px auto 0; color: var(--muted); max-width: 46ch; }
.hero .rule { display: block; width: 34px; height: 10px; background: var(--brand); margin: 24px auto 0; clip-path: polygon(0 0, 100% 0, 100% 40%, 70% 100%, 0 100%); }

/* ---------- شبكة الكتب ---------- */
.books {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--gap-y) 28px;
  padding-bottom: 96px;
}
@media (max-width: 560px) {
  :root { --gap-y: 30px; }
  .books { grid-template-columns: repeat(2, 1fr); column-gap: 16px; }
}
.book { animation: cardIn .55s var(--ease) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes cardIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.book-card {
  display: flex; flex-direction: column; gap: 14px; width: 100%;
  background: none; border: 0; padding: 0; text-align: center;
}
.cover-frame {
  display: flex; align-items: flex-end; justify-content: center;
  aspect-ratio: 2 / 3; width: 100%;
  container-type: inline-size;
}
.cover-frame > img, .cover-frame > .cover-ph {
  border-radius: 3px 6px 6px 3px;
  box-shadow: 0 1px 2px rgba(47, 42, 36, .08), 0 10px 22px -12px rgba(47, 42, 36, .4);
  transition: transform .35s var(--ease), box-shadow .35s var(--ease);
}
.cover-frame > img { width: auto; height: auto; max-width: 100%; max-height: 100%; background: var(--beige); }
.book-card:hover .cover-frame > *,
.book.active .cover-frame > * { transform: translateY(-5px); box-shadow: 0 1px 2px rgba(47,42,36,.08), 0 18px 30px -14px rgba(47,42,36,.45); }
.book-title { font-weight: 600; font-size: 15.5px; line-height: 1.55; transition: color .2s; }
.book.active .book-title { color: var(--brand); }

/* غلاف بديل عند عدم توفر صورة */
.cover-ph {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 20% 10% 12%;
  background: var(--tone, var(--brand));
  background-image: linear-gradient(90deg, rgba(0,0,0,.12) 0, rgba(0,0,0,0) 6%);
  color: var(--ivory); text-align: center;
}
.cover-ph .t { font-family: var(--font-display); font-weight: 700; font-size: 11cqw; line-height: 1.45; }
.cover-ph .line { width: 26%; height: 1px; background: currentColor; opacity: .5; }
.cover-ph .s { font-size: 6.5cqw; opacity: .75; }
.cover-ph.mini { padding: 0; }

.empty-books { text-align: center; color: var(--muted); padding: 40px 0 120px; }

/* ---------- لوحة التفاصيل ---------- */
.details {
  grid-column: 1 / -1;
  display: grid; grid-template-rows: 0fr;
  margin-top: calc(-1 * var(--gap-y));
  transition: grid-template-rows .42s var(--ease), margin-top .42s var(--ease);
}
.details.open { grid-template-rows: 1fr; margin-top: 0; }
.details-inner { overflow: hidden; min-height: 0; }
.details-card {
  position: relative;
  margin-top: 10px;
  background: var(--beige);
  border-radius: var(--radius);
  padding: 30px;
  display: grid;
  grid-template-columns: 170px 1fr 230px;
  gap: 32px;
  align-items: start;
  opacity: 0; transform: translateY(-6px);
  transition: opacity .35s var(--ease) .08s, transform .35s var(--ease) .08s;
}
.details.open .details-card { opacity: 1; transform: none; }
.details-card::before {
  content: ""; position: absolute; top: -7px; right: var(--caret, 50%);
  width: 14px; height: 14px; background: var(--beige);
  transform: translateX(50%) rotate(45deg); border-radius: 2px;
  transition: right .3s var(--ease);
}
.details-card.swap > * { animation: swapIn .35s var(--ease) both; }
@keyframes swapIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.d-close {
  position: absolute; top: 12px; left: 12px;
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: transparent; color: var(--muted);
  display: grid; place-items: center; transition: background .2s, color .2s;
}
.d-close:hover { background: var(--beige-2); color: var(--ink); }
.d-info h3 { font-family: var(--font-display); font-size: 28px; line-height: 1.4; font-weight: 700; }
.d-author { margin: 2px 0 0; color: var(--muted); font-size: 14.5px; }
.d-desc { margin: 14px 0 0; line-height: 1.95; max-width: 60ch; }
.d-buy {
  background: var(--paper); border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.d-price { font-size: 26px; font-weight: 700; line-height: 1.2; }
.d-price .muted { font-size: 15px; font-weight: 500; }
.d-status { font-size: 14px; display: flex; align-items: center; gap: 8px; color: var(--brand); }
.d-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.d-status.low { color: var(--brown); }
.in-cart { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); padding-top: 4px; }

@media (max-width: 820px) {
  .details-card { grid-template-columns: 120px 1fr; gap: 20px; padding: 24px 20px; }
  .d-buy { grid-column: 1 / -1; }
  .d-info h3 { font-size: 23px; padding-inline-end: 28px; }
}
@media (max-width: 480px) {
  .details-card { grid-template-columns: 92px 1fr; gap: 16px; }
  .d-desc { grid-column: 1 / -1; font-size: 15px; }
}

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 6px; border: 0;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 15.5px;
  text-decoration: none; white-space: nowrap;
  transition: background .2s, transform .15s, color .2s;
}
.btn:hover { background: var(--brand-d); }
.btn:active { transform: scale(.98); }
.btn[disabled] { background: var(--beige-2); color: var(--muted); cursor: not-allowed; transform: none; }
.btn.added { background: var(--brand-d); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-ghost:hover { background: var(--beige); }
.btn-light { background: #fff; color: var(--brand-d); }
.btn-light:hover { background: #fff; }
.btn-sm { min-height: 38px; padding: 0 16px; font-size: 14px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); font-size: 13.5px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--danger); }

.stepper {
  display: inline-flex; align-items: center;
  border: 1px solid var(--line); border-radius: 999px; background: var(--ivory); height: 38px;
}
.stepper button {
  width: 36px; height: 36px; border: 0; background: none; border-radius: 50%;
  font-size: 18px; line-height: 1; display: grid; place-items: center; transition: background .2s;
}
.stepper button:hover:not([disabled]) { background: var(--beige); }
.stepper button[disabled] { opacity: .35; cursor: not-allowed; }
.stepper output { min-width: 26px; text-align: center; font-weight: 600; }

/* ---------- شريط السلة السفلي ---------- */
.cart-bar {
  position: fixed; z-index: 30;
  left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
  width: min(720px, 100% - 24px);
  transform: translate(-50%, 150%);
  background: var(--brand); color: #fff;
  border-radius: 4px; padding: 9px; padding-inline-start: 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 14px 34px -14px rgba(47, 42, 36, .55);
  transition: transform .45s var(--ease);
}
.cart-bar.show { transform: translate(-50%, 0); }
.cart-bar .bar-info { display: flex; flex-direction: column; line-height: 1.35; }
.cart-bar .bar-count { font-size: 13.5px; opacity: .8; }
.cart-bar .bar-total { font-weight: 700; font-size: 17px; }
body.has-bar .books { padding-bottom: 130px; }

/* ---------- الإشعارات ---------- */
.toasts {
  position: fixed; top: 82px; left: 50%; transform: translateX(-50%); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; width: max-content; max-width: calc(100% - 32px);
}
.toast {
  background: var(--ink); color: var(--ivory);
  padding: 10px 18px; border-radius: 999px; font-size: 14.5px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 10px 26px -12px rgba(47, 42, 36, .5);
  animation: toastIn .32s var(--ease) both;
}
.toast.error { background: var(--danger); }
.toast.out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

/* ---------- التذييل ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 22px 0; color: var(--muted); font-size: 13.5px; text-align: center; }

/* ================= صفحة إتمام الشراء ================= */
.page-head { padding: 40px 0 26px; }
.page-head h1 { font-family: var(--font-display); font-size: clamp(30px, 4.5vw, 40px); line-height: 1.4; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 14.5px; margin-bottom: 6px; }
.back-link:hover { color: var(--brand); }

.checkout {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px;
  grid-template-areas: "form summary";
  gap: 28px; align-items: start; padding-bottom: 80px;
}
.checkout .summary { grid-area: summary; position: sticky; top: 88px; }
.checkout .order-form { grid-area: form; }
@media (max-width: 900px) {
  .checkout { grid-template-columns: 1fr; grid-template-areas: "summary" "form"; }
  .checkout .summary { position: static; }
}
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.panel + .panel { margin-top: 20px; }
.panel h2 { font-size: 18px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.panel h2 .num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-d);
  display: grid; place-items: center; font-size: 13.5px;
}

.line-item {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--line);
  animation: swapIn .3s var(--ease) both;
}
.line-item:first-child { padding-top: 0; }
.thumb { width: 54px; aspect-ratio: 2 / 3; display: flex; align-items: flex-end; justify-content: center; }
.thumb > img, .thumb > .cover-ph { border-radius: 2px 4px 4px 2px; box-shadow: 0 4px 10px -6px rgba(47,42,36,.4); }
.thumb > img { max-width: 100%; max-height: 100%; width: auto; height: auto; }
.li-title { font-weight: 600; font-size: 15px; line-height: 1.5; }
.li-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.li-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.li-actions .stepper { height: 32px; }
.li-actions .stepper button { width: 30px; height: 30px; font-size: 16px; }
.li-sub { font-weight: 700; white-space: nowrap; align-self: start; }

.totals { padding-top: 14px; }
.totals .row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 15px; }
.totals .row span:first-child { color: var(--muted); }
.totals .row.final { font-weight: 700; font-size: 19px; border-top: 1px solid var(--line); margin-top: 10px; padding-top: 14px; }
.totals .row.final span:first-child { color: var(--ink); }
.totals .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 14px; font-weight: 600; }
.field .opt { color: var(--muted); font-weight: 400; }
.field input, .field textarea, .field select {
  font: inherit; font-size: 16px; width: 100%;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--ivory); color: var(--ink);
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.7; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: #fff; }
.field input[dir="ltr"] { text-align: right; }
.field .err { display: none; color: var(--danger); font-size: 13px; }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); background: var(--danger-soft); }
.field.invalid .err { display: block; animation: swapIn .25s var(--ease); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } .panel { padding: 20px 16px; } }

.pay-options { display: grid; gap: 10px; }
.pay-opt {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; background: var(--ivory);
  transition: border-color .2s, background .2s;
}
.pay-opt:hover { border-color: var(--beige-2); }
.pay-opt input { accent-color: var(--brand); width: 18px; height: 18px; margin: 0; }
.pay-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.pay-opt .pay-name { font-weight: 600; }
.pay-info { margin-top: 12px; background: var(--beige); border-radius: 10px; padding: 14px 16px; font-size: 14.5px; white-space: pre-line; animation: swapIn .3s var(--ease); }
.pay-info strong { display: block; margin-bottom: 2px; }
.pay-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.note { font-size: 13.5px; color: var(--muted); margin-top: 14px; line-height: 1.8; display: flex; gap: 8px; }
.note svg { flex: none; margin-top: 4px; }

.submit-area { margin-top: 20px; }
.btn-wa { width: 100%; min-height: 54px; font-size: 16.5px; }
.submit-hint { text-align: center; font-size: 13px; color: var(--muted); margin-top: 10px; }

.sent-notice { border-color: var(--brand); background: var(--brand-soft); animation: swapIn .4s var(--ease); }
.sent-notice p { margin: 0 0 14px; }
.sent-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.empty-state { text-align: center; padding: 70px 0 120px; }
.empty-state .icon { width: 72px; height: 72px; margin: 0 auto 18px; border-radius: 50%; background: var(--beige); display: grid; place-items: center; color: var(--brand); }
.empty-state h2 { font-family: var(--font-display); font-size: 28px; margin-bottom: 6px; }
.empty-state p { color: var(--muted); margin: 0 0 22px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
