:root{--ink:#12263F;--paper:#F1F4F7;--card:#fff;--line:#DCE3EA;--muted:#5D6D7E;--in:#0E8F6F;--out:#C2432D;--amber:#B7791F;--blue:#2B5FAE;--r:14px}
*{box-sizing:border-box}
body{margin:0;background:var(--paper);color:var(--ink);font-family:Cairo,Tahoma,sans-serif;font-size:16px;line-height:1.6;padding-bottom:84px}
a{color:var(--blue)}
h2{font-size:22px;margin:8px 0 14px}
h3{font-size:17px;margin:0 0 10px}
.wrap{width:100%;max-width:none;margin:0;padding:16px clamp(12px,2vw,28px)}
.topbar{background:var(--ink);color:#fff;display:flex;align-items:center;justify-content:space-between;padding:10px 16px;padding-top:calc(10px + env(safe-area-inset-top))}
.brand{font-weight:800;font-size:18px}
.brand{display:flex;align-items:center;gap:10px;min-width:0}
.brand img{display:block;width:46px;height:46px;flex:0 0 46px;object-fit:contain;border-radius:12px;background:#fff}
.brand span{line-height:1.3}
.who{display:flex;gap:12px;align-items:center;font-size:14px}
.who form{margin:0}
@media(max-width:520px){.topbar{gap:10px;flex-wrap:wrap}.brand{font-size:15px}.brand img{width:40px;height:40px;flex-basis:40px}.who{margin-inline-start:auto}}
button.link{background:none;border:1px solid rgba(255,255,255,.4);color:#fff;border-radius:8px;padding:2px 12px;font:inherit;font-size:13px;cursor:pointer}
.nav{position:fixed;bottom:0;inset-inline:0;background:#fff;border-top:1px solid var(--line);display:flex;padding-bottom:env(safe-area-inset-bottom);z-index:20}
.nav a{flex:1;display:flex;flex-direction:column;align-items:center;gap:2px;padding:8px 2px;color:var(--muted);text-decoration:none;font-size:12px;font-weight:600}
.nav svg{width:22px;height:22px}
.nav a.on{color:var(--ink);box-shadow:inset 0 3px 0 var(--in)}
@media(min-width:800px){
 body{padding-bottom:0}
 .nav{position:static;background:transparent;border:0;width:100%;max-width:none;margin:12px 0 0;padding:0 clamp(12px,2vw,28px);gap:6px}
 .nav a{flex:0 0 auto;flex-direction:row;gap:8px;padding:6px 14px;border-radius:10px;font-size:14px}
 .nav a.on{background:var(--ink);color:#fff;box-shadow:none}
}
:focus-visible{outline:3px solid #7FB2F0;outline-offset:2px}
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:16px;margin-bottom:16px}
[data-live-section="tasks-table"] {
    animation: none !important;
    transition: none !important;
}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;margin-bottom:16px}
.stat{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:12px 14px}
.stat b{display:block;font-size:28px;font-weight:800;line-height:1.2}
.stat span{color:var(--muted);font-size:14px}
.btn{display:inline-block;border:0;border-radius:10px;padding:10px 16px;font:inherit;font-weight:600;font-size:15px;cursor:pointer;text-align:center;text-decoration:none;background:var(--ink);color:#fff}
.btn.primary{background:var(--in)}
.btn.danger{background:var(--out)}
.btn.warn{background:#E8B339;color:#3b2a00}
.btn.ghost{background:#fff;color:var(--ink);border:1px solid var(--line)}
.btn.wide{width:100%}
.btn.sm{padding:5px 12px;font-size:13px}
.btn:disabled{opacity:.55;cursor:wait}
.row{display:flex;gap:10px;flex-wrap:wrap}
.row>*{flex:1}
.badge{display:inline-block;padding:1px 10px;border-radius:999px;font-size:13px;font-weight:600;background:#E6ECF2;color:var(--ink)}
.badge.in,.badge.done{background:#D8F2EA;color:#0A6B52}
.badge.out,.badge.rejected,.badge.late{background:#F9DED8;color:#9A3220}
.badge.pending,.badge.warn{background:#FBEBC8;color:#7A5210}
.badge.progress{background:#DCE8F8;color:#1F4A8A}
.alert{padding:10px 14px;border-radius:10px;margin-bottom:14px;font-weight:600}
.alert.ok{background:#D8F2EA;color:#0A6B52}
.alert.err{background:#F9DED8;color:#9A3220}
.form label{display:block;font-weight:600;font-size:14px;margin:10px 0 4px}
input,select,textarea{width:100%;padding:10px;border:1px solid #C5CFDA;border-radius:10px;font:inherit;background:#fff;color:var(--ink)}
textarea{resize:vertical}
.scroll{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:14px}
th,td{padding:8px 10px;text-align:start;border-bottom:1px solid var(--line);vertical-align:middle;white-space:nowrap}
td.wrap-txt{white-space:normal;min-width:160px}
th{background:#EAF0F5;font-weight:700}
td.empty{text-align:center;color:var(--muted);padding:20px}
.thumb{width:44px;height:44px;object-fit:cover;border-radius:8px;border:1px solid var(--line);vertical-align:middle}
.proof{display:flex;gap:8px;align-items:center}
.map{font-size:13px}
.login{max-width:380px;margin:12vh auto 0}
.login h2{text-align:center}
.login input[name=pin]{letter-spacing:6px;text-align:center;font-size:20px}
/* شاشة الحضور */
.punch-card{text-align:center;background:var(--card);border:1px solid var(--line);border-radius:22px;padding:22px 16px;margin-bottom:16px}
.clock{font-size:44px;font-weight:800;font-variant-numeric:tabular-nums;line-height:1.2}
.date{color:var(--muted);font-size:14px}
.state{margin:8px 0 0;font-weight:600}
.punch{width:210px;height:210px;border-radius:50%;border:0;color:#fff;font:inherit;margin:18px auto 16px;display:flex;flex-direction:column;align-items:center;justify-content:center;cursor:pointer}
.punch.check_in{background:var(--in);box-shadow:0 0 0 10px rgba(14,143,111,.15)}
.punch.check_out{background:var(--out);box-shadow:0 0 0 10px rgba(194,67,45,.15)}
.punch:active{transform:scale(.97)}
.punch:disabled{opacity:.6}
.p-title{font-size:26px;font-weight:800}
.p-sub{font-size:14px;opacity:.9}
.hint{color:var(--muted);font-size:13px;margin:12px 0 0}
.log{list-style:none;margin:0;padding:0}
.log li{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:8px 0;border-bottom:1px solid var(--line);font-size:14px}
.log li:last-child{border:0}
.warnbox{background:#FBEBC8;color:#7A5210;border-radius:10px;padding:10px 14px;margin-bottom:14px;font-weight:600}
/* المهام */
.task h3{display:flex;justify-content:space-between;align-items:center;gap:8px}
.task p{margin:4px 0}
.meta{color:var(--muted);font-size:14px}
.actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
.actions .btn{flex:1;min-width:120px}
.attn{list-style:none;margin:0;padding:0}
.attn li{padding:8px 0;border-bottom:1px solid var(--line);font-size:14px}
.attn li:last-child{border:0}
/* نوافذ */
.modal{position:fixed;inset:0;background:rgba(10,20,35,.55);display:flex;align-items:flex-end;justify-content:center;z-index:50}
.modal[hidden]{display:none}
.sheet{background:#fff;width:100%;max-width:440px;border-radius:20px 20px 0 0;padding:18px;padding-bottom:calc(18px + env(safe-area-inset-bottom))}
@media(min-width:800px){.modal{align-items:center}.sheet{border-radius:20px}}
.sheet video{width:100%;max-height:300px;background:#000;border-radius:12px;object-fit:cover;margin-bottom:12px;transform:scaleX(-1)}
.qgrid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin:10px 0}
.toast{position:fixed;inset-inline:16px;bottom:96px;max-width:440px;margin:auto;padding:12px 16px;border-radius:12px;color:#fff;font-weight:600;z-index:60;text-align:center;background:var(--ink)}
.toast.ok{background:var(--in)}
.toast.err{background:var(--out)}
.toast[hidden]{display:none}
@media(prefers-reduced-motion:no-preference){.punch{transition:transform .12s}}

/* سجل المهام المكتملة للفني: حاوية داخلية قابلة للسحب أفقيًا */
.completed-log-scroll-hint{margin:0 0 7px;font-size:13px}
.completed-task-log{display:block;box-sizing:border-box;width:100%;max-width:100%;min-width:0;overflow-x:auto;overflow-y:hidden;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;touch-action:pan-x pan-y;border:1px solid var(--line);border-radius:10px}
.completed-task-log table{width:max-content;min-width:900px;max-width:none;table-layout:auto}
.completed-task-log:focus-visible{outline:3px solid #7FB2F0;outline-offset:2px}
.completed-task-log::-webkit-scrollbar{height:8px}
.completed-task-log::-webkit-scrollbar-thumb{background:#9aabba;border-radius:999px}

/* صفحة الأداء الشهرية */
.perf-heading{display:flex;justify-content:space-between;align-items:flex-end;gap:16px;flex-wrap:wrap;margin-bottom:18px}
.perf-heading h1{margin:0 0 5px;font-size:24px}
.perf-heading p{margin:0;color:var(--muted)}
.perf-filter{display:flex;align-items:flex-end;flex-wrap:wrap;gap:10px}
.perf-filter label{margin:0}
.perf-filter input{min-width:170px}
.perf-summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:12px;margin-bottom:18px}
.perf-kpi{min-width:0;padding:15px;border:1px solid var(--line);border-radius:var(--r);background:#fff}
.perf-kpi span{display:block;color:var(--muted);font-size:13px;font-weight:600}
.perf-kpi strong{display:block;margin-top:5px;color:var(--ink);font-size:20px;line-height:1.35;overflow-wrap:anywhere}
.perf-table td{min-width:100px}
.perf-table td:first-child{min-width:145px;font-weight:700}
.perf-bar-wrap{display:flex;align-items:center;gap:8px;min-width:135px}
.perf-bar{flex:1;height:9px;overflow:hidden;border-radius:99px;background:#e6ecf2}
.perf-bar>span{display:block;height:100%;border-radius:inherit;background:linear-gradient(90deg,#0e8f6f,#2b5fae)}
.perf-legend{min-width:42px;font-size:12px;font-weight:700}
.perf-note{margin-top:14px;padding:12px 14px;border-radius:12px;color:var(--muted);background:#eaf0f5;font-size:13px}
.perf-empty{padding:24px;text-align:center;color:var(--muted)}
.gap-level-indicator{display:inline-flex;min-width:112px;flex-direction:column;align-items:center;gap:1px;padding:5px 9px;border-radius:10px;text-align:center;line-height:1.35;white-space:normal}
.gap-level-indicator strong{font-size:14px}
.gap-level-indicator small{font-size:11px;font-weight:700}
.gap-level-green{background:#d8f2ea;color:#0a6b52}
.gap-level-yellow{background:#fff1b8;color:#765500}
.gap-level-orange{background:#ffdbb5;color:#8b3f00}
.gap-level-red{background:#f9ded8;color:#9a3220}
.gap-level-black{background:#20242a;color:#fff}
.gap-legend{display:flex;flex-wrap:wrap;gap:7px;margin:10px 0 14px}
.task-reference-thumbnails,.task-reference-photo-list{display:flex;flex-wrap:wrap;gap:8px;margin-top:7px}
.task-reference-thumbnails img{display:block;width:62px;height:62px;object-fit:cover;border:1px solid var(--line);border-radius:8px}
.task-reference-photo-panel{margin:10px 0;padding:10px;border:1px solid var(--line);border-radius:12px;background:#f5f8fb}
.task-reference-photo-panel>strong{display:block;margin-bottom:5px}
.task-reference-photo-list a{display:flex;min-width:76px;flex-direction:column;align-items:center;gap:3px;color:var(--blue);font-size:12px;text-align:center;text-decoration:none}
.task-reference-photo-list img{display:block;width:76px;height:76px;object-fit:cover;border:1px solid var(--line);border-radius:9px;background:#fff}
.task-evidence-thumbnails{display:flex;flex-wrap:wrap;align-items:flex-start;gap:5px;margin-top:5px}
.task-evidence-thumbnails>a{display:flex;width:54px;min-width:0;flex-direction:column;align-items:center;gap:2px;color:var(--blue);font-size:10px;line-height:1.2;text-align:center;text-decoration:none;white-space:normal}
.task-evidence-thumbnails img{display:block;width:40px;height:40px;max-width:40px;object-fit:cover;border:1px solid var(--line);border-radius:6px;background:#fff}
.task-evidence-thumbnails .meta{max-width:72px;white-space:normal;text-align:center;font-size:10px}
.admin-task-create-form{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:15px;margin-top:15px}
.admin-task-create-form>div{min-width:0;max-width:100%}
.admin-task-create-form input,.admin-task-create-form select,.admin-task-create-form textarea{min-width:0;max-width:100%}
.reassign-task-cell{width:160px;min-width:160px;max-width:160px;white-space:normal}
.reassign-task-form{display:grid;width:100%;min-width:0;max-width:100%;gap:6px}
.reassign-task-form label{font-size:12px;font-weight:700;line-height:1.4;overflow-wrap:anywhere}
.reassign-task-form select{width:100%;min-width:0;max-width:100%;padding:7px 6px;font-size:12px}
.reassign-task-form .btn{width:100%;min-width:0;justify-self:stretch;padding:5px 6px;font-size:12px;line-height:1.4;white-space:normal}

/* قواعد خاصة بلوحات الإدارة على الهاتف فقط */
@media(max-width:799px){
 body.admin-view{width:100%;max-width:100%;overflow-x:hidden;padding-bottom:calc(96px + env(safe-area-inset-bottom))}
 .admin-view .topbar{width:100%;min-width:0;padding-inline:12px}
 .admin-view .who{max-width:100%;min-width:0;flex-wrap:wrap;gap:8px}
 .admin-view .wrap{width:100%;max-width:100%;min-width:0;padding:12px 10px}
 .admin-view .card{width:100%;max-width:100%;min-width:0;padding:12px}
 .admin-view .card>*{min-width:0;max-width:100%}
 .admin-view .row{width:100%;min-width:0;gap:8px}
 .admin-view .row>*{min-width:0;max-width:100%;flex:1 1 100%}
 .admin-view .scroll{width:100%;max-width:100%;min-width:0;margin:0;overflow-x:auto;overflow-y:hidden;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch}
 .admin-view .scroll table{width:max-content;min-width:650px;max-width:none;table-layout:auto}
 .admin-view .admin-nav{position:fixed;top:auto;right:0;bottom:0;left:0;width:auto;max-width:none;min-width:0;box-sizing:border-box;direction:rtl;display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:0;margin:0;padding:4px max(4px,env(safe-area-inset-right)) max(5px,env(safe-area-inset-bottom)) max(4px,env(safe-area-inset-left));border-top:1px solid var(--line);background:#fff}
 .admin-view .admin-nav a{display:flex;min-width:0;width:100%;flex:initial;flex-direction:column;justify-content:center;gap:3px;padding:6px 0 4px;font-size:10px;line-height:1.15;white-space:nowrap;text-align:center}
 .admin-view .admin-nav a span{display:block;width:100%;min-width:0;max-width:100%;overflow-wrap:anywhere;white-space:normal;font-size:clamp(9px,2.8vw,11px)}
 .admin-view .admin-nav svg{width:20px;height:20px;flex:0 0 20px}
 .admin-view .attn li{min-width:0;overflow-wrap:anywhere;line-height:1.7}
 .admin-view .table-wrap{display:block;width:100%;max-width:100%;min-width:0;margin:0;overflow-x:auto;overflow-y:hidden;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch;touch-action:pan-x pan-y}
 .admin-view .table-wrap table{width:max-content;max-width:none;table-layout:auto}
 .admin-view .attendance-recent-table table{min-width:720px}
 .admin-view .task-followup-table table{min-width:960px}
 .admin-view .admin-task-create-form{grid-template-columns:minmax(0,1fr);gap:10px}
 .admin-view .admin-task-create-form>div{grid-column:1 / -1;min-width:0;width:100%}
 .admin-view .admin-task-create-form input,.admin-view .admin-task-create-form select,.admin-view .admin-task-create-form textarea{width:100%;min-width:0;max-width:100%}
 .admin-view .reassign-task-cell{width:140px;min-width:140px;max-width:140px;padding-inline:6px}
}

/* ============================================================
   نظام الإشعارات و Web Push
============================================================ */

/* جرس الإشعارات في الهيدر */
.bell{position:relative;display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;border-radius:10px;color:#fff;text-decoration:none;border:1px solid rgba(255,255,255,.25);background:transparent;transition:background .12s,border-color .12s}
.bell svg{width:20px;height:20px}
.bell:hover,.bell:focus-visible,.bell-active{background:rgba(255,255,255,.12);border-color:rgba(255,255,255,.45)}
.bell-badge{position:absolute;top:-4px;inset-inline-end:-4px;min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:#C2432D;color:#fff;font-size:11px;font-weight:800;line-height:18px;text-align:center;box-shadow:0 0 0 2px #12263F;font-variant-numeric:tabular-nums}

/* صندوق الإشعارات الفورية في notifications.php */
.push-box{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding:12px 14px;margin-bottom:14px;border:1px solid #cfe0f5;border-radius:12px;background:#f3f8ff}
.push-box>div{min-width:0;flex:1 1 auto}
.push-box .meta{margin-top:3px}
.push-box .btn.push-on{background:#64748b}
.push-box .btn.push-on:hover{background:#475569}

/* قائمة الإشعارات */
.notif-list{list-style:none;margin:0;padding:0;display:grid;gap:10px}
.notif-item{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;padding:12px 14px;border:1px solid #e2e8f0;border-radius:12px;background:#fff}
.notif-item.notif-unread{border-color:#93c5fd;background:#f0f7ff}
.notif-item.notif-ok{border-inline-start:4px solid #0E8F6F}
.notif-item.notif-warn{border-inline-start:4px solid #B7791F}
.notif-item.notif-info{border-inline-start:4px solid #2B5FAE}
.notif-item.notif-muted{border-inline-start:4px solid #94a3b8}
.notif-main{flex:1;min-width:0}
.notif-head{display:flex;justify-content:space-between;gap:8px;align-items:baseline;flex-wrap:wrap}
.notif-type{font-size:12px;font-weight:800;color:#334155;letter-spacing:.3px}
.notif-time{font-size:12px}
.notif-title{margin-top:4px;font-weight:700;color:#0f172a}
.notif-title a{color:inherit;text-decoration:none}
.notif-title a:hover{text-decoration:underline}
.notif-body{margin-top:4px;font-size:14px;color:#475569;overflow-wrap:anywhere}
.notif-actions{display:flex;gap:6px;flex-wrap:wrap;flex-shrink:0}

@media (max-width:600px){
    .notif-item{flex-direction:column}
    .notif-actions{width:100%}
    .push-box{flex-direction:column;align-items:stretch}
    .push-box .btn{width:100%}
}

/* ============================================================
   بانر الإشعارات غير المفعّلة (يظهر أعلى كل صفحة)
============================================================ */
.push-banner {
    margin: 0 0 14px;
    border: 1px solid #f59e0b;
    background: #fffbeb;
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.push-banner-error {
    border-color: #C2432D;
    background: #fef2f2;
}
.push-banner-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.push-banner-icon {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #f59e0b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.push-banner-icon svg { width: 22px; height: 22px; }
.push-banner-error .push-banner-icon { background: #C2432D; }
.push-banner-text {
    flex: 1 1 200px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.push-banner-text strong {
    color: #78350f;
    font-size: 14px;
    font-weight: 800;
}
.push-banner-error .push-banner-text strong { color: #7f1d1d; }
.push-banner-text span {
    color: #92400e;
    font-size: 13px;
    line-height: 1.5;
}
.push-banner-error .push-banner-text span { color: #991b1b; }
.push-banner-btn {
    flex: 0 0 auto;
    border: 0;
    border-radius: 10px;
    padding: 10px 18px;
    font: inherit;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    background: #12263F;
    color: #fff;
    min-height: 40px;
}
.push-banner-btn:hover, .push-banner-btn:focus-visible {
    background: #0d1a2b;
}
.push-banner-btn:disabled {
    opacity: .7;
    cursor: wait;
}

/* عند فتح القائمة على الموبايل: زر بأخذ عرض كامل */
@media (max-width: 600px) {
    .push-banner-inner { gap: 8px; }
    .push-banner-btn { width: 100%; }
}

/* نبض زر التفعيل للفت الانتباه */
@keyframes pushPulse {
    0%   { box-shadow: 0 0 0 0 rgba(18, 38, 63, .55); }
    70%  { box-shadow: 0 0 0 12px rgba(18, 38, 63, 0); }
    100% { box-shadow: 0 0 0 0 rgba(18, 38, 63, 0); }
}
.push-banner-btn.push-pulse {
    animation: pushPulse 1.8s ease-out infinite;
}
/* بانر معلوماتي (iOS) */
.push-banner-info {
    border-color: #2B5FAE;
    background: #f0f7ff;
}
.push-banner-info .push-banner-icon {
    background: #2B5FAE;
}
.push-banner-info .push-banner-text strong {
    color: #1e3a5f;
}
.push-banner-info .push-banner-text span {
    color: #1e40af;
}

/* ============================================================
   التحديث التلقائي (Live)
============================================================ */
[data-live-task-count].live-updated {
    animation: liveFlash 0.8s ease-out;
}
@keyframes liveFlash {
    0%   { color: #2563eb; transform: scale(1); }
    40%  { color: #10b981; transform: scale(1.25); }
    100% { color: #2563eb; transform: scale(1); }
}

[data-live-refresh-tasks].live-pulse {
    animation: livePulse 1.6s ease-out infinite;
    border-color: #2563eb;
    color: #2563eb;
    font-weight: 700;
}
@keyframes livePulse {
    0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(37, 99, 235, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

/* ============================================================
   زر إلغاء المهمة (Admin)
============================================================ */
.cancel-link {
    display: block;
    margin-top: 8px;
    border: 0;
    background: transparent;
    color: #C2432D;
    padding: 6px 8px;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    border-radius: 6px;
}
.cancel-link:hover,
.cancel-link:focus-visible {
    background: #fee2e2;
    color: #991b1b;
}

/* ============================================================
   أزرار تعديل المهمة + السجل
============================================================ */
.edit-link,
.history-link {
    display: inline-block;
    margin-top: 6px;
    border: 0;
    background: transparent;
    color: #2563eb;
    padding: 4px 6px;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    border-radius: 6px;
}
.edit-link:hover,
.history-link:hover {
    background: #dbeafe;
    color: #1d4ed8;
}
.history-link { color: #64748b; }
.history-link:hover { background: #f1f5f9; color: #334155; }

/* ============================================================
   Dialog تعديل المهمة
============================================================ */
.edit-dialog {
    width: min(94vw, 520px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    border: 0;
    border-radius: 16px;
    color: #1e293b;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .3);
}
.edit-dialog::backdrop { background: rgba(15, 23, 42, .65); }
.edit-dialog h3 { margin: 0 0 6px; font-size: 1.15rem; }
.edit-dialog .form label { margin-top: 10px; }
.edit-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}
.edit-dialog-actions > button { min-height: 44px; flex: 1; }

/* ============================================================
   سجل التعديلات (admin_task_history.php)
============================================================ */
.history-card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 14px;
    background: #fff;
}
.history-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
    flex-wrap: wrap;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #e2e8f0;
}
.history-reason {
    margin: 8px 0;
    padding: 8px 10px;
    background: #fef9c3;
    border-radius: 8px;
    color: #713f12;
    font-size: 14px;
}
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-top: 8px;
}
.history-table th {
    background: #f1f5f9;
    text-align: start;
    padding: 6px 10px;
    font-size: 12px;
}
.history-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
    white-space: normal;
}
.history-table .history-old { color: #991b1b; text-decoration: line-through; opacity: .8; }
.history-table .history-new { color: #047857; font-weight: 700; }

/* Timeline الأحداث */
.events-timeline {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    gap: 10px;
}
.events-timeline > li {
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
}
.event-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
    flex-wrap: wrap;
}
.event-note {
    margin-top: 6px;
    color: #475569;
    font-size: 14px;
}

/* ============================================================
   نظام تحصيل الأموال
============================================================ */
.mc-card {
    border: 2px solid #cbd5e1;
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 16px;
    background: #fff;
    transition: border-color .2s, background-color .2s;
}
.mc-card.mc-zone-green { border-color: #10b981; background: #f0fdf4; }
.mc-card.mc-zone-yellow { border-color: #f59e0b; background: #fffbeb; }
.mc-card.mc-zone-red { border-color: #ef4444; background: #fef2f2; }
.mc-card.mc-zone-black { border-color: #1e293b; background: #f1f5f9; }

.mc-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.mc-zone-label {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 6px;
    background: #e2e8f0;
    color: #334155;
}
.mc-zone-green .mc-zone-label { background: #d1fae5; color: #065f46; }
.mc-zone-yellow .mc-zone-label { background: #fef3c7; color: #78350f; }
.mc-zone-red .mc-zone-label { background: #fee2e2; color: #991b1b; }
.mc-zone-black .mc-zone-label { background: #1e293b; color: #f1f5f9; }

.mc-card h3 { margin: 0 0 4px; font-size: 1.1rem; }
.mc-timer { text-align: center; }
.mc-timer-label { font-size: 12px; color: #64748b; }
.mc-timer-value {
    font-family: monospace;
    font-size: 28px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #0f172a;
}
.mc-zone-green .mc-timer-value { color: #047857; }
.mc-zone-yellow .mc-timer-value { color: #b45309; }
.mc-zone-red .mc-timer-value { color: #b91c1c; }
.mc-zone-black .mc-timer-value { color: #0f172a; }

.mc-form { display: grid; gap: 8px; }
.mc-form label { font-weight: 600; font-size: 13px; }
.mc-form input { width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 10px; font: inherit; }
.mc-feedback { padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.mc-feedback.ok { background: #d1fae5; color: #065f46; }
.mc-feedback.err { background: #fee2e2; color: #991b1b; }

/* Badge في جدول الأدمن */
.mc-zone-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
}
.mc-zone-badge.mc-zone-green { background: #d1fae5; color: #065f46; }
.mc-zone-badge.mc-zone-yellow { background: #fef3c7; color: #78350f; }
.mc-zone-badge.mc-zone-red { background: #fee2e2; color: #991b1b; }
.mc-zone-badge.mc-zone-black { background: #1e293b; color: #fff; }

/* تصنيف العملاء */
.mc-zone {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}
.mc-zone-green { background: #d1fae5; color: #065f46; }
.mc-zone-yellow { background: #fef3c7; color: #78350f; }
.mc-zone-red { background: #fee2e2; color: #991b1b; }
.mc-zone-black { background: #1e293b; color: #fff; }
.mc-zone-gray { background: #e2e8f0; color: #475569; }

/* ============================================================
   Autocomplete العملاء — كل الأنماط في مكان واحد
============================================================ */

/* الحاوية الأساسية */
.client-autocomplete {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 99999;
    background: #ffffff;
    border: 1px solid #dbe4ee;
    border-radius: 14px;
    box-shadow:
        0 4px 6px -1px rgba(15, 23, 42, 0.08),
        0 20px 45px -10px rgba(15, 23, 42, 0.22);
    max-height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px;
    display: block;
    visibility: visible;
    opacity: 1;
    animation: clientAutoFadeIn .18s ease-out;
}

.client-autocomplete[hidden] {
    display: none !important;
}

@keyframes clientAutoFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
.client-autocomplete::-webkit-scrollbar { width: 8px; }
.client-autocomplete::-webkit-scrollbar-track { background: transparent; }
.client-autocomplete::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}
.client-autocomplete::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* العنصر */
.client-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    color: #334155;
    transition: background-color .12s ease, transform .12s ease;
    user-select: none;
}
.client-autocomplete-item + .client-autocomplete-item { margin-top: 2px; }

/* الأيقونة */
.client-autocomplete-item .client-avatar {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #1d4ed8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: .5px;
    text-transform: uppercase;
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12);
}

/* الاسم */
.client-autocomplete-item .client-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: #0f172a;
}
.client-autocomplete-item .client-name mark {
    background: #fef3c7;
    color: #92400e;
    padding: 0 2px;
    border-radius: 3px;
    font-weight: 800;
}

/* عدد المرات */
.client-autocomplete-item .client-meta {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

/* hover */
.client-autocomplete-item:hover,
.client-autocomplete-item.is-active {
    background: #eff6ff;
    transform: translateX(-2px);
}
.client-autocomplete-item:hover .client-avatar,
.client-autocomplete-item.is-active .client-avatar {
    background: linear-gradient(135deg, #bfdbfe 0%, #93c5fd 100%);
    color: #1e3a8a;
}
.client-autocomplete-item.is-active { background: #dbeafe; }

/* لا يوجد نتائج */
.client-autocomplete-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px 14px;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}
.client-autocomplete-empty svg { width: 18px; height: 18px; opacity: .7; }

/* تحميل */
.client-autocomplete-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px 14px;
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
}
.client-autocomplete-loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #cbd5e1;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: clientSpin .7s linear infinite;
}
@keyframes clientSpin { to { transform: rotate(360deg); } }

/* رأس القائمة */
.client-autocomplete-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 8px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 1px solid #f1f5f9;
    margin-bottom: 4px;
}
.client-autocomplete-header .client-count {
    background: #dbeafe;
    color: #1e40af;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
}

/* الحاوية الأب */
.client-input-wrap {
    position: relative;
    display: block;
    width: 100%;
    isolation: isolate;
    align-self: start;
}

/* الموبايل */
@media (max-width: 480px) {
    .client-autocomplete { max-height: 260px; }
    .client-autocomplete-item { padding: 10px 8px; }
    .client-autocomplete-item .client-avatar { flex-basis: 28px; width: 28px; height: 28px; font-size: 12px; }
    .client-autocomplete-item .client-name { font-size: 13px; }
    .client-autocomplete-item .client-meta { font-size: 10px; padding: 2px 6px; }
}
/* ============================================================
   Popup الإشعارات
============================================================ */
.bell {
    /* نحوله إلى button */
    font: inherit;
    padding: 0;
    cursor: pointer;
}

.notif-popup {
    position: fixed;
    top: 60px;
    inset-inline-end: 16px;
    width: min(380px, calc(100vw - 24px));
    max-height: min(70vh, 560px);
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid #dbe4ee;
    border-radius: 16px;
    box-shadow:
        0 4px 6px -1px rgba(15, 23, 42, 0.08),
        0 20px 50px -12px rgba(15, 23, 42, 0.28);
    z-index: 9999;
    overflow: hidden;
    animation: notifPopupFade .16s ease-out;
}
.notif-popup[hidden] { display: none !important; }

@keyframes notifPopupFade {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.notif-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #eef2f7;
    background: #f8fafc;
}
.notif-popup-header strong {
    font-size: 15px;
    color: #0f172a;
}
.notif-popup-count {
    font-size: 12px;
    font-weight: 700;
    color: #1e40af;
    background: #dbeafe;
    padding: 2px 9px;
    border-radius: 999px;
}

.notif-popup-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px;
    overscroll-behavior: contain;
}
.notif-popup-body::-webkit-scrollbar { width: 8px; }
.notif-popup-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.notif-popup-empty {
    padding: 28px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
}

.notif-popup-item {
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: #f8fafc;
    border-inline-start: 3px solid transparent;
    transition: background-color .12s ease;
}
.notif-popup-item:hover { background: #f1f5f9; }
.notif-popup-item.is-unread {
    background: #eff6ff;
    border-inline-start-color: #2563eb;
}
.notif-popup-item.notif-ok { border-inline-start-color: #0E8F6F; }
.notif-popup-item.notif-warn { border-inline-start-color: #B7791F; }
.notif-popup-item.notif-info { border-inline-start-color: #2B5FAE; }
.notif-popup-item.notif-muted { border-inline-start-color: #94a3b8; }

.notif-popup-item-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
    margin-bottom: 4px;
}
.notif-popup-type {
    font-size: 11px;
    font-weight: 800;
    color: #475569;
    letter-spacing: .3px;
}
.notif-popup-time {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

.notif-popup-title {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #0f172a;
    text-decoration: none;
    margin-bottom: 2px;
}
.notif-popup-title:hover { color: #1d4ed8; text-decoration: underline; }

.notif-popup-body-text {
    font-size: 12px;
    color: #64748b;
    line-height: 1.5;
    max-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-bottom: 6px;
}

.notif-popup-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.notif-popup-btn {
    border: 0;
    background: #e2e8f0;
    color: #334155;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 6px;
    cursor: pointer;
}
.notif-popup-btn:hover { background: #cbd5e1; }
.notif-popup-btn:disabled { opacity: .5; cursor: wait; }
.notif-popup-btn-danger {
    background: #fee2e2;
    color: #991b1b;
}
.notif-popup-btn-danger:hover { background: #fecaca; }

.notif-popup-more {
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    padding: 8px 4px;
}

.notif-popup-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #eef2f7;
    background: #f8fafc;
}
.notif-popup-all {
    font-size: 12px;
    font-weight: 700;
    color: #1d4ed8;
    text-decoration: none;
}
.notif-popup-all:hover { text-decoration: underline; }
.notif-popup-markall {
    border: 0;
    background: transparent;
    color: #64748b;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
}
.notif-popup-markall:hover { background: #e2e8f0; color: #334155; }
.notif-popup-markall:disabled { opacity: .5; cursor: wait; }

@media (max-width: 480px) {
    .notif-popup {
        top: 56px;
        inset-inline: 8px;
        width: auto;
        max-height: 65vh;
    }
}
/* ============================================================
   التحديث التلقائي للأقسام
============================================================ */
.live-section-flash {
    animation: liveSectionFlash 0.4s ease-out;
}
/* منع الوميض لجدول المهام وملحقاته */
[data-live-section="tasks-table"].live-section-flash {
    animation: none !important;
    background-color: transparent !important;
}
@keyframes liveSectionFlash {
    0%   { background-color: rgba(37, 99, 235, 0.08); }
    100% { background-color: transparent; }
}
[data-live-task-count].live-updated {
    animation: liveFlash 0.8s ease-out;
}
@keyframes liveFlash {
    0%   { color: #2563eb; transform: scale(1); }
    40%  { color: #10b981; transform: scale(1.25); }
    100% { color: #2563eb; transform: scale(1); }
}
[data-live-refresh-tasks].live-pulse {
    animation: livePulse 1.6s ease-out infinite;
    border-color: #2563eb;
    color: #2563eb;
    font-weight: 700;
}
@keyframes livePulse {
    0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(37, 99, 235, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}
.ref-photos-dialog {
    width: min(94vw, 620px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    border: 0;
    border-radius: 16px;
    color: #1e293b;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .3);
}
.ref-photos-dialog::backdrop { background: rgba(15, 23, 42, .65); }
.ref-photos-dialog h3 { margin: 0 0 6px; font-size: 1.15rem; }
.ref-photos-current {
    margin: 16px 0;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
}
#ref-photos-current-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.ref-photo-item {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}
.ref-photo-item:hover { border-color: #ef4444; }
.ref-photo-item input[type="checkbox"] {
    position: absolute;
    top: 4px;
    inset-inline-start: 4px;
    width: 18px;
    height: 18px;
    accent-color: #ef4444;
    cursor: pointer;
}
.ref-photo-item img {
    display: block;
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}
.ref-photo-item input[type="checkbox"]:checked ~ img { opacity: 0.4; filter: grayscale(1); }
.ref-photo-delete-hint { font-size: 10px; color: #94a3b8; font-weight: 700; }
.ref-photos-add { margin: 16px 0; }
.ref-photos-add label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 13px; }
.ref-photos-add input[type="file"] {
    width: 100%;
    padding: 10px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    font: inherit;
}
.ref-photos-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}
.ref-photos-actions > button { min-height: 44px; flex: 1; }
/* Offline indicator */
body.is-offline::before {
    content: 'أنت غير متصل بالإنترنت — أي إجراء سيُحفظ محليًا';
    position: fixed;
    top: 0; left: 0; right: 0;
    background: #B7791F;
    color: #fff;
    text-align: center;
    padding: 6px;
    font-size: 13px;
    font-weight: 700;
    z-index: 99999;
}
.offline-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #FBEBC8;
    color: #7A5210;
    font-size: 11px;
    font-weight: 700;
}
/* ═══════════════════════════════════════════════════════════
   دور صاحب الشركة — عرض فقط
   إخفاء كل عناصر التعديل تلقائيًا
============================================================ */

/* ── إخفاء عام ── */
body.owner-view .no-owner,
body.owner-view [data-owner-hide],

/* أزرار الصفوف */
body.owner-view .icon-action,
body.owner-view .cancel-link,
body.owner-view .task-actions-tiles,
body.owner-view .detail-actions,

/* أزرار الحضور */
body.owner-view .punch,
body.owner-view .btn.check-in,
body.owner-view .btn.check-out,

/* التحصيل */
body.owner-view .mc-form,
body.owner-view .mc-form button,

/* أزرار إنشاء مهمة */
body.owner-view .tc-submit-bar,
body.owner-view .admin-task-create-form,

/* جداول الإدارة */
body.owner-view .aeu-btn,
body.owner-view .aeu-actions,
body.owner-view .aet-btn,
body.owner-view .aet-actions,
body.owner-view .ae-btn,
body.owner-view .ae-actions,
body.owner-view .ae-actions-bar,

/* النوافذ المنبثقة */
body.owner-view .reject-dialog,
body.owner-view .edit-dialog,
body.owner-view .force-complete-dialog,
body.owner-view .ref-photos-dialog,
body.owner-view .ae-modal,
body.owner-view .aet-modal,
body.owner-view .aeu-modal,

/* الصور القابلة للتعديل */
body.owner-view [data-edit-open],
body.owner-view [data-open-cancel],
body.owner-view [data-open-force-complete],
body.owner-view [data-open-ref-manager],
body.owner-view [data-open-reject],
body.owner-view [data-camera-field],
body.owner-view [data-task-submit],
body.owner-view [data-punch],

/* الفورمات الحساسة */
body.owner-view form[action*="delete"],
body.owner-view form[action*="edit"],
body.owner-view form[action*="cancel"],
body.owner-view form[action*="create"],
body.owner-view form[action*="update"],
body.owner-view form[action*="rate"],
body.owner-view form[action*="set_"],
body.owner-view form[action*="toggle"],
body.owner-view form[action*="reset"],
body.owner-view form[action*="force"],
body.owner-view form[action*="reassign"],
body.owner-view form[action*="approve"],
body.owner-view form[action*="save"],
body.owner-view form[action*="bulk"],
body.owner-view form[action*="add_"],

/* حماية إضافية — أزرار عامة */
body.owner-view .btn.danger:not(.view-only),
body.owner-view .btn.warn:not(.view-only),
body.owner-view .btn.primary:not(.view-only) {
    display: none !important;
}

/* أزرار التعديل داخل Dialogs دائماً مخفية */
body.owner-view dialog[open] { display: none !important; }

/* إخفاء حقول الإدخال داخل الفورمات المعروضة */
body.owner-view input[name="csrf"],
body.owner-view input[name="action"] {
    /* نُبقيها ظاهرة */
}

/* ── الإبقاء على أزرار العرض والتنقل فقط ── */
body.owner-view .btn.ghost,
body.owner-view .btn.sm.ghost,
body.owner-view a.btn:not([href*="edit"]):not([href*="delete"]):not([href*="cancel"]) {
    display: inline-flex !important;
}

/* ── إخفاء شارة "التحكم" من القائمة (احتياطي) ── */
body.owner-view .nav a[href="admin_edit_center.php"],
body.owner-view .nav a[href="admin_edit_users.php"],
body.owner-view .nav a[href="admin_edit_tasks.php"],
body.owner-view .nav a[href="admin_attendance_edit.php"],
body.owner-view .nav a[href="admin_roles.php"],
body.owner-view .nav a[href="admin_users.php"] {
    display: none !important;
}

/* ── مسموح: عرض سجل المهام ── */
body.owner-view .history-link {
    display: inline-flex !important;
}
/* ═══════ زرار إعادة التوجيه ═══════ */
.task-tile.tile-reassign {
    border-color: #ede9fe;
    color: #5b21b6;
}
.task-tile.tile-reassign .task-tile-icon {
    background: #ede9fe;
    color: #7c3aed;
}
.task-tile.tile-reassign:hover,
.task-tile.tile-reassign:focus-visible {
    background: #f5f3ff;
    border-color: #c4b5fd;
    color: #5b21b6;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px -6px rgba(124, 58, 237, .35);
}
.task-tile.tile-reassign:hover .task-tile-icon,
.task-tile.tile-reassign:focus-visible .task-tile-icon {
    background: #ddd6fe;
    color: #6d28d9;
    transform: scale(1.06);
}

/* ═══════ Dialog إعادة التوجيه ═══════ */
.reassign-dialog {
    width: min(94vw, 520px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    border: 0;
    border-radius: 16px;
    color: #1e293b;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .3);
}
.reassign-dialog::backdrop { background: rgba(15, 23, 42, .65); }
.reassign-dialog h3 {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: #5b21b6;
}
.reassign-dialog p {
    margin: 0 0 14px;
    color: #64748b;
    font-size: 13px;
    line-height: 1.65;
}
.reassign-dialog label {
    display: block;
    font-weight: 700;
    font-size: 13px;
    margin-top: 12px;
    margin-bottom: 4px;
    color: #334155;
}
.reassign-dialog select,
.reassign-dialog textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    background: #fff;
}
.reassign-dialog select:focus,
.reassign-dialog textarea:focus {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, .15);
}
.reassign-dialog textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}
.reassign-dialog .req { color: #dc2626; font-weight: 800; }
.reassign-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px dashed #e2e8f0;
}
.reassign-dialog-actions > button {
    min-height: 44px;
    flex: 1;
}
.reject-dialog-form {
    display: flex;
    flex-direction: column;
    gap: 0;
}
/* ═══════════════════════════════════════════════════════════
   Header fixes — بيانات المستخدم + logout + breadcrumb
   ═══════════════════════════════════════════════════════════ */

/* بيانات المستخدم في الـ topbar */
.who {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.who-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 0;
    max-width: 160px;
    text-align: end;
}
.who-name {
    font-size: 13.5px;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    line-height: 1.3;
}
.who-role {
    font-size: 10.5px;
    color: rgba(255,255,255,.65);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    letter-spacing: .2px;
}

/* زر تسجيل الخروج */
.logout-form { margin: 0; display: inline-flex; }
.btn-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.25);
    background: transparent;
    color: #fff;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
    padding: 0;
    flex-shrink: 0;
}
.btn-logout svg { width: 18px; height: 18px; }
.btn-logout:hover,
.btn-logout:focus-visible {
    background: rgba(194, 67, 45, .8);
    border-color: rgba(194, 67, 45, 1);
    outline: none;
}
.btn-logout:active { transform: scale(.95); }

/* الجرس — إصلاح */
.bell {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: #fff;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,.25);
    background: transparent;
    transition: background .12s, border-color .12s;
}
.bell svg { width: 20px; height: 20px; }
.bell:hover,
.bell:focus-visible,
.bell-active {
    background: rgba(255,255,255,.12);
    border-color: rgba(255,255,255,.5);
    outline: none;
}

/* Breadcrumb bar */
.breadcrumb-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12.5px;
    color: #64748b;
    font-weight: 700;
    overflow-x: auto;
    white-space: nowrap;
}
.breadcrumb-bar a {
    color: #2563eb;
    text-decoration: none;
    transition: color .12s;
}
.breadcrumb-bar a:hover { color: #1d4ed8; text-decoration: underline; }
.bc-sep { color: #cbd5e1; }
.bc-current { color: #334155; font-weight: 800; }

/* ═══════════════════════════════════════════════════════════
   Mobile nav — يتّسع حسب عدد العناصر
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 799px) {
    /* ═══════ NAV السفلي للموبايل ═══════ */
    .admin-view .admin-nav,
    body.admin-view .nav.admin-nav {
        position: fixed !important;
        bottom: 0 !important;
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
        margin: 0 !important;
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom)) 4px !important;
        background: #fff !important;
        border-top: 1px solid #e2e8f0 !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 -2px 10px rgba(15, 23, 42, .06);
        z-index: 50;
    }

    .admin-view .admin-nav::-webkit-scrollbar { height: 2px; }
    .admin-view .admin-nav::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 999px;
    }

    .admin-view .admin-nav a,
    .admin-view .admin-nav .nav-item {
        flex: 0 0 auto !important;
        min-width: 68px !important;
        max-width: 80px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 3px !important;
        padding: 6px 4px !important;
        font-size: 10.5px !important;
        line-height: 1.15 !important;
        text-align: center !important;
        scroll-snap-align: start;
        white-space: normal;
        color: #64748b;
        text-decoration: none;
        border-radius: 8px;
        transition: background .12s;
    }

    .admin-view .admin-nav a span,
    .admin-view .admin-nav .nav-item span {
        display: block;
        width: 100%;
        max-width: 100%;
        font-size: 10px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .admin-view .admin-nav svg {
        width: 20px !important;
        height: 20px !important;
        flex: 0 0 20px;
    }

    .admin-view .admin-nav a.on,
    .admin-view .admin-nav .nav-item.on {
        background: #eff6ff;
        color: #1d4ed8;
        font-weight: 800;
    }

    .admin-view .admin-nav a.on::before,
    .admin-view .admin-nav .nav-item.on::before {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        right: 20%;
        height: 3px;
        background: #2563eb;
        border-radius: 0 0 3px 3px;
    }

    .admin-view .admin-nav a {
        position: relative;
    }

    /* ═══════ Body padding-bottom كافي للـ nav ═══════ */
    body.admin-view {
        padding-bottom: 88px !important;
    }
}
/* ═══════════════════════════════════════════════════════════
   الجداول على الموبايل — الحل الصح
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 799px) {

    /* ─── 1. كل table-wrap لازم يعمل scroll أفقي صح ─── */
    body.admin-view .table-wrap,
    body.admin-view .scroll,
    body.admin-view [style*="overflow-x"],
    body.admin-view [style*="overflow-y"] {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        touch-action: pan-x pan-y;
        border-radius: 12px;
    }

    /* ─── 2. الجداول العريضة تفضل جدول وتعمل scroll ─── */
    body.admin-view .table-wrap > table,
    body.admin-view .scroll > table {
        width: max-content !important;
        min-width: 100% !important;
        max-width: none !important;
    }

    /* ─── 3. جدول المهام المضغوط — عرض مناسب ─── */
    body.admin-view table.tasks-compact {
        min-width: 720px !important;
    }

    /* ─── 4. جدول الأداء (perf-table) — عرض أوسع لأن الأعمدة كتير ─── */
    body.admin-view table.perf-table {
        min-width: 900px !important;
    }

    /* ─── 5. الكروت الإحصائية ─── */
    body.admin-view .perf-summary,
    body.admin-view .kpi-grid,
    body.admin-view .analytics-kpis,
    body.admin-view .route-kpis,
    body.admin-view .dash-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    /* ─── 6. الـ KPI card — خطوط أوضح على الموبايل ─── */
    body.admin-view .perf-kpi,
    body.admin-view .analytics-kpi,
    body.admin-view .route-kpi {
        padding: 12px !important;
    }
    body.admin-view .perf-kpi span,
    body.admin-view .analytics-kpi span,
    body.admin-view .route-kpi span {
        font-size: 11px !important;
        line-height: 1.3;
    }
    body.admin-view .perf-kpi strong,
    body.admin-view .analytics-kpi strong,
    body.admin-view .route-kpi strong {
        font-size: 16px !important;
        line-height: 1.2;
    }

    /* ─── 7. hide بعض أعمدة admin_users/admin_clients المزعجة ─── */
    body.admin-view table:not(.tasks-compact):not(.perf-table):not(.tfe-picker-table) th.col-hide-mobile,
    body.admin-view table:not(.tasks-compact):not(.perf-table):not(.tfe-picker-table) td.col-hide-mobile {
        display: none !important;
    }

    /* ─── 8. hint للمستخدم إن الجدول بيتسحب ─── */
    body.admin-view .table-wrap::after {
        content: '';
        display: block;
        height: 4px;
    }
}

/* على الشاشات الصغيرة جدًا */
@media (max-width: 480px) {
    body.admin-view .perf-summary,
    body.admin-view .kpi-grid,
    body.admin-view .analytics-kpis,
    body.admin-view .route-kpis,
    body.admin-view .dash-kpis {
        grid-template-columns: 1fr !important;
    }
}
/* ═══════════════════════════════════════════════════════════
   admin_performance.php — Responsive للموبايل
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 799px) {

    /* KPIs */
    .perf-summary,
    .kpi-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }
    .perf-kpi {
        padding: 12px !important;
        min-width: 0 !important;
    }
    .perf-kpi span {
        font-size: 11px !important;
        line-height: 1.3 !important;
    }
    .perf-kpi strong {
        font-size: 16px !important;
        line-height: 1.2 !important;
    }

    /* الـ Heading + الفلتر */
    .perf-heading {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .perf-heading h1 {
        font-size: 18px !important;
    }
    .perf-filter {
        flex-wrap: wrap;
        gap: 8px;
    }
    .perf-filter input[type="month"],
    .perf-filter .btn {
        width: 100%;
        min-height: 42px;
    }

    /* الجداول */
    .perf-table {
        min-width: 850px !important;
    }
    .table-wrap {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        max-width: 100% !important;
    }

    /* badges المستوى */
    .gap-level-indicator {
        min-width: 88px;
        font-size: 11px;
    }
    .gap-legend {
        gap: 5px;
    }
    .gap-legend .gap-level-indicator {
        font-size: 10px;
        min-width: 80px;
        padding: 4px 6px;
    }
}

@media (max-width: 480px) {
    .perf-summary,
    .kpi-grid {
        grid-template-columns: 1fr !important;
    }
}
/* ═══════════════════════════════════════════════════════════
   ⚡ الكيبورد على الموبايل
   - نخفي الـ NAV وأي عنصر fixed في الأسفل
   - نمنع القفزات المزعجة
   ═══════════════════════════════════════════════════════════ */
/* ═══════════════════════════════════════════════════════════
   ⚡ إخفاء الـ NAV عند فتح الكيبورد
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 799px) {

    body.keyboard-open .nav,
    body.keyboard-open .nav.admin-nav {
        display: none !important;
    }

    body.keyboard-open {
        padding-bottom: 8px !important;
    }

    /* نخفي الزر العائم عشان ما يزحمش */
    body.keyboard-open .cw-fab {
        display: none !important;
    }
}