/* ==========================================================================
   Jeziry Bookshop — Editorial design system
   Plain CSS (no build step). Works alongside the Tailwind Play CDN config in
   templates/components/design_head.html, which exposes the same tokens as
   Tailwind colours (paper, surface, ink, rule, accent, wa).

   Palette (60-30-10):
     60%  paper    — warm off-white page background
     30%  ink/rule — charcoal text, warm-gray secondary text, 1px rules
     10%  accent   — literary oxblood for primary CTAs, active states, key badges
     WhatsApp actions keep their own green (--wa) by design.

   Selectors that must beat @tailwindcss/forms (attribute selectors, 0,1,0)
   are written as element.class (0,1,1).
   ========================================================================== */

:root {
    --paper: #FAF7F0;
    --paper-2: #F3EEE3;
    --paper-3: #EAE2D2;
    --surface: #FFFDF9;
    --ink: #1F1B16;
    --ink-soft: #3B342C;
    --muted: #6B6358;
    --faint: #8F8678;
    --rule: #E4DDD0;
    --rule-strong: #CFC5B3;
    --accent: #8A2E14;
    --accent-hover: #6F2410;
    --accent-soft: #F5E3DA;
    --wa: #1F7A4D;
    --wa-hover: #17633E;
    --wa-soft: #E4F2EA;

    --font-serif: "Playfair Display", "Amiri", Georgia, "Times New Roman", serif;
    --font-sans: "Plus Jakarta Sans", "Vazirmatn", system-ui, -apple-system, "Segoe UI", sans-serif;

    --radius: 0.75rem;
    --tap: 44px;
    --header-h: 56px;

    --shadow-card: 0 1px 2px rgba(31, 27, 22, 0.04), 0 1px 1px rgba(31, 27, 22, 0.03);
    --shadow-cover: 0 1px 1px rgba(31, 27, 22, 0.10), 0 10px 24px -10px rgba(31, 27, 22, 0.35);
    --shadow-lift: 0 2px 4px rgba(31, 27, 22, 0.06), 0 18px 36px -14px rgba(31, 27, 22, 0.38);

    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    color-scheme: light;
}

@media (min-width: 1024px) {
    :root { --header-h: 72px; }
}

/* --------------------------------------------------------------------------
   Horizontal overflow guard.
   `overflow-x: clip` stops sideways scrolling without turning <body> into a
   scroll container, so the sticky header keeps working. Older browsers fall
   back to overflow-x:hidden on <body> only (which propagates to the viewport
   and also leaves sticky intact).
   -------------------------------------------------------------------------- */
body { overflow-x: hidden; }
@supports (overflow: clip) {
    html, body { overflow-x: clip; }
}

/* --------------------------------------------------------------------------
   Typography. One stack per role works in both directions: Latin glyphs come
   from Playfair / Plus Jakarta, Arabic-script glyphs fall through to
   Amiri / Vazirmatn — so an Arabic title on /en/ or an ISBN on /ar/ still
   renders in the right face.
   -------------------------------------------------------------------------- */
body {
    background-color: var(--paper);
    color: var(--ink);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
[dir="rtl"] body { line-height: 1.8; }

h1, h2, h3, .font-literary, .font-serif {
    font-family: var(--font-serif);
    letter-spacing: -0.005em;
}
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3,
[dir="rtl"] .font-literary, [dir="rtl"] .font-serif {
    letter-spacing: 0;
}

/* Arabic script must never be letter-spaced — it breaks the joins between
   letters. Neutralise Tailwind tracking-* utilities on RTL pages, except on
   monospace codes such as order numbers. */
[dir="rtl"] [class*="tracking-"]:not(.font-mono) { letter-spacing: 0; }

/* Fluid editorial scale (mobile → desktop). Amiri has a smaller x-height
   than Playfair, so RTL headings get a gentle size bump and more leading. */
.t-display { --fs: clamp(2.125rem, 1.35rem + 3.6vw, 4rem); font-size: var(--fs); line-height: 1.08; }
.t-h1      { --fs: clamp(1.75rem, 1.35rem + 1.9vw, 2.75rem); font-size: var(--fs); line-height: 1.15; }
.t-h2      { --fs: clamp(1.375rem, 1.2rem + 0.9vw, 1.875rem); font-size: var(--fs); line-height: 1.2; }
.t-h3      { --fs: clamp(1.0625rem, 1rem + 0.35vw, 1.25rem); font-size: var(--fs); line-height: 1.3; }
[dir="rtl"] :is(.t-display, .t-h1, .t-h2, .t-h3) { font-size: calc(var(--fs) * 1.08); line-height: 1.5; }

.eyebrow {
    display: inline-block;
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}
[dir="rtl"] .eyebrow { font-size: 0.8125rem; letter-spacing: 0; text-transform: none; }

.lede { color: var(--muted); font-size: 1rem; line-height: 1.7; }
@media (min-width: 640px) { .lede { font-size: 1.0625rem; } }

.num { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Touch ergonomics
   -------------------------------------------------------------------------- */
.tap { min-height: var(--tap); min-width: var(--tap); }
a, button, summary, label, select { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: var(--tap);
    padding: 0.625rem 1.125rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-lg { min-height: 52px; padding: 0.875rem 1.5rem; font-size: 1rem; border-radius: 0.875rem; }
.btn-block { display: flex; width: 100%; }
.btn-wrap { white-space: normal; }
.btn-icon { padding: 0; width: var(--tap); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-wa { background: var(--wa); color: #fff; }
.btn-wa:hover { background: var(--wa-hover); }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ink:hover { background: var(--ink-soft); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
.btn-outline:hover { border-color: var(--ink); }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); background: var(--paper-2); }

/* --------------------------------------------------------------------------
   Form fields (16px text on phones prevents iOS focus-zoom)
   -------------------------------------------------------------------------- */
input.field, select.field, textarea.field {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 0.625rem 0.875rem;
    background-color: var(--surface);
    color: var(--ink);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.4;
    box-shadow: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
@media (min-width: 768px) {
    input.field, select.field, textarea.field { font-size: 0.9375rem; }
}
input.field::placeholder, textarea.field::placeholder { color: var(--faint); opacity: 1; }
input.field:focus, select.field:focus, textarea.field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(138, 46, 20, 0.14);
}
select.field {
    padding-inline-end: 2.25rem;
    background-position: right 0.75rem center;
}
[dir="rtl"] select.field { background-position: left 0.75rem center; }
input.field[type="search"]::-webkit-search-cancel-button { cursor: pointer; }
.field-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ink-soft);
}
.field-error { margin-top: 0.375rem; font-size: 0.8125rem; color: #B42318; }

input.check {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 0.375rem;
    border: 1px solid var(--rule-strong);
    color: var(--accent);
}
input.check:focus { box-shadow: 0 0 0 3px rgba(138, 46, 20, 0.18); }

/* --------------------------------------------------------------------------
   Surfaces, chips, badges
   -------------------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 1rem;
    box-shadow: var(--shadow-card);
}
.hairline { border-color: var(--rule); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--tap);
    padding: 0.5rem 0.875rem;
    border-radius: 999px;
    border: 1px solid var(--rule-strong);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
    transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip-active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip-active:hover { color: var(--paper); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}
[dir="rtl"] .badge { font-size: 0.75rem; }
.badge-accent { background: var(--accent); color: #fff; }
.badge-soft { background: var(--accent-soft); color: #561C0D; }
.badge-paper { background: rgba(255, 253, 249, 0.92); color: var(--ink); border: 1px solid var(--rule); backdrop-filter: blur(4px); }
.badge-ink { background: rgba(31, 27, 22, 0.86); color: var(--paper); backdrop-filter: blur(4px); }

.stock { display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.75rem; font-weight: 600; }
.stock::before { content: ""; width: 0.4375rem; height: 0.4375rem; border-radius: 999px; background: currentColor; flex-shrink: 0; }
.stock-in { color: var(--wa); }
.stock-out { color: var(--faint); }

/* Horizontally scrolling rows (filter chips, tabs) without visible scrollbars */
.scroll-row {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.scroll-row::-webkit-scrollbar { display: none; }
.scroll-row > * { scroll-snap-align: start; flex-shrink: 0; }

/* --------------------------------------------------------------------------
   Book covers — gallery-wall framing on paper
   -------------------------------------------------------------------------- */
.cover-frame {
    position: relative;
    aspect-ratio: 2 / 3;
    overflow: hidden;
    border-radius: 3px 6px 6px 3px;
    background: var(--paper-3);
    box-shadow: var(--shadow-cover);
    transition: transform .25s ease, box-shadow .25s ease;
}
[dir="rtl"] .cover-frame { border-radius: 6px 3px 3px 6px; }
.cover-frame > img, .cover-frame > a > img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Subtle spine highlight on the binding edge (mirrors in RTL) */
.cover-frame::after {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 7%;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.16), rgba(255, 255, 255, 0.10) 45%, rgba(0, 0, 0, 0));
}
[dir="rtl"] .cover-frame::after { background: linear-gradient(to left, rgba(0, 0, 0, 0.16), rgba(255, 255, 255, 0.10) 45%, rgba(0, 0, 0, 0)); }
.group:hover .cover-frame, .cover-frame:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
@media (prefers-reduced-motion: reduce) {
    .cover-frame, .btn { transition: none; }
    .group:hover .cover-frame, .cover-frame:hover { transform: none; }
}

/* Typographic placeholder cover for books without artwork */
.cover-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 12% 10%;
    background: linear-gradient(160deg, #3B2A22 0%, #2A1F1A 55%, #1F1B16 100%);
    color: #F3EEE3;
}
.cover-placeholder .cp-rule { height: 1px; background: rgba(243, 238, 227, 0.25); }

/* --------------------------------------------------------------------------
   Mobile bottom sheet (filters) built on <details>
   -------------------------------------------------------------------------- */
.sheet > summary { list-style: none; cursor: pointer; }
.sheet > summary::-webkit-details-marker { display: none; }
@media (max-width: 767.98px) {
    .sheet[open] > .sheet-backdrop {
        position: fixed;
        inset: 0;
        z-index: 60;
        background: rgba(31, 27, 22, 0.45);
    }
    .sheet > .sheet-panel {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 61;
        max-height: 85dvh;
        overflow-y: auto;
        background: var(--surface);
        border-radius: 1.25rem 1.25rem 0 0;
        box-shadow: 0 -12px 40px -12px rgba(31, 27, 22, 0.35);
        padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom));
        animation: sheet-up .22s ease-out;
    }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet > .sheet-panel { animation: none; } }

/* --------------------------------------------------------------------------
   Sticky mobile action bar (book detail, cart)
   -------------------------------------------------------------------------- */
.action-bar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 35;
    background: rgba(255, 253, 249, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--rule);
    padding: 0.625rem 1rem calc(0.625rem + env(safe-area-inset-bottom));
    transform: translateY(110%);
    transition: transform .2s ease;
}
.action-bar.is-visible { transform: none; }
@media (min-width: 1024px) { .action-bar { display: none; } }
.has-action-bar { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
@media (min-width: 1024px) { .has-action-bar { padding-bottom: 0; } }

/* --------------------------------------------------------------------------
   Toasts (in-place "Add to bag" feedback, see static/js/cart.js)
   -------------------------------------------------------------------------- */
.toast-stack {
    position: fixed;
    z-index: 60;
    inset-inline: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
/* Sit above the sticky mobile purchase bar when it is showing */
body:has(.action-bar.is-visible) .toast-stack,
.has-action-bar .toast-stack { bottom: calc(88px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) {
    .toast-stack { inset-inline: auto 1.5rem; bottom: 1.5rem; width: 24rem; }
}
@media (min-width: 1024px) {
    body:has(.action-bar.is-visible) .toast-stack,
    .has-action-bar .toast-stack { bottom: 1.5rem; }
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-block: 0.25rem;
    padding-inline: 1rem 0.25rem;
    border-radius: var(--radius);
    border: 1px solid;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lift);
    animation: toast-in .18s ease-out;
}
.toast-success { background: var(--wa-soft); border-color: rgba(31, 122, 77, 0.2); color: var(--wa-hover); }
.toast-error { background: #FEF3F2; border-color: #FECDCA; color: #B42318; }
.toast-text { flex: 1; min-width: 0; padding-block: 0.5rem; overflow-wrap: anywhere; }
.toast-link { flex-shrink: 0; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; min-height: var(--tap); display: inline-flex; align-items: center; }
.toast-close { flex-shrink: 0; width: var(--tap); height: var(--tap); display: inline-flex; align-items: center; justify-content: center; border-radius: 0.5rem; opacity: .6; }
.toast-close:hover { opacity: 1; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s ease, transform .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Bag page while a quantity change is being saved in the background */
#cart-root.is-updating form[data-cart-swap] button { opacity: .5; pointer-events: none; }

.badge-bump { animation: badge-bump .4s ease-out; }
@keyframes badge-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
    .toast, .badge-bump { animation: none; }
    .toast.is-leaving { transition: none; }
}

/* --------------------------------------------------------------------------
   Order status timeline: vertical on phones, horizontal from 640px
   -------------------------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.timeline-step { position: relative; display: flex; align-items: flex-start; gap: 0.875rem; padding-bottom: 1.25rem; }
.timeline-step:last-child { padding-bottom: 0; }
.timeline-dot {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    background: var(--surface);
    border: 2px solid var(--rule-strong);
    color: var(--faint);
}
.timeline-step::before {
    content: "";
    position: absolute;
    inset-inline-start: calc(1rem - 1px);
    top: 2rem;
    bottom: 0;
    width: 2px;
    background: var(--rule);
}
.timeline-step:last-child::before { display: none; }
.timeline-step.is-done .timeline-dot { background: var(--wa); border-color: var(--wa); color: #fff; }
.timeline-step.is-done::before { background: var(--wa); }
.timeline-step.is-current .timeline-dot { box-shadow: 0 0 0 4px var(--wa-soft); }
.timeline-label { padding-top: 0.3rem; font-size: 0.875rem; font-weight: 600; color: var(--faint); }
.timeline-step.is-done .timeline-label { color: var(--ink); }
.timeline-step.is-current .timeline-label { color: var(--wa-hover); }
@media (min-width: 640px) {
    .timeline { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .timeline-step { flex-direction: column; align-items: center; text-align: center; gap: 0.5rem; padding-bottom: 0; }
    .timeline-step::before {
        top: calc(1rem - 1px);
        bottom: auto;
        inset-inline-start: calc(50% + 1rem);
        width: calc(100% - 2rem);
        height: 2px;
    }
    .timeline-label { padding-top: 0; font-size: 0.8125rem; }
}

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */
.prose-editorial { color: var(--ink-soft); line-height: 1.8; font-size: 1rem; }
[dir="rtl"] .prose-editorial { line-height: 2; font-size: 1.0625rem; }

::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--paper-2); }
::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

@media print {
    .no-print, .action-bar { display: none !important; }
    body { background: #fff; }
}

/* Legacy alias (home spotlight, older markup) */
.book-spine-shadow { box-shadow: var(--shadow-cover); }
