/* هوية وريد — بنفسجي */
:root {
  --purple: #95389E;
  --purple-deep: #6e2f74;
  --purple-ink: #3f1a44;
  --lav: #f3e9f5;
  --lav-2: #e7d6eb;
  --teal: #0D7D90;
  --bg: #f7f4f8;
  --card: #ffffff;
  --ink: #2b2230;
  --muted: #7b6e80;
  --line: #e8dfeb;
  --deficit: #b3261e; --deficit-bg: #fdecea;
  --surplus: #0a6a7a; --surplus-bg: #e2f3f5;
  --zero: #2e7d32;    --zero-bg: #e8f4e8;
  --pending: #93600a; --pending-bg: #fff3dc;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
}
a { color: var(--purple-deep); }
h1, h2 { margin: 0 0 .6em; line-height: 1.3; }
h2 { font-size: 1.1rem; color: var(--purple-ink); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 60px; }
.muted { color: var(--muted); }
.small, small { font-size: .82em; }
.nowrap { white-space: nowrap; }
code { background: var(--lav); padding: 1px 6px; border-radius: 4px; }

/* الشريط العلوي */
.topbar { background: var(--purple-deep); color: #fff; border-bottom: 4px solid var(--teal); position: sticky; top: 0; z-index: 20; }
.topbar-in { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: baseline; gap: 10px; color: #fff; text-decoration: none; }
.brand-mark { font-weight: 800; font-size: 1.6rem; letter-spacing: -.5px; }
.brand-sub { opacity: .8; font-size: .9rem; }
.nav { display: flex; align-items: center; gap: 4px; margin-inline-start: auto; flex-wrap: wrap; }
.nav a { color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; opacity: .88; }
.nav a:hover { background: rgba(255,255,255,.1); opacity: 1; }
.nav a.on { background: #fff; color: var(--purple-deep); opacity: 1; }
.nav-sep { width: 1px; height: 22px; background: rgba(255,255,255,.3); margin: 0 6px; }
.nav-toggle { display: none; margin-inline-start: auto; background: none; border: 0; color: #fff; font-size: 1.6rem; cursor: pointer; }

/* بطاقات */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.panel.narrow { max-width: 640px; margin-inline: auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title { font-size: 1.5rem; font-weight: 800; color: var(--purple-ink); margin: 0 0 .3em; }
.page-head .page-title { margin: 0; }
.branch-tag { display: inline-block; background: var(--lav); color: var(--purple-deep); padding: 4px 12px; border-radius: 99px; font-weight: 700; margin: 0 0 14px; }
.empty { background: var(--card); border: 1px dashed var(--lav-2); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }

/* شبكات */
.grid2, .grid3, .grid4 { display: grid; gap: 14px; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.grid-side { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* نماذج */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; color: var(--purple-ink); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: #fff;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(149,56,158,.15); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 600; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--purple); }
.amount-field input { font-size: 1.8rem; font-weight: 800; text-align: center; direction: ltr; color: var(--purple-deep); padding: 14px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; }
.inline-form .w-sm { flex: 0 0 80px; }
form.inline { display: inline; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

/* أزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; border: 0; border-radius: 10px; padding: 10px 18px; min-height: 44px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:focus-visible { outline: 3px solid rgba(149,56,158,.4); outline-offset: 2px; }
.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-deep); }
.btn-primary:disabled { background: #bba5bf; cursor: wait; }
.btn-soft { background: var(--lav); color: var(--purple-deep); }
.btn-soft:hover { background: var(--lav-2); }
.btn-danger { background: var(--deficit-bg); color: var(--deficit); }
.btn-danger:hover { background: var(--deficit); color: #fff; }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: .88rem; }
.btn-lg { padding: 14px; font-size: 1.1rem; }
.btn-block { width: 100%; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-zone { border-top: 1px dashed var(--line); margin-top: 18px; padding-top: 14px; }

/* تنبيهات */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.alert-ok { background: var(--zero-bg); color: var(--zero); }
.alert-err { background: var(--deficit-bg); color: var(--deficit); }
.alert-info { background: var(--lav); color: var(--purple-deep); }

/* حالات الفرق */
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-weight: 700; font-size: .84rem; white-space: nowrap; }
.pill.deficit { background: var(--deficit-bg); color: var(--deficit); }
.pill.surplus { background: var(--surplus-bg); color: var(--surplus); }
.pill.zero { background: var(--zero-bg); color: var(--zero); }
.pill.pending { background: var(--pending-bg); color: var(--pending); }
.pill.missing { background: #efeaf1; color: var(--muted); }
.t-deficit { color: var(--deficit); font-style: normal; }
.t-surplus { color: var(--surplus); font-style: normal; }

/* المؤشرات */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat span { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat b { font-size: 1.45rem; font-weight: 800; color: var(--purple-ink); direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.stat b.split { font-size: 1.1rem; }
.stat small { color: var(--muted); }
.stat-diff .pill { font-size: 1.05rem; padding: 6px 14px; align-self: flex-start; margin-top: 4px; }

/* تبويبات */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { text-decoration: none; padding: 8px 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-weight: 600; color: var(--ink); }
.tabs a b { background: var(--lav); color: var(--purple-deep); border-radius: 99px; padding: 0 8px; margin-inline-start: 4px; font-size: .85rem; }
.tabs a.on { background: var(--purple-deep); color: #fff; border-color: var(--purple-deep); }
.tabs a.on b { background: rgba(255,255,255,.2); color: #fff; }
.filters { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 150px; }

/* قائمة المراجعة */
.rv-list { display: flex; flex-direction: column; gap: 8px; }
.rv-row {
  display: grid; grid-template-columns: 1.4fr 1fr 1fr .9fr 1.3fr auto; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-inline-start: 5px solid var(--line);
  border-radius: 12px; padding: 12px 14px; scroll-margin-top: 90px;
}
.rv-row.pending { border-inline-start-color: #e9b44c; }
.rv-row.done { border-inline-start-color: var(--teal); }
.rv-row.missing { border-inline-start-color: #cbbfd0; background: #fbf9fb; }
.rv-row:target { box-shadow: 0 0 0 3px rgba(149,56,158,.25); }
.rv-headrow { background: transparent; border: 0; padding: 0 14px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.rv-branch { display: flex; flex-direction: column; }
.rv-branch b { font-size: 1.02rem; color: var(--purple-ink); }
.rv-branch small { color: var(--muted); }
.rv-num b { font-size: 1.15rem; direction: ltr; display: block; font-variant-numeric: tabular-nums; }
.rv-in input { text-align: center; direction: ltr; font-weight: 700; }
.rv-wide { grid-column: 2 / -1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.rv-meta { grid-column: 1 / -1; display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.rv-meta .note-branch { color: var(--purple-deep); font-weight: 600; }
.rv-meta .edited { color: var(--pending); font-weight: 600; }
.lbl { display: none; font-size: .78rem; color: var(--muted); font-weight: 600; }
.file-link { font-size: .85rem; font-weight: 600; text-decoration: none; }
.carry { display: inline-flex; gap: 4px; align-items: center; }

/* الجداول */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
.tbl th { background: var(--lav); color: var(--purple-ink); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
.tbl tbody tr:hover { background: #fcf9fd; }
.tbl tfoot td { background: var(--purple-deep); color: #fff; font-weight: 800; }
.tbl tfoot .pill { background: #fff; }
.tbl .num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .col-total { background: #f7eef9; font-weight: 700; }
.tbl tfoot .col-total { background: var(--purple-ink); }
.tbl .note { min-width: 140px; max-width: 260px; }
.tbl tr.inactive { opacity: .55; }
.role { font-weight: 700; font-size: .85rem; }
.role-admin { color: var(--deficit); } .role-accountant { color: var(--teal); } .role-branch { color: var(--purple-deep); }
.details { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); font-weight: 600; } .details dd { margin: 0; }

/* الفلاتر */
.filter-panel label { font-size: .82rem; }
.filter-go { display: flex; align-items: flex-end; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.quick a { font-size: .85rem; font-weight: 600; text-decoration: none; padding: 4px 12px; border-radius: 99px; background: var(--lav); }

/* رفع الإيصال */
.uploader { border: 2px dashed var(--lav-2); border-radius: 12px; padding: 14px; background: #fcf9fd; display: flex; flex-direction: column; gap: 10px; }
.up-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.up-head b { color: var(--purple-ink); }
.up-head .check { font-size: .82rem; font-weight: 600; }
.up-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.up-actions .btn { flex-direction: row; font-size: .95rem; }
.up-status { font-size: .88rem; color: var(--muted); }
.up-status.busy { color: var(--pending); font-weight: 700; }
.up-status.ok { color: var(--zero); font-weight: 700; }
.up-status.err { color: var(--deficit); font-weight: 700; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs:empty { display: none; }
.thumb { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.thumb canvas { display: block; max-height: 110px; width: auto; }
.thumb button { position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(63,26,68,.8); color: #fff; font-size: 16px; line-height: 1; cursor: pointer; }
.thumb-file { display: flex; align-items: center; gap: 8px; padding: 10px 40px 10px 12px; }
.thumb-file span { font-size: 1.6rem; }

/* الفروع */
.branch-list { display: flex; flex-direction: column; gap: 6px; }
.branch-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--line); }
.branch-row.inactive { opacity: .55; }
.branch-row .inline-form { flex: 1; }
.bid { color: var(--muted); font-size: .8rem; min-width: 34px; }
.region-name { font-weight: 800; color: var(--purple-ink); font-size: 1.05rem; }

/* الدخول */
.auth { min-height: 88vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 18px; border-top: 6px solid var(--purple); padding: 28px; box-shadow: 0 10px 40px rgba(110,47,116,.12); }
.auth-brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 22px; color: var(--muted); font-weight: 600; }
.auth-brand .brand-mark { color: var(--purple-deep); font-size: 2.6rem; line-height: 1.1; }

/* الصفحة العامة */
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.home { max-width: 720px; margin: 6vh auto 0; text-align: center; }
.home-title { font-size: 2.2rem; font-weight: 800; color: var(--purple-ink); margin: 0; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 28px; }
.home-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 16px; border-radius: 18px; text-decoration: none;
  background: var(--card); border: 1.5px solid var(--lav-2); color: var(--purple-ink); }
.home-card b { font-size: 1.35rem; }
.home-card small { color: var(--muted); }
.home-card.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.home-card.primary small { color: rgba(255,255,255,.8); }
.home-card:hover { transform: translateY(-2px); }
.home-ico { font-size: 2rem; line-height: 1; }
.nav-staff { font-size: .88rem; }
.center { text-align: center; }
.shift-note { margin: -4px 0 0; font-size: .86rem; color: var(--teal); font-weight: 600; }
.shift-note:empty { display: none; }
.success-card { text-align: center; }
.success-card .details { text-align: right; max-width: 420px; margin: 16px auto 20px; }
.success-card .row-actions { justify-content: center; }
.success-ico { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; background: var(--zero-bg); color: var(--zero);
  display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 800; }
.big { font-size: 1.3rem; color: var(--purple-deep); }
.tag { display: inline-block; background: var(--surplus-bg); color: var(--surplus); border-radius: 6px; padding: 0 6px; font-weight: 700; font-size: .78rem; }

/* الشفتات داخل المراجعة */
.shifts { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; background: #faf7fb; border-radius: 10px; padding: 8px; }
.shift { display: grid; grid-template-columns: 1.4fr .8fr 1.6fr auto; gap: 8px 12px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.shift-who { display: flex; flex-direction: column; line-height: 1.4; }
.shift-who b { font-size: .88rem; color: var(--teal); }
.shift-amt { font-weight: 800; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.shift-meta { display: flex; flex-direction: column; line-height: 1.4; }
.note-branch { color: var(--purple-deep); font-weight: 600; }
.edited { color: var(--pending); font-weight: 600; }
.file-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.btn-xs { padding: 4px 10px; min-height: 32px; font-size: .8rem; border-radius: 8px; }
.entry-cards { display: flex; flex-direction: column; gap: 12px; }
.entry-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.entry-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }

/* معاينة الإيصال */
.modal-open { overflow: hidden; }
.pdf-modal { position: fixed; inset: 0; z-index: 100; background: rgba(40,16,44,.92); display: flex; flex-direction: column; }
.pdf-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top)); background: var(--purple-deep); color: #fff; }
.pdf-bar b { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.pdf-tools { display: flex; gap: 6px; }
.pdf-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pdf-body canvas { background: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.35); max-width: none; border-radius: 4px; }
.pdf-msg { color: #fff; margin-top: 30vh; text-align: center; }
.pdf-msg a { color: #fff; }

.print-only { display: none; }

/* الجوال */
@media (max-width: 1000px) {
  .grid4 { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: repeat(2, 1fr); }
  .grid-side { grid-template-columns: 1fr; }
  .rv-row { grid-template-columns: 1fr 1fr; }
  .rv-headrow { display: none; }
  .rv-branch { grid-column: 1 / -1; }
  .rv-note { grid-column: 1 / -1; }
  .rv-act { grid-column: 1 / -1; }
  .rv-act .btn { width: 100%; }
  .rv-wide { grid-column: 1 / -1; }
  .lbl { display: block; }
  .shift { grid-template-columns: 1fr auto; }
  .shift-meta, .shift-file { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .nav-toggle { display: block; }
  .nav { display: none; position: absolute; top: 64px; right: 0; left: 0; background: var(--purple-deep); flex-direction: column; align-items: stretch; padding: 8px 12px 14px; border-bottom: 4px solid var(--teal); }
  .nav-open .nav { display: flex; }
  .nav-sep { display: none; }
  .brand-sub { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .page-title { font-size: 1.3rem; }
  .filters input, .filters select { min-width: 0; flex: 1; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat b { font-size: 1.15rem; }
  .details { grid-template-columns: 1fr; }
  .home-actions { grid-template-columns: 1fr; }
  .home-card { padding: 22px 16px; flex-direction: row; justify-content: center; gap: 12px; }
  .home-card small { display: none; }
  .pdf-bar b { max-width: 100%; flex-basis: 100%; }
  .pdf-tools { width: 100%; justify-content: space-between; }
  .pdf-tools .btn { flex: 1; }
}
@media (max-width: 420px) {
  .grid4 { grid-template-columns: 1fr; }
  .up-actions { grid-template-columns: 1fr; }
}

/* الطباعة / حفظ PDF */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 10px; }
  .no-print, .topbar, .alert { display: none !important; }
  .print-only { display: flex; }
  .print-head { gap: 16px; align-items: center; border-bottom: 3px solid var(--purple); padding-bottom: 8px; margin-bottom: 10px; }
  .print-head .brand-mark { color: var(--purple-deep); font-size: 2rem; }
  .print-head h1 { font-size: 1.3rem; margin: 0; color: var(--purple-ink); }
  .print-head p { margin: 0; }
  main.wrap { max-width: none; padding: 0; }
  .panel { border: 0; padding: 0; margin-bottom: 12px; }
  .table-wrap { overflow: visible; border: 0; }
  .tbl { font-size: 9px; }
  .tbl th, .tbl td { padding: 4px 5px; border: 1px solid #ccc; }
  .tbl th { position: static; }
  .tbl thead { display: table-header-group; }
  .tbl tr { page-break-inside: avoid; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat { padding: 6px 10px; }
  .stat b { font-size: 1rem; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
