/* BuyDocs — shared theme
 * --------------------------------------------------------------
 *
 * Loaded by every page. Provides the base typography, the design
 * tokens that every page-level CSS already references via :root,
 * a unified pagination component, and a mobile responsive layer.
 *
 * Colors are tuned for warmth + clarity:
 *   - Gold is the brand accent; not the page background.
 *   - Whites are slightly off-white so light cards have a
 *     visible edge against the page.
 *   - Greys have proper contrast progression for hierarchy.
 *
 * Page-specific component CSS still lives inline in each
 * template; this file only defines tokens and a few shared
 * components, so changes here propagate visually without
 * touching templates.
 */

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

:root {
    /* Brand */
    --gold-primary:   #f5b800;
    --gold-light:     #fcd34d;
    --gold-lighter:   #fef3c7;
    --gold-bg:        #fffbeb;
    --gold-deep:      #b45309;

    /* Text & surfaces */
    --dark-primary:   #1f2937;   /* slightly cooler than #3d3d3d — better contrast */
    --dark-secondary: #374151;
    --dark-muted:     #6b7280;
    --dark-soft:      #9ca3af;

    /* Status colors */
    --green-primary:  #10b981;
    --green-light:    #d1fae5;
    --green-dark:     #047857;
    --blue-primary:   #3b82f6;
    --blue-light:     #dbeafe;
    --red-primary:    #ef4444;
    --red-light:      #fee2e2;

    /* Neutrals */
    --white:          #ffffff;
    --gray-50:        #f9fafb;
    --gray-100:       #f3f4f6;
    --gray-200:       #e5e7eb;
    --gray-300:       #d1d5db;

    /* Spacing scale (4-px base) */
    --sp-1:  4px;  --sp-2:  8px;  --sp-3: 12px;  --sp-4: 16px;
    --sp-5: 20px;  --sp-6: 24px;  --sp-8: 32px;  --sp-10: 40px;
    --sp-12: 48px; --sp-16: 64px;

    /* Radius scale */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;

    /* Shadow scale (warm-tinted, soft) */
    --shadow-sm: 0 1px 3px rgba(31, 41, 55, 0.06), 0 1px 2px rgba(31, 41, 55, 0.04);
    --shadow-md: 0 4px 12px rgba(31, 41, 55, 0.08), 0 2px 6px rgba(31, 41, 55, 0.04);
    --shadow-lg: 0 12px 32px rgba(31, 41, 55, 0.10), 0 4px 12px rgba(31, 41, 55, 0.06);
    --shadow-gold: 0 8px 28px rgba(245, 184, 0, 0.25);

    /* Animation */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
    color: var(--dark-primary);
    background: var(--white);
    line-height: 1.7;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Persian text uses tabular-style figures so numbers in tables/cards align */
body { font-variant-numeric: tabular-nums; }

a { text-decoration: none; color: inherit; cursor: pointer; }
button { font-family: inherit; border: none; outline: none; cursor: pointer; }
img { max-width: 100%; height: auto; }

/* Selection — match brand */
::selection { background: var(--gold-light); color: var(--dark-primary); }

/* Focus rings — accessible without being visually loud */
:focus-visible {
    outline: 2px solid var(--gold-primary);
    outline-offset: 2px;
    border-radius: 8px;
}

/* ============================================================
 * Modal close buttons — single source of truth
 *
 * Used for ALL window/popup close X buttons across the app.
 * Position is `top: 16px; right: 16px` so on the Persian RTL pages it sits
 * in the visual top-right of the modal — the natural spot the user's eye
 * lands first when reading right-to-left.
 *
 * Uses an SVG ✕ inside (templates put `<svg ...>` content in the button)
 * for crisp rendering at any pixel density. Falls back to gracefully
 * absorb a Unicode `×` text node if a template hasn't been updated yet.
 *
 * Both .modal-close and .modal-close-btn class names are supported because
 * the templates use both.
 * ============================================================ */
.modal-close,
.modal-close-btn {
    position: absolute !important;
    top: 16px !important;
    right: 16px !important;
    left: auto !important;
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: var(--gray-100) !important;
    color: var(--dark-secondary) !important;
    border: 0 !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.1rem !important;
    line-height: 1 !important;
    cursor: pointer;
    transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out), transform 0.15s var(--ease-out);
    z-index: 2;
}
.modal-close:hover,
.modal-close-btn:hover {
    background: var(--red-light) !important;
    color: var(--red-primary) !important;
    transform: rotate(90deg);
}
.modal-close svg,
.modal-close-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
    stroke-linecap: round;
}

/* ============================================================
 * Toast / Notification
 *
 * Visual design intentionally matches the rest of the theme:
 *   - Cream paper background (gold-bg) — same warm tone as the page
 *   - Round gold icon badge on the leading edge — echoes the ✓ check
 *     that appears on the login role tiles when selected
 *   - No hard border — soft warm shadow defines the bubble
 *   - Close button is a soft cream chip with an SVG ✕ stroke,
 *     not a Unicode character
 *
 * Status colors via .toast.status-{success|error|warning|info}.
 * showToast() auto-detects from the leading emoji of the message.
 * ============================================================ */
.toast {
    position: fixed !important;
    top: 24px !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -120%) !important;
    background: var(--gold-bg) !important;
    color: var(--dark-primary) !important;
    padding: 10px 14px 10px 10px !important;
    border-radius: 100px !important;
    border: 0 !important;
    font-weight: 700 !important;
    font-size: 0.92rem !important;
    z-index: 3000 !important;
    box-shadow:
        0 18px 40px rgba(180, 83, 9, 0.18),
        0 6px 14px rgba(31, 41, 55, 0.10) !important;
    transition: transform 0.5s var(--ease-out), opacity 0.35s var(--ease-out) !important;
    opacity: 0 !important;
    display: flex !important;
    flex-direction: row-reverse !important; /* RTL: icon visual right, close left */
    align-items: center !important;
    gap: 10px !important;
    line-height: 1.5 !important;
    text-align: right !important;
    max-width: min(440px, calc(100vw - 24px)) !important;
    min-width: 240px !important;
    pointer-events: auto;
}
.toast.visible {
    transform: translate(-50%, 0) !important;
    opacity: 1 !important;
}

/* The circular icon badge — echoes login.html's role-tile check mark.
   Default color is gold; status modifiers override it. */
.toast::before {
    content: '';
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gold-primary) center / 18px 18px no-repeat;
    box-shadow: 0 2px 6px rgba(180, 83, 9, 0.3);
    /* Default icon: filled circle with white check */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
}

.toast-msg {
    flex: 1 1 auto;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: var(--dark-primary);
    padding: 2px 4px;
}

/* Close button — soft chip, not a flat gray circle. SVG ✕ inside. */
.toast-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(180, 83, 9, 0.08);
    color: var(--gold-deep);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 0;
    padding: 0;
    transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out), transform 0.15s var(--ease-out);
}
.toast-close:hover {
    background: var(--gold-primary);
    color: var(--white);
    transform: rotate(90deg);
}
.toast-close svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
    stroke-linecap: round;
}

/* ---- Status color variants ----
   Each variant changes (a) the icon-badge background, (b) the bubble tint,
   and (c) sets the inline SVG icon. */

/* Success (default already gold) */
.toast.status-success::before {
    background-color: var(--green-primary);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.35);
}
.toast.status-success {
    background: var(--green-light) !important;
    box-shadow: 0 18px 40px rgba(6, 95, 70, 0.18), 0 6px 14px rgba(31, 41, 55, 0.10) !important;
}
.toast.status-success .toast-close { background: rgba(6, 95, 70, 0.10); color: var(--green-dark); }
.toast.status-success .toast-close:hover { background: var(--green-primary); color: var(--white); }

.toast.status-error::before {
    background-color: var(--red-primary);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><line x1='18' y1='6' x2='6' y2='18'/><line x1='6' y1='6' x2='18' y2='18'/></svg>");
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.35);
}
.toast.status-error {
    background: var(--red-light) !important;
    box-shadow: 0 18px 40px rgba(127, 29, 29, 0.18), 0 6px 14px rgba(31, 41, 55, 0.10) !important;
}
.toast.status-error .toast-close { background: rgba(127, 29, 29, 0.10); color: var(--red-primary); }
.toast.status-error .toast-close:hover { background: var(--red-primary); color: var(--white); }

.toast.status-warning::before {
    background-color: #f59e0b;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><line x1='12' y1='9' x2='12' y2='13'/><line x1='12' y1='17' x2='12.01' y2='17'/></svg>");
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.35);
}

.toast.status-info::before {
    background-color: var(--blue-primary);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><line x1='12' y1='8' x2='12' y2='8'/><line x1='12' y1='12' x2='12' y2='16'/></svg>");
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.35);
}
.toast.status-info {
    background: var(--blue-light) !important;
    box-shadow: 0 18px 40px rgba(30, 64, 175, 0.18), 0 6px 14px rgba(31, 41, 55, 0.10) !important;
}
.toast.status-info .toast-close { background: rgba(30, 64, 175, 0.10); color: var(--blue-primary); }
.toast.status-info .toast-close:hover { background: var(--blue-primary); color: var(--white); }

@media (max-width: 640px) {
    .toast {
        top: 14px !important;
        /* Stretch close to the viewport edges so messages fit on one line.
           Leave 8px breathing room each side. */
        max-width: calc(100vw - 16px) !important;
        width: calc(100vw - 16px) !important;
        min-width: 0 !important;
        font-size: 0.95rem !important;
        padding: 10px 14px 10px 10px !important;
        gap: 10px !important;
        border-radius: 100px !important;
    }
    .toast::before {
        width: 38px;
        height: 38px;
        background-size: 22px 22px;
    }
    .toast-close {
        width: 40px;
        height: 40px;
    }
    .toast-close svg {
        width: 18px;
        height: 18px;
        stroke-width: 2.6;
    }
    .toast-msg {
        font-weight: 700;
        line-height: 1.45;
        padding: 0 2px;
        /* Default Persian wraps at word boundaries; this allows a single
           long token (like a URL) to break instead of forcing a wrap of
           the whole line. */
        word-break: break-word;
    }
}

/* Very narrow phones (iPhone SE / older Androids) — keep readable but allow
   a slightly more compact layout if the message is long. */
@media (max-width: 380px) {
    .toast {
        font-size: 0.92rem !important;
        padding: 9px 12px 9px 9px !important;
        gap: 9px !important;
    }
    .toast::before {
        width: 36px;
        height: 36px;
        background-size: 20px 20px;
    }
    .toast-close {
        width: 38px;
        height: 38px;
    }
}

/* ============================================================
 * Modal — scroll behavior fix
 *
 * When a .modal-overlay opens, app.js adds .modal-open to <body>
 * which locks page scrolling. The .modal element itself becomes
 * the scroll container so long forms (edit-product, edit-coupon)
 * scroll independently of the page behind them.
 *
 * !important is used to override per-template inline rules.
 * ============================================================ */
body.modal-open {
    overflow: hidden !important;
    /* Don't let the iOS rubber-band scroll fall through */
    touch-action: none;
}
.modal-overlay {
    /* Center the modal vertically + add safe-area padding so it doesn't
       hug the viewport edges on phones. */
    align-items: flex-start !important;
    padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}
.modal-overlay.active {
    /* Help iOS Safari realize the overlay is the scroll context */
    overscroll-behavior: contain;
}
.modal-overlay .modal {
    /* The modal box itself doesn't need to scroll — let the overlay scroll
       and the modal will move within it. But cap the height so on a tiny
       viewport the modal still fits with its safe-area padding. */
    max-height: none !important;
    width: 100%;
    margin: auto !important;
}
@media (max-width: 640px) {
    .modal-overlay {
        padding: 12px !important;
        align-items: flex-start !important;
    }
    .modal-overlay .modal {
        border-radius: 16px !important;
    }
}

/* ============================================================
 * Pagination component (used by seller and buyer panels)
 * ============================================================ */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    justify-content: center;
    align-items: center;
    margin: var(--sp-6) 0 var(--sp-2);
}
.pg-btn {
    min-width: 40px;
    height: 40px;
    padding: 0 var(--sp-3);
    border-radius: var(--radius-sm);
    background: var(--white);
    border: 1px solid var(--gray-200);
    color: var(--dark-primary);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s var(--ease-out);
    font-variant-numeric: tabular-nums;
}
.pg-btn:hover:not(:disabled) {
    background: var(--gold-bg);
    border-color: var(--gold-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.pg-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.pg-btn.active {
    background: var(--gold-primary);
    border-color: var(--gold-primary);
    color: var(--white);
    box-shadow: var(--shadow-gold);
}
.pg-dots {
    color: var(--dark-muted);
    padding: 0 var(--sp-1);
    user-select: none;
}

/* ============================================================
 * Mobile responsive layer
 * Targets common breakage points across templates without
 * requiring per-page rewrites.
 * ============================================================ */
@media (max-width: 640px) {
    /* Tap targets — Apple/Material both want >= 44px */
    button, .btn, .hbtn, .pc-link, .dl-btn, .pg-btn,
    .submit-btn, .coupon-btn, .pc-link-copy, .pc-link-coupon {
        min-height: 44px;
    }

    /* Headings shrink on small screens */
    h1 { font-size: 1.6rem !important; line-height: 1.3 !important; }
    h2 { font-size: 1.3rem !important; line-height: 1.35 !important; }
    h3 { font-size: 1.1rem !important; line-height: 1.4 !important; }

    /* Generic page padding */
    .container, .panel, .card, .product-card, .order-card,
    .purchase-card, .blog-card {
        padding-inline: var(--sp-4) !important;
    }

    /* Tables and code blocks become horizontally scrollable */
    table { display: block; overflow-x: auto; max-width: 100%; }
    pre, code { white-space: pre-wrap; word-break: break-word; }

    /* Forms — full width inputs & 16px font to prevent iOS auto-zoom */
    input[type="text"], input[type="number"], input[type="tel"],
    input[type="email"], input[type="password"], textarea, select {
        width: 100% !important;
        font-size: 16px !important;
    }

    /* Tab bars wrap and scroll horizontally instead of cramping */
    .tabs, .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar, .nav-tabs::-webkit-scrollbar { display: none; }
    .tab { white-space: nowrap; }

    /* Card grids collapse to single column */
    .product-grid, .blog-grid, .grid-2, .grid-3 {
        grid-template-columns: 1fr !important;
    }

    /* Pagination buttons get a touch-friendly size */
    .pg-btn { min-width: 44px; height: 44px; }
}

/* Even-narrower phones (e.g. iPhone SE) */
@media (max-width: 380px) {
    .container, .panel, .card { padding-inline: var(--sp-3) !important; }
    h1 { font-size: 1.4rem !important; }
    .pg-btn { min-width: 40px; height: 40px; font-size: 0.85rem; }
}

/* Reduced motion — respect the user's OS setting */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
