/* سُفرة — الهوية: أخضر داكن، أبيض، ذهبي هادئ */
:root {
  --g900: #092D00; --g800: #0E3A05; --g700: #164A0B; --g600: #22601A; --g500: #3B7A31;
  --g100: #E9F1E5; --g50: #F4F8F2;
  --gold: #B8963E; --gold-d: #7A6226; --gold-l: #F6EFD9;
  --ink: #15200F; --ink2: #4B5747; --ink3: #6B7566; --line: #E2E8DE; --bg: #F7F9F5; --white: #fff;
  --red: #B42318; --red-l: #FDECEA; --amber: #9A6700; --amber-l: #FFF4D6; --blue: #1D5FA8; --blue-l: #E8F1FB;
  --r: 14px; --r-sm: 10px; --sh: 0 1px 2px rgba(9,45,0,.06), 0 4px 14px rgba(9,45,0,.05);
  --font: 'Tajawal', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --side: 264px; --top: 60px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { overflow-x: clip; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 16px; line-height: 1.6; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--g700); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
.hidden { display: none !important; }
.muted { color: var(--ink3); }
.small { font-size: 14px; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: embed; }
.num { font-variant-numeric: tabular-nums; }

/* تحميل البداية */
.boot { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; }
.boot-logo { width: 180px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--g100); border-top-color: var(--g700); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* صفحة الدخول */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--g900); }
.auth-card { width: 100%; max-width: 420px; background: var(--white); border-radius: 22px; padding: 36px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-logo { display: block; width: 170px; margin: 0 auto 6px; }
.auth-tag { text-align: center; color: var(--gold-d); font-weight: 700; margin-bottom: 26px; }
.auth h1 { font-size: 22px; margin-bottom: 18px; text-align: center; }

/* الهيكل */
.shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; height: var(--top); background: var(--g900); color: #fff; display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.topbar .brand img { height: 30px; display: block; }
.topbar .spacer { flex: 1; }
.topbar .ctx { display: flex; gap: 8px; align-items: center; min-width: 0; }
.topbar select, .topbar input[type=date] { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: #fff; border-radius: 10px; padding: 6px 10px; height: 38px; max-width: 170px; }
.topbar select option { color: var(--ink); }
.topbar input[type=date]::-webkit-calendar-picker-indicator { filter: invert(1); }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 0; background: transparent; color: inherit; display: inline-grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: rgba(127,127,127,.12); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #7DDB6A; box-shadow: 0 0 0 3px rgba(125,219,106,.25); flex: none; }
.live-dot.off { background: #E0A040; box-shadow: 0 0 0 3px rgba(224,160,64,.25); }

.sidebar { position: fixed; top: var(--top); bottom: 0; right: 0; width: var(--side); background: var(--white); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 10px 30px; z-index: 25; transform: translateX(100%); transition: transform .2s; }
.sidebar.open { transform: none; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
.nav-group { font-size: 13px; color: var(--ink3); font-weight: 700; padding: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500; min-height: 44px; }
.nav a:hover { background: var(--g50); }
.nav a.active { background: var(--g100); color: var(--g900); font-weight: 700; }
.nav a svg { color: var(--g600); flex: none; }
.side-user { margin: 10px; padding: 14px; border-radius: 12px; background: var(--g50); }
.side-user b { display: block; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 20; }

.main { padding: 18px 14px 100px; max-width: 1280px; margin: 0 auto; }
.daybar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; background: var(--white); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; margin-bottom: 16px; font-size: 15px; }
.daybar .dn { font-weight: 800; color: var(--g900); }
.daybar .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--gold); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 24px; font-weight: 800; color: var(--g900); flex: 1 1 auto; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--white); border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.bottomnav a, .bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--ink3); text-decoration: none; background: none; border: 0; padding: 4px 0; min-height: 48px; cursor: pointer; }
.bottomnav .active { color: var(--g900); font-weight: 700; }

@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .shell .main { margin-right: var(--side); padding: 24px 28px 60px; }
  .bottomnav, .menu-btn, .scrim { display: none !important; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 6px 10px 8px; row-gap: 6px; }
  .topbar .ctx { order: 10; width: 100%; }
  .topbar .ctx select, .topbar .ctx input[type=date] { flex: 1 1 0; max-width: none; min-width: 0; }
  .topbar .brand img { height: 26px; }
  .sidebar { top: 0; z-index: 45; }
  .scrim { z-index: 44; }
  .page-head h1 { font-size: 21px; }
}

/* البطاقات والإحصائيات */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--sh); }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 18px; font-weight: 800; margin-bottom: 12px; color: var(--g900); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; flex: 1; }
.grid { display: grid; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat .v { font-size: 28px; font-weight: 800; color: var(--g900); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 14px; color: var(--ink2); }
.stat.accent { background: var(--g900); border-color: var(--g900); }
.stat.accent .v, .stat.accent .l { color: #fff; }
.stat.gold { border-color: var(--gold); background: var(--gold-l); }
.stat.warn .v { color: var(--amber); }
.stat.bad .v { color: var(--red); }
.section-title { font-size: 17px; font-weight: 800; color: var(--g900); margin: 22px 0 10px; }
.two-col { display: grid; gap: 16px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; } }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.quick a { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 12px; background: var(--white); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 700; min-height: 56px; }
.quick a:hover { border-color: var(--g500); }
.quick a svg { color: var(--gold); flex: none; }

/* الأزرار والحقول */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px; border-radius: 11px; border: 1px solid var(--line); background: var(--white); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--g500); }
.btn.primary { background: var(--g700); border-color: var(--g700); color: #fff; }
.btn.primary:hover { background: var(--g800); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.danger { color: var(--red); border-color: #F3C2BC; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: 14px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .lbl { font-weight: 700; font-size: 15px; }
.field .hint { font-size: 13px; color: var(--ink3); }
.input, select.input, textarea.input { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #CBD5C4; border-radius: 10px; background: #fff; }
textarea.input { min-height: 84px; resize: vertical; }
.input:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid rgba(34,96,26,.25); outline-offset: 1px; border-color: var(--g600); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }
.form-grid { display: grid; gap: 0 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--g700); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters .input { width: auto; flex: 1 1 150px; }
.search { position: relative; flex: 2 1 220px; }
.search svg { position: absolute; top: 12px; right: 12px; color: var(--ink3); }
.search .input { padding-right: 40px; }
.seg { display: inline-flex; background: var(--g50); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 700; color: var(--ink2); min-height: 36px; }
.seg button.on { background: var(--white); color: var(--g900); box-shadow: var(--sh); }

/* الشارات */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--g50); color: var(--ink2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--g100); color: var(--g800); border-color: #CFE0C8; }
.badge.warn { background: var(--amber-l); color: var(--amber); border-color: #F2DFA8; }
.badge.bad { background: var(--red-l); color: var(--red); border-color: #F3C2BC; }
.badge.info { background: var(--blue-l); color: var(--blue); border-color: #C9DCF3; }
.badge.gold { background: var(--gold-l); color: var(--gold-d); border-color: #E8D9AE; }

/* الجداول */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--white); }
table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
.t th, .t td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t th { background: var(--g50); font-weight: 800; color: var(--g900); white-space: nowrap; position: sticky; top: 0; }
.t th.sortable { cursor: pointer; user-select: none; }
.t th.sortable:hover { color: var(--g600); }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover { background: #FBFCFA; }
.t td.actions { white-space: nowrap; text-align: left; }
.empty { padding: 30px 16px; text-align: center; color: var(--ink3); }

/* قائمة الحضور */
.att-list { display: flex; flex-direction: column; gap: 8px; }
.att-item { display: flex; align-items: center; gap: 12px; background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.att-item.present { border-color: #BFD9B5; background: #FAFDF8; }
.att-item .who { flex: 1; min-width: 0; }
.att-item .who b { display: block; overflow-wrap: anywhere; }
.att-item .meta { font-size: 13px; color: var(--ink3); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.att-item .time { font-weight: 800; color: var(--g700); font-variant-numeric: tabular-nums; }
.btn.here { background: var(--g700); color: #fff; border-color: var(--g700); min-width: 104px; min-height: 48px; font-size: 16px; }
.btn.here:active { transform: scale(.97); }
.att-more { min-width: 44px; padding: 0; }

/* النوافذ */
.modal-back { position: fixed; inset: 0; background: rgba(9,20,5,.45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--white); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head h3 { flex: 1; font-size: 19px; font-weight: 800; color: var(--g900); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; margin-top: 18px; flex-wrap: wrap; }
@media (min-width: 700px) { .modal-back { align-items: center; } .modal { border-radius: 20px; padding: 24px; } }
.banner { padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; display: flex; gap: 8px; align-items: flex-start; }
.banner.warn { background: var(--amber-l); color: #6B4800; }
.banner.info { background: var(--blue-l); color: #154A85; }
.banner.bad { background: var(--red-l); color: var(--red); }
.banner.ok { background: var(--g100); color: var(--g800); }

/* الإشعارات */
#toasts { position: fixed; z-index: 90; bottom: 84px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); pointer-events: none; }
.toast { background: var(--g900); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-weight: 500; animation: tin .2s ease-out; pointer-events: auto; }
.toast.err { background: var(--red); }
.toast.warn { background: #7A5200; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 1024px) { #toasts { bottom: 24px; } }

/* التقييم */
.crit { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.stars { display: inline-flex; gap: 4px; direction: ltr; }
.stars button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 800; cursor: pointer; color: var(--ink2); }
.stars button.on { background: var(--gold); border-color: var(--gold); color: #fff; }
.score { font-size: 26px; font-weight: 800; color: var(--g900); }

/* الملف */
.profile-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.avatar { width: 64px; height: 64px; border-radius: 18px; background: var(--g900); color: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 800; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv dt { color: var(--ink3); }
.kv dd { margin: 0; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 700; color: var(--ink3); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--g900); border-color: var(--gold); }

/* المهمات والفرق */
.team-block { border: 1px solid var(--line); border-radius: var(--r); background: var(--white); margin-bottom: 14px; overflow: hidden; }
.team-block > header { background: var(--g50); padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.team-block > header h3 { font-size: 17px; font-weight: 800; color: var(--g900); flex: 1; }
.task { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.task:last-child { border-bottom: 0; }
.task .body { flex: 1; min-width: 0; }
.task .ttl { font-weight: 800; }
.pick-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.member .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.member select { width: auto; min-width: 140px; }

/* صورة توزيع المهمات */
.export-stage { overflow: auto; background: #E8ECE5; border-radius: var(--r); padding: 16px; max-height: 75vh; }
.xp { width: 1080px; background: #fff; font-family: var(--font); color: #15200F; direction: rtl; padding: 56px 56px 44px; }
.xp.tall { min-height: 1920px; display: flex; flex-direction: column; }
.xp-head { display: flex; align-items: center; gap: 28px; border-bottom: 4px solid #B8963E; padding-bottom: 26px; margin-bottom: 26px; }
.xp-logo { background: #092D00; border-radius: 22px; padding: 18px 22px; }
.xp-logo img { width: 190px; display: block; }
.xp-titles { flex: 1; }
.xp-tag { color: #7A6226; font-weight: 700; font-size: 24px; }
.xp-h { font-size: 52px; font-weight: 800; color: #092D00; line-height: 1.2; }
.xp-date { display: flex; flex-wrap: wrap; gap: 10px 26px; font-size: 26px; font-weight: 700; color: #15200F; margin-bottom: 22px; }
.xp-date .pill { background: #092D00; color: #fff; padding: 4px 18px; border-radius: 999px; }
.xp table { width: 100%; border-collapse: collapse; font-size: 27px; }
.xp th { background: #092D00; color: #fff; text-align: right; padding: 14px 18px; font-weight: 800; }
.xp td { padding: 13px 18px; border-bottom: 1px solid #E2E8DE; vertical-align: top; overflow-wrap: anywhere; }
.xp tr:nth-child(even) td { background: #F6F9F4; }
.xp .xp-team td { background: #F6EFD9 !important; color: #092D00; font-weight: 800; font-size: 28px; border-bottom: 2px solid #B8963E; }
.xp .xp-team .ld { font-weight: 500; color: #7A6226; font-size: 23px; margin-right: 12px; }
.xp td.n { font-weight: 700; width: 38%; }
.xp.dense table { font-size: 23px; }
.xp.dense td { padding: 9px 16px; }
.xp.dense2 table { font-size: 20px; }
.xp.dense2 td { padding: 7px 14px; }
.xp-foot { margin-top: 28px; display: flex; justify-content: space-between; color: #4B5747; font-size: 22px; border-top: 2px solid #E2E8DE; padding-top: 18px; gap: 20px; }
.xp.tall .xp-body { flex: 1; }

/* الطباعة وPDF */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 14mm 12mm 16mm; @bottom-center { content: counter(page) " / " counter(pages); font-family: var(--font); font-size: 10pt; color: #555; } }
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
}
.pr { font-family: var(--font); color: #111; font-size: 11pt; direction: rtl; }
.pr-head { display: flex; align-items: center; gap: 16px; border-bottom: 2px solid #B8963E; padding-bottom: 10px; margin-bottom: 12px; }
.pr-head img { width: 110px; }
.pr-head .t1 { font-size: 17pt; font-weight: 800; color: #092D00; }
.pr-head .t2 { font-size: 10pt; color: #444; }
.pr h2 { font-size: 13pt; color: #092D00; margin: 14px 0 6px; break-after: avoid; }
.pr table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.pr th, .pr td { border: 1px solid #C9D2C3; padding: 4px 6px; text-align: right; font-size: 10pt; vertical-align: top; overflow-wrap: anywhere; }
.pr th { background: #EEF3EA; font-weight: 800; }
.pr thead { display: table-header-group; }
.pr tr { break-inside: avoid; }
.pr .vol-page { break-before: page; }
.pr .landscape { page: land; }
@page land { size: A4 landscape; margin: 12mm 10mm 14mm; @bottom-center { content: counter(page) " / " counter(pages); font-family: var(--font); font-size: 10pt; color: #555; } }
.pr td.i, .pr th.i { width: 26px; white-space: nowrap; text-align: center; }
.pr .vol-page:first-child { break-before: auto; }
.pr .keep { break-inside: avoid; }
.pr .sum { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.pr .sum div { border: 1px solid #C9D2C3; border-radius: 6px; padding: 5px 8px; }
.pr .sum b { display: block; font-size: 13pt; color: #092D00; }
