/* KetabForoosh — direction B, dark
   Self-hosted Vazirmatn, warm near-black page with cards barely lifted off it
   (borders, not shadows — shadows don't read on dark), green for every action —
   used sparingly, as an accent, never a fill.
   Mobile-first; desktop just has to work. */

@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  /* Neutrals were warmed toward rust before; now they're desaturated toward the green instead —
     just enough to stop clashing with the accent, nowhere near enough to read as a green page. */
  --bg: #10130f;
  --surface: #171b16;
  --ink: #e8ece7;
  --muted: #8f978f;
  /* Bright green is readable as text on the dark canvas; the deeper action tone keeps white
     button labels above 4.5:1. One color could not satisfy both jobs. */
  --accent: #34c77b;
  --action: #1e7a50;
  --danger-ink: #e5766b;
  --danger-bg: #291614;
  --line: #232a22;
  --radius-card: 16px;
  /* Shadows don't read against a near-black page, so every --shadow-* token is a hairline
     border in disguise (box-shadow, not `border`, so it never touches the box model of the
     dozens of selectors already written against these tokens). --shadow-lift gets a touch of
     real shadow on top, for hover/active states that want to feel like they lifted. */
  --shadow-card: 0 0 0 1px var(--line);
  --shadow-lift: 0 0 0 1px var(--line), 0 4px 14px rgba(0, 0, 0, .35);
  --shadow-cover: 0 0 0 1px var(--line);
  --tap: 2.75rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

h1, h2, h3, button, .brand, .price { font-weight: 700; }

/* Default for the plain, unclassed <a> tags scattered through admin tables and a few dev/inline
   spots (edit/view/download/cancel links) — previously unstyled, so they rendered browser-default
   blue. Every intentionally-styled link (nav, cards, buttons) uses a class and outranks this on
   specificity, so this only catches what nothing else claims. */
a { color: var(--accent); }

img { display: block; max-width: 100%; height: auto; }
a, button, input, select, textarea { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-color: color-mix(in srgb, var(--accent) 55%, white);
  outline-offset: 2px;
}

/* ---------- layout shell ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.25rem clamp(1.25rem, 5vw, 5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-header a { color: var(--ink); text-decoration: none; }
.site-header > a, .site-header > form button {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}

.site-header .brand, .brand { color: var(--accent); font-size: 1.4rem; text-decoration: none; }

.container { width: min(72rem, calc(100% - 2.5rem)); margin: 3rem auto; }
.narrow { width: min(40rem, calc(100% - 2.5rem)); }
.container h1, .auth-card h1 { font-size: clamp(1.9rem, 4.5vw, 3rem); margin: 0 0 1.25rem; }

/* ---------- hero ---------- */

@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero {
  width: min(52rem, calc(100% - 2.5rem));
  margin: clamp(4rem, 12vh, 8rem) auto;
  padding: clamp(2rem, 6vw, 4rem);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
/* A faint accent glow, clipped to the card's own rounded corners — the one place green is
   allowed to spread out rather than sit on a glyph, and even then at 18% and blurred to nothing. */
.hero::before {
  content: "";
  position: absolute;
  top: -25%;
  left: -10%;
  right: -10%;
  height: 60%;
  background: radial-gradient(ellipse at top, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%);
  pointer-events: none;
}
.hero > * { position: relative; }
.eyebrow { color: var(--accent); font-weight: 700; margin: 0 0 .3rem; }
h1 { margin: .4rem 0 1rem; font-size: clamp(2.1rem, 7vw, 4.5rem); line-height: 1.15; }

.hero .secondary-button { transition: background-color .15s ease, transform .15s ease, box-shadow .15s ease; }
.hero .secondary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
  .hero { animation: rise-in .5s ease both; }
  .latest .book-card { animation: rise-in .45s ease both; }
  .latest .book-card:nth-child(1) { animation-delay: .05s; }
  .latest .book-card:nth-child(2) { animation-delay: .09s; }
  .latest .book-card:nth-child(3) { animation-delay: .13s; }
  .latest .book-card:nth-child(4) { animation-delay: .17s; }
  .latest .book-card:nth-child(5) { animation-delay: .21s; }
  .latest .book-card:nth-child(6) { animation-delay: .25s; }
}

.latest h2 { margin: 0 0 1rem; }
.see-all { display: flex; justify-content: center; margin-top: 1.75rem; }
.see-all a { color: var(--accent); font-weight: 700; text-decoration: none; }
.see-all a:hover { text-decoration: underline; }

/* ---------- buttons & form controls ---------- */

input, select, textarea, button {
  font: inherit;
  border-radius: .85rem;
  border: 1px solid var(--line);
}
input, select, textarea {
  min-height: var(--tap);
  padding: .6rem .9rem;
  background: var(--surface);
  color: var(--ink);
}
input { min-width: 0; }
textarea { min-height: 8rem; resize: vertical; }

button, .secondary-button {
  display: inline-flex;
  min-height: var(--tap);
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .65rem 1.35rem;
  background: var(--action);
  color: #fff;
  border: 0;
  border-radius: .85rem;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
  transition: background-color .15s ease;
}
button:hover, .secondary-button:hover { background: color-mix(in srgb, var(--action) 88%, black); }

.search { margin-block: 2rem; }
.search label { display: block; margin-bottom: .5rem; font-weight: 700; }
.search-row { display: flex; gap: .5rem; }
.search-row input { flex: 1; }

/* ---------- cards & book grid ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: .9375rem; /* ~15px */
  margin-bottom: 1rem;
}

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1.25rem; }
.book-card {
  padding: 1rem;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: box-shadow .15s ease, transform .15s ease;
}
.book-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-4px); }
.book-card a { color: inherit; text-decoration: none; }
.book-card h2, .book-card h3 { font-size: 1.05rem; margin: .6rem 0 .3rem; }
.book-card p { margin: .2rem 0; font-size: .92rem; }
/* :not(.price) — an unqualified `color` here would beat the .price rule below on specificity
   (class+element vs. class alone) and every book-grid price would render muted instead of
   accent. Pre-existing, not dark-mode-specific; caught while eyeballing this screen in the new
   palette. */
.book-card p:not(.price) { color: var(--muted); }

.book-card img, .cover-placeholder {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 10px;
  background: var(--line);
  box-shadow: var(--shadow-cover);
}
.cover-placeholder { display: grid; place-items: center; color: var(--muted); box-shadow: none; font-size: .85rem; }

.price { color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums; }
.price-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: .45rem; }
.old-price { color: var(--muted); font-size: .78rem; text-decoration: line-through; }

.empty { padding: 2rem 0; color: var(--muted); text-align: center; }

.pagination { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: .75rem; margin-top: 2rem; }
.pagination a {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.1rem;
  border-radius: .85rem;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  box-shadow: var(--shadow-card);
}
.pagination a:hover { box-shadow: var(--shadow-lift); }
.pagination span { color: var(--muted); font-weight: 700; }

/* ---------- chips ---------- */

.chips { display: flex; flex-wrap: wrap; list-style: none; gap: .3125rem; margin: .5625rem 0; padding: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  list-style: none;
  padding: .1875rem .5rem; /* ~3px 8px */
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--line); /* keeps the pill visible sitting on a white .card */
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
}

/* ---------- book detail (book.html — owned by another engineer, contract only) ---------- */

.book-detail-head { display: flex; gap: .9375rem; align-items: flex-start; }
.book-detail-meta { flex: 1; min-width: 0; }
.book-detail-meta h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 0 .3rem; }

.detail-cover, .summary-cover, .receipt-cover {
  flex: 0 0 auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: var(--shadow-cover);
}
.detail-cover { width: 9rem; }
.summary-cover { width: 4.5rem; } /* ~72px */
.receipt-cover { width: 4.5rem; }

/* a placeholder never gets the "real photo" shadow, whichever size class it's paired with —
   compound selector so it beats the box-shadow set above regardless of source order */
.cover-placeholder.detail-cover,
.cover-placeholder.summary-cover,
.cover-placeholder.receipt-cover { box-shadow: none; }

.byline { color: var(--muted); font-size: .92rem; margin: .2rem 0; }
.muted { color: var(--muted); }
.description { margin-top: 1.5rem; line-height: 2; white-space: pre-wrap; color: var(--ink); }

/* ---------- checkout (checkout.html — owned by another engineer, contract only) ---------- */

.checkout-summary { display: flex; gap: .875rem; align-items: center; }
.checkout-summary h2 { margin: 0 0 .2rem; font-size: 1.2rem; }
.total-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.total-row .price { font-size: 1.4rem; }
.fine-print { color: var(--muted); font-size: .8125rem; line-height: 1.8; }

/* ---------- sticky pay bar (book.html + checkout.html — contract, documented in report) ---------- */

.pay-bar-spacer { height: 0; }

.pay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6875rem; /* ~11px */
  margin-top: 1.5rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.pay-bar-price { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.pay-bar-label { font-size: .75rem; color: var(--muted); font-weight: 700; }
.pay-bar-price strong { font-size: 1rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; } /* 16px/800 */

.pay-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: .8125rem 1.625rem; /* ~13px 26px */
  background: var(--action);
  color: #fff;
  border: 0;
  border-radius: .75rem; /* 12px */
  font-weight: 800;
  font-size: .9375rem; /* 15px */
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s ease;
}
.pay-button:hover { background: color-mix(in srgb, var(--action) 88%, black); }

/* ---------- order / receipt (order.html) ---------- */

.receipt-order-id {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}
.receipt-order-id .order-code {
  font-size: 1.1rem;
  font-weight: 700;
  padding: .3rem .7rem;
  border-radius: .6rem;
  background: var(--bg);
  color: var(--ink);
  user-select: all;
}

.receipt-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.receipt-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.receipt-body { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.receipt-body h2 { margin: 0; font-size: 1.05rem; }

/* ---------- payment result ---------- */

.result-card { text-align: center; }
.result-card h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }
.result-failure h1 { color: var(--danger-ink); }
.order-code {
  display: inline-block;
  font-weight: 700;
  padding: .3rem .7rem;
  border-radius: .6rem;
  background: var(--bg);
  color: var(--ink);
  user-select: all;
}
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .75rem; margin-top: 1.25rem; }

/* ---------- notices ---------- */

.notice {
  background: var(--surface);
  border-inline-start: 4px solid var(--accent);
  border-radius: .8rem;
  padding: .9rem 1.1rem;
  color: var(--ink);
  font-size: .95rem;
  line-height: 1.7;
  box-shadow: var(--shadow-card);
  margin-bottom: 1rem;
}
.notice.error { border-inline-start-color: var(--danger-ink); background: var(--danger-bg); color: var(--danger-ink); }

/* ---------- auth / admin (structure untouched, tokens inherited) ---------- */

.auth-card {
  width: min(28rem, calc(100% - 2.5rem));
  margin: 8vh auto;
  padding: 2rem;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.auth-card form { display: grid; gap: .7rem; }
.form-error { padding: .8rem; border-radius: .6rem; background: var(--danger-bg); color: var(--danger-ink); }

.admin-nav { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; }
.admin-nav a {
  padding: 1.5rem;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.admin-form { display: grid; gap: 1rem; }
.admin-form label { display: grid; gap: .4rem; font-weight: 700; }

.table-wrap { max-width: 100%; overflow-x: auto; border-radius: .8rem; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .9rem; border-bottom: 1px solid var(--line); text-align: right; }

.order-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.inline-form { display: inline; margin-inline-start: 1rem; }

/* ---------- dev-only fake payment page ---------- */

.fake-actions { display: grid; gap: 1rem; }

/* =====================================================================
   Responsive — breakpoints preserved: 60rem / 45rem / 30rem / 22rem.
   Mobile is the priority; desktop must merely work.
   ===================================================================== */

@media (max-width: 60rem) {
  .container { margin-block: 2rem; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 1rem; }
}

@media (max-width: 45rem) {
  .site-header { padding: 1rem 1.25rem; }
  .container { width: min(100% - 2rem, 72rem); margin-block: 1.5rem; }
  .narrow { width: calc(100% - 2rem); }
  .hero { width: calc(100% - 2rem); margin-block: 2rem; padding: clamp(1.5rem, 7vw, 2.5rem); }

  .auth-card { width: calc(100% - 2rem); margin-block: 1.5rem; padding: 1.5rem; }

  .receipt-item { flex-wrap: wrap; }
  .receipt-body { flex-direction: column; align-items: flex-start; }
  .receipt-body .secondary-button { width: 100%; }

  th, td { min-width: 7rem; padding: .75rem; }
  .inline-form { display: block; margin: .6rem 0 0; }
  .inline-form button { width: 100%; }

  /* the pay bar becomes a fixed dock at the bottom of the viewport */
  .pay-bar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    border-radius: 16px 16px 0 0;
    padding: .85rem 1.25rem calc(.85rem + env(safe-area-inset-bottom));
    box-shadow: 0 -1px 0 var(--line);
  }
  .pay-bar-spacer { height: calc(4.75rem + env(safe-area-inset-bottom)); }
}

/* ---------- footer ---------- */

.site-footer {
  margin-top: 4rem;
  padding: 2rem clamp(1.25rem, 5vw, 5rem);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.footer-links { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin: 0 0 .75rem; padding: 0; list-style: none; }
.footer-links a { color: var(--muted); text-decoration: none; font-size: .9rem; }
.footer-links a:hover { color: var(--ink); }
.footer-note { margin: 0; color: var(--muted); font-size: .82rem; }
/* cursor:pointer lives here, not on the eNamad <img>'s own inline style attribute — CSP's
   style-src 'self' silently drops inline styles, so the visual has to come from our own sheet. */
.site-footer img { display: inline-block; margin-top: 1rem; cursor: pointer; }

/* ---------- legal / static pages ---------- */

.legal-page h1 { margin-bottom: .5rem; }
.legal-page .updated { color: var(--muted); font-size: .85rem; margin: 0 0 2rem; }
.legal-page h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
.legal-page p, .legal-page li { line-height: 1.9; color: var(--ink); }
.legal-page ul { padding-inline-start: 1.4rem; margin: .5rem 0; }
.legal-page a { color: var(--accent); }

@media (max-width: 30rem) {
  .site-header { align-items: stretch; }
  .site-header .secondary-button { width: 100%; }
  .search-row { display: grid; grid-template-columns: 1fr; }
  .search-row button { width: 100%; }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .book-card { padding: .75rem; }
  .book-card h2, .book-card h3 { font-size: 1rem; }
  .pagination { gap: .65rem; }
  .pagination a { flex: 1; text-align: center; }
  .fake-actions .secondary-button, .admin-form button { width: 100%; }
  .actions { flex-direction: column; }
  .actions .secondary-button { width: 100%; }
  .receipt-order-id { justify-content: center; text-align: center; }

  /* only stack the cover + meta once a row genuinely has no room for both */
  /* Deliberately still a row at phone width: stacking centres the title, byline, chips and price
     into a brochure and pushes the description below the fold. Only the very narrowest screens
     (under 22rem, below) give up and stack. */
  .detail-cover { width: 7rem; }
}

@media (max-width: 22rem) {
  .book-grid { grid-template-columns: 1fr; }
  /* Last resort: below this a 7rem cover leaves the title no room to breathe. */
  .book-detail-head { flex-direction: column; align-items: center; text-align: center; }
  .detail-cover { width: min(11rem, 55vw); }
  .book-detail-meta { width: 100%; }
  .chips { justify-content: center; }
}
