/* ============================================================
   THEME.CSS — نظام تصميم سجاد الفخامة (Saaaad Al-Fakhama)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800;900&display=swap');

:root {
    /* Brand colors */
    --brand: #731931;
    --brand-dark: #5C1428;
    --brand-light: #8E3A4A;
    --brand-50: #FAF0F2;
    --brand-100: #F5E1E6;
    --brand-200: #EBC4CE;

    /* Neutrals */
    --bg: #F8F5F6;
    --surface: #FFFFFF;
    --surface-2: #FAFAFA;
    --border: #EAEAEA;
    --border-light: #F0F0F0;
    --text: #2B2B2B;
    --text-secondary: #6B6B6B;
    --text-muted: #9B9B9B;

    /* Semantic */
    --success: #15803D;
    --success-bg: #DCFCE7;
    --success-border: #BBF7D0;
    --warning: #B45309;
    --warning-bg: #FEF3C7;
    --warning-border: #FDE68A;
    --danger: #B91C1C;
    --danger-bg: #FEE2E2;
    --danger-border: #FECACA;
    --info: #1E40AF;
    --info-bg: #DBEAFE;
    --info-border: #BFDBFE;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(20, 20, 20, 0.03);
    --shadow-sm: 0 1px 3px rgba(20, 20, 20, 0.05), 0 1px 2px rgba(20, 20, 20, 0.04);
    --shadow: 0 4px 12px rgba(20, 20, 20, 0.05), 0 1px 2px rgba(20, 20, 20, 0.04);
    --shadow-lg: 0 10px 24px rgba(20, 20, 20, 0.08), 0 4px 8px rgba(20, 20, 20, 0.04);
    --shadow-xl: 0 24px 60px rgba(115, 25, 49, 0.18);
    --shadow-brand: 0 8px 24px rgba(115, 25, 49, 0.25);

    /* Radii */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 999px;

    /* Layout */
    --sidebar-w: 260px;
    --sidebar-w-collapsed: 78px;
    --topbar-h: 64px;

    /* Transitions */
    --t-fast: 120ms ease;
    --t: 200ms ease;
    --t-slow: 320ms ease;
}

/* ============== Base ============== */
* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Cairo', system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 14.5px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--text); }

a { color: var(--brand); text-decoration: none; transition: var(--t-fast); }
a:hover { color: var(--brand-dark); }

::selection { background: var(--brand); color: white; }

/* ============== APP SHELL ============== */
.app-shell {
    min-height: 100vh;
    position: relative;
}

.app-main {
    margin-right: var(--sidebar-w);   /* Sidebar على اليمين دائماً - عربي RTL */
    min-height: 100vh;
    transition: margin-right var(--t-slow);
}

/* ============== SIDEBAR (RIGHT for RTL) ============== */
.app-sidebar {
    position: fixed;
    top: 0;
    right: 0;                          /* جسدياً على اليمين */
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);   /* الحد على يسار الـ sidebar */
    z-index: 1040;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform var(--t-slow);
}

.sidebar-brand {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
}

.sidebar-brand img {
    height: 42px;
    width: auto;
    filter: brightness(0) invert(1);  /* اجعل اللوغو أبيض ضد الخلفية النبيذية */
}

.sidebar-brand-text {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.2;
    flex: 1;
}

.sidebar-brand-text small {
    display: block;
    font-weight: 400;
    font-size: 11px;
    opacity: 0.85;
    margin-top: 2px;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px 12px;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-section {
    padding: 10px 14px 6px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    font-weight: 700;
}

.sidebar-nav { padding: 0; margin: 0; list-style: none; }

.sidebar-nav .nav-item { margin-bottom: 2px; }

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14.5px;
    transition: var(--t-fast);
    cursor: pointer;
    position: relative;
}

.sidebar-nav .nav-link i {
    font-size: 18px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    background: var(--brand-50);
    color: var(--brand);
}

.sidebar-nav .nav-link.active {
    background: var(--brand);
    color: white;
    box-shadow: var(--shadow-sm);
}

.sidebar-nav .nav-link.is-action {
    background: var(--brand-50);
    color: var(--brand);
    font-weight: 600;
    border: 1px dashed var(--brand-200);
}

.sidebar-nav .nav-link.is-action:hover {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
}

.sidebar-nav .nav-badge {
    margin-right: auto;                /* badge في آخر السطر (يسار في RTL) */
    font-size: 11px;
    background: var(--brand-100);
    color: var(--brand);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

.sidebar-nav .nav-link.active .nav-badge {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border-light);
    background: var(--surface-2);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-card-info {
    flex: 1;
    min-width: 0;
}

.user-card-name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-card-role {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.btn-logout {
    width: 100%;
    margin-top: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--t-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-logout:hover {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger);
}

/* ============== TOPBAR ============== */
.app-topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow-xs);
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.sidebar-toggle:hover { background: var(--brand-50); color: var(--brand); }

.topbar-title {
    flex: 1;
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
}

.topbar-title small {
    display: block;
    font-weight: 400;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============== CONTENT ============== */
.app-content {
    padding: 24px;
    max-width: 1500px;
    margin: 0 auto;
}

/* ============== PAGE HEADER ============== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-header h2, .page-header h3 { margin: 0; font-size: 22px; font-weight: 700; }

.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============== CARD ============== */
.card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-light);
    padding: 14px 20px;
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.card-body { padding: 20px; }

.card-title { margin: 0; font-weight: 600; font-size: 15px; }

/* ============== BUTTONS ============== */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 8px 16px;
    transition: var(--t-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    font-size: 14px;
}

.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: var(--radius-xs); }
.btn-lg { padding: 12px 22px; font-size: 16px; }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: white;
    box-shadow: 0 1px 2px rgba(115, 25, 49, 0.2);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: white;
    box-shadow: var(--shadow-brand);
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--brand);
    border-color: var(--brand);
    background: transparent;
}
.btn-outline-primary:hover {
    background: var(--brand);
    border-color: var(--brand);
    color: white;
}

.btn-light, .btn-outline-secondary, .btn-secondary {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text-secondary);
}
.btn-light:hover, .btn-outline-secondary:hover, .btn-secondary:hover {
    background: var(--brand-50);
    border-color: var(--brand-200);
    color: var(--brand);
}

.btn-success { background: var(--success); border-color: var(--success); color: white; }
.btn-success:hover { background: #166534; border-color: #166534; color: white; }
.btn-outline-success { color: var(--success); border-color: var(--success); }
.btn-outline-success:hover { background: var(--success); border-color: var(--success); color: white; }

.btn-warning { background: var(--warning); border-color: var(--warning); color: white; }
.btn-warning:hover { background: #92400E; border-color: #92400E; color: white; }
.btn-outline-warning { color: var(--warning); border-color: var(--warning); }
.btn-outline-warning:hover { background: var(--warning); border-color: var(--warning); color: white; }

.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: #991B1B; border-color: #991B1B; color: white; }
.btn-outline-danger { color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); border-color: var(--danger); color: white; }

.btn-info { background: var(--info); border-color: var(--info); color: white; }

/* ============== TABLES ============== */
.table {
    margin-bottom: 0;
    color: var(--text);
}

.table thead { background: var(--bg); }

.table thead th {
    border-bottom: 1px solid var(--border) !important;
    border-top: none !important;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 12px 14px;
    white-space: nowrap;
}

.table tbody tr {
    transition: var(--t-fast);
}

.table tbody tr:hover { background: var(--brand-50); }

.table tbody td {
    border-color: var(--border-light) !important;
    padding: 12px 14px;
    vertical-align: middle;
}

.table-hover tbody tr:hover {
    background-color: var(--brand-50);
}

/* ============== BADGES ============== */
.badge {
    padding: 4px 10px;
    font-weight: 600;
    border-radius: var(--radius-pill);
    font-size: 11.5px;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge.bg-primary { background: var(--brand) !important; }
.badge.bg-success { background: var(--success-bg) !important; color: var(--success) !important; border: 1px solid var(--success-border); }
.badge.bg-warning { background: var(--warning-bg) !important; color: var(--warning) !important; border: 1px solid var(--warning-border); }
.badge.bg-danger { background: var(--danger-bg) !important; color: var(--danger) !important; border: 1px solid var(--danger-border); }
.badge.bg-info { background: var(--info-bg) !important; color: var(--info) !important; border: 1px solid var(--info-border); }
.badge.bg-secondary { background: var(--border-light) !important; color: var(--text-secondary) !important; }

/* ============== FORMS ============== */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 9px 12px;
    font-size: 14.5px;
    transition: var(--t-fast);
    background: var(--surface);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(115, 25, 49, 0.12);
}

.form-control:disabled, .form-control[readonly] {
    background: var(--surface-2);
    color: var(--text-secondary);
}

.form-control-sm, .form-select-sm { font-size: 13.5px; padding: 6px 10px; }

.form-label {
    font-weight: 500;
    font-size: 13.5px;
    color: var(--text);
    margin-bottom: 6px;
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.form-check-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(115, 25, 49, 0.12);
}

/* ============== ALERTS ============== */
.alert {
    border-radius: var(--radius);
    border: 1px solid transparent;
    padding: 12px 16px;
}

.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }

/* ============== UTILITIES ============== */
.text-brand { color: var(--brand) !important; }
.bg-brand { background: var(--brand) !important; color: white; }
.border-brand { border-color: var(--brand) !important; }

.icon-circle {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.icon-circle.bg-brand-soft { background: var(--brand-100); color: var(--brand); }
.icon-circle.bg-success-soft { background: var(--success-bg); color: var(--success); }
.icon-circle.bg-warning-soft { background: var(--warning-bg); color: var(--warning); }
.icon-circle.bg-danger-soft { background: var(--danger-bg); color: var(--danger); }
.icon-circle.bg-info-soft { background: var(--info-bg); color: var(--info); }

/* Avatar with initials */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: white;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
}

/* ============== STAT CARDS ============== */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 18px 20px;
    transition: var(--t-fast);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.stat-card-row { display: flex; align-items: flex-start; gap: 14px; }

.stat-card-label {
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-card-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
    margin-top: 6px;
}

.stat-card-sub {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 4px;
}

/* ============== DROPDOWN ============== */
.dropdown-menu {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}

.dropdown-item {
    border-radius: var(--radius-xs);
    padding: 8px 12px;
    font-size: 14px;
}

.dropdown-item:hover, .dropdown-item:focus {
    background: var(--brand-50);
    color: var(--brand);
}

/* ============== RESPONSIVE ============== */
@media (max-width: 991.98px) {
    .app-main { margin-right: 0; }
    /* Sidebar مخفي خارج الشاشة من جهة اليمين، ينزلق للداخل عند الفتح */
    .app-sidebar { transform: translateX(100%); }
    .app-sidebar.show { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(20, 20, 20, 0.5);
        z-index: 1035;
        backdrop-filter: blur(2px);
    }
    .sidebar-backdrop.show { display: block; }
}

@media (max-width: 575px) {
    .app-content { padding: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .stat-card-value { font-size: 22px; }
}

/* ============== PRINT ============== */
@media print {
    .app-sidebar, .app-topbar, .sidebar-toggle, .d-print-none { display: none !important; }
    .app-main { margin: 0 !important; }
    .app-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; page-break-inside: avoid; }
    body { background: white !important; }
}
