/* ============================================================
   style.css - نظام إدارة مصفوفة التدريب والاعتمادات
   ============================================================ */

:root {
    --primary: #1565c0;
    --primary-dark: #0d47a1;
    --primary-light: #e3f2fd;
    --accent: #00897b;
    --danger: #c62828;
    --warning: #f9a825;
    --success: #2e7d32;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --border: #e0e4ea;
    --text: #263238;
    --text-muted: #6b7785;
    --sidebar-width: 250px;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(20, 30, 60, 0.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, 'Arial', sans-serif;
    background: var(--bg);
    color: var(--text);
    /* الاتجاه يُحدَّد عبر سمة dir في وسم html (rtl افتراضياً للعربية) */
    font-size: 15px;
}

a { color: inherit; text-decoration: none; }

/* -------------------- Shell / Layout -------------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0d47a1, #1565c0);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
    z-index: 50;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
}
.brand-icon { font-size: 28px; }
.brand-logo-img { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; background: #fff; padding: 3px; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; opacity: 0.8; }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 14px 10px;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 8px;
    color: rgba(255,255,255,0.88);
    font-size: 14.5px;
    transition: background 0.15s;
}
.sidebar-nav a .icon { font-size: 17px; width: 22px; text-align: center; }
.sidebar-nav a:hover { background: rgba(255,255,255,0.12); }
.sidebar-nav a.active { background: rgba(255,255,255,0.22); font-weight: 600; }

.sidebar-footer {
    padding: 14px 18px;
    font-size: 11.5px;
    opacity: 0.65;
    border-top: 1px solid rgba(255,255,255,0.15);
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 60;
    width: 42px;
    height: 42px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 45;
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 16px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar h1 { font-size: 19px; margin: 0; color: var(--primary-dark); }
.topbar-date { font-size: 13px; color: var(--text-muted); }

.page-content {
    padding: 22px 26px 60px;
    min-width: 0;
    overflow-x: hidden;
}

/* -------------------- Cards -------------------- */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-right: 4px solid var(--primary);
}
.stat-card.c-blue { border-right-color: #1565c0; }
.stat-card.c-teal { border-right-color: #00897b; }
.stat-card.c-green { border-right-color: #2e7d32; }
.stat-card.c-orange { border-right-color: #f9a825; }
.stat-card.c-red { border-right-color: #c62828; }
.stat-card.c-purple { border-right-color: #6a1b9a; }

.stat-icon { font-size: 28px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* شريحة إحصائية مصغّرة (سجل التدريب / تقارير التكلفة) */
.stat-chip {
    background: var(--card-bg, #fff);
    border: 1px solid #e6ecf3;
    border-radius: 10px;
    padding: 10px 14px;
    min-width: 130px;
    flex: 0 0 auto;
}
.stat-chip .stat-label { font-size: 12px; }
.stat-chip .stat-value { font-size: 20px; }

/* مبدّل الفرع في الترويسة */
.branch-switch {
    width: auto;
    max-width: 190px;
    padding: 7px 12px;
    border: 1px solid #d8e0ec;
    border-radius: 9px;
    background: #fff;
    font-size: 13px;
    color: var(--text, #1b2431);
    cursor: pointer;
}

.panel {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 22px;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.panel-title { font-size: 16px; font-weight: 700; color: var(--primary-dark); }

/* -------------------- Toolbar / Filters -------------------- */

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 180px; }

/* -------------------- Buttons -------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 7px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.05s;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(0.98); }
.btn.secondary { background: #eceff3; color: var(--text); }
.btn.secondary:hover { background: #dfe3ea; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8e1c1c; }
.btn.success { background: var(--success); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    padding: 5px 8px;
    border-radius: 6px;
    color: var(--text-muted);
}
.icon-btn:hover { background: #eef1f5; color: var(--text); }
.icon-btn.edit:hover { color: var(--primary); }
.icon-btn.delete:hover { color: var(--danger); }

/* -------------------- Inputs -------------------- */

input, select, textarea {
    font-family: inherit;
    font-size: 14px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
label { font-size: 13px; color: var(--text-muted); margin-bottom: 5px; display: block; font-weight: 600; }

.field { margin-bottom: 14px; }
.field-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } }

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}
.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
    color: var(--text);
    font-size: 13.5px;
    cursor: pointer;
}
.checkbox-grid input[type="checkbox"] { width: auto; }

/* -------------------- Table -------------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table-wrap::-webkit-scrollbar { height: 9px; }
.table-wrap::-webkit-scrollbar-thumb { background: #c3d0e0; border-radius: 6px; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.8px;
}
table.data-table th, table.data-table td {
    padding: 11px 12px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data-table th {
    background: #f7f9fc;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 12.8px;
    position: sticky;
    top: 0;
}
table.data-table tbody tr:hover { background: #fafcff; }
table.data-table td.wrap { white-space: normal; }
.actions-cell { display: flex; gap: 4px; }

.empty-row td {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
}

/* -------------------- فرز الأعمدة + ترقيم الصفحات (لكل الجداول) -------------------- */
.th-sort { cursor: pointer; user-select: none; white-space: nowrap; transition: background 0.12s, color 0.12s; }
.th-sort:hover { color: var(--primary); background: #eaf2fd; }
/* مؤشر دائم يوضّح أن العمود قابل للفرز */
.th-sort .sort-caret::after { content: '⇅'; opacity: 0.5; font-size: 12px; margin: 0 4px; }
/* العمود المفروز حالياً: خلفية زرقاء + خط عريض + سهم واضح */
.th-sort.sort-asc, .th-sort.sort-desc { background: #d6e8fb; color: var(--primary-dark); font-weight: 800; }
.th-sort.sort-asc .sort-caret::after { content: '▲'; opacity: 1; color: var(--primary); font-weight: 900; }
.th-sort.sort-desc .sort-caret::after { content: '▼'; opacity: 1; color: var(--primary); font-weight: 900; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--text-muted); }
.pager .pg-btn { padding: 5px 11px; border: 1px solid var(--border); border-radius: 7px; background: #fff; cursor: pointer; font-family: inherit; font-size: 13px; color: var(--text); }
.pager .pg-btn:hover:not(:disabled) { background: #eef1f5; }
.pager .pg-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pager .pg-info { margin: 0 6px; }

/* -------------------- Badges -------------------- */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.badge.gray { background: #eceff3; color: #546070; }
.badge.green { background: #e3f5e6; color: var(--success); }
.badge.red { background: #fce8e8; color: var(--danger); }
.badge.orange { background: #fff3d6; color: #b07800; }
.badge.blue { background: var(--primary-light); color: var(--primary-dark); }
.badge.teal { background: #d9f2ee; color: #00695c; }

.progress-bar-track {
    background: #eceff3;
    border-radius: 20px;
    height: 8px;
    width: 100%;
    overflow: hidden;
}
.progress-bar-fill { height: 100%; border-radius: 20px; background: var(--primary); }
.progress-bar-fill.full { background: var(--success); }
.progress-bar-fill.mid { background: var(--warning); }
.progress-bar-fill.low { background: var(--danger); }
.progress-label { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* -------------------- Modal -------------------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
    z-index: 200;
    animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    background: #fff;
    border-radius: 12px;
    max-width: 640px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    animation: slideDown 0.18s ease;
}
@keyframes slideDown { from { transform: translateY(-14px); opacity: 0;} to { transform: translateY(0); opacity: 1;} }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16.5px; color: var(--primary-dark); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px 22px; max-height: 65vh; overflow-y: auto; }
.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

/* -------------------- Toast -------------------- */

.toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.toast {
    background: #263238;
    color: #fff;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13.5px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    animation: fadeIn 0.2s ease;
    min-width: 220px;
}
.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }

/* -------------------- Misc -------------------- */

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list .badge { margin: 0; }

.report-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
@media (max-width: 900px) { .report-grid { grid-template-columns: 1fr; } }

.filter-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-tabs button {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-muted);
}
.filter-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.loading-row { text-align: center; padding: 24px; color: var(--text-muted); }

/* -------------------- Responsive -------------------- */

/* أجهزة لوحية والجوّال (آيباد عمودي وأصغر): قائمة جانبية منزلقة */
@media (max-width: 880px) {
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
    .sidebar {
        position: fixed;
        right: -100%;
        top: 0;
        transition: right 0.25s ease;
        box-shadow: 0 0 30px rgba(0,0,0,0.25);
    }
    .sidebar.open { right: 0; }
    .sidebar-overlay.open { display: block; }
    .topbar { padding: 12px 16px; padding-right: 62px; gap: 8px; }
    .topbar h1 { font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar-right { flex-shrink: 0; }
    .topbar-right { gap: 8px; }
    .topbar-date { display: none; }            /* التاريخ غير ضروري على الشاشات الصغيرة */
    .branch-switch { max-width: 150px; font-size: 12.5px; padding: 6px 10px; }
    .lang-switch-btn { padding: 6px 10px; }
    .page-content { padding: 16px; }
    .cards-grid { grid-template-columns: repeat(2, 1fr); }
    .modal-overlay { padding: 20px 12px; }
}

/* منع تكبير iOS التلقائي عند التركيز على الحقول (يتطلب حجم خط ≥ 16px) + لمس أسهل */
@media (max-width: 768px) {
    input, select, textarea { font-size: 16px; }
    .modal-body { max-height: 72vh; }
}

/* جوّال (شاشة متوسطة/صغيرة) */
@media (max-width: 560px) {
    html, body { font-size: 14.5px; }
    .cards-grid { grid-template-columns: 1fr; gap: 12px; }
    .stat-card { padding: 15px 16px; }
    .stat-icon { font-size: 24px; }
    .stat-value { font-size: 21px; }
    .panel { padding: 15px; }
    .user-name-label { display: none; }        /* نُبقي الصورة + شارة الدور فقط */
    .user-menu-btn { padding: 6px 8px; }
    .branch-switch { max-width: 128px; }
    .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }
    .modal-footer .btn { flex: 1 1 auto; justify-content: center; }  /* أزرار أوسع لللمس */
    .filter-tabs button { padding: 6px 11px; font-size: 12.5px; }
}

/* جوّال صغير جداً */
@media (max-width: 400px) {
    .page-content { padding: 12px; }
    .toolbar .grow { min-width: 140px; }
    .branch-switch { max-width: 108px; }
}

/* -------------------- Topbar user menu -------------------- */

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-menu { position: relative; }
.lang-switch-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: #f4f6f9;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 7px 13px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.lang-switch-btn:hover { background: #eceff3; }
.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f4f6f9;
    border: 1px solid var(--border);
    border-radius: 30px;
    padding: 6px 14px 6px 8px;
    cursor: pointer;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
}
.user-menu-btn:hover { background: #eceff3; }
.user-avatar { font-size: 16px; }
.user-name-label { font-weight: 600; }

.user-menu-dropdown {
    display: none;
    position: absolute;
    left: 0;
    top: calc(100% + 8px);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    min-width: 190px;
    z-index: 60;
    overflow: hidden;
}
.user-menu-dropdown.open { display: block; }
.user-menu-dropdown button, .user-menu-dropdown a {
    display: block;
    width: 100%;
    text-align: right;
    padding: 11px 16px;
    background: none;
    border: none;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
}
.user-menu-dropdown button:hover, .user-menu-dropdown a:hover { background: #f4f6f9; }

/* -------------------- Viewer mode (إخفاء أزرار التعديل) -------------------- */

.viewer-mode .icon-btn.edit,
.viewer-mode .icon-btn.delete,
.viewer-mode #btnAddProgram,
.viewer-mode #btnAddJob,
.viewer-mode #btnAddEmployee,
.viewer-mode #btnAddUser,
.viewer-mode #btnAddExtraCourse,
.viewer-mode #btnUploadIdPhoto,
.viewer-mode #btnAddDocument,
.viewer-mode .edit-only {
    display: none !important;
}

/* -------------------- Login page -------------------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0d47a1, #1565c0 60%, #00897b);
}
.login-wrap { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
    background: #fff;
    border-radius: 14px;
    padding: 34px 30px;
    box-shadow: 0 15px 45px rgba(0,0,0,0.25);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.login-brand .brand-icon { font-size: 34px; }
.login-brand .brand-title { font-weight: 700; font-size: 16px; color: var(--primary-dark); }
.login-brand .brand-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.login-alert {
    background: #fce8e8;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13.5px;
    margin-bottom: 16px;
}
.login-form .field { margin-bottom: 16px; }
.login-footer {
    text-align: center;
    color: rgba(255,255,255,0.85);
    font-size: 12.5px;
    margin-top: 18px;
}

/* -------------------- Employee profile / documents -------------------- */

.profile-header {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}
.id-photo-box {
    width: 130px;
    height: 90px;
    border-radius: 8px;
    background: #eceff3;
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.id-photo-box img { width: 100%; height: 100%; object-fit: cover; }
.id-photo-box .placeholder { color: var(--text-muted); font-size: 12px; text-align: center; padding: 6px; }

.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}
.doc-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #fafcff;
}
.doc-card .doc-icon { font-size: 26px; }
.doc-card .doc-title { font-weight: 600; font-size: 13.5px; margin: 8px 0 3px; }
.doc-card .doc-meta { font-size: 11.5px; color: var(--text-muted); }
.doc-card .doc-actions { display: flex; gap: 6px; margin-top: 10px; }

/* جرس الإشعارات في الشريط العلوي (تأكيد الدورات من مدراء الأقسام/الفروع) */
.notif-bell { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; text-decoration: none; font-size: 18px; line-height: 1; color: inherit; transition: background .15s; }
.notif-bell:hover { background: rgba(0, 0, 0, 0.06); }
.notif-badge { position: absolute; top: 3px; inset-inline-end: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: #e53935; color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; box-shadow: 0 0 0 2px var(--surface, #fff); }

