:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #12211f;
  --muted: #64736f;
  --line: #e2e8e6;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e3f4f1;
  --ok: #15803d;
  --ok-soft: #e4f6ea;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --info: #1d4ed8;
  --info-soft: #e6eefe;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: .9rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { max-width: 960px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-size: 1.05rem; }
.logout { display: flex; align-items: center; gap: 10px; margin: 0; }
.who { color: var(--muted); font-size: .9rem; }
.tabs { max-width: 960px; margin: 0 auto; padding: 0 8px; display: flex; gap: 2px; overflow-x: auto; }
.tabs a { padding: 10px 12px; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }

.wrap { max-width: 960px; margin: 0 auto; padding: 18px 16px 60px; }
.narrow { max-width: 420px; margin: 6vh auto 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--bad-soft); color: var(--bad); }

label { display: block; font-weight: 500; font-size: .92rem; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; font: inherit; color: inherit;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 4px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: var(--brand-ink);
}
button:disabled { opacity: .6; cursor: default; }
.btn.ghost, button.ghost { background: transparent; color: var(--brand); border-color: var(--line); }
button.danger { background: transparent; color: var(--bad); border-color: var(--line); }
button.sm, .btn.sm { padding: 6px 12px; font-size: .88rem; }
button.link { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 500; }
button.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .85rem; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.b-present { background: var(--ok-soft); color: var(--ok); }
.b-late, .b-late_now, .b-pending { background: var(--warn-soft); color: var(--warn); }
.b-absent { background: var(--bad-soft); color: var(--bad); }
.b-excused { background: var(--info-soft); color: var(--info); }
.b-expected { background: #eef1f0; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; }
th { text-align: right; color: var(--muted); font-weight: 500; font-size: .85rem; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

details.edit summary { cursor: pointer; color: var(--brand); font-size: .88rem; font-weight: 500; list-style: none; }
details.edit summary::-webkit-details-marker { display: none; }
details.edit[open] { background: var(--bg); border-radius: 10px; padding: 10px; margin-top: 6px; min-width: 230px; }
details.edit .field { margin-bottom: 8px; }

.week { display: grid; gap: 8px; }
.week-row { display: grid; grid-template-columns: 80px 1fr 1fr; gap: 8px; align-items: center; }

/* صفحة الموظف */
.hero { text-align: center; padding: 26px 18px; }
.hero .big { font-size: 1.15rem; font-weight: 600; margin-bottom: 4px; }
.scan-btn { width: 100%; padding: 18px; font-size: 1.15rem; border-radius: 16px; margin-top: 16px; }
.scanner { position: fixed; inset: 0; background: #000; z-index: 50; display: none; flex-direction: column; }
.scanner.on { display: flex; }
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .frame { position: absolute; top: 50%; left: 50%; width: min(64vw, 280px); aspect-ratio: 1; transform: translate(-50%, -60%); border: 3px solid #fff; border-radius: 22px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); pointer-events: none; }
.scanner .bar { position: relative; z-index: 2; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); background: #000; color: #fff; text-align: center; }
.scanner .bar button { margin-top: 10px; background: #fff; color: #000; }
.result { border-radius: var(--radius); padding: 16px; margin-top: 16px; font-weight: 600; display: none; white-space: pre-line; text-align: right; }
.result.on { display: block; }
.result.ok { background: var(--ok-soft); color: var(--ok); }
.result.pending { background: var(--warn-soft); color: var(--warn); }
.result.err { background: var(--bad-soft); color: var(--bad); }

/* طباعة وعرض الكود */
body.bare { background: #fff; }
.qr-page { text-align: center; padding: 30px 16px; }
.qr-page h1 { font-size: 1.8rem; margin-bottom: 6px; }
.qr-box { display: inline-block; padding: 16px; border: 3px solid var(--ink); border-radius: 20px; margin: 20px 0; background: #fff; }
.qr-box svg, .qr-box img { display: block; width: min(76vw, 420px); height: auto; }
.countdown { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; max-width: 420px; margin: 0 auto; }
.countdown i { display: block; height: 100%; background: var(--brand); width: 100%; }
@media print { .no-print { display: none !important; } }
