/* Reset and Base Styles */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary-color: #8b5cf6;
    --primary-dark: #7c3aed;
    --secondary-color: #ec4899;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --dark: #1e293b;
    --light: #f8fafc;
    --gray: #64748b;
    --border: #e2e8f0;
}

body {
    font-family: 'Cairo', sans-serif;
    line-height: 1.6;
    color: var(--dark);
    background: var(--light);
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Header & Navigation */
.header { background: white; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); position: sticky; top: 0; z-index: 1000; }
.navbar { padding: 1rem 0; }
.navbar .container { display: flex; justify-content: space-between; align-items: center; }
.logo { font-size: 1.5rem; font-weight: 700; color: var(--primary-color); text-decoration: none; }

/* Hamburger Menu */
.hamburger { display: none; flex-direction: column; gap: 4px; background: none; border: none; cursor: pointer; padding: 8px; z-index: 1001; }
.hamburger span { display: block; width: 25px; height: 3px; background: var(--primary-color); border-radius: 3px; transition: all 0.3s; }
.navbar-menu { display: flex; gap: 2rem; align-items: center; }
.nav-link { color: var(--dark); text-decoration: none; font-weight: 500; transition: color 0.3s; }
.nav-link:hover { color: var(--primary-color); }

/* Mobile Navigation */
@media (max-width: 768px) {
    .hamburger { display: flex; }
    .navbar-menu { position: fixed; top: 70px; right: -100%; width: 280px; height: calc(100vh - 70px); background: white; flex-direction: column; align-items: flex-start; padding: 2rem; gap: 1.5rem; box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1); transition: right 0.3s ease-in-out; overflow-y: auto; }
    .navbar-menu.active { right: 0; }
    .navbar-menu .nav-link, .navbar-menu .btn { width: 100%; text-align: right; padding: 0.75rem 1rem; }
}

/* Buttons */
.btn { display: inline-block; padding: 0.75rem 1.5rem; border-radius: 8px; text-decoration: none; font-weight: 600; transition: all 0.3s; border: none; cursor: pointer; }
.btn-primary { background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); color: white; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(139, 92, 246, 0.3); }
.btn-secondary { background: var(--gray); color: white; }
.btn-danger { background: var(--danger-color); color: white; }

/* Hero Section */
.hero { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 6rem 0; text-align: center; }
.hero h1 { font-size: 3rem; margin-bottom: 1rem; }
.hero p { font-size: 1.25rem; margin-bottom: 2rem; opacity: 0.9; }

/* Categories */
.categories-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; }
.category-card { background: white; padding: 2rem; border-radius: 12px; text-align: center; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); transition: transform 0.3s; text-decoration: none; color: var(--dark); }
.category-card:hover { transform: translateY(-5px); }
.category-icon { font-size: 3rem; margin-bottom: 1rem; }
.section-title { text-align: center; font-size: 2.5rem; margin-bottom: 3rem; color: var(--dark); }

/* =========================================
   Smart Grid Layout (نظام الشبكة الذكي)
   ========================================= */

.masonry-grid {
    display: grid;
    /* هذا السطر يجعل الأعمدة تتمدد تلقائياً لتملأ الشاشة */
    /* الكارت لن يقل عن 280 بكسل، وسيتمدد ليملأ الفراغ */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); 
    gap: 1.5rem;
    padding-bottom: 2rem;
    align-items: start; /* يمنع الكروت القصيرة من التمدد طولياً */
}

.masonry-item {
    /* لا نحتاج هذا الكلاس في نظام الـ Grid الجديد، لكن سنتركه لعدم تكسير الـ HTML */
    width: 100%;
}

.template-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    height: 100%; /* لضمان تساوي الأطوال لو أردت، أو احذفه لتباين الأطوال */
}

.template-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

/* ضبط الصورة لتظهر كاملة دائماً */
.template-image {
    width: 100%;
    height: auto !important; /* يلغي الارتفاع الثابت */
    aspect-ratio: unset; /* إلغاء النسبة الثابتة لترك الصورة بطبيعتها */
    object-fit: cover; /* يملأ العرض */
    display: block;
}

.template-info {
    padding: 1rem;
    background: #fff;
    text-align: center;
    border-top: 1px solid #f1f5f9;
}

.template-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

/* تحسينات للموبايل */
@media (max-width: 576px) {
    .masonry-grid {
        grid-template-columns: 1fr; /* عمود واحد */
        gap: 1rem;
    }
}

/* Footer */
.footer { background: var(--dark); color: white; padding: 3rem 0 1rem; margin-top: 4rem; }
.footer-content { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; }
.footer-bottom { text-align: center; padding-top: 2rem; border-top: 1px solid rgba(255, 255, 255, 0.1); margin-top: 2rem; }

/* Alerts & Forms */
.alert { padding: 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.form-control { width: 100%; padding: 0.75rem; border: 2px solid var(--border); border-radius: 8px; }

/* Mobile & General Fixes */
@media (max-width: 768px) {
    .container { padding: 0 15px; }
    .hero h1 { font-size: 2rem; }
    .section-title { font-size: 1.75rem; }
}