:root{
  --col:560px;
  --bg:#e8edf4; --paper:#fff; --ink:#14213d; --muted:#5a6882;
  --blue:#2549b8; --blue-d:#1a3690; --rule:#c6daf0; --margin:#d6455a;
  --ok:#1f7a4d; --err:#b3263a; --line:#d5dde9;
  --font:'Tajawal','Segoe UI',Tahoma,Arial,sans-serif;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--bg);color:var(--ink);font:400 17px/1.7 var(--font)}
a{color:var(--blue)}
.wrap{max-width:860px;margin:0 auto;padding:0 18px}

.topbar{background:var(--ink);color:#fff}
.topbar-in{display:flex;align-items:center;justify-content:space-between;gap:16px;min-height:64px;flex-wrap:wrap}
.brand{color:#fff;text-decoration:none;font-weight:800;font-size:1.25rem;display:flex;flex-direction:column;line-height:1.25;padding:8px 0}
.brand small{font-weight:400;font-size:.85rem;color:#b9c5dd}
.nav{display:flex;gap:4px;flex-wrap:wrap}
.nav a{color:#dbe4f5;text-decoration:none;padding:6px 12px;border-radius:6px;font-size:.95rem}
.nav a:hover{background:rgba(255,255,255,.12)}
.nav a.on{background:#fff;color:var(--ink);font-weight:700}
main{padding-top:26px;padding-bottom:30px;min-height:70vh}
.foot{color:var(--muted);font-size:.9rem;padding-bottom:28px;text-align:center}
h1{font-size:1.6rem;margin:0 0 14px;font-weight:800}
h2{font-size:1.15rem;margin:0 0 10px}

/* ===== واجهة الزائر ===== */
.picker{text-align:center;margin:6px 0 4px}
.picker h1{margin-bottom:14px}
.picker select{display:block;width:min(100%,var(--col));height:68px;margin:0 auto;padding:0 52px;font:700 1.5rem var(--font);
  text-align:center;text-align-last:center;color:var(--ink);cursor:pointer;appearance:none;-webkit-appearance:none;
  border:2px solid var(--ink);border-radius:14px;
  background:#fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%2314213d' stroke-width='2'/></svg>") no-repeat left 20px center/18px}
.picker select:hover,.picker select:focus{border-color:var(--blue)}
.updated{margin:12px 0 0;color:var(--muted);font-size:.92rem}
.updated b{color:var(--ink);font-weight:700}
.hint,.empty{color:var(--muted);margin:26px 0;text-align:center}
.hint.small{font-size:.88rem;margin:12px 0 0}
.actions{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;width:min(100%,var(--col));margin:22px auto 14px}
.actions>.btn,.actions>.cols{height:48px;width:100%;padding:0 10px;display:flex;align-items:center;justify-content:center}
.cols{gap:8px;border:1.5px solid var(--line);border-radius:8px;background:var(--paper);font-size:.95rem}
.cols b{min-width:1.2em;text-align:center}
.cols .btn.sm{width:32px;height:32px;padding:0;font-size:1.1rem;line-height:1}

.tip{display:flex;align-items:center;gap:16px;width:min(100%,var(--col));margin:0 auto 20px;padding:14px 18px;background:#fff;
  border:1.5px solid var(--line);border-right:5px solid var(--blue);border-radius:12px}
.tip-text p{margin:0;color:var(--muted);font-size:.93rem;line-height:1.7}
.tip-icon{flex-shrink:0;color:var(--blue)}
.tip-text b{color:var(--ink)}

/* ورقة السجل: خطوط دفتر + هامش أحمر */
.sheets{display:flex;flex-direction:column;gap:20px}
.page{background:var(--paper);border-radius:6px;box-shadow:0 1px 0 var(--line),0 12px 28px -18px rgba(20,33,61,.35);padding:20px 22px 22px}
.sheet-head{text-align:center;border-bottom:2px solid var(--ink);padding-bottom:8px;margin-bottom:4px}
.head-top{display:flex;justify-content:space-between;align-items:baseline;gap:12px;font-size:.88rem;line-height:1.5}
.sheet-head .school{color:var(--ink);font-weight:700;text-align:right}
.sheet-head .year{color:var(--muted);text-align:left;white-space:nowrap}
.sheet-foot{display:flex;justify-content:space-between;gap:12px;margin-top:10px;padding-top:6px;border-top:1.5px solid var(--ink);font-size:.9rem;line-height:1.5}
.sheet-foot[hidden],.sheet-foot [hidden]{display:none}
.sheet-foot .f-name{margin-inline-end:auto}
.prof-form{display:grid;grid-template-columns:1fr 1fr;gap:10px;width:min(100%,var(--col));margin:0 auto 14px}
.prof-form label{margin:0}
.prof-form input{margin-top:4px}
.sheet-head h2{font-size:1.2rem;font-weight:800;margin:2px 0;line-height:1.4}
.sheet-head .meta{color:var(--muted);font-size:.85rem;line-height:1.4}
.register{width:100%;border-collapse:collapse;table-layout:fixed;font-size:13px}
.register th{text-align:right;font-weight:700;font-size:12px;color:var(--muted);padding:0 8px;height:26px;line-height:1.2;border-bottom:1.5px solid var(--rule)}
.register td{padding:0 8px;border-bottom:1.5px solid var(--rule);height:26px;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.register .num{width:46px;text-align:center;border-left:2px solid var(--margin);color:var(--muted);font-variant-numeric:tabular-nums}
.register .nom{width:34%}
.register th.extra{color:var(--ink);cursor:text;border-right:1px solid var(--rule);overflow:hidden;white-space:nowrap}
.register td.extra{border-right:1px solid var(--rule)}
.register th.extra:empty::before{content:attr(data-ph);color:#a3b0c6;font-weight:400}
.register tr{page-break-inside:avoid}

/* حجم مضغوط: 36 تلميذاً في الصفحة (PDF والطباعة) */
/* largeur = celle du conteneur html2pdf (190mm): ne jamais dépasser, sinon la droite est coupée; le padding absorbe le léger débordement du texte */
.sheets.pdf-mode{width:100%;padding:0 12px;gap:0;background:#fff}
.pdf-mode .page{box-shadow:none;border-radius:0;padding:0;page-break-after:always;break-after:page}
.pdf-mode .page:last-child{page-break-after:auto;break-after:auto}
.pdf-mode .register{font-size:12px}
.pdf-mode .register th,.pdf-mode .register td{height:23px}
.pdf-mode .register th.extra:empty::before{content:none}

/* ===== مشترك ===== */
.btn{font:inherit;font-weight:700;cursor:pointer;border:1.5px solid var(--line);background:var(--paper);color:var(--ink);
  padding:8px 18px;border-radius:8px}
.btn:hover{border-color:var(--blue)}
.btn.primary{background:var(--blue);border-color:var(--blue);color:#fff}
.btn.primary:hover{background:var(--blue-d)}
.btn.danger{color:var(--err)}
.btn.danger:hover{background:var(--err);border-color:var(--err);color:#fff}
.btn.sm{padding:3px 12px;font-size:.9rem}
.btn:disabled{opacity:.6;cursor:wait}
:focus-visible{outline:3px solid #7aa2ff;outline-offset:2px}

/* ===== فضاء المشرف ===== */
.dlg{border:0;border-radius:14px;padding:22px 24px;max-width:440px;width:calc(100% - 32px);color:var(--ink);font-family:var(--font);
  box-shadow:0 24px 60px -12px rgba(20,33,61,.5)}
.dlg::backdrop{background:rgba(20,33,61,.55)}
.dlg h3{margin:0 0 6px;font-size:1.15rem}
.dlg p{margin:0 0 16px;color:var(--muted)}
.dlg small{display:block;margin-top:12px;color:var(--err)}
.dlg-actions{display:flex;flex-direction:column;gap:8px}

.flash{padding:10px 14px;border-radius:8px;margin-bottom:16px;border:1.5px solid}
.flash.ok{background:#e6f4ec;border-color:#a9d6bb;color:var(--ok)}
.flash.err{background:#fbe9ec;border-color:#efb3bd;color:var(--err)}
.card{background:var(--paper);border:1.5px solid var(--line);border-radius:10px;padding:18px;margin-bottom:18px}
.card.narrow{max-width:420px;margin:20px auto}
label{display:block;font-weight:500;font-size:.95rem;margin-bottom:12px}
input,select,textarea{display:block;width:100%;font:inherit;padding:8px 10px;margin-top:4px;border:1.5px solid var(--line);
  border-radius:8px;background:#fff;color:var(--ink)}
input:focus,select:focus,textarea:focus{border-color:var(--blue);outline:none}
.inline-form{display:flex;gap:10px;align-items:flex-end;flex-wrap:wrap}
.inline-form label{margin:0}
.inline-form.tight{flex-wrap:nowrap;align-items:center}
.inline-form.tight input{margin:0}
.grow{flex:1;min-width:160px}
.two{display:grid;grid-template-columns:1fr 1fr;gap:18px}
.two .card{margin-bottom:0}
.two{margin-bottom:18px}
.table-wrap{padding:0;overflow-x:auto}
.grid{width:100%;border-collapse:collapse}
.grid th{text-align:right;font-size:.9rem;color:var(--muted);padding:10px 12px;border-bottom:1.5px solid var(--line);background:#f6f8fb}
.grid td{padding:8px 12px;border-bottom:1px solid var(--line);vertical-align:middle}
.grid tr:last-child td{border-bottom:0}
.grid input,.grid select{margin:0;padding:5px 8px}
.c{text-align:center!important}
.nowrap{white-space:nowrap}
.d-inline{display:inline}

@media (max-width:520px){
  .actions,.prof-form{grid-template-columns:1fr}
}
@media (max-width:640px){
  body{font-size:16px}
  .two{grid-template-columns:1fr}
  .sheet{padding:18px 12px 22px}
  .inline-form.tight{flex-wrap:wrap}
}
@media (prefers-reduced-motion:no-preference){.btn,.chip{transition:background .15s,border-color .15s,color .15s}}

@media print{
  body{background:#fff;font-size:13px}
  .topbar,.picker,.actions,.hint,.tip,.prof-form,.foot,.flash{display:none!important}
  main{padding:0;min-height:0}.wrap{max-width:none;padding:0}
  .sheets{display:block}
  .page{box-shadow:none;padding:0;border-radius:0;page-break-after:always;break-after:page}
  .page:last-child{page-break-after:auto;break-after:auto}
  .register{font-size:12px}
  .register th,.register td{height:23px}
  .register th.extra:empty::before{content:none}
  @page{size:A4;margin:10mm}
}

/* أرقام اسم القسم: عزل الاتجاه حتى لا ينعكس ترتيبها */
.sheet-head h2 bdi{unicode-bidi:isolate;direction:rtl}

.nav-user{color:#fff;font-weight:700;padding:6px 12px;font-size:.95rem}

/* ===== إدخال النقط ===== */
.grade-filters{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;max-width:900px;margin:0 auto 18px}
.grade-filters label{display:block;font-weight:700;font-size:.92rem}
.grade-filters select{display:block;width:100%;height:44px;margin-top:4px;font:inherit;padding:0 10px;border:1.5px solid var(--line);border-radius:8px;background:#fff}
.grades{max-width:720px;margin:0 auto}
.grades-head{display:flex;justify-content:space-between;align-items:baseline;gap:12px;flex-wrap:wrap}
.muted{color:var(--muted)}
.grade-table{font-size:15px}
.grade-table td,.grade-table th{height:44px}
.grade-table .nom{width:auto}
.grade-table .gcol{width:150px;text-align:center}
.grade-table td.nom{white-space:normal}
input.grade{width:110px;height:38px;text-align:center;font:700 1.1rem var(--font);font-variant-numeric:tabular-nums;letter-spacing:1px;
  border:1.5px solid var(--line);border-radius:8px;background:#fff;color:var(--ink)}
input.grade:focus{outline:none;border-color:var(--blue);box-shadow:0 0 0 3px rgba(37,73,184,.18)}
input.grade.bad{border-color:var(--err);background:#fdecef}
.grades-foot{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:16px;flex-wrap:wrap}
@media (max-width:700px){.grade-filters{grid-template-columns:1fr 1fr}}

/* ===== نقط القسم وبطاقات النقط (فضاء المشرف) ===== */
.report-actions{display:flex;flex-wrap:wrap;gap:10px;width:auto;max-width:none;margin:0 0 16px}
.report-actions .btn{height:44px;padding:0 18px;display:inline-flex;align-items:center;text-decoration:none}
.report-sheet{background:var(--paper);border-radius:6px;box-shadow:0 1px 0 var(--line),0 12px 28px -18px rgba(20,33,61,.35);padding:20px 22px;overflow-x:auto}
.report-table{width:100%;border-collapse:collapse;font-size:13px}
.report-table th,.report-table td{border:1px solid var(--rule);padding:4px 6px;text-align:center;line-height:1.3}
.report-table thead th{background:#f3f6fb;color:var(--ink);font-weight:700}
.report-table th.sub small{color:var(--muted);font-weight:400}
.report-table th.k{font-size:11px;color:var(--muted)}
.report-table .nom{text-align:right;white-space:nowrap}
.report-table .num{width:34px;color:var(--muted)}
.report-table td.v{font-variant-numeric:tabular-nums}
.report-table .m,.report-table td.gen{font-weight:700}
.report-table td.gen,.report-table th.gen{background:#eef3ff}
.report-table tfoot th,.report-table tfoot td{background:#f9fafc}
.pdf-mode .report-table{font-size:11px}
.pdf-mode .no-print{display:none!important}

.bulletins{display:grid;gap:18px}
.bulletin{background:var(--paper);border-radius:6px;box-shadow:0 1px 0 var(--line),0 12px 28px -18px rgba(20,33,61,.35);padding:22px 24px;max-width:794px;margin:0 auto;width:100%}
.b-info{display:flex;justify-content:space-between;gap:12px;margin:14px 0 12px;font-size:15px}
.b-table{font-size:13px}
.b-table th.prof,.b-table td.prof{text-align:right;font-size:11.5px;width:22%}
.b-sum{display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin:16px 0}
.b-sum div{border:1.5px solid var(--ink);border-radius:8px;padding:8px 6px;text-align:center}
.b-sum span{display:block;font-size:12px;color:var(--muted)}
.b-sum b{display:block;font-size:1.1rem;font-variant-numeric:tabular-nums}
.b-notes{border:1.5px solid var(--line);border-radius:8px;height:90px;padding:8px 12px;font-size:13px;color:var(--muted)}
.b-sign{display:flex;justify-content:space-between;margin-top:22px;height:70px;font-size:13px;color:var(--muted);padding:0 24px}
.pdf-mode .bulletin{box-shadow:none;padding:0;max-width:none}
@page report{size:A4 landscape;margin:10mm}
@media print{
  .no-print{display:none!important}
  .report-sheet{page:report;box-shadow:none;padding:0;overflow:visible}
  .report-table{font-size:10.5px}
  .bulletins{display:block}
  .bulletin{box-shadow:none;padding:0;max-width:none;break-after:page;page-break-after:always}
  .bulletin:last-child{break-after:auto;page-break-after:auto}
}

/* ===== modales larges (gestion des profs) ===== */
.dlg.wide{max-width:760px;max-height:92vh;overflow:auto}
.dlg-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px}
.dlg-head h2,.dlg-head h3{margin:0}
.dlg-x{border:0;background:none;font-size:1.6rem;line-height:1;cursor:pointer;color:var(--muted);padding:0 4px}
.dlg-x:hover{color:var(--ink)}
.tabs{display:flex;gap:6px;border-bottom:1.5px solid var(--line);margin-bottom:16px}
.tabs button{font:inherit;font-weight:700;border:0;background:none;padding:8px 14px;cursor:pointer;color:var(--muted);border-bottom:3px solid transparent;margin-bottom:-1.5px}
.tabs button.on{color:var(--blue);border-bottom-color:var(--blue)}
.page-head{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin-bottom:14px}
.page-head h1{margin:0}
.dlg form label:last-of-type{margin-bottom:12px}

/* espace admin : page plus large (tableaux) */
.is-admin .wrap{max-width:1280px}
@media print{.is-admin .wrap{max-width:none}}
.sub-cell{display:flex;flex-wrap:wrap;align-items:center;gap:4px 12px}
.sub-cell small{white-space:nowrap}
