/* ============================================
   HOME / BASE LAYOUT
   Global resets, body, container, main,
   sections, pagination, dev banner,
   dark theme globals, RTL globals, 
   performance optimizations
   ============================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---- Prevent Horizontal Scroll & iOS Zoom ---- */
html, body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: none) and (pointer: coarse) {
    html, body {
        touch-action: pan-y;
        overscroll-behavior: none;
        overscroll-behavior-x: none;
        overscroll-behavior-y: none;
    }
}

@media (max-width: 768px) {
    html, body {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    html::-webkit-scrollbar,
    body::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
}

@media (hover: none) and (pointer: coarse) {
    * {
        touch-action: manipulation;
    }
}

@media (hover: none) and (pointer: coarse) {
    body {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
}

input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ---- HTML & Body ---- */
html {
    overflow-x: hidden;
    width: 100%;
    min-height: 100%;
    background-color: var(--primary-color);
    font-family: 'Lexend', -apple-system, BlinkMacSystemFont, sans-serif !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

@media (hover: none) and (pointer: coarse) {
    html {
        overscroll-behavior-y: none;
    }
}

body {
    font-family: 'Lexend', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(180deg, #f8f8f8 0%, #efefef 50%, #e8e8e8 100%);
    background-attachment: fixed;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    padding-top: calc(65px + env(safe-area-inset-top));
    overflow-x: hidden;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

@media (hover: none) and (pointer: coarse) {
    body {
        overscroll-behavior-y: none;
    }
}

/* Subtle dot pattern overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, rgba(139, 0, 0, 0.03) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 0;
}

/* ---- Pull To Refresh (Mobile) ---- */
.pull-refresh-indicator {
    position: fixed;
    top: calc(6px + env(safe-area-inset-top));
    left: 50%;
    transform: translate(-50%, -60px);
    background: rgba(15, 15, 15, 0.92);
    color: #ffffff;
    border-radius: 16px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    line-height: 1.2;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    z-index: 120;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.pull-refresh-indicator.visible {
    opacity: 1;
}

.pull-refresh-indicator.ready {
    background: rgba(20, 20, 20, 0.96);
}

.pull-refresh-indicator.refreshing {
    background: rgba(12, 12, 12, 0.96);
}

.pull-refresh-spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: #d4af37;
    animation: pullRefreshSpin 1s linear infinite;
    opacity: 0.85;
}

.pull-refresh-indicator:not(.refreshing) .pull-refresh-spinner {
    animation: none;
    border-top-color: rgba(255, 255, 255, 0.65);
}

@keyframes pullRefreshSpin {
    to { transform: rotate(360deg); }
}

@media (min-width: 769px) {
    .pull-refresh-indicator {
        display: none;
    }
}

/* Make main content grow to push footer down */
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Container ---- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    box-sizing: border-box;
    text-align: left;
}

/* ---- Main ---- */
main {
    padding: 30px 0;
    padding-top: 15px;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    flex: 1;
    margin-bottom: 0;
    position: relative;
    z-index: 1;
}

/* ---- Headings ---- */
h2 {
    margin-bottom: 20px;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 22px;
    letter-spacing: 0.3px;
    position: relative;
    display: inline-block;
}

h2::after {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 50px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), #c9a227);
    border-radius: 2px;
}

/* ---- Development Banner ---- */
.dev-banner {
    background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
    color: #fff;
    text-align: center;
    padding: 8px 15px;
    font-size: 13px;
    font-weight: 500;
    position: relative;
    z-index: 1000;
}

.dev-banner-en,
.dev-banner-ar {
    display: inline;
}

.dev-banner-ar {
    margin-left: 15px;
    padding-left: 15px;
    border-left: 1px solid rgba(255,255,255,0.4);
    font-family: 'Lexend', sans-serif;
}

@media (max-width: 600px) {
    .dev-banner {
        font-size: 11px;
        padding: 6px 10px;
    }
    .dev-banner-ar {
        display: block;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        margin-top: 4px;
    }
}

/* ---- Plates Stats Bar ---- */
.plates-stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border-radius: 12px;
    margin-bottom: 16px;
    border: 1px solid #e9ecef;
    flex-wrap: wrap;
    gap: 10px;
}

.stats-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.plate-count-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #333;
    padding: 6px 12px;
    background: linear-gradient(135deg, var(--primary-color) 0%, #a01020 100%);
    border-radius: 20px;
    color: white;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.plate-count-badge:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(139, 0, 0, 0.3);
}

.plate-count-badge .plate-icon {
    font-size: 14px;
}

.plate-count-badge .plate-label {
    font-size: 11px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

#plate-count {
    font-weight: 700;
    color: #d4af37;
}

.showing-info {
    font-size: 13px;
    color: #666;
}

.stats-right {
    display: flex;
    align-items: center;
}

/* ---- Pagination Controls ---- */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    color: #333;
    font-size: 13px;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    font-size: 13px;
    color: #666;
    min-width: 50px;
    text-align: center;
}

/* Bottom Pagination */
.pagination-bottom {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 20px 0;
    margin-top: 20px;
    border-top: 1px solid #eee;
    flex-wrap: wrap;
}

.page-numbers {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
}

.page-number {
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    transition: all 0.2s ease;
}

.page-number:hover {
    background: #f5f5f5;
    border-color: var(--primary-color);
}

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

.page-number.ellipsis {
    border: none;
    cursor: default;
    background: transparent;
}

.page-number.ellipsis:hover {
    background: transparent;
}

body.rtl .pagination-controls,
body.rtl .pagination-bottom {
    flex-direction: row-reverse;
}

body.rtl .pagination-btn svg {
    transform: scaleX(-1);
}

@media (max-width: 600px) {
    .plates-stats-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .stats-left {
        justify-content: center;
    }
    
    .stats-right {
        justify-content: center;
    }
    
    .pagination-bottom {
        gap: 8px;
    }
    
    .pagination-btn span {
        display: none;
    }
    
    .pagination-btn {
        padding: 10px;
    }
}

/* ---- Sponsored Section ---- */
.sponsored-section {
    margin-top: 20px;
    margin-bottom: 30px;
    position: relative;
    z-index: 1;
}

.sponsored-section h2 {
    margin-top: 0;
    background: linear-gradient(90deg, var(--primary-color), #c41020, #d4af37);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer-vvip 3s ease-in-out infinite;
}

@keyframes shimmer-vvip {
    0%, 100% { background-position: 0% center; }
    50% { background-position: 100% center; }
}

.sponsored-section h2::after {
    background: linear-gradient(90deg, #c9a227, #e8c547, #c9a227);
    width: 60px;
    height: 3px;
}

/* ---- Section Box ---- */
.section-box {
    background: linear-gradient(180deg, #ffffff 0%, #fefefe 100%);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.02);
    margin-bottom: 30px;
    border: 1px solid rgba(0, 0, 0, 0.03);
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.all-plates-section.section-box {
    overflow: visible;
}

.section-box:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.03);
}

/* Section Divider */
.section-divider {
    width: 100%;
    height: 0;
    border-bottom: 1.5px solid var(--border-color);
    margin: 32px 0 24px 0;
    opacity: 0.7;
}

/* Messages */
.loading-message, .error-message, .no-results {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
    font-size: 16px;
    width: 100%;
    grid-column: 1 / -1;
}

.error-message {
    color: var(--primary-color);
}

.filtering {
    position: relative;
    overflow: hidden;
}

.filtering::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shine 1s ease;
}

@keyframes shine {
    to { left: 100%; }
}

/* ---- Mobile Layout Adjustments ---- */
@media (max-width: 768px) {
    .all-plates-section.section-box,
    .sponsored-section.section-box {
        margin-left: -20px;
        margin-right: -20px;
        width: calc(100% + 40px);
        border-radius: 24px 24px 0 0;
        padding-top: 28px;
        padding-bottom: 32px;
    }

    .sponsored-section.section-box {
        border-radius: 24px;
    }

    main {
        padding-bottom: 80px;
    }

    main.container {
        padding-bottom: 30px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 12px;
    }
    
    .section-box {
        padding: 20px 15px;
        border-radius: 12px;
    }
    
    .sponsored-plates {
        margin-left: 0;
        margin-right: 0;
        padding-left: 15px;
        padding-right: 15px;
    }
}

/* Responsive grid */
@media (max-width: 1200px) {
    .plates-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 992px) {
    .plates-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .plates-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
}

/* ---- SEO Content ---- */
.seo-content {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.seo-content h3, 
.seo-content h4, 
.seo-content p, 
.seo-content ul {
    margin: 0;
    padding: 0;
}

/* ---- Performance Optimizations ---- */
.plates-grid {
    contain: layout style;
    will-change: contents;
    will-change: scroll-position;
    backface-visibility: hidden;
    perspective: 1000;
}

.sponsored-plates {
    contain: layout;
    transform: translateZ(0);
}

/* Loading indicator */
#loading-indicator {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    margin: 10px auto;
    max-width: 300px;
    backdrop-filter: blur(5px);
}

/* Smooth batch loading */
.plate-card-batch {
    animation: batchFadeIn 0.5s ease-out;
}

@keyframes batchFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ---- Transitions ---- */
html, body {
    transition: background-color 0.3s ease;
}

.section-box, .site-footer {
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* ---- Dark Theme Global ---- */
html.dark-theme,
body.dark-theme {
    background-color: #000000 !important;
    background-image: linear-gradient(135deg, #260202 0%, #000000 100%) !important;
    color: #e0e0e0 !important;
}

body.dark-theme .container {
    background: transparent !important;
}

body.dark-theme main.container {
    background: transparent !important;
}

body.dark-theme .section-box {
    background: #2d2d2d !important;
    color: #e0e0e0 !important;
    border: 1px solid #404040 !important;
}

body.dark-theme .sponsored-section {
    background: #1a1a1a !important;
    border-color: rgba(255, 255, 255, 0.06) !important;
}

body.dark-theme .all-plates-section {
    background: #1a1a1a !important;
}

body.dark-theme .all-plates-section.section-box {
    background: #1a1a1a !important;
}

body.dark-theme .site-footer {
    background-color: #000000 !important;
    color: #e0e0e0 !important;
}

/* Card dark mode styles moved to cards/dark-mode.css */

body.dark-theme .filter-header h2,
body.dark-theme .sponsored-section h2,
body.dark-theme .all-plates-section h2 {
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
}

/* Dark mode pagination */
[data-theme="dark"] .plates-stats-bar {
    background: linear-gradient(135deg, #1a1a1a 0%, #222 100%);
    border-color: #333;
}

[data-theme="dark"] .showing-info {
    color: #aaa;
}

[data-theme="dark"] .pagination-btn {
    background: #222;
    border-color: #444;
    color: #ddd;
}

[data-theme="dark"] .pagination-btn:hover:not(:disabled) {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

[data-theme="dark"] .page-info {
    color: #aaa;
}

[data-theme="dark"] .pagination-bottom {
    border-top-color: #333;
}

[data-theme="dark"] .page-number {
    background: #222;
    border-color: #444;
    color: #ddd;
}

[data-theme="dark"] .page-number:hover {
    background: #333;
    border-color: var(--primary-color);
}

[data-theme="dark"] .page-number.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ---- RTL Global Layout ---- */
body.rtl {
    direction: ltr;
}

body.rtl .container {
    direction: ltr;
    text-align: left;
}

body.rtl .section-box {
    text-align: left;
}

/* RTL section headers */
body.rtl .sponsored-section h2,
body.rtl .filter-header h2,
body.rtl .all-plates-section h2 {
    text-align: right;
    margin-left: auto;
    margin-right: 0;
    display: block;
    width: fit-content;
    position: relative;
}

body.rtl .sponsored-section h2::after,
body.rtl .filter-header h2::after,
body.rtl .all-plates-section h2::after {
    right: 0 !important;
    left: auto !important;
    transform-origin: right center !important;
}

body.rtl .sponsored-section h2,
body.rtl .filter-header h2,
body.rtl .all-plates-section h2 {
    border-image-source: linear-gradient(to left, #8B0000, transparent) !important;
    border-image-slice: 1 !important;
}
