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

/* =========================================================
   RaqibGuard Design System
   ========================================================= */
:root {
    /* الألوان الأساسية */
    --primary-color: #00B894;
    --primary-dark: #009e7f;
    --primary-light: #E6FFFA;
    --navy-dark: #0D1B2A;
    --navy-light: #16283F;

    /* الحياد والخلفيات */
    --border-grey: #E6ECF1;
    --bg-light: #F4FAF9;
    --white: #FFFFFF;
    --text-muted: #6C757D;
    --text-main: #0D1B2A;

    /* حالات الدلالة */
    --danger: #d63031;
    --danger-bg: #FFE3E3;
    --warning: #e67e22;
    --warning-bg: #FFF4E6;
    --info: #3498db;
    --info-bg: #E8F4FD;
    --success: #00B894;
    --success-bg: #E6FFFA;

    /* مقاييس موحّدة */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-card: 0 2px 4px rgba(13, 27, 42, 0.04);
    --shadow-elevated: 0 8px 24px rgba(13, 27, 42, 0.10);
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --focus-ring: 0 0 0 3px rgba(0, 184, 148, 0.35);

    /* أسماء بديلة (توافق مع كود قديم) */
    --primary: var(--primary-color);
    --border-color: var(--border-grey);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-main);
    direction: rtl;
}

a { color: inherit; }

/* إتاحة رؤية واضحة للتركيز أثناء التنقل بلوحة المفاتيح */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* =========================================================
   تخطيط لوحة التحكم (Sidebar + Topbar)
   ========================================================= */
.dashboard-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--navy-dark);
    color: var(--white);
    padding: 24px 16px 16px;
    box-sizing: border-box;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    z-index: 40;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    margin: 0 -4px;
    padding: 0 4px;
}

.sidebar-footer {
    flex-shrink: 0;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-sub-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #9fd8c8;
    background: rgba(0, 184, 148, 0.12);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}
.sidebar-sub-status.warn {
    color: #ffcf9e;
    background: rgba(230, 126, 34, 0.15);
}

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

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
}

.user-meta { min-width: 0; }
.user-name {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    font-size: 11px;
    color: #9fb3c8;
}

.sidebar .brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 900;
    color: var(--primary-color);
    padding: 0 8px;
    margin-bottom: 30px;
}

.sidebar .nav-section-label {
    font-size: 11px;
    color: #7C8DA6;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin: 18px 8px 8px;
    font-weight: 700;
}

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

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

.sidebar .nav-link {
    color: #C6D0DB;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background-color .15s ease, color .15s ease;
}

.sidebar .nav-link .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar .nav-link:hover {
    background-color: var(--navy-light);
    color: var(--white);
}

.sidebar .nav-link.active {
    background-color: var(--primary-color);
    color: var(--white);
    font-weight: 700;
}

.sidebar .nav-link.logout {
    color: #FF8080;
    margin-top: 24px;
}
.sidebar .nav-link.logout:hover { background-color: rgba(214, 48, 49, .18); color: #fff; }

.sidebar-backdrop { display: none; }

/* الشريط العلوي داخل المحتوى */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.topbar .page-heading h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 800;
    color: var(--navy-dark);
}

.topbar .page-heading p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary-color); text-decoration: underline; }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .current { color: var(--navy-dark); font-weight: 600; }

.menu-toggle {
    display: none;
    background: var(--navy-dark);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    font-size: 18px;
    cursor: pointer;
}

.main-content {
    flex: 1;
    padding: 28px 32px;
    min-width: 0;
}

/* =========================================================
   مكوّنات عامة قابلة لإعادة الاستخدام
   ========================================================= */
.card {
    background-color: var(--white);
    border: 1px solid var(--border-grey);
    border-radius: var(--radius-md);
    padding: 22px;
    box-shadow: var(--shadow-card);
    transition: box-shadow .18s ease, transform .18s ease;
}

.card > h3:first-child, .card > h2:first-child { margin-top: 0; }

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.metric-card {
    background-color: var(--white);
    border: 1px solid var(--border-grey);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-card);
    transition: box-shadow .18s ease, transform .18s ease;
    position: relative;
    overflow: hidden;
}
.metric-card:hover {
    box-shadow: var(--shadow-elevated);
    transform: translateY(-2px);
}
.metric-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 70px; height: 70px;
    background: radial-gradient(circle at top right, rgba(0,184,148,0.08), transparent 70%);
}

.metric-card .title {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.metric-card .value {
    font-size: 28px;
    font-weight: 800;
    color: var(--navy-dark);
    line-height: 1.2;
}

.metric-card .value.highlight { color: var(--primary-color); }
.metric-card .value.danger { color: var(--danger); }

/* شبكات */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 28px; }

/* الجداول */
.table-wrap {
    background: var(--white);
    border: 1px solid var(--border-grey);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-card);
}
.table-wrap .table-scroll { width: 100%; overflow-x: auto; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 560px;
}

table.data-table thead tr {
    background: var(--navy-dark);
    color: #fff;
    text-align: right;
}

table.data-table th {
    padding: 12px 14px;
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
}

table.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-grey);
    font-size: 14px;
    vertical-align: middle;
}

table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr { transition: background-color .12s ease; }
table.data-table tbody tr:hover { background: var(--bg-light); }

.table-empty {
    text-align: center;
    padding: 36px 20px;
    color: var(--text-muted);
}

/* الشارات */
.badge {
    display: inline-block;
    padding: 4px 11px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg-light); color: var(--text-muted); }

.risk-badge { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: bold; }
.risk-high { background: var(--danger-bg); color: var(--danger); }
.risk-medium { background: var(--warning-bg); color: var(--warning); }
.risk-low { background: var(--success-bg); color: var(--success); }

/* التنبيهات */
.alert {
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger  { background: var(--danger-bg); color: var(--danger); }
.alert-info    { background: var(--info-bg); color: var(--info); }

/* الأزرار */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: inherit;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: filter .15s ease, transform .05s ease;
}
.btn:hover { filter: brightness(0.94); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-secondary { background: var(--white); color: var(--navy-dark); border: 1px solid var(--border-grey); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-success { background: #2ecc71; color: #fff; }
.btn-sm { padding: 7px 13px; font-size: 12px; border-radius: var(--radius-sm); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* قائمة منسدلة صغيرة موحّدة (تُستخدم لتغيير خطة/دور من صف بجدول) */
.select-sm {
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-grey);
    font-family: inherit;
    font-size: 12px;
    background: var(--white);
    color: var(--text-main);
}
.select-sm:focus { border-color: var(--primary-color); }

/* التوافق مع الكود القديم */
.cta-btn { background: var(--primary-color); color: #fff; padding: 12px 22px; border-radius: var(--radius-sm); font-weight: 700; }

/* النماذج */
.form-grid { display: grid; gap: 16px; }
.form-field label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--navy-dark);
}
.form-field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="password"],
.form-field input[type="number"],
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-grey);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: var(--white);
    color: var(--text-main);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
    border-color: var(--primary-color);
}

/* شريط الحالة العام المبسّط (إشارة مرور) */
.status-banner {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 22px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    border: 1px solid transparent;
}
.status-banner .status-emoji { font-size: 32px; line-height: 1; }
.status-banner .status-title { font-size: 16px; font-weight: 800; margin-bottom: 3px; }
.status-banner .status-desc { font-size: 13px; opacity: .85; }
.status-low    { background: var(--success-bg); color: #046c5a; border-color: #b9f0e2; }
.status-medium { background: var(--warning-bg); color: #8a5210; border-color: #f6d9ae; }
.status-high   { background: var(--danger-bg); color: #8f1f1f; border-color: #f5c2c2; }

/* بطاقات الإجراءات السريعة — "اضغط فقط" لغير المختصين */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 26px;
}
.quick-action-card {
    display: block;
    background: var(--white);
    border: 1px solid var(--border-grey);
    border-radius: var(--radius-lg);
    padding: 22px 18px;
    text-decoration: none;
    color: inherit;
    text-align: center;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.quick-action-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-elevated);
    border-color: var(--primary-color);
}
.quick-action-card .qa-icon { font-size: 34px; margin-bottom: 10px; }
.quick-action-card .qa-title { font-weight: 800; color: var(--navy-dark); font-size: 15px; margin-bottom: 5px; }
.quick-action-card .qa-desc { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.quick-action-card.qa-primary { background: var(--navy-dark); border-color: var(--navy-dark); }
.quick-action-card.qa-primary .qa-title { color: #fff; }
.quick-action-card.qa-primary .qa-desc { color: #b9c6d4; }

.section-eyebrow {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    margin: 0 0 12px;
}

/* تلميح مبسّط أسفل رقم كل مؤشر */
.metric-hint {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* أيقونة (؟) شرح صغيرة بجانب أي مصطلح تقني */
.info-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border-grey);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 800;
    cursor: help;
    vertical-align: middle;
}
.info-tip:hover { background: var(--primary-color); color: #fff; }
/* زر إظهار الخيارات المتقدمة */
.advanced-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    padding: 6px 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.advanced-toggle:hover { color: var(--primary-color); }

.mode-option {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: var(--bg-light);
    border: 2px solid var(--border-grey);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    cursor: pointer;
}
.mode-option input:checked ~ span strong { color: var(--primary-color); }

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; }
.empty-state p { margin: 4px 0; }

/* شبكة مؤشرات صفحة الدخول */
.section-title { font-size: 18px; font-weight: 800; color: var(--navy-dark); margin: 0 0 16px; }

/* =========================================================
   الاستجابة للشاشات الصغيرة
   ========================================================= */
@media (max-width: 900px) {
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }

    .sidebar {
        position: fixed;
        right: 0;
        top: 0;
        transform: translateX(100%);
        box-shadow: var(--shadow-elevated);
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-backdrop.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(13, 27, 42, .45);
        z-index: 30;
    }

    .main-content { padding: 18px; }
    .topbar { align-items: flex-start; }
    table.data-table { min-width: 480px; }
}
