/* حاسبة المرتبات — واجهة عربية RTL للموبايل */
:root {
  color-scheme: light dark;
  --paper: #eef2f7;
  --card: #ffffff;
  --ink: #12263a;
  --muted: #5a6b7d;
  --line: #dbe3ec;
  --navy: #17324d;
  --navy-ink: #ffffff;
  --accent: #1f6fb2;
  --accent-soft: #dcebf8;
  --ok: #1b7a4b;       --ok-soft: #d8f1e3;
  --bad: #b3342c;      --bad-soft: #fbe1de;
  --info: #2a5fc4;     --info-soft: #dfe8fb;
  --warn: #8a5a00;     --warn-soft: #fcefc9;
  --mute: #5a6b7d;     --mute-soft: #e6ebf1;
  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1722;
    --card: #15212e;
    --ink: #e6eef6;
    --muted: #97a8b9;
    --line: #243445;
    --navy: #0a1117;
    --accent: #6bb3ee;
    --accent-soft: #17344d;
    --ok: #55d390;       --ok-soft: #123a28;
    --bad: #ff8d84;      --bad-soft: #43201d;
    --info: #8fb2ff;     --info-soft: #1b2b4f;
    --warn: #f1c35b;     --warn-soft: #3d3010;
    --mute: #97a8b9;     --mute-soft: #1d2b3a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
small { color: var(--muted); font-size: .8125rem; }
h1, h2, h3 { margin: 0; line-height: 1.25; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 640px; margin: 0 auto; position: relative; background: var(--paper); }

/* ---------- الهيدر ---------- */
.top {
  background: var(--navy); color: var(--navy-ink);
  padding: calc(env(safe-area-inset-top) + 12px) 18px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.top h1 { font-size: 1.2rem; font-weight: 800; }
.top small { color: rgba(255,255,255,.72); }
.badge-net { font-size: .75rem; background: rgba(255,255,255,.16); border-radius: 99px; padding: 3px 10px; }
.badge-net:empty { display: none; }

main { flex: 1; overflow-y: auto; padding: 14px 14px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); -webkit-overflow-scrolling: touch; }

/* ---------- الشريط السفلي ---------- */
.tabs {
  position: absolute; inset-inline: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
}
.tabs button {
  background: none; border: 0; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .75rem; font-weight: 600;
}
.tabs button svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }
.tabs button.on span { font-weight: 800; }

/* ---------- عناصر عامة ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px; margin-bottom: 12px; }
.card.flat { padding: 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.title-row { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 12px; }
.title-row h2 { font-size: 1.05rem; font-weight: 800; }

.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
}

.btn {
  border: 0; border-radius: var(--r-md); padding: 12px 18px; min-height: 46px;
  font-weight: 700; background: var(--accent); color: #fff;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: .9rem; }
.btn:disabled { opacity: .55; }
@media (prefers-color-scheme: dark) { .btn { color: #06121c; } }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; font-weight: 700; margin-bottom: 5px; }
.field > label > span { display: block; font-size: .85rem; font-weight: 700; margin-bottom: 5px; }
.field > small { display: block; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], textarea, select {
  width: 100%; min-height: 46px; padding: 9px 12px;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--paper);
}
input[type=number], input[type=date], .ltr { direction: ltr; text-align: right; }
input.num { direction: ltr; text-align: center; }
textarea { min-height: 70px; resize: vertical; }

.chip { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--mute-soft); color: var(--mute); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.banner { border-radius: var(--r-md); padding: 10px 14px; margin-bottom: 12px; font-size: .9rem; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

.empty { text-align: center; padding: 36px 18px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 6px; }

/* ---------- الحضور ---------- */
.datebar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.datebar .nav { width: 46px; height: 46px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--card); font-size: 1.3rem; font-weight: 800; color: var(--accent); }
.datebar .mid { flex: 1; text-align: center; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 4px 8px; position: relative; min-height: 46px; display: flex; flex-direction: column; justify-content: center; }
.datebar .mid b { font-size: 1rem; }
.datebar .mid input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.sumline { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.seg button { border: 1.5px solid var(--line); background: var(--paper); border-radius: var(--r-sm); min-height: 42px; font-weight: 700; font-size: .9rem; color: var(--muted); }
.seg.pay { grid-template-columns: repeat(3, 1fr); margin-top: 6px; }
.seg.pay button.on { background: var(--info); border-color: var(--info); color: #fff; }
.seg button.on.p { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg button.on.a { background: var(--bad); border-color: var(--bad); color: #fff; }
.seg button.on.l { background: var(--info); border-color: var(--info); color: #fff; }
.seg button.on.o { background: var(--mute); border-color: var(--mute); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { color: #06121c !important; } }
.nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.nums label span { display: block; font-size: .75rem; color: var(--muted); font-weight: 700; margin-bottom: 3px; text-align: center; }
.nums input { min-height: 42px; padding: 6px; }

/* ---------- الموظفون ---------- */
.emp-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: start; }
.emp-row:last-child { border-bottom: 0; }
.emp-row b { display: block; }
.fab { position: absolute; inset-inline-start: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: #fff; font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgba(18,38,58,.3); }
@media (prefers-color-scheme: dark) { .fab { color: #06121c; } }

/* ---------- كشف الشهر ---------- */
.total-card { background: var(--navy); color: #fff; border-radius: var(--r-lg); padding: 18px; margin-bottom: 12px; border: 0; }
.total-card small { color: rgba(255,255,255,.7); }
.total-card .big { font-size: 2.1rem; font-weight: 800; line-height: 1.15; margin: 2px 0 10px; }
.total-card .big small { font-size: 1rem; color: rgba(255,255,255,.75); margin-inline-start: 4px; }
.total-card .meta { display: flex; gap: 22px; }
.total-card .meta b { display: block; font-size: 1.1rem; }

.rep-head { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px; background: none; border: 0; text-align: start; }
.rep-head .amount { font-weight: 800; font-size: 1.15rem; color: var(--navy); text-align: end; }
@media (prefers-color-scheme: dark) { .rep-head .amount { color: var(--accent); } }
.rep-head .amount small { display: block; font-weight: 600; }
.rep-body { padding: 4px 14px 14px; border-top: 1px dashed var(--line); }
.leader { display: flex; align-items: baseline; gap: 6px; padding: 7px 0; }
.leader .lab { flex: none; max-width: 70%; }
.leader .lab small { display: block; }
.leader .dots { flex: 1; border-bottom: 2px dotted var(--line); transform: translateY(-4px); min-width: 14px; }
.leader .val { flex: none; font-weight: 700; }
.leader.minus .val { color: var(--bad); }
.leader.plus .val { color: var(--ok); }
.leader.net { margin-top: 6px; padding-top: 10px; border-top: 2px solid var(--ink); font-size: 1.15rem; font-weight: 800; }
.leader.net .val { color: var(--ink); }
.adj { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btnrow .btn { flex: 1; }

/* ---------- نافذة سفلية ---------- */
.sheet-wrap { position: absolute; inset: 0; background: rgba(8,16,26,.55); display: flex; align-items: flex-end; z-index: 20; }
.sheet { background: var(--card); width: 100%; max-height: 92%; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { font-size: 1.15rem; margin-bottom: 14px; }
.daylist .d { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: start; }
.daylist .d .n { width: 34px; font-weight: 800; }
.daylist .d.off { opacity: .6; }

/* ---------- الإعدادات ---------- */
.set-group { margin-bottom: 18px; }
.set-group > h3 { font-size: .95rem; margin: 0 4px 8px; color: var(--muted); font-weight: 800; }
.days-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.days-pick label { cursor: pointer; }
.days-pick input { position: absolute; opacity: 0; pointer-events: none; }
.days-pick span { display: inline-block; padding: 8px 12px; border-radius: 99px; border: 1.5px solid var(--line); font-weight: 700; font-size: .85rem; background: var(--paper); }
.days-pick input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.days-pick input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { .days-pick input:checked + span { color: #06121c; } }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-of-type { border-bottom: 0; }
.kv b { text-align: end; }

/* ---------- شاشة التفعيل ---------- */
.lock { flex: 1; overflow-y: auto; padding: calc(env(safe-area-inset-top) + 40px) 22px 30px; display: flex; flex-direction: column; gap: 16px; }
.lock .logo { width: 72px; height: 72px; border-radius: 20px; background: var(--navy); display: grid; place-items: center; }
.lock .logo svg { width: 40px; height: 40px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lock h1 { font-size: 1.6rem; font-weight: 800; }
.lock .code-in { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.35rem; letter-spacing: .12em; text-align: center; text-transform: uppercase; direction: ltr; min-height: 56px; }
.status-box { border-radius: var(--r-lg); padding: 14px 16px; font-weight: 600; background: var(--mute-soft); color: var(--ink); }
.status-box.warn { background: var(--warn-soft); color: var(--warn); }
.status-box.bad { background: var(--bad-soft); color: var(--bad); }
.status-box.ok { background: var(--ok-soft); color: var(--ok); }

#toast { position: fixed; inset-inline: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px); margin: 0 auto; max-width: 420px; background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: var(--r-md); font-weight: 600; text-align: center; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
#toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

.dategrp { display: flex; gap: 8px; align-items: stretch; }
.dategrp input { flex: 1; min-width: 0; }
.dategrp .btn { flex: none; width: auto; min-height: 46px; padding: 0 18px; }

/* خانة البحث بالاسم: صغيرة وهادئة، تتلوّن عند التركيز */
.qbox { position: relative; display: flex; align-items: center; height: 38px; margin: 0 0 10px; background: var(--card); border: 1.5px solid var(--line); border-radius: 999px; padding: 0 12px; transition: border-color .15s, box-shadow .15s; }
.qbox:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.qbox svg { width: 17px; height: 17px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.qbox:focus-within svg { stroke: var(--accent); }
.qbox input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: .92rem; padding: 0 8px; outline: none; box-shadow: none; -webkit-appearance: none; appearance: none; }
.qbox input::-webkit-search-cancel-button { display: none; }
.qbox input::placeholder { color: var(--muted); }
.qx { flex: none; width: 24px; height: 24px; border: 0; border-radius: 50%; background: var(--mute-soft); color: var(--muted); font-size: 1.05rem; line-height: 1; display: grid; place-items: center; cursor: pointer; padding: 0; }
.qx[hidden] { display: none; }
.noq { text-align: center; color: var(--muted); padding: 22px 12px; font-size: .92rem; }
