/* ============================================================================
   منصة الإشراف على مسابقة المحاظر - التصميم العام
   طراز إسلامي أنيق: أخضر داكن، ذهبي، زخارف هندسية (خاتم/نجمة ثمانية)
   ========================================================================== */

:root {
    --green:       #0b5d3b;
    --green-dark:  #07402a;
    --green-deep:  #052e1e;
    --green-soft:  #e7f2ec;
    --gold:        #c9a227;
    --gold-light:  #e6cf7d;
    --gold-soft:   #faf3dd;
    --paper:       #faf8f2;
    --card:        #ffffff;
    --ink:         #1d2b23;
    --ink-soft:    #5a6b61;
    --danger:      #9b2c2c;
    --danger-soft: #fdecec;
    --info-soft:   #eaf3fb;
    --radius:      14px;
    --shadow:      0 4px 24px rgba(11, 93, 59, 0.10);
    --shadow-lg:   0 10px 40px rgba(11, 93, 59, 0.16);
    --font-body:   'Tajawal', Tahoma, Arial, sans-serif;
    --font-title:  'Amiri', 'Tajawal', serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* خلفية الزخرفة الهندسية (نجمة ثمانية متكررة) */
.pattern-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background-color: var(--paper);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='88' height='88'><g fill='none' stroke='%23c9a227' stroke-opacity='0.13' stroke-width='1'><rect x='18' y='18' width='52' height='52'/><rect x='18' y='18' width='52' height='52' transform='rotate(45 44 44)'/><circle cx='44' cy='44' r='7'/></g><g fill='none' stroke='%230b5d3b' stroke-opacity='0.07' stroke-width='1'><circle cx='0' cy='0' r='14'/><circle cx='88' cy='0' r='14'/><circle cx='0' cy='88' r='14'/><circle cx='88' cy='88' r='14'/></g></svg>");
}

/* أمواج إسلامية متحركة (أقواس متعانقة) أسفل الخلفية الرئيسية */
@keyframes waveDriftR {
    from { background-position-x: 0; }
    to   { background-position-x: 480px; }
}
@keyframes waveDriftL {
    from { background-position-x: 0; }
    to   { background-position-x: -480px; }
}
body:not(.login-page) .pattern-bg::before,
body:not(.login-page) .pattern-bg::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background-repeat: repeat-x;
    background-position: bottom;
}
body:not(.login-page) .pattern-bg::before {
    height: 170px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='170'><g fill='none' stroke='%23c9a227' stroke-opacity='0.55' stroke-width='1.6'><path d='M-10 145 Q30 70 60 145 T130 145 T200 145 T270 145'/><path d='M-10 158 Q30 88 60 158 T130 158 T200 158 T270 158'/></g><g fill='%23c9a227' fill-opacity='0.55'><circle cx='60' cy='82' r='2.6'/><circle cx='200' cy='82' r='2.6'/></g></svg>");
    animation: waveDriftR 60s linear infinite;
    opacity: .6;
}
body:not(.login-page) .pattern-bg::after {
    height: 125px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='125'><g fill='none' stroke='%230b5d3b' stroke-opacity='0.45' stroke-width='1.6'><path d='M-10 105 Q50 45 110 105 T230 105 T350 105'/><path d='M-10 118 Q50 62 110 118 T230 118 T350 118'/></g><g fill='%230b5d3b' fill-opacity='0.5'><path d='M110 58 l5 8 -5 8 -5 -8 z'/></g></svg>");
    animation: waveDriftL 85s linear infinite;
    opacity: .55;
}

/* ============================== الحركات ================================= */

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
    50%      { transform: translateX(-2px); }
}
@keyframes pulseDot {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}
@keyframes spinSlow {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
@keyframes shimmer {
    0%   { background-position: 200% center; }
    100% { background-position: -200% center; }
}

.fade-up  { animation: fadeUp .7s cubic-bezier(.22,.8,.35,1) both; animation-delay: var(--d, 0s); }
.fade-in  { animation: fadeIn .5s ease both; }
.shake    { animation: shake .6s ease; }
.pulse    { animation: pulseDot 1.6s ease-in-out infinite; }

/* ============================ الشريط العلوي ============================== */

/* تدرج لوني متحرك بلطف بين ألوان الواجهة */
@keyframes topbarGradient {
    0%   { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}
.topbar {
    background: linear-gradient(120deg,
        var(--green-deep) 0%,
        var(--green-dark) 22%,
        #116644 40%,
        #2a7a52 52%,
        #6d7a35 63%,
        #116644 76%,
        var(--green-dark) 90%,
        var(--green-deep) 100%);
    background-size: 320% 100%;
    animation: topbarGradient 26s ease-in-out infinite alternate;
    color: #fff;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 40;
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 22px;
    flex-wrap: wrap;
}
.topbar-ornament {
    height: 7px;
    background:
        linear-gradient(90deg, var(--gold) 0%, var(--gold-light) 25%, var(--gold) 50%, var(--gold-light) 75%, var(--gold) 100%);
    background-size: 200% 100%;
    animation: shimmer 8s linear infinite;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #fff;
}
.brand-emblem img,
.brand-emblem svg { display: block; filter: drop-shadow(0 2px 6px rgba(0,0,0,.35)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.brand-text strong { font-family: var(--font-title); font-size: 1.12rem; letter-spacing: .3px; }
.brand-text small  { color: var(--gold-light); font-size: .78rem; }

.mainnav {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-inline-start: auto;
}
.mainnav a {
    color: #dfe9e3;
    text-decoration: none;
    font-weight: 500;
    font-size: .95rem;
    padding: 8px 14px;
    border-radius: 10px;
    transition: background .25s, color .25s, transform .2s;
    position: relative;
}
.mainnav a:hover { background: rgba(255,255,255,.1); color: #fff; transform: translateY(-1px); }
.mainnav a.active {
    background: rgba(201,162,39,.18);
    color: var(--gold-light);
}
.mainnav a.active::after {
    content: '✦';
    position: absolute;
    bottom: -4px;
    right: 50%;
    transform: translateX(50%);
    font-size: .55rem;
    color: var(--gold);
}

.userbox { display: flex; align-items: center; gap: 12px; }
.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(201,162,39,.4);
    border-radius: 30px;
    padding: 4px 16px 4px 12px;
    line-height: 1.3;
}
.user-icon { font-size: 1.25rem; }
.user-chip strong { display: block; font-size: .88rem; }
.user-chip small  { color: var(--gold-light); font-size: .72rem; }

/* ============================== الحاوية ================================= */

.container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 30px 24px 50px;
    flex: 1;
}

.page-head { margin-bottom: 24px; }
.page-head h1 {
    font-family: var(--font-title);
    color: var(--green-dark);
    font-size: 2rem;
    position: relative;
    display: inline-block;
    padding-bottom: 4px;
}
.page-head h1::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 60%;
    height: 3px;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--gold), transparent);
}
.page-sub { color: var(--ink-soft); margin-top: 6px; }

.page-head-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}

/* ============================== البطاقات ================================ */

.panel {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid #e8e4d8;
    box-shadow: var(--shadow);
    padding: 26px 28px;
    margin-bottom: 26px;
    position: relative;
    overflow: hidden;
}
.panel::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--green), var(--gold), var(--green));
    opacity: .75;
}

.panel-head { text-align: center; margin-bottom: 22px; }
.panel-head h2 {
    font-family: var(--font-title);
    color: var(--green-dark);
    font-size: 1.35rem;
}

.ornament-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--gold);
    font-size: 1.1rem;
    margin-top: 2px;
    user-select: none;
}
.ornament-divider::before,
.ornament-divider::after {
    content: '';
    width: 90px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold));
}
.ornament-divider::after { background: linear-gradient(90deg, var(--gold), transparent); }
.ornament-divider.small { font-size: .85rem; }
.ornament-divider.small::before, .ornament-divider.small::after { width: 50px; }
.orn-star { animation: spinSlow 14s linear infinite; display: inline-block; }

.two-col {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 26px;
    align-items: start;
}
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

/* ========================= البطاقات الإحصائية =========================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card);
    border: 1px solid #e8e4d8;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform .3s, box-shadow .3s;
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    left: -28px;
    bottom: -28px;
    width: 92px;
    height: 92px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M50 5 L59 32 L88 32 L65 49 L73 78 L50 60 L27 78 L35 49 L12 32 L41 32 Z' fill='none' stroke='%23c9a227' stroke-opacity='0.25' stroke-width='2'/></svg>");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: .8;
    pointer-events: none;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    flex-shrink: 0;
}
.icon-green { background: var(--green-soft); }
.icon-gold  { background: var(--gold-soft); }

.stat-value {
    display: block;
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--green-dark);
    line-height: 1.2;
}
.stat-value small { font-size: 1rem; color: var(--ink-soft); font-weight: 500; }
.stat-label { color: var(--ink-soft); font-size: .88rem; }
.stat-label small { color: var(--gold); }

/* ========================= بطاقات المستويات ============================== */

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
}
.level-card {
    border: 1px solid #e2ddcf;
    border-radius: var(--radius);
    padding: 20px;
    background:
        linear-gradient(180deg, #fdfcf8, #f7f4ea);
    transition: transform .3s, box-shadow .3s;
}
.level-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.level-card-warn { background: linear-gradient(180deg, #fdf8ef, #faf0dd); }

.level-badge {
    display: inline-block;
    font-family: var(--font-title);
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--green-dark), var(--green));
    border-radius: 24px;
    padding: 4px 18px;
    font-size: 1.02rem;
    margin-bottom: 14px;
    box-shadow: 0 3px 10px rgba(11,93,59,.3);
}
.badge-warn { background: linear-gradient(135deg, #8a6d1a, var(--gold)); }

.level-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 8px;
    text-align: center;
    margin-bottom: 14px;
}
.lv-num { display: block; font-size: 1.35rem; font-weight: 800; color: var(--green-dark); }
.lv-lbl { font-size: .74rem; color: var(--ink-soft); }

.level-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    font-size: .84rem;
    color: var(--ink-soft);
}

/* ========================== أشرطة التقدم ================================ */

.progress-track {
    background: #e9e5d8;
    border-radius: 20px;
    height: 12px;
    overflow: hidden;
    flex: 1;
}
.progress-track.slim { height: 8px; }
.progress-fill {
    height: 100%;
    width: var(--w, 0%);
    border-radius: 20px;
    background: linear-gradient(90deg, var(--green), #17925e);
    position: relative;
    transition: width 1.2s cubic-bezier(.25,.8,.35,1);
}
.progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
    background-size: 200% 100%;
    animation: shimmer 2.5s linear infinite;
}
.fill-warn { background: linear-gradient(90deg, #b07f1d, var(--gold)); }

/* ============================= الجداول ================================== */

.table-wrap { overflow-x: auto; border-radius: 10px; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
    min-width: 640px;
}
.table thead th {
    background: linear-gradient(135deg, var(--green-dark), var(--green));
    color: #fff;
    padding: 11px 12px;
    text-align: center;
    font-weight: 700;
    white-space: nowrap;
    position: sticky;
    top: 0;
}
.table thead th:first-child { border-radius: 0 10px 0 0; }
.table thead th:last-child  { border-radius: 10px 0 0 0; }
.table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee9dc;
    text-align: center;
    vertical-align: middle;
}
.table tbody tr { transition: background .2s; }
.table tbody tr:hover { background: var(--green-soft); }

/* أعمدة قابلة للترتيب بالنقر (تصاعدي ثم تنازلي) */
.table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background .2s;
}
.table thead th.sortable::after {
    content: '⇅';
    display: inline-block;
    margin-inline-start: 6px;
    font-size: .72rem;
    opacity: .5;
    transition: opacity .2s;
}
.table thead th.sortable:hover { background: var(--green-dark); }
.table thead th.sortable:hover::after { opacity: .9; }
.table thead th.sortable.sort-asc::after {
    content: '▲';
    opacity: 1;
    color: var(--gold-light);
}
.table thead th.sortable.sort-desc::after {
    content: '▼';
    opacity: 1;
    color: var(--gold-light);
}

.cell-strong { font-weight: 700; color: var(--green-dark); }
.cell-id     { color: var(--ink-soft); font-size: .82rem; }
.cell-sub    { display: block; color: var(--ink-soft); font-size: .76rem; }
.cell-date   { font-size: .82rem; color: var(--ink-soft); white-space: nowrap; }
.cell-progress { min-width: 130px; }
.cell-progress small { color: var(--ink-soft); font-size: .76rem; }
.cell-actions { white-space: nowrap; }
.cell-actions form { display: inline-block; }
.cell-mini-rates { white-space: nowrap; }
.mini-rate {
    display: inline-block;
    background: var(--gold-soft);
    border: 1px solid #eaddb2;
    color: #7a621a;
    font-size: .74rem;
    border-radius: 8px;
    padding: 1px 8px;
    margin: 1px 2px;
}

/* الشارات */
.rate-badge {
    display: inline-block;
    border-radius: 20px;
    padding: 2px 12px;
    font-weight: 700;
    font-size: .85rem;
}
.rate-good { background: var(--green-soft); color: var(--green-dark); }
.rate-mid  { background: var(--gold-soft);  color: #7a621a; }
.rate-low  { background: var(--danger-soft); color: var(--danger); }

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-weight: 800;
    font-size: .9rem;
    background: #eef1ea;
    color: var(--ink-soft);
}
.rank-1 { background: linear-gradient(135deg, #f5d54c, var(--gold)); color: #4d3d05; box-shadow: 0 2px 8px rgba(201,162,39,.5); }
.rank-2 { background: linear-gradient(135deg, #e3e6e8, #b9c1c7); color: #3d444a; }
.rank-3 { background: linear-gradient(135deg, #e8c39a, #c68f57); color: #4d3014; }

.grade-badge {
    display: inline-block;
    background: var(--green-soft);
    color: var(--green-dark);
    font-weight: 800;
    border-radius: 10px;
    padding: 3px 14px;
    border: 1px solid #cfe4d9;
}
.grade-badge.grade-fail { background: var(--danger-soft); color: var(--danger); border-color: #f2d4d4; }
.grade-empty { color: #b3aa93; font-size: .82rem; }

.status-badge {
    display: inline-block;
    border-radius: 20px;
    padding: 2px 12px;
    font-size: .8rem;
    font-weight: 700;
    white-space: nowrap;
}
.status-open   { background: var(--green-soft); color: var(--green-dark); }
.status-closed { background: var(--danger-soft); color: var(--danger); }
.status-none   { background: #f0ede4; color: #8b8878; }

/* ============================= الأزرار =================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: .92rem;
    border: none;
    border-radius: 10px;
    padding: 10px 22px;
    cursor: pointer;
    text-decoration: none;
    transition: transform .2s, box-shadow .25s, background .25s;
    line-height: 1.4;
}
.btn:active { transform: scale(.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--green-dark), var(--green));
    color: #fff;
    box-shadow: 0 4px 14px rgba(11,93,59,.35);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(11,93,59,.5); transform: translateY(-2px); }

.btn-gold {
    background: linear-gradient(135deg, #a8861c, var(--gold));
    color: #fff;
    box-shadow: 0 4px 14px rgba(201,162,39,.4);
}
.btn-gold:hover { box-shadow: 0 6px 20px rgba(201,162,39,.55); transform: translateY(-2px); }

.btn-danger {
    background: linear-gradient(135deg, #7c1d1d, var(--danger));
    color: #fff;
}
.btn-danger:hover { box-shadow: 0 5px 16px rgba(155,44,44,.45); transform: translateY(-2px); }

.btn-ghost {
    background: transparent;
    color: var(--green-dark);
    border: 1.5px solid #c9d6cd;
}
.btn-ghost:hover { background: var(--green-soft); border-color: var(--green); }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); border-color: #fff; }

.btn-sm { padding: 5px 13px; font-size: .8rem; border-radius: 8px; }
.btn-lg { padding: 13px 30px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-arrow { transition: transform .3s; }
.btn:hover .btn-arrow { transform: translateX(-5px); }

/* ============================= النماذج ================================== */

.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: .88rem; color: var(--green-dark); }
.req { color: var(--danger); }

input[type=text], input[type=password], input[type=number], select {
    font-family: var(--font-body);
    font-size: .95rem;
    padding: 10px 14px;
    border: 1.5px solid #d9d4c3;
    border-radius: 10px;
    background: #fffdf8;
    color: var(--ink);
    transition: border-color .25s, box-shadow .25s;
    width: 100%;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(11,93,59,.13);
}

.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}
.filter-bar .field { margin-bottom: 0; min-width: 170px; }
.filter-bar .field-grow { flex: 1; min-width: 240px; }
.filter-bar .btn { margin-bottom: 1px; }
.filter-bar.grow { flex: 1; }

.inline-form { display: inline-block; }
.pw-form {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    align-items: center;
}
.pw-form input { max-width: 200px; padding: 6px 10px; font-size: .84rem; }

/* رفع الملفات */
.file-drop { position: relative; }
.file-drop input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}
.file-drop-inner {
    border: 2px dashed #cbc396;
    border-radius: var(--radius);
    background: var(--gold-soft);
    padding: 30px 18px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color .25s, background .25s, transform .2s;
}
.file-drop:hover .file-drop-inner,
.file-drop.dragover .file-drop-inner {
    border-color: var(--gold);
    background: #f6ecc9;
    transform: scale(1.01);
}
.file-icon { font-size: 2rem; }
.file-text { color: #7a621a; font-weight: 500; }
.file-name { color: var(--green-dark); font-weight: 800; font-size: .9rem; min-height: 1.2em; }

.hint-box {
    background: var(--green-soft);
    border: 1px solid #cfe4d9;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: .86rem;
    color: #2c4a3b;
    margin-bottom: 16px;
}

/* ============================= التنبيهات ================================ */

.alert {
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 12px;
    padding: 13px 18px;
    margin-bottom: 18px;
    font-weight: 500;
    border: 1px solid transparent;
}
.alert-icon { font-size: 1.05rem; }
.alert-success { background: var(--green-soft); color: var(--green-dark); border-color: #bcdccb; }
.alert-error   { background: var(--danger-soft); color: var(--danger); border-color: #f0cdcd; }
.alert-info    { background: var(--info-soft); color: #245a83; border-color: #cbe0f0; }

.empty-note { text-align: center; color: var(--ink-soft); padding: 26px 10px; }

/* ======================= مؤشر الموثوقية (Gauge) ========================= */

.gauge-wrap, .empty-gauge { text-align: center; }
.gauge { width: 230px; max-width: 100%; }
.gauge-track { stroke: #ece7d8; }
.gauge-arc {
    stroke-dasharray: 251;
    stroke-dashoffset: 251;
    transition: stroke-dashoffset 1.6s cubic-bezier(.25,.8,.35,1);
}
.gauge-good .gauge-arc { stroke: #17925e; }
.gauge-mid  .gauge-arc { stroke: var(--gold); }
.gauge-low  .gauge-arc { stroke: var(--danger); }
.gauge-value {
    font-family: var(--font-body);
    font-size: 26px;
    font-weight: 800;
    fill: var(--green-dark);
}
.gauge-label {
    font-weight: 800;
    font-size: 1.05rem;
    margin-top: -8px;
}
.gauge-label.gauge-good { color: #17925e; }
.gauge-label.gauge-mid  { color: #a8861c; }
.gauge-label.gauge-low  { color: var(--danger); }
.gauge-file { color: var(--ink-soft); font-size: .85rem; margin-top: 8px; }

.sub-title {
    font-family: var(--font-title);
    color: var(--green-dark);
    font-size: 1.05rem;
    margin: 20px 0 10px;
    border-inline-start: 4px solid var(--gold);
    padding-inline-start: 10px;
}

.field-bars { display: flex; flex-direction: column; gap: 8px; }
.field-bar-row { display: flex; align-items: center; gap: 12px; }
.fb-label { width: 105px; font-size: .82rem; color: var(--ink); flex-shrink: 0; }
.fb-pct   { width: 44px; font-size: .8rem; font-weight: 700; color: var(--green-dark); flex-shrink: 0; }

.issue-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.issue-list li {
    background: var(--gold-soft);
    border-inline-start: 3px solid var(--gold);
    border-radius: 8px;
    padding: 7px 14px;
    font-size: .86rem;
    color: #6b5514;
}

/* ======================== خلايا دورات المسابقة ========================== */

.table-sessions td.session-cell { padding: 8px; min-width: 210px; }
.session-box {
    border-radius: 12px;
    padding: 10px 12px;
    border: 1px solid #e6e1d1;
    background: #fcfbf6;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: box-shadow .25s;
}
.session-box:hover { box-shadow: var(--shadow); }
.status-box-open   { background: #f2faf6; border-color: #bfe0cf; }
.status-box-closed { background: #fdf6f6; border-color: #eccfcf; }
.session-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.session-count { color: var(--ink-soft); font-size: .74rem; }
.session-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ========================= تبويبات المستويات ============================ */

.level-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.level-tab {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    text-align: center;
    text-decoration: none;
    background: var(--card);
    border: 2px solid #e6e1d1;
    border-radius: var(--radius);
    padding: 16px;
    transition: transform .25s, border-color .25s, box-shadow .25s;
}
.level-tab:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.level-tab .tab-title {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1.12rem;
    color: var(--green-dark);
}
.level-tab.active {
    border-color: var(--gold);
    background: linear-gradient(180deg, #fffdf6, var(--gold-soft));
    box-shadow: var(--shadow);
}
.level-tab.active .tab-title::after { content: ' ✦'; color: var(--gold); }

/* ========================== شريط أدوات الوكيل =========================== */

.agent-toolbar {
    display: flex;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.agent-progress { min-width: 260px; flex: 1; }
.progress-caption { display: block; font-size: .84rem; color: var(--ink-soft); margin-bottom: 5px; }
.progress-caption strong { color: var(--green-dark); }

/* إدخال الدرجات */
.grade-input-wrap {
    display: flex;
    align-items: center;
    gap: 7px;
    justify-content: center;
}
.grade-input {
    width: 84px;
    text-align: center;
    font-weight: 800;
    font-size: 1rem;
    color: var(--green-dark);
    padding: 7px 8px;
}
.grade-input.changed { border-color: var(--gold); background: var(--gold-soft); }
.save-indicator { width: 22px; font-size: 1rem; }
.save-indicator.ok  { color: #17925e; animation: fadeIn .3s ease; }
.save-indicator.err { color: var(--danger); }
tr.row-saved { animation: rowFlash 1.2s ease; }
@keyframes rowFlash {
    0%   { background: #d8f3e5; }
    100% { background: transparent; }
}

.center-note { text-align: center; padding: 50px 20px; }
.big-icon { font-size: 3rem; margin-bottom: 10px; }
.center-note h2 { font-family: var(--font-title); color: var(--green-dark); }

/* ===================== الحضور والغياب وحصص النجاح ======================= */

.att-badge {
    display: inline-block;
    border-radius: 20px;
    padding: 2px 12px;
    font-size: .78rem;
    font-weight: 700;
    white-space: nowrap;
}
.att-present { background: var(--green-soft); color: var(--green-dark); }
.att-absent  { background: var(--danger-soft); color: var(--danger); }
.att-none    { background: #f0ede4; color: #8b8878; }

.att-toggle {
    font-family: var(--font-body);
    font-size: .8rem;
    font-weight: 700;
    border: 1.5px solid #d0cbb8;
    background: linear-gradient(180deg, #fbf9f2, #f1ede0);
    color: #8b8878;
    border-radius: 20px;
    padding: 4px 16px;
    cursor: pointer;
    transition: background .25s, color .25s, border-color .25s, transform .15s, box-shadow .25s;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.att-toggle::before { content: '◌ '; font-size: .72rem; }
.att-toggle:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.14); }
.att-toggle.is-present {
    background: linear-gradient(180deg, #edf8f2, var(--green-soft));
    color: var(--green-dark);
    border-color: #9fcdb4;
}
.att-toggle.is-present::before { content: '✔ '; }
.att-toggle.is-absent {
    background: linear-gradient(180deg, #fdf1f1, var(--danger-soft));
    color: var(--danger);
    border-color: #dda8a8;
}
.att-toggle.is-absent::before { content: '✖ '; }

tr.row-absent { opacity: .62; }
tr.row-absent .cell-strong { text-decoration: line-through; text-decoration-color: rgba(155,44,44,.5); }

.level-missing {
    display: inline-block;
    background: var(--gold-soft);
    border: 1px dashed var(--gold);
    color: #7a621a;
    font-size: .76rem;
    font-weight: 700;
    border-radius: 8px;
    padding: 1px 10px;
    white-space: nowrap;
}

.quota-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.quota-chip {
    background: var(--gold-soft);
    border: 1px solid #e6d9ae;
    color: #6b5514;
    border-radius: 20px;
    padding: 4px 16px;
    font-size: .84rem;
}
.quota-chip strong { color: var(--green-dark); }
.quota-chip-off { opacity: .55; }

.quota-badge {
    display: inline-block;
    background: linear-gradient(135deg, #f5e6b3, var(--gold-soft));
    border: 1px solid var(--gold);
    color: #6b5514;
    font-weight: 800;
    font-size: .78rem;
    border-radius: 20px;
    padding: 2px 12px;
    white-space: nowrap;
}
.quota-input { max-width: 150px; text-align: center; font-weight: 700; }
.quota-actions { text-align: center; margin-top: 18px; }

.level-tab.tab-unleveled { border-style: dashed; }

/* ===================== نافذة تعديل بيانات المترشح ======================= */

body.modal-open { overflow: hidden; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(7, 46, 30, .55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}
/* display:flex أعلاه يتغلب على سمة hidden: يجب إعادة الإخفاء صراحةً */
.modal-backdrop[hidden] { display: none; }
.modal-card {
    background: var(--card);
    border-radius: 18px;
    border: 1px solid #e6dfc9;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 24px 26px;
    position: relative;
}
.modal-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 5px;
    border-radius: 18px 18px 0 0;
    background: linear-gradient(90deg, var(--green), var(--gold), var(--green));
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-head h3 {
    font-family: var(--font-title);
    color: var(--green-dark);
    font-size: 1.2rem;
}
.modal-close {
    border: none;
    background: #f0ede4;
    color: var(--ink-soft);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    font-size: .95rem;
    transition: background .2s, color .2s;
}
.modal-close:hover { background: var(--danger-soft); color: var(--danger); }

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
}
.modal-grid .field-span { grid-column: 1 / -1; }
@media (max-width: 560px) { .modal-grid { grid-template-columns: 1fr; } }

.modal-error {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #f0cdcd;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: .86rem;
    margin: 6px 0;
}
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    margin-top: 14px;
}

/* نافذة التأكيد الأنيقة */
.confirm-card {
    max-width: 420px;
    text-align: center;
    padding: 28px 26px 22px;
}
.confirm-icon {
    width: 58px;
    height: 58px;
    margin: 0 auto 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
    background: var(--gold-soft);
    color: #a8861c;
    border: 2px solid var(--gold);
}
.confirm-msg {
    font-size: 1rem;
    font-weight: 500;
    color: var(--ink);
    white-space: pre-line;
    margin-bottom: 6px;
}
.confirm-actions { justify-content: center; }

/* ================= نافذة ضبط المقبولين على الحصة (القرعة) ================ */

.qa-card { max-width: 720px; }
.qa-meter {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.qa-meter-chip {
    border-radius: 20px;
    padding: 6px 18px;
    font-weight: 800;
    font-size: .95rem;
    border: 2px solid transparent;
    transition: background .25s, color .25s, border-color .25s;
}
.qa-meter-chip.qa-ok    { background: var(--green-soft); color: var(--green-dark); border-color: #9fcdb4; }
.qa-meter-chip.qa-over  { background: var(--danger-soft); color: var(--danger); border-color: #dda8a8; }
.qa-meter-chip.qa-under { background: var(--gold-soft); color: #8a6d1a; border-color: #e6d9ae; }
.qa-hint { font-size: .8rem; color: var(--ink-soft); flex: 1; min-width: 180px; }

.qa-groups {
    max-height: 46vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 2px;
}
.qa-group {
    border: 1px solid #e6e1d1;
    border-radius: 12px;
    background: #fcfbf6;
    padding: 10px 14px;
}
.qa-group-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.qa-group-count { font-size: .8rem; color: var(--ink-soft); }
.qa-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .2s, opacity .2s;
}
.qa-row:hover { background: var(--green-soft); }
.qa-row.qa-off { opacity: .5; }
.qa-row.qa-off .qa-name { text-decoration: line-through; text-decoration-color: rgba(155,44,44,.5); }
.qa-check { width: 17px; height: 17px; accent-color: var(--green); flex-shrink: 0; }
.qa-num { font-weight: 700; color: var(--green-dark); min-width: 64px; }
.qa-name { flex: 1; }

/* أزرار رأس الصفحة */
.head-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

/* ============================ ترقيم الصفحات ============================= */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-top: 22px;
}
.page-link {
    background: var(--card);
    border: 1.5px solid #d9d4c3;
    border-radius: 10px;
    color: var(--green-dark);
    font-weight: 700;
    text-decoration: none;
    padding: 7px 18px;
    transition: background .2s, border-color .2s;
}
.page-link:hover { background: var(--green-soft); border-color: var(--green); }
.page-info { color: var(--ink-soft); font-size: .9rem; }

/* ============================== التذييل ================================= */

.footer {
    text-align: center;
    padding: 26px 20px 30px;
    color: var(--ink-soft);
    font-size: .86rem;
    border-top: 1px solid #e8e3d4;
    background: linear-gradient(180deg, transparent, rgba(201,162,39,.05));
}
.footer-ornament { color: var(--gold); font-size: 1rem; margin-bottom: 6px; }
.footer-ministry { color: var(--green-dark); font-weight: 700; }

/* ========================== صفحة تسجيل الدخول =========================== */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}
.login-stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.rotating-star { position: absolute; }
.rotating-star.star-1 { top: -90px; left: -90px; animation: spinSlow 60s linear infinite; }
.rotating-star.star-2 { bottom: -60px; right: -60px; animation: spinSlow 45s linear infinite reverse; }

.login-wrap { position: relative; z-index: 1; width: 100%; max-width: 480px; padding: 24px; }
.login-card {
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(6px);
    border-radius: 22px;
    border: 1px solid #e6dfc9;
    box-shadow: 0 18px 60px rgba(11,93,59,.22);
    padding: 40px 38px 34px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.login-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--green), var(--gold), var(--green));
    background-size: 200% 100%;
    animation: shimmer 6s linear infinite;
}
.login-emblem { margin-bottom: 10px; }
.login-emblem svg { filter: drop-shadow(0 4px 12px rgba(11,93,59,.3)); }

/* الشعار الرسمي (أرموارية الجمهورية) */
.armoirie { display: inline-block; }
.armoirie-login {
    filter: drop-shadow(0 6px 18px rgba(208,30,37,.28));
    animation: emblemIn 1s cubic-bezier(.22,.8,.35,1) both;
}
@keyframes emblemIn {
    from { opacity: 0; transform: scale(.6) rotate(-8deg); }
    to   { opacity: 1; transform: scale(1) rotate(0); }
}
.login-republic {
    font-family: var(--font-title);
    font-size: 1.3rem;
    color: var(--green-dark);
}
.login-motto {
    color: var(--gold);
    font-family: var(--font-title);
    font-weight: 700;
    font-size: .95rem;
}
.login-ministry {
    font-family: var(--font-title);
    font-size: 1.12rem;
    color: var(--green-dark);
    margin-top: 4px;
}
.login-app {
    color: var(--ink-soft);
    font-size: .92rem;
    font-weight: 500;
    margin: 4px 0 22px;
}
.login-form { text-align: right; }
.login-footer {
    text-align: center;
    color: var(--ink-soft);
    font-size: .8rem;
    margin-top: 18px;
}

/* ==================== لمسات عامة (تحديد، تركيز، تمرير) =================== */

::selection { background: rgba(201,162,39,.35); color: var(--green-deep); }

a:focus-visible, button:focus-visible, .btn:focus-visible {
    outline: 3px solid rgba(201,162,39,.55);
    outline-offset: 2px;
    border-radius: 10px;
}

.table-wrap {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--gold) #f0ece0;
}
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: #f0ece0; border-radius: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 8px; }

/* عند طباعة شاشات الإدارة من المتصفح: يُخفى الرقم الوطني تلقائياً */
@media print {
    .col-nid { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* ============================= استجابة ================================== */

/* شاشات متوسطة (لوحات) */
@media (max-width: 1000px) {
    .mainnav { gap: 2px; }
    .mainnav a { padding: 7px 10px; font-size: .88rem; }
    .stat-value { font-size: 1.6rem; }
}

/* هواتف وشاشات صغيرة */
@media (max-width: 760px) {
    .container { padding: 18px 12px 40px; }
    .panel { padding: 20px 14px; margin-bottom: 18px; }
    .page-head h1 { font-size: 1.55rem; }
    .page-sub { font-size: .88rem; }

    /* الشريط العلوي: صفان (الشعار + المستخدم، ثم قائمة قابلة للتمرير) */
    .topbar-inner { padding: 8px 12px; gap: 10px; }
    .brand { flex: 1; min-width: 0; }
    .brand-emblem img { width: 38px; height: 38px; }
    .brand-text strong { font-size: .95rem; }
    .brand-text small  { font-size: .68rem; }
    .brand-text strong, .brand-text small {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .userbox { margin-inline-start: auto; flex-shrink: 0; }
    .user-chip { padding: 3px 12px 3px 10px; }
    .user-chip .user-icon { display: none; }
    .user-chip strong {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .mainnav {
        order: 3;
        width: 100%;
        margin-inline-start: 0;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .mainnav::-webkit-scrollbar { display: none; }
    .mainnav a { white-space: nowrap; flex-shrink: 0; }

    /* الشبكات والبطاقات */
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
    .stat-card { padding: 14px; gap: 10px; }
    .stat-icon { width: 44px; height: 44px; font-size: 1.3rem; border-radius: 11px; }
    .stat-value { font-size: 1.35rem; }
    .stat-label { font-size: .78rem; }
    .level-grid { gap: 14px; }
    .two-col { gap: 18px; }

    /* الجداول: خط أصغر + تمرير أفقي سلس */
    .table { font-size: .84rem; min-width: 560px; }
    .table thead th { padding: 9px 8px; }
    .table tbody td { padding: 8px 8px; }

    /* النماذج وشريط الفلاتر */
    .filter-bar { align-items: stretch; }
    .filter-bar .field { min-width: 100%; }
    .filter-bar .field-grow { min-width: 100%; }
    .filter-bar .btn { width: 100%; }
    .agent-toolbar { flex-direction: column; align-items: stretch; gap: 14px; }
    .agent-progress { min-width: 0; }

    /* دورات المسابقة */
    .session-actions .btn { flex: 1; }

    /* ترقيم الصفحات */
    .pagination { gap: 10px; flex-wrap: wrap; }
}

/* هواتف صغيرة جداً */
@media (max-width: 420px) {
    .login-wrap { padding: 12px; }
    .login-card { padding: 28px 18px 26px; border-radius: 16px; }
    .login-republic { font-size: 1.08rem; }
    .login-ministry { font-size: .98rem; }
    .armoirie-login { width: 96px; height: 96px; }
    .rotating-star.star-1 { width: 240px; height: 240px; }
    .rotating-star.star-2 { width: 160px; height: 160px; }
    .page-head h1 { font-size: 1.35rem; }
    .level-stats { grid-template-columns: repeat(2, 1fr); }
    .btn-lg { padding: 12px 20px; font-size: .98rem; }
    .cell-actions .btn { margin-bottom: 4px; }
}
