:root {
  --brand: #FFB20C;
  --brand-2: #F29104;
  --brand-soft: #FFF3D6;
  --green: #2F930A;
  --green-soft: #E6F3DF;
  --ink: #1D2318;
  --ink-2: #3A4135;
  --muted: #6E7368;
  --line: #E7E4DA;
  --bg: #F7F5EF;
  --surface: #FFFFFF;
  --danger: #C0392B;
  --danger-soft: #FBE7E4;
  --blue: #2B7BB9;
  --blue-soft: #E3EFF8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29,35,24,.06), 0 4px 16px rgba(29,35,24,.05);
  --side: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
/* منع التكبير: النقر المزدوج، وتكبير iOS التلقائي عند الكتابة في حقل خطه أصغر من 16 */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* لا شيء يتجاوز عرض الشاشة: Safari يوسّع الصفحة كاملة لو عنصر واحد أعرض منها */
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
img, svg, input, select, textarea, button { max-width: 100%; }
.input { min-width: 0; }
/* رمز الدخول حقل نصي مخفي بالنقاط، حتى لا يعامله الآيفون ككلمة مرور ويقترح حفظها */
.input.pin { -webkit-text-security: disc; text-security: disc; letter-spacing: 3px; }
input[type=date], input[type=time], input[type=month] { -webkit-appearance: none; appearance: none; min-width: 0; }
@media (pointer: coarse) { input, select, textarea { font-size: 16px !important; } }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.num, td.n, .tabnum { font-variant-numeric: tabular-nums; }

/* ===== الهيكل ===== */
.shell { display: flex; min-height: 100vh; }
.side {
  width: var(--side); flex: 0 0 var(--side);
  background: var(--ink); color: #EDEBE3;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 18px 14px;
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 12px; }
.side .brand img { width: 54px; height: auto; }
.side .brand b { display: block; font-size: 17px; color: #fff; }
.side .brand small { color: var(--brand); font-size: 12px; letter-spacing: .5px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px; color: #CFCDC4; font-weight: 500;
}
.nav a svg { width: 20px; height: 20px; flex: 0 0 20px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: var(--brand); color: var(--ink); font-weight: 600; }
.side .me { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 8px 0; font-size: 13px; color: #A9A79E; display: flex; justify-content: space-between; align-items: center; }
.side .me button { background: none; border: 1px solid rgba(255,255,255,.15); color: #EDEBE3; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 13px; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.topbar { display: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== المكونات ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid > *, .stack > * { min-width: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

.stat { padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 28px; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 14px; font-weight: 500; color: var(--muted); }
.stat.y { background: var(--brand); border-color: var(--brand); }
.stat.y .k { color: #5C4300; }
.stat.g .v { color: var(--green); }
.stat.r .v { color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { border-color: #CFCBBE; background: #FBFAF6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--ink); font-weight: 600; }
.btn.primary:hover { background: #F5A800; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.04); }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 6px; width: 34px; height: 34px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.field > small { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 9px 12px; outline: none; min-height: 40px;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,178,12,.22); }
.input.sm { padding: 5px 8px; min-height: 34px; font-size: 14px; }
input[type=time].input, input[type=date].input, input[type=month].input { direction: ltr; text-align: right; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .span2 { grid-column: span 2; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--green); }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 6px 0 -2px; grid-column: 1 / -1; padding-top: 8px; border-top: 1px dashed var(--line); }
.section-title:first-child { border-top: 0; padding-top: 0; }

.seg { display: inline-flex; background: #EFEDE5; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.days-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.days-pick label { border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: 13px; background: #fff; }
.days-pick input { display: none; }
.days-pick label:has(input:checked) { background: var(--ink); color: #fff; border-color: var(--ink); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; border: 0; background: none; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs .on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }

/* الجداول */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #FBFAF6; position: sticky; top: 0; }
.t td { padding: 10px 12px; border-bottom: 1px solid #F0EEE7; vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: #FCFBF7; }
.t td.n, .t th.n { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t tfoot td { font-weight: 700; background: #FBFAF6; border-top: 1px solid var(--line); }
.t tr.row-off td { background: #FAF9F5; color: var(--muted); }
.t tr.clickable { cursor: pointer; }
.t .name { font-weight: 600; }
.t .meta { color: var(--muted); font-size: 12.5px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: #EFEDE5; color: var(--ink-2); }
.pill.green { background: var(--green-soft); color: #23700A; }
.pill.red { background: var(--danger-soft); color: var(--danger); }
.pill.yellow { background: var(--brand-soft); color: #8A5A00; }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.dark { background: var(--ink); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.note { background: var(--brand-soft); border: 1px solid #F6DFA3; border-radius: 12px; padding: 12px 14px; font-size: 14px; color: #5C4300; }
.note.green { background: var(--green-soft); border-color: #C8E4B9; color: #23560E; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.kv { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 6px 16px; font-size: 14px; }
.kv dd { overflow-wrap: anywhere; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.datebar { display: flex; align-items: center; gap: 6px; }
.datebar .input { width: auto; }

/* بطاقات الأرصدة */
.bal { padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.bal .k { font-size: 13px; color: var(--muted); }
.bal .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bal .d { font-size: 12.5px; color: var(--muted); }

/* الحضور السريع */
.att-row .input.sm { width: 92px; }
.att-row select.input.sm { width: auto; }
.saving { opacity: .55; }
.flash { animation: flash .9s ease; }
@keyframes flash { 0% { background: var(--green-soft); } 100% { background: transparent; } }

/* النوافذ */
.modal-back { position: fixed; inset: 0; background: rgba(20,24,17,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; animation: fade .15s ease; }
.modal { background: #fff; border-radius: 18px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2); animation: pop .18s ease; }
.modal.wide { max-width: 820px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-h h3 { margin: 0; font-size: 17px; }
.modal-b { padding: 18px 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-h, .modal-f { flex: 0 0 auto; }
body.modal-open { overflow: hidden; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-start; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 200; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: pop .18s ease; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }

/* الدخول */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.auth .box { width: 100%; max-width: 380px; background: #fff; border-radius: 20px; padding: 28px; }
.auth .logo { display: flex; justify-content: center; margin-bottom: 10px; }
.auth .logo img { width: 120px; }
.auth h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.auth p { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }

.loading { padding: 60px; text-align: center; color: var(--muted); }
.spin { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* قسيمة الراتب */
.slip { font-size: 14px; }
.slip .hd { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 14px; }
.slip .hd img { width: 70px; }
.slip table { width: 100%; border-collapse: collapse; }
.slip td { padding: 6px 4px; border-bottom: 1px dashed var(--line); }
.slip td.n { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.slip .tot td { border-top: 2px solid var(--ink); border-bottom: 0; font-weight: 700; font-size: 16px; }
.slip h4 { margin: 14px 0 4px; font-size: 13px; color: var(--muted); }

@media print {
  body { background: #fff; }
  body.printing > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; padding: 10mm; }
}
.print-area { display: none; }

/* الجوال */
@media (max-width: 960px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .shell { display: block; }
  /* القائمة المسكّرة تُشال من الصفحة كاملة: Safari يحسب العناصر المزاحة خارج الشاشة ويسمح بالتمرير الأفقي لها */
  .side { position: fixed; inset: 0 0 0 auto; z-index: 90; height: 100%; display: none; }
  .side.open { display: flex; box-shadow: -10px 0 40px rgba(0,0,0,.3); animation: slideIn .22s ease; }
  @keyframes slideIn { from { transform: translateX(100%); } }
  .shell, .main { width: 100%; max-width: 100%; overflow-x: hidden; }
  .datebar { max-width: 100%; }
  .datebar .input { width: 150px; }
  .page-head > * { max-width: 100%; min-width: 0; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; display: none; }
  .scrim.open { display: block; }
  .topbar { display: flex; align-items: center; justify-content: flex-start; gap: 10px; padding: 10px 12px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 50; }
  .topbar img { height: 34px; }
  .topbar .who { margin-inline-start: auto; font-size: 13px; color: var(--ink); background: var(--brand); padding: 3px 10px; border-radius: 99px; font-weight: 600; max-width: 35vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar b { white-space: nowrap; }
  .topbar button { background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; display: flex; }
  .topbar button svg { width: 24px; height: 24px; }
  .main { padding: 18px 16px 50px; }
  .page-head h1 { font-size: 20px; }
  .g2, .g3 { grid-template-columns: minmax(0,1fr); }
  .form-grid { grid-template-columns: minmax(0,1fr); }
  .form-grid .span2 { grid-column: auto; }
  .stat .v { font-size: 22px; }
  .modal-back { align-items: flex-end; padding: 0; height: 100vh; height: 100dvh; }
  /* dvh = الارتفاع الظاهر فعلاً بين شريطي Safari، حتى يبقى زر الحفظ ظاهراً تحت */
  .modal { border-radius: 18px 18px 0 0; max-height: 80vh; max-height: 80dvh; }
  .modal-f { padding-bottom: calc(14px + env(safe-area-inset-bottom)); background: #fff; border-radius: 0; }
  .hide-m { display: none; }
}
