@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap');

:root {
    --primary-color: #C5A021;
    --primary-dark: #A6851B;
    --primary-light: #FDF9E7;
    --primary-gradient: linear-gradient(135deg, #C5A021 0%, #D4AF37 100%);

    --bg-body: #F8F9FA;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-sidebar: #0F172A;
    /* Deep Navy for Luxury */

    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    --border-color: rgba(0, 0, 0, 0.05);
    --border-luxury: rgba(255, 255, 255, 0.1);

    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-blur: blur(12px);

    --shadow-premium: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
    --shadow-soft: 0 4px 20px -2px rgba(0, 0, 0, 0.03);

    --radius-premium: 1.25rem;
    --radius-button: 0.75rem;

    --sidebar-width: 300px;
    --header-height: 90px;
    --font-main: 'Cairo', sans-serif;
    --transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);

    --success: #10B981;
    --error: #EF4444;
    --warning: #F59E0B;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* --- Layout Reset & Stability --- */
body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    display: block;
    /* Ensure block model */
    overflow-x: hidden;
}

/* --- Sidebar --- */
/* --- Sidebar Professional Styling --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0; /* RTL Base */
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    
    /* Smooth Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    font-size: 1.4rem;
    font-weight: 800;
    color: #fff;
    gap: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    flex-shrink: 0; /* Prevent shrinking */
    background: var(--bg-sidebar); /* Sticky effect if needed */
}

.brand i {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.8rem;
}

.nav-menu {
    list-style: none;
    padding: 1.5rem 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item a, 
.nav-link {
    display: flex;
    align-items: center;
    padding: 0.9rem 1.25rem;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    border-radius: var(--radius-button);
    font-weight: 600;
    transition: var(--transition);
    border: 1px solid transparent;
}

.nav-item a:hover, 
.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    transform: translateX(-5px);
}

.nav-item a.active, 
.nav-link.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.nav-item a.active i,
.nav-link.active i {
    color: var(--primary-color);
    filter: drop-shadow(0 0 8px rgba(197, 160, 33, 0.4));
}

.nav-item a i, 
.nav-link i {
    width: 28px;
    font-size: 1.1rem;
    transition: var(--transition);
}

/* --- Main Content --- */
.main-content {
    /* Calculate width */
    width: calc(100% - 300px);
    width: calc(100% - var(--sidebar-width));

    /* Push content to left side */
    margin-right: 300px;
    margin-right: var(--sidebar-width);
    margin-left: 0;

    min-height: 100vh;
    display: block;
    position: relative;
    z-index: 1;
    /* Ensure clickable */
    background: var(--bg-body);
    /* Ensure opacity */
}

/* RTL/LTR Handling */
[dir="ltr"] .sidebar {
    left: 0;
    right: auto;
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.1);
}

[dir="ltr"] .main-content {
    margin-left: var(--sidebar-width);
    margin-right: 0;
}

/* --- Top Bar --- */
.top-bar {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 40;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.user-img {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    border: 2px solid var(--border-color);
}

/* --- Dashboard Content --- */
.container-fluid {
    padding: 2rem;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--primary-light);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-primary);
    display: block;
    margin-bottom: 0.25rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* --- Tables & Lists --- */
.table-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    padding: 0;
}

.table-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: #F9FAFB;
}

th {
    padding: 1rem 1.5rem;
    text-align: right;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1rem 1.5rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #F9FAFB;
}

/* Status Badges */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-block;
}

.status-active {
    background-color: #DCFCE7;
    color: #166534;
}

.status-draft {
    background-color: #FEF3C7;
    color: #92400E;
}

/* --- Buttons --- */
.btn-add,
.btn-primary {
    background: var(--primary-color);
    color: white;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn-add:hover,
.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: #F9FAFB;
    border-color: var(--text-muted);
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-icon:hover {
    background: #F3F4F6;
    color: var(--primary-dark);
}

/* --- Forms & Editor --- */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Quill Editor Fixes */
.ql-toolbar.ql-snow {
    border-color: var(--border-color) !important;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: #F9FAFB;
}

.ql-container.ql-snow {
    border-color: var(--border-color) !important;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    min-height: 300px;
    font-family: var(--font-main) !important;
    font-size: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
        width: 100%;
    }

    .top-bar {
        padding: 0 1rem;
    }
}

/* RTL Helpers */
[dir="rtl"] .main-content {
    margin-right: var(--sidebar-width);
    margin-left: 0;
}

/* --- Modern UI Components --- */

/* Toggle Switch */
.switch {
    display: inline-block;
    height: 24px;
    position: relative;
    width: 44px;
}

.switch input {
    display: none;
}

.slider {
    background-color: #cbd5e1;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    background-color: #fff;
    bottom: 4px;
    content: "";
    height: 16px;
    left: 4px;
    position: absolute;
    transition: .4s;
    width: 16px;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* SEO Preview */
.seo-preview {
    background: #fff;
    border: 1px solid #dfe1e5;
    border-radius: 8px;
    padding: 16px;
    max-width: 600px;
    margin-top: 1rem;
    font-family: arial, sans-serif;
}

.seo-title {
    color: #1a0dab;
    font-size: 20px;
    line-height: 1.3;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.seo-title:hover {
    text-decoration: underline;
}

.seo-url {
    color: #202124;
    font-size: 14px;
    line-height: 1.3;
    margin-bottom: 2px;
}

.seo-desc {
    color: #4d5156;
    font-size: 14px;
    line-height: 1.58;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: #fff;
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    border-right: 4px solid var(--primary-color);
    animation: slideInLeft 0.3s ease;
    min-width: 300px;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--error);
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Premium Card Upgrades */
.premium-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.01), 0 2px 4px -1px rgba(0, 0, 0, 0.01);
    transition: var(--transition);
}

.premium-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.03);
}

.premium-card h4 {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.premium-card i {
    width: 36px;
    height: 36px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

/* Sub-Tab Navigation */
.sub-nav {
    display: inline-flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
}

.sub-nav-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: #64748b;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.sub-nav-btn.active {
    background: #fff;
    color: var(--primary-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Group Label Enhancement */
.setting-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid #f8fafc;
}

.setting-item-row:last-child {
    border-bottom: none;
}

.setting-info {
    max-width: 70%;
}

.setting-info .label-text {
    display: block;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.setting-info .desc-text {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* --- Premium Settings Layout: Grid-Focus --- */
.settings-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 3rem;
}

.settings-nav {
    position: sticky;
    top: 110px;
    height: fit-content;
    background: var(--bg-surface);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-premium);
    padding: 1rem;
    box-shadow: var(--shadow-soft);
}

.settings-nav .nav-link {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding: 0.9rem 1.2rem;
    border-radius: var(--radius-button);
}

.settings-nav .nav-link:hover {
    background: #f1f5f9;
    color: var(--primary-dark);
}

.settings-nav .nav-link.active {
    background: var(--primary-gradient);
    color: #fff !important;
}

/* Premium Card Overhaul */
.premium-card {
    background: var(--bg-surface);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-premium);
    padding: 2.5rem;
    margin-bottom: 2.5rem;
    box-shadow: var(--shadow-premium);
}

.premium-card h4 {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 2rem;
    color: var(--text-primary);
    border-right: 4px solid var(--primary-color);
    padding-right: 15px;
}

/* Form Controls: Soft & Clean */
.form-control {
    background: #fff;
    border: 1.5px solid #edf2f7;
    border-radius: var(--radius-button);
    padding: 1rem 1.25rem;
    font-size: 1rem;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(197, 160, 33, 0.1);
    outline: none;
}

/* Font & Toggle UI */
.font-option {
    padding: 1.5rem;
    border: 2px solid #edf2f7;
    border-radius: var(--radius-button);
    text-align: center;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 700;
    transition: var(--transition);
}

.font-option.active {
    border-color: var(--primary-color);
    background: var(--primary-light);
    color: var(--primary-dark);
    transform: scale(1.02);
}

.switch {
    width: 50px;
    height: 28px;
}

.slider:before {
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
}

input:checked+.slider:before {
    transform: translateX(22px);
}

/* Responsive & RTL */
@media (max-width: 1200px) {
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .settings-nav {
        position: relative;
        top: 0;
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        padding: 0.5rem;
    }

    .settings-nav .nav-link {
        margin-bottom: 0;
        margin-left: 0.5rem;
    }
}

/* Responsive fixes */
@media (max-width: 1024px) {
    .settings-grid {
        grid-template-columns: 1fr !important;
    }
}