/* =============================================================================
   DUKAN ALHUJOOR - PROFESSIONAL THEME V2.0
   Re-designed for a cleaner, more professional, and user-friendly experience.
   ============================================================================= */

/* --- 1. FONTS & ROOT VARIABLES --- */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

:root {
    /* Color Palette */
    --primary-color: #007bff; /* A professional and trustworthy blue */
    --primary-dark: #0056b3;
    --secondary-color: #6c757d; /* A calm, neutral gray */
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    
    /* Typography */
    --font-family-base: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --text-primary: #212529; /* Dark gray for text, better than pure black */
    --text-secondary: #6c757d;
    --text-light: #f8f9fa;

    /* Background & Surfaces */
    --bg-body: #f8f9fa; /* Light gray background */
    --bg-surface: #ffffff; /* White for cards, headers, etc. */
    --border-color: #dee2e6;

    /* Sizing & Spacing */
    --border-radius: 0.5rem; /* Softer corners */
    --spacing-unit: 1rem;

    /* Shadows (Subtle and soft) */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: all 0.2s ease-in-out;
}

/* --- 2. DARK THEME VARIABLES --- */
[data-theme="dark"] {
    --primary-color: #3f9eff;
    --primary-dark: #69b4ff;
    --secondary-color: #8a939b;
    --success-color: #34c759;
    --error-color: #ff453a;
    --warning-color: #ffcc00;
    
    --text-primary: #e5e5e5;
    --text-secondary: #8a939b;

    --bg-body: #121212; /* A deep, rich black */
    --bg-surface: #1e1e1e; /* Elevated surfaces */
    --border-color: #3a3a3c;
    
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
}


/* --- 3. GLOBAL RESETS & BODY STYLES --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family-base);
    line-height: 1.7;
    color: var(--text-primary);
    background-color: var(--bg-body);
    min-height: 100vh;
    direction: rtl;
    text-align: right;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: calc(var(--spacing-unit) * 1.5);
}


/* --- 4. LAYOUT: HEADER & FOOTER --- */
header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-unit) calc(var(--spacing-unit) * 1.5);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color var(--transition-fast);
}

.logo-img {
    height: 36px;
}

footer {
    text-align: center;
    padding: calc(var(--spacing-unit) * 2);
    margin-top: calc(var(--spacing-unit) * 2);
    color: var(--text-secondary);
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}

.vision-banner {
    background-color: var(--primary-color);
    color: var(--text-light);
    padding: 0.75rem 0;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition-fast);
}

/* Dark theme adjustment */
[data-theme="dark"] .vision-banner {
    background-color: #1e1e1e; /* A dark surface color */
    border-bottom: 1px solid var(--border-color);
}

.vision-banner .container {
    padding-top: 0;
    padding-bottom: 0;
}

.vision-text {
    margin: 0;
    font-weight: 600;
    font-size: 0.95rem;
}

/* --- 5. COMPONENTS --- */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--text-light);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background-color: transparent;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-secondary:hover {
    background-color: var(--primary-color);
    color: var(--text-light);
}

/* Product Cards */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: calc(var(--spacing-unit) * 1.5);
    margin-top: var(--spacing-unit);
}

.product-card {
    background-color: var(--bg-surface);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: var(--transition-fast);
    display: flex;
    flex-direction: column;
    position: relative; /* For the condition badge */
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.product-image-container {
    width: 100%;
    height: 220px;
    background-color: #eee;
    overflow: hidden;
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.product-card:hover .product-image {
    transform: scale(1.05);
}

.product-info {
    padding: calc(var(--spacing-unit) * 1.25);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.product-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.product-price {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: var(--spacing-unit);
}

.product-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: auto; /* Pushes meta to the bottom */
}

/* NEW: Product Condition Badge */
.product-condition-badge {
    position: absolute;
    top: var(--spacing-unit);
    right: var(--spacing-unit);
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-light);
    border-radius: calc(var(--border-radius) / 2);
    z-index: 10;
}

.badge-new { background-color: var(--success-color); }
.badge-used { background-color: var(--warning-color); color: #333; }


/* Forms */
.form-card {
    background-color: var(--bg-surface);
    padding: calc(var(--spacing-unit) * 2);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    max-width: 700px;
    margin: calc(var(--spacing-unit) * 2) auto;
}

.form-header {
    text-align: center;
    margin-bottom: calc(var(--spacing-unit) * 2);
}

.form-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
}

.form-group {
    margin-bottom: calc(var(--spacing-unit) * 1.5);
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: var(--font-family-base);
    transition: var(--transition-fast);
    background-color: var(--bg-body);
    color: var(--text-primary);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

.submit-btn {
    width: 100%;
}

/* Alerts */
.alert {
    padding: var(--spacing-unit);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-unit);
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}


/* --- 6. RESPONSIVE DESIGN --- */
@media (max-width: 768px) {
    .container {
        padding: var(--spacing-unit);
    }
    
    .header-content {
        padding: 0.75rem var(--spacing-unit);
    }

    .products-grid {
        grid-template-columns: 1fr;
    }

    .form-card {
        padding: var(--spacing-unit);
    }

    .form-title {
        font-size: 1.5rem;
    }
}
.form-card, .auth-card {
    padding: 1.5rem; /* تقليل الحشو الداخلي على الهواتف */
}

.form-title, .auth-title {
    font-size: 1.5rem; /* تصغير حجم العنوان الرئيسي */
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr; /* جعل الأعمدة تحت بعضها البعض دائمًا */
    gap: 0; /* إزالة الفجوة بين أعمدة الشبكة */
}

.form-actions {
    flex-direction: column; /* جعل الأزرار تحت بعضها البعض */
    gap: 1rem;
}

/* --- 7. MOBILE NAVIGATION STYLES --- */

.mobile-menu-toggle {
    display: flex; /* Initially hidden on desktop */
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1010;
}

.mobile-menu-toggle span {
    width: 30px;
    height: 3px;
    background: var(--text-primary);
    border-radius: 10px;
    transition: all 0.3s linear;
    position: relative;
    transform-origin: 1px;
}

.mobile-nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1001;
}

.mobile-nav-overlay.open {
    opacity: 1;
    visibility: visible;
}

.mobile-nav {
    position: fixed;
    top: 0;
    right: -100%; /* Start off-screen */
    width: 280px;
    height: 100%;
    background: var(--bg-surface);
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    transition: right 0.3s ease-in-out;
    z-index: 1002;
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.mobile-nav.open {
    right: 0;
}

.nav-close {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-size: 2rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.mobile-nav .nav-links {
    list-style: none;
    padding-top: 2rem;
}

.mobile-nav .nav-links a {
    display: block;
    padding: 0.75rem 0;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 600;
    transition: color 0.2s ease;
}

.mobile-nav .nav-links a:hover {
    color: var(--primary-color);
}


/* Responsive visibility */
.desktop-links { display: none !important; }

@media (min-width: 769px) {
    .mobile-menu-toggle { display: none; }
    .desktop-links { display: flex !important; }
}
/* --- 8. ADMIN TABLE STYLES --- */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--spacing-unit);
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    padding: 0.75rem;
    text-align: right;
    border: 1px solid var(--border-color);
    vertical-align: middle;
}

.admin-table thead {
    background-color: var(--bg-body);
    font-weight: 600;
}

.admin-table tbody tr:nth-of-type(even) {
    background-color: var(--bg-body);
}

.table-product-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: calc(var(--border-radius) / 2);
}

.table-product-image-placeholder {
    width: 50px;
    height: 50px;
    background-color: #e9ecef;
    border-radius: calc(var(--border-radius) / 2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.product-name-cell {
    font-weight: 600;
}

.price-cell {
    color: var(--success-color);
    font-weight: 600;
}

/* General Badge Styling */
.badge {
    padding: 0.25em 0.6em;
    font-size: 0.8em;
    font-weight: 700;
    line-height: 1;
    color: var(--text-light);
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
}
.badge-available, .badge-new { background-color: var(--success-color); }
.badge-sold { background-color: var(--secondary-color); }
.badge-hidden { background-color: var(--error-color); }
.badge-used { background-color: var(--warning-color); color: #333; }


.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.btn.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}
.btn-success { background-color: var(--success-color); color: white;}
.btn-warning { background-color: var(--warning-color); color: #333;}
.btn-danger { background-color: var(--error-color); color: white;}
/* --- 9. ENHANCED CATEGORY FILTERS (FINAL VERSION) --- */

/* --- 9. RESPONSIVE WRAPPING FILTERS (FINAL) --- */

.category-filters-wrapper {
    margin-bottom: 2rem;
}

.category-filters-list {
    display: flex;
    gap: 0.75rem;
    
    /* --- Mobile First: Horizontal Scrolling by Default --- */
    overflow-x: auto;
    padding-bottom: 10px; /* Space for shadow if items are tall */
    
    /* Hide scrollbar for a clean look on mobile */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE */
}
.category-filters-list::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

.category-filter-item {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 2rem; /* Pill shape */
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0; /* Prevent items from shrinking on mobile */
}

.category-filter-item:hover {
    background-color: var(--primary-color);
    color: var(--text-light);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.category-filter-item.active {
    background-color: var(--primary-color);
    color: var(--text-light);
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

/* --- Desktop: Enable Wrapping --- */
/* This media query applies only to screens wider than 768px */
@media (min-width: 769px) {
    .category-filters-list {
        flex-wrap: wrap; /* This is the magic property! */
        overflow-x: hidden; /* Disable horizontal scroll on desktop */
        padding-bottom: 0;
    }
/* --- 11. GLOBAL TYPOGRAPHY & BUTTON UNIFICATION --- */

/* Apply base font to form elements for consistency */
body, button, input, select, textarea {
    font-family: var(--font-family-base);
}

/* Ensure all auth-related buttons use the unified .btn class */
.auth-btn, .submit-btn {
    /* Inherit all styles from .btn and .btn-primary */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem; /* Larger padding for main action buttons */
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    text-decoration: none;
    font-weight: 700; /* Bolder text */
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
    width: 100%;
    background-color: var(--primary-color);
    color: var(--text-light);
    border-color: var(--primary-color);
}

.auth-btn:hover, .submit-btn:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.auth-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}
.auth-link:hover {
    text-decoration: underline;
}


/* --- 12. EDIT PRODUCT PAGE IMAGE STYLING --- */

.current-image-container {
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
    margin-bottom: 1.5rem;
    text-align: center;
}

.current-image-label {
    display: block;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-unit);
    font-size: 0.9rem;
}

.current-image-wrapper {
    position: relative;
    width: 200px; /* Max width of the image container */
    height: 200px; /* Max height of the image container */
    margin: 0 auto;
    border-radius: var(--border-radius);
    overflow: hidden;
    background-color: #e9ecef;
}

.current-product-image {
    width: 100%;
    height: 100%;
    object-fit: cover; /* This ensures the image covers the area without distortion */
}

.delete-image-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: var(--transition-fast);
    box-shadow: var(--shadow);
    opacity: 0; /* Hidden by default */
}

.current-image-wrapper:hover .delete-image-btn {
    opacity: 1; /* Show on hover */
}
/* --- 13. ADMIN UI ENHANCEMENTS --- */

/* Badge for Admin in Header */
.admin-badge {
    font-size: 1rem;
    margin-right: -0.5rem; /* To bring it closer to the name */
    margin-left: 0.5rem;
    cursor: default;
}

/* Styling for the user-info container in desktop header */
.user-info-desktop {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--bg-body);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    transition: var(--transition-fast);
}

.user-avatar-desktop {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.user-name-desktop {
    font-weight: 600;
}

/* Special styling when the user is an admin */
.user-info-desktop:has(.admin-badge) {
    border-color: var(--warning-color);
    background-color: #fffbeb;
}

[data-theme="dark"] .user-info-desktop:has(.admin-badge) {
    background-color: #2e240b;
}


/* Styling for general nav-links and logout link */
.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    padding: 0.5rem 0;
    position: relative;
}
.nav-link::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: 0;
    right: 0;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
}
.nav-link:hover::after {
    width: 100%;
}

.logout-link {
    color: var(--error-color) !important;
}
.logout-link:hover::after {
    background-color: var(--error-color);
}

/* Styling for the new Admin Control Panel link in header */
.nav-link.admin-link-header {
    color: var(--warning-color) !important;
    font-weight: 700;
}
.nav-link.admin-link-header:hover::after {
    background-color: var(--warning-color);
}
/* --- 14. ADMIN PANEL SHORTCUT --- */
.admin-panel-shortcut {
    background-color: #fffbeb;
    border: 1px solid var(--warning-color);
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}
.admin-panel-content {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* للسماح بالالتفاف على الشاشات الصغيرة */
    gap: 1rem;
}
.admin-panel-content span {
    font-weight: 600;
    color: #856404;
}
[data-theme="dark"] .admin-panel-shortcut {
    background-color: #2e240b;
}
[data-theme="dark"] .admin-panel-content span {
    color: var(--warning-color);
}
/* --- 15. RESPONSIVE PROFILE PAGE STYLING --- */

.profile-header {
    display: flex;
    flex-direction: row; /* Horizontal on desktop */
    align-items: flex-start; /* Align items to the top */
    gap: 1.5rem;
    background-color: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.profile-header-avatar {
    flex-shrink: 0;
}

.profile-avatar-img, .profile-avatar-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
}

.profile-avatar-placeholder {
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: bold;
}

.profile-header-content {
    flex-grow: 1;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.profile-header-info h1 {
    font-size: 1.8rem;
    margin: 0 0 0.5rem 0;
}
.profile-header-info p {
    margin: 0.25rem 0;
    color: var(--text-secondary);
}
.profile-header-info .join-date {
    font-size: 0.9rem;
}

/* --- MOBILE RESPONSIVENESS FOR PROFILE HEADER --- */
@media (max-width: 768px) {
    .profile-header {
        flex-direction: column; /* Stack vertically on mobile */
        align-items: center; /* Center items on mobile */
        text-align: center;
    }

    .profile-header-content {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .profile-header-info {
        margin-bottom: 1.5rem; /* Space between info and button */
    }

    .profile-header-actions .btn {
        width: 100%; /* Make button full-width on mobile */
    }
}