/* =========================================================
   STACKS — design tokens
   Minimal, high-contrast: white background, black text and
   buttons, restrained color used only where it earns its
   place (errors, sale, urgency). Built RTL-aware throughout
   using CSS logical properties so Arabic just works.
   ========================================================= */

:root {
  /* color */
  --ink:        #0A0A0A;   /* primary text + buttons */
  --ink-soft:   #262626;   /* hover state for black buttons */
  --paper:      #FFFFFF;   /* page background */
  --card:       #FFFFFF;   /* card background (white, defined by border) */
  --line:       rgba(0, 0, 0, 0.13);
  --line-soft:  rgba(0, 0, 0, 0.06);
  --ash:        #6E6E6E;   /* secondary / muted text */
  --danger:     #D7263D;   /* errors, sale, urgency — used sparingly */
  --danger-soft:rgba(215, 38, 61, 0.08);
  --success:    #1B8A4B;   /* admin: completed status only */
  --warning:    #B8782A;   /* admin: pending status only */
  --placeholder-grad: linear-gradient(160deg, #F1F1F1, #E1E1E1);
  --shadow:     0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 28px rgba(0, 0, 0, 0.07);
  --overlay-bg: rgba(0, 0, 0, 0.45);

  /* type — Cairo covers Arabic + Latin, so one family does both */
  --font-display: "Cairo", "Segoe UI", Tahoma, sans-serif;
  --font-body:    "Cairo", "Segoe UI", Tahoma, sans-serif;
  --font-mono:    "Cairo", "Segoe UI", Tahoma, sans-serif;

  /* layout */
  --radius: 10px;
  --radius-pill: 999px;
  --container: 1180px;
}

/* ---------- reset ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-weight: 700; }
p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.hidden { display: none !important; }

/* Arabic script is cursive — letter-spacing breaks the joins between
   letters, so neutralize all tracking once the page flips to RTL. */
[dir="rtl"] * { letter-spacing: normal !important; }

.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ash);
  font-weight: 600;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 22px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary, .btn-brass { background: var(--ink); color: #fff; }
.btn-primary:hover, .btn-brass:hover { background: var(--ink-soft); }
.btn-primary:disabled, .btn-brass:disabled { background: var(--line); color: var(--ash); cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-text { background: none; border: none; padding: 4px 0; color: var(--ink); font-weight: 700; text-decoration: underline; text-decoration-color: var(--line); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

/* ---------- form fields (shared with admin) ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label {
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ash);
  font-weight: 600;
}
.field input,
.field select,
.field textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  color: var(--ink);
}
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--ink); outline: none; }
.field textarea { resize: vertical; min-height: 90px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-hint { font-size: 0.78rem; color: var(--ash); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; }
.checkbox-row label { text-transform: none; font-weight: 400; font-size: 0.9rem; letter-spacing: 0; color: var(--ink); }

/* ---------- badges / tags ---------- */
.sale-badge {
  position: absolute;
  top: 10px;
  inset-inline-end: 10px;
  background: var(--danger);
  color: #fff;
  text-transform: uppercase;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  pointer-events: none;
}
.tag {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ash);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-weight: 600;
}

/* =========================================================
   HEADER
   ========================================================= */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 76px;
  gap: 16px;
}
.logo {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.header-actions { display: flex; align-items: center; gap: 14px; }
.header-link {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}
.header-link:hover { text-decoration: underline; }

.lang-switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.lang-switch button {
  background: transparent;
  border: none;
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ash);
}
.lang-switch button.is-active { background: var(--ink); color: #fff; }

.cart-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  border: 1px solid var(--ink);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font-size: 0.84rem;
  font-weight: 700;
}
.cart-btn:hover { background: var(--ink-soft); }
.cart-count {
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* =========================================================
   HERO
   ========================================================= */
.hero {
  background: var(--paper);
  color: var(--ink);
  padding: 60px 0 48px;
}
.hero h1 {
  font-size: clamp(2.1rem, 4.2vw, 3.2rem);
  line-height: 1.12;
  max-width: 16ch;
  color: var(--ink);
}
.hero p.lede {
  margin-top: 14px;
  max-width: 48ch;
  color: var(--ash);
  font-size: 1.05rem;
}
.hero-meta {
  margin-top: 26px;
  display: flex;
  gap: 30px;
  font-size: 0.84rem;
  color: var(--ash);
}
.hero-meta strong { color: var(--ink); font-size: 1.05rem; display: block; font-family: var(--font-display); }

.search-bar {
  margin-top: 30px;
  max-width: 520px;
  display: flex;
  background: var(--card);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  overflow: hidden;
}
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 14px 18px;
  color: var(--ink);
  font-size: 0.95rem;
}
.search-bar input:focus { outline: none; }
.search-bar button {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 0 22px;
  font-weight: 700;
  font-size: 0.84rem;
}
.search-bar button:hover { background: var(--ink-soft); }

/* =========================================================
   CATALOG / FILTERS
   ========================================================= */
.catalog-bar {
  padding: 30px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ash);
}
.chip[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.chip:hover { border-color: var(--ink); }
.result-count { font-size: 0.82rem; color: var(--ash); }

/* =========================================================
   PRODUCT GRID & CARD
   ========================================================= */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 22px;
  padding: 20px 0 64px;
}
.book-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.book-card__cover {
  position: relative;
  aspect-ratio: 3/4;
  background: var(--placeholder-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
}
.book-card__cover img { width: 100%; height: 100%; object-fit: cover; }
.book-card__cover .placeholder {
  font-family: var(--font-display);
  font-weight: 700;
  text-align: center;
  color: rgba(0,0,0,0.32);
  padding: 14px;
  font-size: 0.85rem;
  line-height: 1.3;
}
.book-card__body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 5px; flex: 1; border-top: 1px solid var(--line); }
.book-card__sku { font-size: 0.7rem; color: var(--ash); }
.book-card__title { font-size: 1.02rem; line-height: 1.3; cursor: pointer; font-weight: 700; }
.book-card__title:hover { text-decoration: underline; }
.book-card__author { color: var(--ash); font-size: 0.86rem; }
.book-card__footer { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.book-card__price { font-weight: 800; font-size: 0.98rem; }
.book-card__price .was { font-weight: 400; color: var(--ash); text-decoration: line-through; margin-inline-end: 6px; font-size: 0.85rem; }
.book-card__stock { font-size: 0.72rem; color: var(--ash); font-weight: 600; }
.book-card__stock.low { color: var(--danger); }
.add-to-cart-btn {
  width: 100%;
  margin-top: 12px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 11px;
  font-size: 0.8rem;
  font-weight: 700;
}
.add-to-cart-btn:hover { background: var(--ink-soft); }
.add-to-cart-btn:disabled { background: var(--line); color: var(--ash); cursor: not-allowed; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 20px;
  color: var(--ash);
}
.empty-state h3 { color: var(--ink); margin-bottom: 8px; }

/* =========================================================
   MODAL / OVERLAY (shared shell for product modal + checkout drawer)
   ========================================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 60;
  display: none;
}
.overlay.is-open { display: block; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 61;
  display: none;
}
.modal.is-open { display: block; }
.modal__close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  line-height: 1;
}
.modal__close:hover { background: var(--ink); color: #fff; border-color: var(--ink); }

.product-modal { display: grid; grid-template-columns: 220px 1fr; gap: 0; }
.product-modal__cover { background: var(--placeholder-grad); min-height: 280px; display: flex; align-items: center; justify-content: center; }
.product-modal__cover img { width: 100%; height: 100%; object-fit: cover; }
.product-modal__body { padding: 28px 26px; }
.product-modal__body h2 { font-size: 1.5rem; margin-bottom: 4px; }
.product-modal__author { color: var(--ash); margin-bottom: 14px; }
.product-modal__desc { color: var(--ink-soft); font-size: 0.94rem; margin-bottom: 18px; }
.product-modal__price { font-size: 1.3rem; font-weight: 800; margin-bottom: 16px; }
.qty-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.qty-control { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.qty-control button { background: var(--paper); border: none; width: 34px; height: 34px; font-size: 1rem; }
.qty-control button:hover { background: var(--line-soft); }
.qty-control span { width: 38px; text-align: center; }

@media (max-width: 560px) {
  .product-modal { grid-template-columns: 1fr; }
  .product-modal__cover { min-height: 180px; }
}

/* =========================================================
   CART / CHECKOUT DRAWER
   ========================================================= */
.drawer {
  position: fixed;
  top: 0;
  inset-inline-end: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background: var(--card);
  box-shadow: 0 0 30px rgba(0,0,0,0.18);
  z-index: 62;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}
[dir="rtl"] .drawer { transform: translateX(-100%); }
.drawer.is-open { transform: translateX(0); }
.drawer__header {
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer__header h2 { font-size: 1.1rem; }
.drawer__body { flex: 1; overflow-y: auto; padding: 18px 22px; }
.drawer__footer { padding: 18px 22px; border-top: 1px solid var(--line); }

.cart-line {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px dashed var(--line);
}
.cart-line__thumb { width: 48px; height: 64px; border-radius: 4px; background: var(--placeholder-grad); overflow: hidden; }
.cart-line__thumb img { width: 100%; height: 100%; object-fit: cover; }
.cart-line__title { font-size: 0.9rem; line-height: 1.3; font-weight: 600; }
.cart-line__price { font-size: 0.78rem; color: var(--ash); margin-top: 2px; }
.cart-line__controls { display: flex; align-items: center; gap: 8px; }
.cart-line__controls button { background: none; border: 1px solid var(--line); border-radius: 4px; width: 22px; height: 22px; font-size: 0.85rem; line-height: 1; }
.cart-line__remove { font-size: 0.7rem; color: var(--danger); background: none; border: none; text-decoration: underline; margin-top: 4px; padding: 0; }

.cart-empty { text-align: center; padding: 50px 10px; color: var(--ash); }

.discount-row { display: flex; gap: 8px; margin: 14px 0; }
.discount-row input { flex: 1; }
#discount-message { font-size: 0.78rem; margin-top: 6px; font-weight: 600; }
#discount-message.ok { color: var(--success); }
#discount-message.err { color: var(--danger); }

.totals-line { display: flex; justify-content: space-between; font-size: 0.92rem; padding: 4px 0; color: var(--ink-soft); }
.totals-line.grand { font-size: 1.15rem; font-weight: 800; color: var(--ink); border-top: 1px solid var(--line); margin-top: 8px; padding-top: 10px; }
.totals-line .label-mono { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ash); font-weight: 600; }

/* =========================================================
   CHECKOUT
   ========================================================= */
.checkout-view { padding: 18px 22px; }
.checkout-summary {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 0.86rem;
}
.checkout-summary .row { display: flex; justify-content: space-between; padding: 3px 0; }
.cod-note { display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; font-size: 0.82rem; color: var(--ash); margin-top: 14px; }

.confirmation { text-align: center; padding: 50px 26px; }
.confirmation .check-badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto 20px;
}
.confirmation h2 { margin-bottom: 8px; }
.confirmation .order-id { color: var(--ash); margin-bottom: 22px; font-weight: 600; }

/* =========================================================
   FOOTER
   ========================================================= */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--paper);
  color: var(--ash);
  padding: 28px 0;
  margin-top: 20px;
}
.site-footer .container { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.site-footer a { font-size: 0.84rem; font-weight: 600; color: var(--ink); }
.site-footer a:hover { text-decoration: underline; }

/* =========================================================
   TOAST
   ========================================================= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.86rem;
  font-weight: 600;
  z-index: 80;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  .site-header .container { height: 64px; flex-wrap: wrap; }
  .hero { padding: 40px 0 36px; }
  .header-link { display: none; }
}
