@font-face { font-family: Tajawal; src: url(fonts/Tajawal-Regular.ttf); font-weight: 400; }
@font-face { font-family: Tajawal; src: url(fonts/Tajawal-Medium.ttf); font-weight: 500; }
@font-face { font-family: Tajawal; src: url(fonts/Tajawal-Bold.ttf); font-weight: 700; }

:root {
  --navy: #17345c;
  --navy-2: #1f4373;
  --navy-3: #0f2444;
  --orange: #f6a51f;
  --orange-soft: #fff4e0;
  --bg: #f4f6fa;
  --card: #fff;
  --line: #e3e8f0;
  --text: #1b2433;
  --muted: #6b778a;
  --ok: #1e8e5a;
  --ok-soft: #e4f5ec;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --bad: #c53b3b;
  --bad-soft: #fbe7e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 64, .06), 0 2px 8px rgba(16, 32, 64, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Tajawal, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy-2); }
.num, td.num, input.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; text-align: right; }
.ltr { direction: ltr; unicode-bidi: plaintext; }

/* ─── الهيكل ─── */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 22px 14px;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 0 22px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 14px; }
.brand img { width: 118px; }
.brand span { font-size: 13px; color: rgba(255,255,255,.7); letter-spacing: .3px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: rgba(255,255,255,.82); text-decoration: none; font-weight: 500; transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; flex: none; opacity: .9; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(246,165,31,.16); color: var(--orange); }
.nav .badge { margin-inline-start: auto; background: var(--orange); color: var(--navy-3); border-radius: 99px; font-size: 12px; padding: 0 7px; font-weight: 700; }
.sidebar .me { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; font-size: 14px; }
.sidebar .me b { display: block; }
.sidebar .me small { color: rgba(255,255,255,.6); }
.sidebar .me button { margin-top: 10px; width: 100%; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 8px; padding: 7px; cursor: pointer; }
.sidebar .me button:hover { background: rgba(255,255,255,.08); }

main { padding: 26px 30px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; color: var(--navy); }
.page-head .sub { color: var(--muted); font-size: 14px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--navy); }

/* ─── عناصر ─── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h2 { font-size: 17px; margin: 0 0 14px; color: var(--navy); }
.card h3 { font-size: 15px; margin: 0 0 10px; }
.grid { display: grid; gap: 16px; }
.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)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  main { padding: 18px; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: #fff;
  border-radius: 9px; padding: 8px 15px; cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--text);
  transition: background .15s, border-color .15s, transform .08s;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: #f2f5f9; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.accent { background: var(--orange); border-color: var(--orange); color: var(--navy-3); font-weight: 700; }
.btn.accent:hover { background: #f0991a; }
.btn.danger { color: var(--bad); border-color: #f0caca; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef2f7; }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn.lg { padding: 11px 20px; font-size: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field > span .req { color: var(--bad); }
.input, select.input, textarea.input {
  border: 1px solid #d5dce6; border-radius: 9px; padding: 8px 11px; background: #fff; width: 100%; min-height: 40px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(31,67,115,.12); }
textarea.input { min-height: 90px; resize: vertical; }
.input[readonly] { background: #f6f8fb; }
.hint { font-size: 12.5px; color: var(--muted); }
fieldset { border: none; padding: 0; margin: 0; }
.form-section { margin-bottom: 22px; }
.form-section > h3 { font-size: 14px; color: var(--navy); margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 160px; }
.toolbar .search { flex: 1; min-width: 220px; max-width: 380px; }

table.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { text-align: right; font-weight: 500; color: var(--muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover td { background: #f7f9fc; }
.table tfoot td { font-weight: 700; background: #fafbfd; border-top: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .4; display: block; margin: 0 auto 8px; }

.pill { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.muted { background: #eef1f5; color: var(--muted); }
.pill.navy { background: #e6ecf5; color: var(--navy); }

.avatar { width: 38px; height: 38px; border-radius: 9px; object-fit: cover; background: #e8edf4; display: inline-grid; place-items: center; color: var(--navy); font-weight: 700; font-size: 15px; flex: none; overflow: hidden; }
.who { display: flex; align-items: center; gap: 10px; }
.who b { display: block; font-weight: 500; }
.who small { color: var(--muted); font-size: 12.5px; }

.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat .k { color: var(--muted); font-size: 13.5px; }
.stat .v { font-size: 28px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--muted); }
.stat.accent { border-top: 3px solid var(--orange); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--navy); }
.tabs a.active { color: var(--navy); border-bottom-color: var(--orange); }

.profile-head { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; }
.profile-head .big-avatar { width: 84px; height: 84px; border-radius: 14px; object-fit: cover; background: #e8edf4; display: grid; place-items: center; font-size: 30px; color: var(--navy); font-weight: 700; overflow: hidden; }
.profile-head h1 { margin: 0; font-size: 22px; color: var(--navy); }
.profile-head .meta { color: var(--muted); font-size: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ─── الصورة والبطاقة ─── */
.steps { display: grid; gap: 18px; }
.step { display: grid; grid-template-columns: 34px 1fr; gap: 14px; }
.step .n { width: 34px; height: 34px; border-radius: 50%; background: #e6ecf5; color: var(--navy); display: grid; place-items: center; font-weight: 700; }
.step.done .n { background: var(--ok); color: #fff; }
.step.current .n { background: var(--orange); color: var(--navy-3); }
.step h3 { margin: 4px 0 4px; font-size: 16px; color: var(--navy); }
.step p.d { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.photo-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.photo-box { width: 220px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.photo-box .frame { width: 220px; height: 220px; border-radius: 10px; border: 1px dashed #c9d3e0; background: #f7f9fc center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; overflow: hidden; position: relative; }
.photo-box .frame img { width: 100%; height: 100%; object-fit: cover; }
.photo-box .frame.portrait { height: 260px; }
.photo-box .frame img.contain { object-fit: contain; background: #f2f4f7; }
.photo-box label { font-size: 13px; color: var(--muted); }
.drop { cursor: pointer; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--orange); background: var(--orange-soft); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #dfe5ee; border-top-color: var(--orange); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-overlay { position: absolute; inset: 0; background: rgba(255,255,255,.88); display: grid; place-items: center; align-content: center; gap: 10px; font-size: 13px; color: var(--navy); text-align: center; padding: 10px; }

.cropper { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start; }
.crop-stage { position: relative; width: 360px; height: 360px; border-radius: 10px; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px var(--line); touch-action: none; cursor: grab; }
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.crop-controls { display: flex; flex-direction: column; gap: 14px; min-width: 240px; flex: 1; max-width: 340px; }
.crop-controls input[type=range] { width: 100%; accent-color: var(--navy); direction: ltr; }
.crop-controls .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }

.card-preview { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start; }
.card-preview iframe { width: 420px; height: 600px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* ─── نوافذ ─── */
.modal-back { position: fixed; inset: 0; background: rgba(15, 30, 55, .45); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .15s ease-out; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(10,25,50,.25); animation: pop .18s ease-out; }
.modal.wide { width: min(820px, 100%); }
.modal header { padding: 18px 22px 0; display: flex; align-items: center; }
.modal header h2 { margin: 0; font-size: 18px; color: var(--navy); }
.modal header .x { margin-inline-start: auto; }
.modal .body { padding: 18px 22px; }
.modal footer { padding: 0 22px 20px; display: flex; gap: 8px; justify-content: flex-start; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }

#toasts { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--navy-3); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; animation: pop .2s ease-out; font-size: 14.5px; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ─── الدخول ─── */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--navy); padding: 20px; }
.auth .box { background: #fff; border-radius: 16px; padding: 30px 30px 26px; width: min(400px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth .logo-wrap { background: var(--navy); border-radius: 12px; padding: 18px; display: grid; place-items: center; margin-bottom: 20px; }
.auth .logo-wrap img { width: 130px; }
.auth h1 { font-size: 20px; margin: 0 0 4px; color: var(--navy); }
.auth p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.auth form { display: grid; gap: 14px; }

/* ─── الرواتب ─── */
.pay-table input.cell { width: 104px; min-height: 34px; padding: 4px 8px; border: 1px solid transparent; border-radius: 7px; background: #f6f8fb; text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.pay-table input.cell:hover { border-color: #d5dce6; }
.pay-table input.cell:focus { outline: none; border-color: var(--navy-2); background: #fff; }
.pay-table input.cell.small { width: 64px; }
.pay-table td.net { font-weight: 700; color: var(--navy); white-space: nowrap; }
.pay-table td:first-child { min-width: 170px; }
.pay-table .who b { white-space: nowrap; }
.table tfoot td { white-space: nowrap; }
.table td a { text-decoration: none; white-space: nowrap; }
.table td a:hover { text-decoration: underline; }
.lock-note { background: var(--ok-soft); color: var(--ok); padding: 9px 14px; border-radius: 9px; font-size: 14px; margin-bottom: 14px; }

.check { width: 18px; height: 18px; accent-color: var(--navy); cursor: pointer; }
.muted { color: var(--muted); }
.mt { margin-top: 16px; }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.callout { background: var(--orange-soft); border: 1px solid #f7dca8; border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.callout.info { background: #eaf1fb; border-color: #cfdcf0; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 9px 0; border-bottom: 1px solid #eef1f6; display: flex; gap: 10px; align-items: center; font-size: 14px; }
.list-plain li:last-child { border-bottom: none; }
.bar { height: 8px; background: #eef1f6; border-radius: 99px; overflow: hidden; flex: 1; }
.bar i { display: block; height: 100%; background: var(--navy-2); border-radius: 99px; }
.code-tag { font-family: Lato, Tajawal, sans-serif; direction: ltr; unicode-bidi: plaintext; font-weight: 700; color: var(--navy); }

.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .sidebar, .no-print, .page-head .actions, #toasts, .toolbar, .tabs { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  .card { border: none; box-shadow: none; }
  .print-only { display: block; }
  .pay-table input.cell { background: transparent; border: none; width: auto; }
  body.print-slip > *:not(.modal-back) { display: none !important; }
  body.print-slip .modal-back { position: static; background: none; padding: 0; }
  body.print-slip .modal { box-shadow: none; width: 100%; max-height: none; }
  body.print-slip .modal header .x, body.print-slip .modal footer { display: none; }
}

/* ─── اللغة ─── */
.lang-btn { margin-top: 8px; width: 100%; background: transparent; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 8px; padding: 6px; cursor: pointer; font-size: 13px; }
.lang-btn:hover { background: rgba(255,255,255,.08); }
.lang-btn.auth-lang { display: block; width: auto; margin: -14px 0 10px; margin-inline-start: auto; padding: 4px 12px; color: var(--navy); border-color: var(--line); }
.lang-btn.auth-lang:hover { background: #f3f6fa; }
[dir="ltr"] .table th, [dir="ltr"] .num, [dir="ltr"] td.num, [dir="ltr"] input.num { text-align: left; }
[dir="ltr"] .back svg { transform: scaleX(-1); }
