/**
 * ===================================================================
 * منصة سند — نظام التصميم الموحد (Sanad Unified Design System V2)
 * ===================================================================
 * معمارية CSS موحدة، متناسقة، متجاوبة، تدعم الوضع الليلي والنهاري،
 * ونظام الأزرار والأيقونات والجداول والـ Sidebar الهرمي ونوافذ العرض.
 */

@import url('/css/fonts.css');   /* الخطوط مستضافة محلياً: public/fonts */

/* ===================================================================
   1. متغيرات النظام المركزية (Design Tokens)
   =================================================================== */
:root {
    /* الخطوط العربية والإنجليزية */
    --font-primary: 'Cairo', 'IBM Plex Sans Arabic', 'Tajawal', 'Almarai', system-ui, -apple-system, sans-serif;
    --font-heading: 'Cairo', 'Tajawal', 'Almarai', sans-serif;
    --font-numbers: 'Outfit', 'Cairo', sans-serif;

    /* تدرجات ومقاييس المسافات الثابتة (Spacing Scale) */
    --s-space-1: 4px;
    --s-space-2: 8px;
    --s-space-3: 12px;
    --s-space-4: 16px;
    --s-space-5: 20px;
    --s-space-6: 24px;
    --s-space-8: 32px;
    --s-space-10: 40px;
    --s-space-12: 48px;

    /* أنصاف الأقطار (Border Radius Scale) */
    --s-radius-xs: 4px;
    --s-radius-sm: 8px;
    --s-radius-md: 12px;
    --s-radius-lg: 16px;
    --s-radius-xl: 20px;
    --s-radius-full: 9999px;

    /* أحجام التخطيط الرئيسية (Layout Dimensions) */
    --s-sidebar-width: 270px;
    --s-sidebar-collapsed: 76px;
    --s-topbar-height: 68px;

    /* نظام الألوان الدلالي الفاخر — الوضع الليلي الافتراضي (Dark Theme) */
    --bg-main: #0B0F19;
    --bg-surface: #111827;
    --bg-surface-elevated: #1F2937;
    --bg-card: #111827;
    --bg-glass: rgba(17, 24, 39, 0.85);

    --border-color: rgba(255, 255, 255, 0.09);
    --border-glow: rgba(14, 165, 233, 0.28);
    --border-subtle: rgba(255, 255, 255, 0.05);

    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;

    /* لوحة الألوان الوظيفية (Functional Palette) */
    --s-primary: #0284C7;
    --s-primary-hover: #0369A1;
    --s-primary-subtle: rgba(2, 132, 199, 0.14);
    --s-primary-glow: rgba(2, 132, 199, 0.25);

    --s-success: #10B981;
    --s-success-hover: #059669;
    --s-success-subtle: rgba(16, 185, 129, 0.14);

    --s-danger: #EF4444;
    --s-danger-hover: #DC2626;
    --s-danger-subtle: rgba(239, 68, 68, 0.14);

    --s-warning: #F59E0B;
    --s-warning-hover: #D97706;
    --s-warning-subtle: rgba(245, 158, 11, 0.14);

    --s-info: #0284C7;
    --s-info-hover: #0369A1;
    --s-info-subtle: rgba(2, 132, 199, 0.14);

    --s-purple: #8B5CF6;
    --s-purple-subtle: rgba(139, 92, 246, 0.14);

    --s-gold: #E3B04B;
    --s-gold-subtle: rgba(227, 176, 75, 0.14);

    /* الظلال (Shadow System) */
    --s-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.15);
    --s-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --s-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --s-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
    --s-shadow-glow: 0 0 20px rgba(2, 132, 199, 0.2);

    /* أسماء متوافقة للمتغيرات الشائعة */
    --s-border: var(--border-color);
    --s-text-primary: var(--text-primary);
    --s-text-secondary: var(--text-secondary);
    --s-text-muted: var(--text-muted);
    --s-surface: var(--bg-surface);
    --s-surface-hover: var(--bg-surface-elevated);
}

/* سمة الوضع النهاري (Light Theme) */
[data-theme="light"] {
    --bg-main: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-surface-elevated: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-glass: rgba(255, 255, 255, 0.9);

    --border-color: #E2E8F0;
    --border-glow: rgba(2, 132, 199, 0.2);
    --border-subtle: #F1F5F9;

    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    --s-primary-subtle: rgba(2, 132, 199, 0.08);
    --s-success-subtle: rgba(16, 185, 129, 0.08);
    --s-danger-subtle: rgba(239, 68, 68, 0.08);
    --s-warning-subtle: rgba(245, 158, 11, 0.08);
    --s-info-subtle: rgba(2, 132, 199, 0.08);
    --s-purple-subtle: rgba(139, 92, 246, 0.08);
    --s-gold-subtle: rgba(227, 176, 75, 0.08);

    --s-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --s-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --s-shadow-md: 0 4px 14px rgba(0, 0, 0, 0.07);
    --s-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
    --s-shadow-glow: 0 0 16px rgba(2, 132, 199, 0.12);
}

/* ===================================================================
   2. إعادة الضبط العام والأساسيات (Reset & Base Styles)
   =================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-main);
    color: var(--text-primary);
    direction: rtl;
    text-align: right;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: var(--bg-surface-elevated);
    border-radius: var(--s-radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--s-primary);
}

/* ===================================================================
   3. هيكل التخطيط العام (App Layout Grid)
   =================================================================== */
.app-container {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
    min-width: 0;
}

/* القائمة الجانبية (Sidebar) */
.sidebar {
    width: var(--s-sidebar-width);
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 1000;
    transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(16px);
    overflow: hidden;
}

.sidebar-header {
    height: var(--s-topbar-height);
    padding: 0 var(--s-space-5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-brand-wrapper {
    display: flex;
    align-items: center;
    gap: var(--s-space-3);
    text-decoration: none;
}

.sanad-icon-box {
    width: 40px;
    height: 40px;
    border-radius: var(--s-radius-md);
    background: #141A28;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(227, 176, 75, 0.25);
}

.sanad-s-path {
    fill: none;
    stroke: #E3B04B;
    stroke-width: 19;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 620;
    stroke-dashoffset: 620;
    animation: sanadDraw 1.2s cubic-bezier(.65,0,.35,1) forwards;
}

.sanad-beam {
    opacity: 0;
    animation: sanadBeamIn 0.4s ease-out forwards;
    animation-delay: 1.0s;
    transform-origin: 84px 85px;
}

@keyframes sanadDraw {
    to { stroke-dashoffset: 0; }
}

@keyframes sanadBeamIn {
    from { opacity: 0; transform: rotate(-8deg) scaleX(0.3); }
    to   { opacity: 1; transform: rotate(-8deg) scaleX(1); }
}

.brand-text-block {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.2s ease;
}

.brand-title {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    line-height: 1.2;
}

.brand-subtitle {
    font-size: 10px;
    color: #E3B04B;
    font-weight: 800;
    letter-spacing: 1px;
    font-family: var(--font-numbers);
}

/* زر تصغير/توسيع القائمة الجانبية (Sidebar Collapse Button) */
.sidebar-collapse-toggle {
    width: 28px;
    height: 28px;
    border-radius: var(--s-radius-sm);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-collapse-toggle:hover {
    color: var(--text-primary);
    border-color: var(--s-primary);
    background: var(--s-primary-subtle);
}

/* قائمة الروابط والمجموعات الهرمية (Hierarchical Navigation) */
.sidebar-nav {
    flex: 1;
    padding: var(--s-space-4) var(--s-space-3);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: var(--s-space-1);
}

.nav-section-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--s-space-3) var(--s-space-3) var(--s-space-1);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* بطاقة المجموعة المنسدلة (Accordion Group) */
.nav-group {
    display: flex;
    flex-direction: column;
    border-radius: var(--s-radius-md);
    overflow: hidden;
}

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--s-radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: right;
    transition: all 0.2s ease;
    user-select: none;
}

.nav-group-header:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.nav-group-header.is-active,
.nav-group.is-open > .nav-group-header {
    color: var(--text-primary);
}

.nav-group-header.is-active {
    background: var(--s-primary-subtle);
    color: #38BDF8;
}

.nav-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    overflow: hidden;
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.nav-group-header:hover .nav-icon,
.nav-link:hover .nav-icon,
.nav-link.active .nav-icon,
.nav-group-header.is-active .nav-icon {
    color: #38BDF8;
}

.nav-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-chevron {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-group.is-open > .nav-group-header .nav-chevron {
    transform: rotate(-90deg);
    color: var(--text-primary);
}

/* القائمة الفرعية المنسدلة (Accordion Submenu) */
.nav-submenu {
    display: none;
    flex-direction: column;
    padding-right: 32px;
    padding-left: 8px;
    gap: 3px;
    margin: 4px 0 6px;
    position: relative;
}

.nav-submenu::before {
    content: '';
    position: absolute;
    right: 21px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border-color);
    border-radius: var(--s-radius-full);
}

.nav-group.is-open > .nav-submenu {
    display: flex;
    animation: submenuExpand 0.2s ease forwards;
}

@keyframes submenuExpand {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.nav-sublink {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: var(--s-radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 500;
    transition: all 0.18s ease;
    position: relative;
}

.nav-sublink:hover {
    color: var(--text-primary);
    background: var(--bg-surface-elevated);
}

.nav-sublink.active {
    color: #38BDF8;
    background: var(--s-primary-subtle);
    font-weight: 700;
}

.nav-sublink.active::before {
    content: '';
    position: absolute;
    right: -13px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--s-primary);
    box-shadow: 0 0 6px var(--s-primary);
}

/* الروابط الفردية العادية (Standard Nav Link) */
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--s-radius-md);
    font-weight: 600;
    font-size: 13.5px;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--s-primary-subtle);
    color: #38BDF8;
    font-weight: 700;
}

/* تذييل القائمة الجانبية (Sidebar Footer) */
.sidebar-footer {
    padding: var(--s-space-4);
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
}

/* نسبة المنصة لمطوّرها في أسفل القائمة */
.sidebar-credit {
    margin-top: 8px;
    font-size: 10.5px;
    color: var(--text-muted);
    text-align: center;
    justify-content: center;
}

.tenant-badge-card {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: var(--s-radius-md);
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

/* وضع القائمة المصغرة (Collapsed Sidebar Mode) */
body.sidebar-collapsed .sidebar {
    width: var(--s-sidebar-collapsed);
}

body.sidebar-collapsed .main-wrapper {
    margin-right: var(--s-sidebar-collapsed);
}

body.sidebar-collapsed .brand-text-block,
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .nav-chevron,
body.sidebar-collapsed .nav-section-title,
body.sidebar-collapsed .nav-submenu,
body.sidebar-collapsed .sidebar-credit,
body.sidebar-collapsed .tenant-badge-card > div:last-child {
    display: none !important;
}

/* زر التوسيع يبقى ظاهراً تحت الشعار، وسهمه معكوس (N79) */
body.sidebar-collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    height: auto;
    min-height: var(--s-topbar-height);
    padding: 8px 0;
}

body.sidebar-collapsed .sidebar-collapse-toggle svg {
    transform: rotate(180deg);
}

body.sidebar-collapsed .nav-group-header,
body.sidebar-collapsed .nav-link {
    justify-content: center;
    padding: 12px;
}

body.sidebar-collapsed .nav-item-left {
    justify-content: center;
}

/* شاشة المحتوى الرئيسية (Main Content Wrapper) */
.main-wrapper {
    flex: 1;
    margin-right: var(--s-sidebar-width);
    width: calc(100% - var(--s-sidebar-width));
    max-width: calc(100% - var(--s-sidebar-width));
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    background: radial-gradient(circle at 85% 0%, rgba(2, 132, 199, 0.04) 0%, transparent 40%),
                radial-gradient(circle at 10% 85%, rgba(16, 185, 129, 0.03) 0%, transparent 35%);
}

/* ===================================================================
   4. الشريط العلوي والمسارات الملاحية (Topbar & Breadcrumbs)
   =================================================================== */
.topbar {
    height: var(--s-topbar-height);
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--s-space-6);
    position: sticky;
    top: 0;
    z-index: 900;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--s-space-3);
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
}

.mobile-menu-btn {
    display: none;
    width: 38px;
    height: 38px;
    border-radius: var(--s-radius-md);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
}

/* المسار الملاحي الهرمي (Breadcrumbs) */
.breadcrumbs-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.15s ease;
}

.breadcrumb-item:hover {
    color: var(--text-primary);
}

.breadcrumb-item.active {
    color: var(--text-primary);
    font-weight: 700;
}

.breadcrumb-sep {
    font-size: 11px;
    color: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--s-space-3);
}

/* شارات الحالة والمؤسسة في الشريط العلوي */
.tenant-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface-elevated);
    padding: 6px 14px;
    border-radius: var(--s-radius-full);
    border: 1px solid var(--border-color);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.subscription-pill {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--s-radius-full);
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #F59E0B;
    font-size: 11.5px;
    font-weight: 700;
}

/* قائمة المستخدم الشخصية */
.user-profile-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px;
    border-radius: var(--s-radius-full);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--s-radius-full);
    background: linear-gradient(135deg, #0284C7, #10B981);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: 13px;
}

/* ===================================================================
   5. نظام الأزرار الموحد والشامل (Universal Button System)
   =================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-space-2);
    font-family: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    white-space: nowrap;
    outline: none;
}

.btn:focus-visible {
    box-shadow: 0 0 0 3px var(--s-primary-glow);
}

.btn:disabled, .btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

/* المقاسات الثلاثة المعتمدة فقط (Sizes Scale) */
.btn-sm {
    height: 32px;
    padding: 0 var(--s-space-3);
    font-size: 12px;
    border-radius: var(--s-radius-sm);
}

.btn-md, .btn:not(.btn-sm):not(.btn-lg) {
    height: 38px;
    padding: 0 var(--s-space-4);
    font-size: 13.5px;
    border-radius: var(--s-radius-md);
}

.btn-lg {
    height: 46px;
    padding: 0 var(--s-space-6);
    font-size: 15px;
    border-radius: var(--s-radius-md);
}

/* الأنماط والألوان (Button Variants) */
.btn-primary {
    background: linear-gradient(135deg, #0284C7 0%, #0369A1 100%);
    color: #FFFFFF;
    border-color: #0284C7;
    box-shadow: 0 2px 10px rgba(2, 132, 199, 0.28);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0369A1 0%, #075985 100%);
    box-shadow: 0 4px 16px rgba(2, 132, 199, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-success, .btn-emerald {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: #FFFFFF;
    border-color: #10B981;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.28);
}

.btn-success:hover, .btn-emerald:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-danger, .btn-rose {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    color: #FFFFFF;
    border-color: #EF4444;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.28);
}

.btn-danger:hover, .btn-rose:hover {
    background: linear-gradient(135deg, #DC2626 0%, #B91C1C 100%);
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
}

.btn-warning, .btn-amber {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: #000000;
    font-weight: 700;
    border-color: #F59E0B;
}

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

.btn-outline:hover {
    border-color: var(--s-primary);
    color: #38BDF8;
    background: var(--s-primary-subtle);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: var(--s-radius-md);
}

.btn-icon.btn-sm {
    width: 32px;
    height: 32px;
    border-radius: var(--s-radius-sm);
}

/* ===================================================================
   6. نظام الجداول الموحد (Unified Table System)
   =================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--s-radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    font-size: 13.5px;
}

.table th {
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    font-weight: 700;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .table tbody tr:hover td {
    background: rgba(0, 0, 0, 0.015);
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===================================================================
   7. نظام النماذج والمدخلات (Unified Forms & Inputs)
   =================================================================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--s-space-4);
}

.form-label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-secondary);
}

.form-label .required {
    color: var(--s-danger);
    margin-right: 2px;
}

.form-control,
.form-select {
    height: 40px;
    padding: 0 14px;
    border-radius: var(--s-radius-md);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13.5px;
    outline: none;
    transition: all 0.2s ease;
    width: 100%;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--s-primary);
    box-shadow: 0 0 0 3px var(--s-primary-subtle);
}

textarea.form-control {
    height: auto;
    min-height: 90px;
    padding: 10px 14px;
    resize: vertical;
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-helper {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===================================================================
   8. نظام البطاقات والحاويات (Unified Cards & Grid)
   =================================================================== */
.content-body {
    flex: 1;
    padding: var(--s-space-6);
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

.grid {
    display: grid;
    gap: var(--s-space-5);
}

.grid-cols-6 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }   /* صف مؤشرات (U31): كان بلا قاعدة فتتراكم البطاقات */
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-1 { grid-template-columns: 1fr; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--s-radius-lg);
    padding: var(--s-space-5);
    backdrop-filter: blur(12px);
    box-shadow: var(--s-shadow-sm);
    transition: all 0.22s ease;
    position: relative;
    overflow: hidden;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: var(--s-shadow-md);
}

/* ===================================================================
   9. شارات الحالة والامتثال (Status Badges)
   =================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--s-radius-full);
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
    border: 1px solid transparent;
}

.badge-success, .badge-emerald {
    background: var(--s-success-subtle);
    color: var(--s-success);
    border-color: rgba(16, 185, 129, 0.28);
}

.badge-danger, .badge-rose {
    background: var(--s-danger-subtle);
    color: var(--s-danger);
    border-color: rgba(239, 68, 68, 0.28);
}

.badge-warning, .badge-amber {
    background: var(--s-warning-subtle);
    color: var(--s-warning);
    border-color: rgba(245, 158, 11, 0.28);
}

.badge-info, .badge-blue {
    background: var(--s-primary-subtle);
    color: #38BDF8;
    border-color: rgba(2, 132, 199, 0.28);
}

.badge-gray, .badge-secondary {
    background: rgba(156, 163, 175, 0.12);
    color: var(--text-secondary);
    border-color: rgba(156, 163, 175, 0.24);
}

/* ===================================================================
   9-ب. التبويبات (Tabs)
   صفحة المشروع: .tabs-nav و.tab-btn و.tab-pane (app.js يبدّل الصنف active).
   صفحة /hr: .tab-btn و.tab-content (switchHRTab). القسم بلا active مخفي.
   =================================================================== */
.tabs-nav {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
    overflow-x: auto;
}

.tab-btn {
    padding: 12px 18px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: #38BDF8;
    border-bottom-color: var(--s-primary);
}

.tab-pane,
.tab-content {
    display: none;
}

.tab-pane.active,
.tab-content.active {
    display: block;
    animation: tabFadeIn 0.25s ease;
}

@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   10. النوافذ المنبثقة والإشعارات (Modals & Toast)
   =================================================================== */
.modal-backdrop,
.modal {
    position: fixed;
    inset: 0;
    background: rgba(11, 15, 25, 0.82);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--s-space-4);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal-backdrop.show,
.modal.show {
    display: flex !important;
    opacity: 1;
}

.modal-content,
.modal-dialog {
    background: var(--bg-surface);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--s-radius-xl);
    width: 100%;
    max-width: 620px;
    box-shadow: var(--s-shadow-lg);
    position: relative;
    overflow: hidden;
    transform: scale(0.96) translateY(12px);
    animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-content::before,
.modal-dialog::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #38BDF8, #818CF8, #C084FC, #34D399);
}

@keyframes modalPop {
    to { transform: scale(1) translateY(0); }
}

.modal-header {
    padding: var(--s-space-5) var(--s-space-6);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3,
.modal-header .modal-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
}

.modal-header .close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-header .close-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.modal-body {
    padding: var(--s-space-6);
    max-height: calc(85vh - 140px);
    overflow-y: auto;
}

.modal-footer,
.modal-actions {
    padding: var(--s-space-4) var(--s-space-6);
    background: var(--bg-surface-elevated);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--s-space-3);
}

/* حاوية الإشعارات اللحظية (Toast Container) */
.toast-container {
    position: fixed;
    bottom: var(--s-space-6);
    left: var(--s-space-6);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: var(--s-space-3);
}

.toast {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--s-radius-md);
    padding: 12px 18px;
    box-shadow: var(--s-shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
    animation: toastSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.toast-success { border-right: 4px solid var(--s-success); color: var(--text-primary); }
.toast-error   { border-right: 4px solid var(--s-danger);  color: var(--text-primary); }

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   11. حالات الشاشات الفارغة (Empty States)
   =================================================================== */
.empty-state {
    padding: var(--s-space-12) var(--s-space-6);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--s-space-3);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg-surface-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--text-muted);
    margin-bottom: var(--s-space-2);
}

.empty-state-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
}

.empty-state-text {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 400px;
}

/* ===================================================================
   12. نظام التجاوب الشامل والشاشات الموحدة (Unified Responsive System)
   =================================================================== */

/* عناصر التخطيط الأساسية المتجاوبة (Responsive Utilities) */
.responsive-grid,
.grid-kpi {
    display: grid;
    gap: var(--s-space-4);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    width: 100%;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--s-space-4);
    width: 100%;
}

.action-group,
.btn-group-responsive {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--s-space-2);
}

.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--s-radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    margin-bottom: var(--s-space-4);
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: var(--border-glow);
    border-radius: 4px;
}

img, svg, canvas, video {
    max-width: 100%;
    height: auto;
}

#sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

#sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* 1. الشاشات الفائقة (Large Desktop: 1920px+) */
@media (min-width: 1920px) {
    .content-body {
        max-width: 1840px;
        padding: var(--s-space-8);
    }
}

/* 2. الشاشات العادية (Desktop: 1440px - 1919px) */
@media (min-width: 1440px) and (max-width: 1919px) {
    .content-body {
        max-width: 1560px;
    }
}

/* 3. الحواسب المحمولة (Laptop: 1024px - 1439px) */
@media (min-width: 1024px) and (max-width: 1439px) {
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
}

/* 4. الأجهزة اللوحية وما دونها (Tablet & Mobile: <= 1023px) */
@media (max-width: 1023px) {
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        right: 0;
        width: 280px;
        max-width: 85vw;
        transform: translateX(100%);
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.5);
        z-index: 1001;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    body.sidebar-collapsed .sidebar {
        width: 280px !important;
        transform: translateX(100%);
    }

    body.sidebar-collapsed .sidebar.open {
        transform: translateX(0) !important;
    }

    body.sidebar-collapsed .brand-text-block,
    body.sidebar-collapsed .nav-text,
    body.sidebar-collapsed .nav-chevron,
    body.sidebar-collapsed .nav-section-title,
    body.sidebar-collapsed .sidebar-credit,
    body.sidebar-collapsed .tenant-badge-card > div:last-child {
        display: flex !important;
    }

    /* التصغير للحاسوب فقط: في الجوال تعمل المجموعات كالمعتاد ولو حُفظت حالة التصغير (N79) */
    body.sidebar-collapsed .nav-group.is-open > .nav-submenu {
        display: flex !important;
    }

    body.sidebar-collapsed .sidebar-header {
        flex-direction: row;
        justify-content: space-between;
        height: var(--s-topbar-height);
        padding: 0 var(--s-space-5);
    }

    .sidebar-collapse-toggle {
        display: none !important;
    }

    .main-wrapper {
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    body.sidebar-collapsed .main-wrapper {
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .topbar {
        padding: 0 var(--s-space-4);
    }

    .breadcrumbs-nav {
        display: none;
    }

    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-cols-2 { grid-template-columns: 1fr; }

    .projects-command-col,
    .finance-command-col,
    .chart-command-col,
    .tasks-command-col,
    .hr-command-col,
    .equipment-command-col {
        grid-column: span 12 !important;
    }

    .modal-content {
        max-width: 90vw;
    }
}

/* 5. الهواتف الذكية (Mobile: <= 767px) */
@media (max-width: 767px) {
    .topbar {
        height: 60px;
        padding: 0 12px;
    }

    .topbar-right {
        gap: 6px;
    }

    .tenant-pill {
        padding: 4px 8px;
        font-size: 11px;
        max-width: 130px;
    }
    .tenant-pill span:last-child {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .subscription-pill {
        padding: 4px 8px;
        font-size: 10.5px;
    }

    .subscription-pill span:first-of-type {
        display: none;
    }

    .user-profile-menu > div:nth-child(2) {
        display: none;
    }

    .content-body {
        padding: 12px 10px;
    }

    .kpi-row,
    .grid-cols-4,
    .grid-cols-3,
    .grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    .form-grid,
    .form-row-2 {
        grid-template-columns: 1fr !important;
    }

    .action-group,
    .filter-bar,
    .page-header-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .action-group .btn,
    .filter-bar .btn,
    .page-header-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .modal-backdrop {
        padding: 8px;
    }

    .modal-content,
    .modal-dialog {
        width: calc(100vw - 16px) !important;
        max-width: calc(100vw - 16px) !important;
        max-height: 92vh !important;
        margin: 8px auto !important;
        border-radius: var(--s-radius-lg);
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-body {
        padding: 14px 16px;
        max-height: calc(92vh - 120px);
    }

    .modal-footer {
        padding: 10px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }

    .executive-header h1,
    .page-header h1 {
        font-size: 18px !important;
    }

    .card {
        padding: 14px 12px;
    }
}

/* 6. الهواتف الصغيرة جداً (Small Mobile: 320px - 374px) */
@media (max-width: 374px) {
    .topbar {
        padding: 0 8px;
    }

    .tenant-pill {
        display: none;
    }

    .content-body {
        padding: 8px 6px;
    }

    .btn-sm {
        padding: 0 8px;
        font-size: 11px;
    }
}

/* ===================================================================
   الشريط العلوي على الجوال: زر القائمة لا ينكمش ولا يُدفع خارج الشاشة
   (عناصر الجهة الأخرى كانت أعرض من الشاشة فتضغط زر القائمة إلى عرض صفر)
   =================================================================== */
@media (max-width: 1023px) {
    .topbar-left {
        flex-shrink: 0;
        overflow: visible;
    }
    .mobile-menu-btn {
        flex-shrink: 0;
    }
    .topbar-right {
        min-width: 0;
    }
}

@media (max-width: 480px) {
    /* اسم المؤسسة يظهر في القائمة الجانبية ولوحة التحكم؛ يُخفى هنا لإفساح المجال */
    .tenant-pill {
        display: none;
    }
}
/* حقول التاريخ والشهر والوقت بالعربية (U25): المتصفح يعرضها بلغته (09/01/2026، September، AM) ويتجاهل lang،
   فيُخفى نصها الأصلي حين لا تكون مُركَّزة ويُعرض فوقها: 01-09-2026، سبتمبر 2026، 08:00 ص (public/js/app.js) */
.sanad-dt-wrap { position: relative; display: inline-block; max-width: 100%; vertical-align: middle; }
.sanad-dt-wrap.sanad-dt-block { display: block; width: 100%; }
.sanad-dt-wrap > input.sanad-dt:not(:focus)::-webkit-datetime-edit { color: transparent; }
.sanad-dt-wrap > input.sanad-dt[type="time"] { min-width: 104px; }
.sanad-dt-wrap > input.sanad-dt:focus + .sanad-dt-text { display: none; }
.sanad-dt-text {
    position: absolute; top: 0; bottom: 0;
    display: flex; align-items: center; justify-content: flex-start;
    pointer-events: none; white-space: nowrap; overflow: hidden; color: var(--text-primary, inherit);
    font-variant-numeric: tabular-nums;
}
.sanad-dt-text.sanad-dt-empty, .sanad-dt-wrap > input.sanad-dt:disabled + .sanad-dt-text { color: var(--text-muted, #94A3B8); }

/* ── جدول يصير بطاقات على الجوال (U40): table.table-cards، وكل خلية تأخذ تسميتها من data-label ──
   الأعمدة المهمة (الصافي والحالة) تأتي بعد الاسم مباشرة فتُرى على التابلت بلا سحب الجدول */
@media (max-width: 768px) {
    table.table-cards thead { display: none; }
    table.table-cards, table.table-cards tbody { display: block; width: 100%; }
    table.table-cards tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 14px 16px; }
    table.table-cards tbody tr > td { display: block; padding: 0 !important; min-width: 0; text-align: right !important; white-space: normal; }
    table.table-cards td[data-label]::before { content: attr(data-label); display: block; font-size: 10.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
    table.table-cards td.card-wide, table.table-cards td[colspan] { grid-column: 1 / -1; }
    table.table-cards td.card-wide > div { flex-wrap: wrap; }
}

/* ── نافذة نموذجها مباشرة داخلها وشريط حفظه .modal-actions ابنٌ للنموذج (U42؛ :has لا يتداخل): هامش داخلي، والنموذج يمرّ داخل النافذة،
   وشريط الحفظ (.modal-actions) ثابت أسفلها ظاهر دون تمرير، على الجوال والكمبيوتر ── */
.modal-content:has(> form > .modal-actions) {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 32px);
}
.modal-content > form:has(> .modal-actions) {
    padding: 18px 24px 0;
    overflow-y: auto;
    min-height: 0;
}
.modal-content > form:has(> .modal-actions) > .modal-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 8px -24px 0 !important;
}
@media (max-width: 767px) {
    .modal-content:has(> form > .modal-actions) { max-height: calc(100dvh - 16px) !important; }
    .modal-content > form:has(> .modal-actions) { padding: 14px 16px 0; }
    .modal-content > form:has(> .modal-actions) > .modal-actions { margin: 8px -16px 0 !important; padding: 10px 16px; flex-wrap: wrap; }
    .modal-content > form:has(> .modal-actions) > .modal-actions .btn { flex: 1; justify-content: center; }
}
