/* 1. Import Persian Font (Vazirmatn) */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');

/* 2. Global Variables & Reset */
:root {
    --primary-dark: #002223;   /* Deepest Teal (Backgrounds) */
    --secondary-dark: #003738; /* Lighter Teal (Buttons/Accents) */
    --cream-bg: #FFFAF0;       /* Cream (Body Background/Text) */
    --text-color: #333333;
    --white: #FFFFFF;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden; /* Forces the browser to cut off anything sticking out */
    width: 100%;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--cream-bg);
    font-family: 'Vazirmatn', sans-serif; /* Persian Font */
    direction: rtl; /* Crucial for Persian layout */
    color: var(--primary-dark);
    font-feature-settings: "ss01";
}

/* ==========================================================================
   GLOBAL PAGE PRELOADER 
   ========================================================================== */
.preloader {
    position: fixed;
    inset: 0;
    background-color: var(--cream-bg); /* Seamlessly matches your background style */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999999; /* Higher than nav (1000) and message container (5000) */
    opacity: 1;
    visibility: visible;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

/* Fades out elegantly when JavaScript triggers */
.preloader.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* Modern infinite spinning loader wheels */
.loader-spinner {
    width: 55px;
    height: 55px;
    border: 5px solid rgba(0, 34, 35, 0.08); /* Faint track line */
    border-top: 5px solid var(--secondary-dark); /* Bold accent color for spinner head */
    border-radius: 50%;
    animation: spinLoader 1s linear infinite;
}

@keyframes spinLoader {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* --- Sidebar Container Adjustments --- */
.sidebar-menu {
    position: fixed;
    top: 90px;
    left: -320px; /* Slightly further out to be safe */
    width: 280px;
    height: calc(100vh - 90px);
    background-color: #002223;
    z-index: 10000; /* Sidebar must be HIGHER than overlay (2500) */
    transition: left 0.4s ease;
    display: flex;
    flex-direction: column;
}

/* Ensure this class is exactly what JS is adding */
.sidebar-menu.active {
    left: 0 !important; /* !important helps override any conflicts */
}

.sidebar-links-container {
    padding-top: 40px; /* Moves the first link ("Dashboard") down slightly */
    padding-right: 15px;
    padding-left: 15px;
}

.sidebar-links-container ul {
    list-style: none;
    padding: 0;
}

.sidebar-links-container li {
    margin-bottom: 8px; /* Spacing between buttons */
}

/* --- The Link Style (Matching Reference) --- */
.sidebar-links-container li a {
    display: block;
    padding: 12px 20px;
    color: #FFFAF0; /* Cream text */
    text-decoration: none;
    font-size: 1rem;
    font-weight: 400;
    border-radius: 8px;
    transition: all 0.2s ease-in-out;
    opacity: 0.9;
}

/* Hover State */
.sidebar-links-container li a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    opacity: 1;
}

/* --- The "Active" State from the Image --- */
.sidebar-links-container li a.active {
    background-color: #003738; /* Slightly lighter teal highlight */
    color: #ffffff;
    font-weight: 500;
    opacity: 1;
    /* Optional: subtle border if you want more definition */
    border-right: 4px solid #a8d5d6; 
}

/* --- Logout Button Styling --- */
.drawer-footer {
    margin-top: auto;
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.logout-btn {
    width: 100%;
    background: transparent;
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: 0.3s;
}

.logout-btn:hover {
    background: #ff6b6b;
    color: white;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    display: none;
    z-index: 2500; /* Overlay should be LOWER than sidebar */
}

.menu-overlay.show {
    display: block;
}

/* 3. Navigation Bar Container */
nav {
    background-color: var(--primary-dark);
    display: flex;
    justify-content: space-between; /* Spreads Logo, Menu, and User apart */
    align-items: center;
    padding: 0 2rem; /* Horizontal padding */
    height: 90px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: sticky; /* Keeps nav at top when scrolling */
    top: 0;
    z-index: 1000;
}

/* 4. Logo Section */
.logo img {
    /* Overriding HTML attributes for better control */
    height: 60px; 
    width: auto;
    object-fit: contain;
    /* Optional: If your logo is black, this makes it cream to match the theme. 
       Remove if your logo is already light colored. */
    /* filter: brightness(0) saturate(100%) invert(98%) sepia(3%) saturate(1090%) hue-rotate(307deg) brightness(107%) contrast(101%); */
}

/* 5. Menu Items */
.items {
    display: flex;
    gap: 30px; /* Space between links */
}

.items a {
    text-decoration: none;
    color: var(--cream-bg);
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
}

/* Hover Effect for Links */
.items a:hover {
    color: #a8d5d6; /* A slight teal tint on hover */
}

.items a::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: -5px;
    right: 0;
    background-color: var(--cream-bg);
    transition: width 0.3s;
}

.items a:hover::after {
    width: 100%;
}

/* 6. User & Basket Section */
.user {
    display: flex;
    align-items: center; 
    gap: 20px;           
}

.basket {
    display: flex;
    align-items: center;
}

/* 1. FIXED: Added position: relative here */
.cart-wrapper {
    position: relative; /* This is the anchor for the badge */
    display: flex;
    align-items: center;
    line-height: 1; 
    text-decoration: none;
}

/* 2. Numeric badge styling (Remains mostly same, but ensures it stays on top) */
.cart-badge {
    position: absolute;
    top: -10px;         /* Adjusted slightly for better look with flex */
    right: -10px;       
    background-color: #e63946; 
    color: white;
    font-size: 11px;
    font-weight: bold;
    width: 18px;
    height: 18px;
    border-radius: 50%; 
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;        /* Ensures it stays above the icon */
}

/* 3. Icons (Preserved your cream filter and hover effects) */
.basket img, 
.person-btn img {
    display: block;
    width: 24px;
    height: 24px;
    cursor: pointer;
    filter: brightness(0) saturate(100%) invert(98%) sepia(3%) saturate(1090%) hue-rotate(307deg) brightness(107%) contrast(101%);
    transition: transform 0.2s ease;
}

.basket img:hover {
    transform: scale(1.1);
}

/* 4. Person Button (Preserved your styling) */
.user {
    margin-right: auto; /* IMPORTANT: Forces icons to the far LEFT in RTL */
    display: flex;
    align-items: center;
    gap: 20px;
}

.person-btn {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--secondary-dark);
    padding: 6px 18px; /* Slightly slimmer height */
    border-radius: 10px; /* Pill Shape */
    border: 1px solid rgba(255, 255, 250, 0.1);
    transition: all 0.3s ease;
}

.person-btn:hover {
    background-color: #004d4f;
    transform: translateY(-1px);
}

.user-label {
    color: var(--cream-bg);
    font-size: 0.85rem;
    font-weight: 700;
}

.person-btn:hover {
    background-color: #004d4f; /* Lighter on hover */
}

.person-btn a {
    text-decoration: none;
    color: var(--cream-bg);
    font-size: 0.9rem;
    font-weight: 700;
}

.hamburger {
    display: none;
    cursor: pointer;
    flex-direction: column;
    gap: 5px;
}

.hamburger .bar {
    width: 25px;
    height: 3px;
    background-color: var(--cream-bg);
    border-radius: 5px;
    transition: all 0.3s ease;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    nav {
        display: flex;
        flex-direction: row; /* Keep them in a row */
        justify-content: space-between;
        align-items: center;
        padding: 0 15px;
    }

    /* Logo stays on the right (Order 1) */
    .logo {
        order: 1;
    }

    /* User (Basket/Login) in the middle (Order 2) */
    .user {
        order: 2;
        margin-right: auto; /* Pushes the user section toward the hamburger */
        margin-left: 15px;  /* Space between login and hamburger */
    }

    /* Hamburger on the far left (Order 3) */
    .hamburger {
        display: flex;
        order: 3;
    }

    /* Ensure the menu list still works correctly */
    .items {
        position: fixed;
        right: -100%;
        top: 90px;
        width: 100%;
        height: calc(100vh - 90px);
        background-color: var(--primary-dark);
        display: flex;
        flex-direction: column;
        z-index: 1000;
        transition: 0.3s;
        text-align: center;
        padding-top: 20px;
    }

    .items.active {
        right: 0;
    }

    /* Adjust nav layout for mobile */
    nav {
        padding: 0 1rem;
        justify-content: space-between;
    }

    /* Hamburger Animation (Turn into X) */
    .hamburger.active .bar:nth-child(2) {
        opacity: 0;
    }
    .hamburger.active .bar:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }
    .hamburger.active .bar:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }
}

/* Base style for all alerts */
/* Update your existing .messages-container styles */
.messages-container {
    position: fixed;
    top: 100px; /* Sits just below your 90px navbar */
    left: 50%;
    transform: translateX(-50%);
    z-index: 5000; /* Stays above everything */
    width: 90%;
    max-width: 400px;
    pointer-events: none; /* Allows clicking through the container */
}

.alert {
    pointer-events: auto; /* Re-enable clicking for the alert itself */
    padding: 15px 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    animation: slideDown 0.5s ease forwards;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Green Styling for SUCCESS */
.alert.success {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

/* Red Styling for ERROR / DANGER */
.alert.error, .alert.danger {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

/* Optional: Yellow for WARNING */
.alert.warning {
    background-color: #fff3cd;
    color: #856404;
    border-color: #ffeeba;
}

/* Optional: Blue for INFO */
.alert.info {
    background-color: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
}

/* Footer Section */

footer {
    background-color: var(--primary-dark);
    color: var(--cream-bg);
    padding: 60px 5% 20px 5%;
    direction: rtl;
    margin-top: 50px;
}

.footer-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 30px;
}

.footer-section {
    flex: 1;
    min-width: 200px;
}

/* Logo Section */
.f-logo img {
    max-width: 150px;
    margin-bottom: 20px;
}

.f-services{
    margin-right: 80px;
}

/* Titles */
.footer-section .title {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 20px;
    color: var(--cream-bg);
    position: relative;
    padding-bottom: 10px;
}

.footer-section .title::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 40px;
    height: 2px;
    background-color: var(--secondary-dark);
}

/* Services Links */
.f-items {
    list-style: none;
    padding: 0;
}

.f-items li {
    margin-bottom: 10px;
}

.f-items a {
    color: var(--cream-bg);
    text-decoration: none;
    font-size: 0.9rem;
    transition: 0.3s;
    opacity: 0.8;
}

.f-items a:hover {
    opacity: 1;
    padding-right: 5px;
    color: var(--white);
}

/* About Us & Contact */
.about-us p, .contact-us p {
    font-size: 0.9rem;
    line-height: 1.8;
    opacity: 0.8;
}

.contact-us span {
    font-weight: bold;
    color: var(--white);
}

/* Socials & Email */
.social-links {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.social-links img {
    width: 30px;
    height: 30px;
    transition: transform 0.3s;
    filter: brightness(0) invert(1);
}

.social-links a:hover img {
    transform: translateY(-5px);
}

.email {
    display: flex;
    align-items: center;
    gap: 10px;
}

.email img {
    width: 20px;
    filter: brightness(0) invert(1);
}

.email a {
    color: var(--cream-bg);
    text-decoration: none;
    font-size: 0.9rem;
}

/* Copyright */
.copyright {
    text-align: center;
    margin-top: 50px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 250, 240, 0.1);
    font-size: 0.8rem;
    opacity: 0.6;
}

/* --- Responsive Footer --- */
@media (max-width: 992px) {
    .footer-section {
        flex: 1 1 45%; /* 2 columns on tablets */
    }
}

@media (max-width: 600px) {
    .footer-container {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .footer-section {
        width: 100%;
    }

    .footer-section .title::after {
        right: 50%;
        transform: translateX(50%); /* Centers the underline on mobile */
    }

    .f-services{
        margin-right: 0px;
    }

    .social-links {
        justify-content: center;
    }

    .email {
        justify-content: center;
    }
}