:root {
  --bg: #f4f3ef; --card: #fff; --ink: #1d2523; --mute: #66726f; --line: #dfe3df;
  --brand: #0f5c4d; --brand-ink: #fff; --soft: #e1efeb;
  --warn: #8a5a00; --warn-bg: #fbf0d6; --bad: #a3322a; --bad-bg: #f8e0dd; --ok: #1f6b3a; --ok-bg: #dcefe2;
  --r: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.right { text-align: right; }

/* layout */
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.nav { background: var(--card); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; padding: 4px 10px 16px; font-size: 16px; }
.nav a { display: block; padding: 9px 10px; border-radius: var(--r); color: var(--ink); text-decoration: none; }
.nav a.on { background: var(--soft); color: var(--brand); font-weight: 600; }
.nav .who { margin-top: auto; padding: 10px; font-size: 13px; color: var(--mute); border-top: 1px solid var(--line); }
main { padding: 22px 26px 60px; max-width: 980px; width: 100%; }

/* controls */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.sp { justify-content: space-between; }
.grow { flex: 1 1 160px; }
.btn { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: var(--r); padding: 10px 14px; min-height: 44px; cursor: pointer; font-weight: 600; }
.btn.alt { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.sm { min-height: 44px; padding: 6px 10px; font-size: 13px; }
.btn.danger { background: #fff; color: var(--bad); border: 1px solid var(--bad); }
.btn[disabled] { opacity: .5; cursor: default; }
label { display: block; font-size: 13px; color: var(--mute); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 9px 10px; min-height: 44px; border: 1px solid #c4cac6; border-radius: var(--r); background: #fff; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.err { background: var(--bad-bg); color: var(--bad); padding: 9px 12px; border-radius: var(--r); margin-bottom: 12px; font-size: 14px; }
.note { background: var(--soft); padding: 9px 12px; border-radius: var(--r); margin-bottom: 12px; font-size: 14px; }

/* lists */
.item { display: flex; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow-wrap: anywhere; }
.item .time { width: 54px; font-variant-numeric: tabular-nums; font-weight: 600; flex: none; }
.item a.t { color: var(--ink); text-decoration: none; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--brand); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--mute); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.num { font-variant-numeric: tabular-nums; }

dialog { border: 0; border-radius: 12px; padding: 18px; width: min(520px, calc(100vw - 24px)); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(20, 30, 28, .45); }
dialog h1 { margin-bottom: 12px; }

.auth { max-width: 380px; margin: 9vh auto; padding: 0 16px; }
.auth .card { padding: 22px; }
.toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); background: #1d2523; color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 14px; z-index: 10; }

/* phones */
@media (max-width: 760px) {
  .shell { display: block; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 5; }
  .nav .brand, .nav .who { display: none; }
  .nav a { flex: 1; text-align: center; padding: 10px 2px; font-size: 13px; min-height: 44px; }
  main { padding: 16px 14px 90px; }
  .grid2 { grid-template-columns: 1fr; }
  .item { flex-wrap: wrap; }
  .item .time { width: auto; min-width: 48px; }
  h1 { font-size: 18px; }
}
.row.sp { margin-bottom: 14px; }
.row.sp h1 { margin: 0; }
.item .actions { width: 100%; }
@media (min-width: 761px) { .item .actions { width: auto; } }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: start; }
.col { background: #ebeae5; border-radius: var(--r); padding: 10px; }
.col h2 { margin-bottom: 8px; }
.lead { display: flex; flex-direction: column; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; margin-bottom: 8px; color: var(--ink); text-decoration: none; }
.lead b { overflow-wrap: anywhere; }
@media (max-width: 760px) { .board { grid-template-columns: 1fr; } }
.row select { width: auto; flex: 1 1 140px; }
.stat b.neg { color: var(--bad, #b3261e); }

/* attendance toggles */
.seg { display: flex; gap: 4px; }
.segbtn { width: 38px; min-height: 38px; border: 1px solid #c4cac6; background: #fff; border-radius: 8px; font-weight: 700; cursor: pointer; }
.segbtn.on { color: #fff; border-color: transparent; background: #55605a; }
.segbtn.on.ok { background: #1f7a4d; } .segbtn.on.bad { background: #b3392f; } .segbtn.on.warn { background: #b7791f; }
.segbtn:disabled { cursor: default; opacity: .7; }

.funnel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fstage { display: flex; flex-direction: column; padding: 10px; border: 1px solid #e0e4e1; border-radius: 10px; text-decoration: none; color: inherit; background: #fafbfa; }
.fstage b { font-size: 22px; } .fstage span { color: #55605a; font-size: 13px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--mute); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--mute); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); }
.scroll { overflow-x: auto; }
.nav select { margin: 0 0 10px; }
@media (max-width: 760px) { .nav { overflow-x: auto; justify-content: flex-start; } .nav a { flex: 0 0 auto; min-width: 74px; } }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; padding: 0; flex: none; accent-color: var(--brand); }
.item:has(> input[type=checkbox]), .item:has(> input[type=radio]) { flex-wrap: nowrap; }
[dir=rtl] .right { text-align: left; }
[dir=rtl] .tbl th { text-align: right; }
[dir=rtl] body { font-family: system-ui, 'Segoe UI', Tahoma, 'Noto Naskh Arabic', 'Noto Sans Arabic', sans-serif; }
[dir=rtl] input[type=number], [dir=rtl] input[type=date], [dir=rtl] input[type=month], [dir=rtl] input[name=username], [dir=rtl] input[name=password], [dir=rtl] input[name=code] { direction: ltr; text-align: right; }

.qrbox{display:inline-block;text-align:center;margin:8px 0;padding:8px;background:#fff;border:1px solid var(--line,#ddd);border-radius:10px}.qrbox svg{display:block;margin:0 auto 4px;max-width:100%;height:auto}

/* UX pass: touch targets of 44px, links in lists get a 44px hit area, reduced motion respected */
.tabs a { display: inline-flex; align-items: center; min-height: 44px; }
.item a.t, .item a, .nav a, p > a:not(.btn), .muted a { display: inline-block; min-height: 44px; line-height: 44px; padding: 0 2px; }
.item .muted.small a, td a { line-height: 1.2; padding: 12px 2px; min-height: 44px; display: inline-block; }
input[type=checkbox], input[type=radio] { width: 24px; min-height: 24px; height: 24px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
.skip { position: absolute; left: -999px; top: 0; background: #fff; color: var(--brand); padding: 12px 16px; z-index: 100; font-weight: 600; }
.skip:focus { left: 8px; top: 8px; }
main:focus { outline: none; }
.offline { position: sticky; top: 0; z-index: 50; background: #7a4b00; color: #fff; text-align: center; padding: 6px 10px; font-size: 14px; }

/* LMS */
.pbar { height: 10px; background: #e6e9ef; border-radius: 5px; margin: 6px 0; overflow: hidden; }
.pbar > div { height: 10px; background: var(--brand); border-radius: 5px; }
.video { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--r); background: #000; }
.prose p { margin: 0 0 12px; white-space: pre-wrap; }
.qbox { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin: 0 0 12px; }
.qbox legend { font-weight: 600; padding: 0 6px; }
.item.opt { cursor: pointer; min-height: 44px; }
.okc { border-color: var(--ok); } .warnc { border-color: var(--warn); }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 110px; }
.spark .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; align-items: center; }
.spark .col div { width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.spark .col span { font-size: 10px; color: var(--mute); margin-top: 2px; }
.cert { background: #fff; border: 6px double var(--brand); border-radius: 6px; padding: 32px 20px; text-align: center; margin: 12px 0; }
.cert .who2 { font-size: 26px; font-weight: 700; margin: 6px 0 12px; }
.cert .what { font-size: 20px; font-weight: 600; color: var(--brand); margin: 6px 0; }
@media print { .nav, .noprint, .skip, .toast, .offline { display: none !important; } .shell { display: block; } main { padding: 0; max-width: none; } body { background: #fff; } }
.spark .col { min-width: 0; }
.item.opt input { width: 22px; height: 22px; flex: none; }

.rc-head { border-bottom: 2px solid var(--brand, #0f5c4d); margin: 8px 0 12px; padding-bottom: 8px; }
.rc-comment { margin: 8px 0; }
.rc-sign { display: none; }
@media print {
  .rc-sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 48px; }
  .rc-sign div { border-top: 1px solid #000; padding-top: 6px; font-size: 12px; text-align: center; }
  .rc .card { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; }
  .rc .stats { grid-template-columns: repeat(5, 1fr); }
  .rc .btn, .tabs { display: none !important; }
  @page { size: A4; margin: 14mm; }
}
