/* =====================================================
   Storefront Design System
   The single source of truth for tokens, typography and
   spacing. Mirrors admin/css/admin.css so the shop and the
   dashboard read as one product.

   Load order: style.css  ->  theme.css  ->  (page <style>)  ->  responsive.css
   See DESIGN-SPEC.md
   ===================================================== */

:root {
    /* === Brand: orange === */
    --primary:          #f97316;
    --primary-dark:     #ea580c;
    --primary-darker:   #c2410c;
    --primary-light:    #fb923c;
    --primary-lighter:  #fff7ed;
    --primary-50:       #fff7ed;   /* legacy alias */
    --primary-100:      #ffedd5;
    --primary-gradient: linear-gradient(135deg, #f97316 0%, #ea580c 100%);

    /* === Neutrals: black theme === */
    --gray-900: #111827;
    --gray-800: #1f2937;
    --gray-700: #374151;
    --gray-600: #4b5563;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --gray-50:  #f9fafb;
    --white:    #ffffff;
    --black:    #000000;

    --secondary:      #1f2937;
    --secondary-dark: #111827;
    --accent:         #f97316;
    --accent-dark:    #ea580c;
    --dark-gradient:  linear-gradient(135deg, #1f2937 0%, #111827 100%);

    /* === Status === */
    --success: #10b981; --success-light: #d1fae5; --success-dark: #065f46;
    --danger:  #ef4444; --danger-light:  #fee2e2; --danger-dark:  #991b1b;
    --warning: #f59e0b; --warning-light: #fef3c7; --warning-dark: #92400e;
    --info:    #06b6d4; --info-light:    #cffafe; --info-dark:    #0e7490;

    /* === Radius === */
    --radius-sm:   6px;
    --radius:      10px;
    --radius-lg:   14px;
    --radius-xl:   20px;
    --radius-full: 9999px;

    /* === Shadows === */
    --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow:    0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.04);
    --shadow-md: 0 8px 16px -4px rgba(0,0,0,.10);
    --shadow-lg: 0 16px 32px -8px rgba(0,0,0,.12);
    --shadow-xl: 0 24px 48px -12px rgba(0,0,0,.18);
    --shadow-primary: 0 4px 12px rgba(249,115,22,.30);

    /* === Transitions === */
    --transition-fast: 150ms ease;
    --transition:      200ms ease;
    --transition-slow: 300ms ease;

    /* === Type scale === */
    --fs-xs:   11px;
    --fs-sm:   12px;
    --fs-base: 14px;
    --fs-md:   15px;
    --fs-lg:   17px;
    --fs-xl:   20px;
    --fs-2xl:  24px;
    --fs-3xl:  30px;

    /* === Spacing === */
    --sp-1:  4px;
    --sp-2:  8px;
    --sp-3:  12px;
    --sp-4:  16px;
    --sp-5:  20px;
    --sp-6:  24px;
    --sp-8:  32px;
    --sp-10: 40px;

    --section-spacing: 36px;
    --card-pad:        18px;
    --grid-gap:        16px;

    --container-max: 1320px;
    --container-pad: 16px;
}

/* =====================================================
   Global guards — nothing may exceed the viewport
   ===================================================== */

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Flex/grid children default to min-width:auto, which is the single most
   common cause of horizontal overflow. Reset it globally. */
*, *::before, *::after {
    min-width: 0;
}

img, video, canvas, svg, iframe, embed, object {
    max-width: 100%;
}

img, video {
    height: auto;
}

/* =====================================================
   Base typography
   ===================================================== */

body {
    font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: var(--fs-md);          /* 15px — was 19px */
    line-height: 1.65;
    color: var(--gray-700);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
    font-family: inherit;
    font-weight: 700;
    line-height: 1.3;
    color: var(--gray-900);
}

h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
h5 { font-size: var(--fs-md); }
h6 { font-size: var(--fs-base); }

p  { line-height: 1.7; }

small, .text-sm { font-size: var(--fs-sm); }
.text-xs        { font-size: var(--fs-xs); }
.text-muted     { color: var(--gray-500); }

/* Prices and figures line up in columns */
.price, .product-price, .amount, .total, td.num, .stat-card .info h3 {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

/* Arabic labels and long identifiers must never blow out a container */
.order-number, .sku, .tracking-code, .coupon-code,
code, kbd, samp, .break-any {
    overflow-wrap: anywhere;
    word-break: break-word;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: var(--fs-base);
}

/* =====================================================
   Layout
   ===================================================== */

.container {
    width: 100%;
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--container-pad);
}

.section,
section.section {
    padding-block: var(--section-spacing);
}

/* Section heading — orange rule under a dark title, matching the
   dashboard's card headers. */
.section-title,
.section-header h2 {
    font-size: var(--fs-2xl);
    font-weight: 800;
    color: var(--gray-900);
    line-height: 1.3;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
    flex-wrap: wrap;
}

/* =====================================================
   Components — matched to admin/css/admin.css
   ===================================================== */

.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--sp-5);
    overflow: hidden;
}

.card-header {
    padding: 14px var(--card-pad);
    background: linear-gradient(135deg, #1f2937, #374151);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.card-header h3,
.card-header h2 {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--white);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin: 0;
}

.card-header i { color: var(--primary); }

.card-body   { padding: var(--card-pad); }
.card-footer {
    padding: var(--sp-3) var(--card-pad);
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 10px 18px;
    min-height: 40px;
    font-size: var(--fs-base);
    font-weight: 600;
    font-family: inherit;
    line-height: 1.2;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }

.btn-primary   { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-primary); }

.btn-secondary { background: var(--gray-800); color: var(--white); }
.btn-secondary:hover { background: var(--gray-900); }

.btn-success { background: var(--success); color: var(--white); }
.btn-danger  { background: var(--danger);  color: var(--white); }
.btn-warning { background: var(--warning); color: var(--gray-900); }
.btn-info    { background: var(--info);    color: var(--white); }

.btn-light {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}
.btn-light:hover { background: var(--gray-200); }

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: var(--white); }

.btn-sm    { padding: 7px 13px; min-height: 34px; font-size: var(--fs-sm); }
.btn-lg    { padding: 13px 26px; min-height: 48px; font-size: var(--fs-md); }
.btn-block { width: 100%; }

/* --- Forms --- */
.form-group { margin-bottom: var(--sp-4); }

.form-group label,
.form-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control,
input[type="text"].form-control,
input[type="email"].form-control,
input[type="password"].form-control,
input[type="tel"].form-control,
input[type="number"].form-control,
select.form-control,
textarea.form-control {
    width: 100%;
    padding: 11px 14px;
    font-size: var(--fs-base);
    font-family: inherit;
    color: var(--gray-800);
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}

.form-control::placeholder { color: var(--gray-400); }

textarea.form-control { min-height: 110px; resize: vertical; }
select.form-control   { cursor: pointer; }

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 3px 9px;
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 1.5;
    border-radius: var(--radius-full);
}

.badge-primary   { background: var(--primary-lighter); color: var(--primary-dark); }
.badge-success   { background: var(--success-light);   color: var(--success-dark); }
.badge-danger    { background: var(--danger-light);    color: var(--danger-dark); }
.badge-warning   { background: var(--warning-light);   color: var(--warning-dark); }
.badge-info      { background: var(--info-light);      color: var(--info-dark); }
.badge-secondary { background: var(--gray-200);        color: var(--gray-600); }

/* --- Alerts --- */
.alert {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 12px 16px;
    margin-bottom: var(--sp-4);
    font-size: var(--fs-base);
    font-weight: 500;
    border-radius: var(--radius);
}

.alert-success { background: var(--success-light); color: var(--success-dark); }
.alert-danger,
.alert-error   { background: var(--danger-light);  color: var(--danger-dark); }
.alert-warning { background: var(--warning-light); color: var(--warning-dark); }
.alert-info    { background: var(--info-light);    color: var(--info-dark); }

/* --- Tables --- */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-base);
}

.table th,
.table td {
    padding: 12px 14px;
    text-align: start;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    background: var(--gray-50);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}

.table tbody tr { transition: var(--transition); }
.table tbody tr:hover { background: var(--gray-50); }

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: var(--sp-10) var(--sp-5);
}
/* Direct child only: as a descendant selector this also caught the icon inside
   the empty state's own call-to-action button and blew it up to 48px. */
.empty-state > i { font-size: 48px; color: var(--gray-300); margin-bottom: var(--sp-4); }
.empty-state .btn i { font-size: inherit; color: inherit; margin-bottom: 0; }
.empty-state h4 { font-size: var(--fs-lg); color: var(--gray-700); margin-bottom: 6px; }
.empty-state p  { color: var(--gray-500); margin-bottom: var(--sp-4); }

/* --- Pagination --- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: var(--sp-6);
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    font-size: var(--fs-base);
    font-weight: 500;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    transition: var(--transition);
}

.pagination a:hover {
    background: var(--primary-lighter);
    border-color: var(--primary);
    color: var(--primary);
}

.pagination .active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

/* =====================================================
   Grids — sparse data must still look intentional
   ===================================================== */

/* auto-fit (not auto-fill) collapses the empty tracks, and the max side of
   minmax() stops two lonely cards from stretching to half the page.
   `justify-content: start` is deliberate: in RTL that is the right edge, so a
   half-empty row still lines its first card up under the section heading.
   Centring the row instead leaves the cards floating out of alignment with
   the title above them. */
.products-grid,
.categories-grid,
.brands-grid,
.vendors-grid,
.blog-grid {
    display: grid;
    gap: var(--grid-gap);
    justify-content: start;
    align-items: stretch;
}

.products-grid  { grid-template-columns: repeat(auto-fit, minmax(220px, 290px)); }
.categories-grid{ grid-template-columns: repeat(auto-fit, minmax(165px, 230px)); }
.brands-grid    { grid-template-columns: repeat(auto-fit, minmax(140px, 190px)); }
.vendors-grid   { grid-template-columns: repeat(auto-fit, minmax(230px, 320px)); }
.blog-grid      { grid-template-columns: repeat(auto-fit, minmax(270px, 380px)); }

/* =====================================================
   Product card — one tile, everywhere
   ===================================================== */

.product-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
}

.product-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
}

.product-card .product-image {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--gray-50);
    overflow: hidden;
}

.product-card .product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: var(--sp-2);
    transition: var(--transition-slow);
}

.product-card:hover .product-image img { transform: scale(1.04); }

.product-card .product-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 6px;
    padding: var(--sp-3);
}

.product-card .product-title,
.product-card .product-info h3 {
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.45;
    color: var(--gray-900);
    /* two-line clamp keeps every tile the same height */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(1.45em * 2);
}

.product-card .product-category {
    font-size: var(--fs-xs);
    color: var(--gray-500);
}

.product-card .product-price {
    font-size: var(--fs-lg);
    font-weight: 800;
    color: var(--primary);
}

.product-card .product-price .old-price,
.product-card .old-price {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--gray-400);
    text-decoration: line-through;
    margin-inline-start: 6px;
}

/* Push the CTA to the bottom so every card lines up */
.product-card .btn,
.product-card .add-to-cart {
    margin-top: auto;
}

.product-card .product-badges {
    position: absolute;
    top: var(--sp-2);
    inset-inline-start: var(--sp-2);
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    z-index: 2;
}

.product-badge {
    padding: 3px 9px;
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--white);
    border-radius: var(--radius-full);
}

.badge-sale { background: var(--danger); }
.badge-new  { background: var(--success); }
.badge-hot  { background: var(--primary); }

/* =====================================================
   Utilities
   ===================================================== */

.flex-start   { justify-content: flex-start !important; }
.stack-tight  > * + * { margin-top: var(--sp-2); }
.no-scroll    { overflow: hidden !important; }
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Horizontal scroller for thumbnail strips, chips, filter pills */
.scroll-x {
    display: flex;
    gap: var(--sp-2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: var(--sp-1);
}
.scroll-x > * { flex: 0 0 auto; }

/* =====================================================
   Responsive typography + spacing
   (layout-level responsive rules live in css/responsive.css,
    which loads after the page <style> blocks)
   ===================================================== */

@media (max-width: 1200px) {
    :root { --container-max: 1140px; }
}

@media (max-width: 992px) {
    :root {
        --section-spacing: 30px;
        --card-pad: 16px;
        --grid-gap: 14px;
    }
    h1 { font-size: 26px; }
    h2 { font-size: 22px; }
}

@media (max-width: 768px) {
    :root {
        --section-spacing: 24px;
        --card-pad: 14px;
        --grid-gap: 12px;
        --container-pad: 14px;
    }

    body { font-size: var(--fs-base); line-height: 1.6; }

    h1 { font-size: var(--fs-2xl); }
    h2 { font-size: var(--fs-xl); }
    h3 { font-size: var(--fs-lg); }

    .section-title,
    .section-header h2 { font-size: var(--fs-xl); }

    /* Tap targets */
    .btn { min-height: 42px; }
    .btn-sm { min-height: 38px; }

    .products-grid   { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .categories-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
    .blog-grid,
    .vendors-grid    { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    :root { --container-pad: 12px; --grid-gap: 10px; }

    /* Two columns of products, never one — a single-column product
       list reads as a broken page on a phone. */
    .products-grid   { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .categories-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

    .product-card .product-info { padding: var(--sp-2); }
    .product-card .product-title { font-size: var(--fs-sm); }
    .product-card .product-price { font-size: var(--fs-md); }
}

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