/* تأجير — تصميم رسمي هادئ: أسطح مسطحة، حدود رفيعة، لون أساسي واحد، بلا ظلال ولا تدرجات. */
:root {
  --desk: #E8EBEF;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-2: #FAFBFC;
  --line: #E2E5EA;
  --line-2: #CBD1D9;
  --text: #151C26;
  --text-2: #475262;
  --text-3: #6F7988;
  --primary: #163A61;
  --primary-press: #0F2C4B;
  --primary-soft: #EDF1F6;
  --primary-line: #D3DCE8;
  --danger: #8E2B2B;
  --focus: 0 0 0 3px rgba(22, 58, 97, .16);
  --r: 8px;
  --r-sm: 6px;
  --appbar: 56px;
  --tabbar: 62px;
  --bar: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
svg.ic { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.row-amount, .stat-n, .kv-v, .code-box { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.danger-text { color: var(--danger); }

/* الإطار */
#app { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: var(--bg); }
@media (min-width: 520px) {
  body { background: var(--desk); }
  #app { border-inline: 1px solid var(--line); }
  .tabbar, .bar { border-inline: 1px solid var(--line); }
}

.flow > * + * { margin-top: 16px; }
.flow > .sec-head { margin-top: 24px; }
.flow > .sec-head:first-child { margin-top: 0; }
.flow > .sec-head + * { margin-top: 8px; }
.flow-sm > * + * { margin-top: 10px; }

/* الشريط العلوي */
.appbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--appbar);
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.appbar-title {
  flex: 1; min-width: 0;
  padding: 0 8px;
  font-size: 17px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar-btn {
  height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--r-sm);
}
.appbar-btn:hover { background: var(--bg); }
.appbar-text { padding: 0 12px; color: var(--primary); font-weight: 600; font-size: 14px; }

.main { padding: 16px 16px 24px; }
.main.has-tabbar { padding-bottom: calc(var(--tabbar) + var(--safe-b) + 24px); }
.main.has-bar { padding-bottom: calc(var(--bar) + var(--safe-b) + 24px); }

/* البحث */
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; right: 14px; color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%; height: 48px;
  padding: 0 44px 0 14px;
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r);
  outline: none; font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--text-3); font-size: 14.5px; }
.search input:focus { border-color: var(--primary); box-shadow: var(--focus); }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* الأرقام */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
}
.stats-2 { grid-template-columns: 1fr 1.4fr; }
.stat { padding: 12px 14px; min-width: 0; }
.stat + .stat { border-inline-start: 1px solid var(--line); }
.stat-n { font-size: 21px; font-weight: 600; line-height: 1.25; white-space: nowrap; }
.stat-l { margin-top: 2px; font-size: 12.5px; color: var(--text-3); }

/* رؤوس الأقسام */
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sec-title { font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font-size: 13px; color: var(--text-2);
}
.tool:hover { border-color: var(--text-3); color: var(--text); }
.list-count { font-size: 12.5px; color: var(--text-3); }
.page-note { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); }
.footnote { text-align: center; font-size: 12.5px; color: var(--text-3); }

/* القوائم */
.group {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden;
}
.group.pad { padding: 16px; }
.group.pad p { font-size: 14.5px; color: var(--text-2); }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px;
  text-align: right;
  background: var(--surface);
}
.row + .row, .row + .day-head, .row + .btn-row { border-top: 1px solid var(--line); }
.row[data-go], button.row { cursor: pointer; }
.row[data-go]:hover, button.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.row-title { min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amount { flex: none; font-weight: 600; font-size: 15px; white-space: nowrap; }
.row-amount small { font-weight: 400; font-size: 12px; color: var(--text-3); }
.row-sub { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { margin-top: 1px; font-size: 13px; color: var(--text-3); }
.row-meta.st-rented { color: var(--primary); }
.closed-mark { display: inline-flex; vertical-align: -3px; margin-inline-end: 6px; color: var(--text-3); }
.row-closed .row-title, .row-closed .row-amount { color: var(--text-2); font-weight: 500; }
.row-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-foot .row-meta { margin-top: 0; }
.row-actions { display: flex; gap: 8px; flex: none; }
.row-foot .row-actions { margin-block: 4px -2px; }
.row-foot .icon-btn { width: 36px; height: 36px; }
.row-ic {
  width: 36px; height: 36px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  background: var(--bg); color: var(--text-2);
}
.chev { flex: none; color: var(--text-3); }
.code-box {
  flex: none; min-width: 44px; height: 44px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  color: var(--text-2);
}
.icon-btn:hover { border-color: var(--text-3); color: var(--text); }
.icon-btn.plain { border-color: transparent; }
.icon-btn.plain:hover { background: var(--bg); }
.group-foot {
  display: flex; justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  font-size: 14px; color: var(--text-2);
}
.group-foot b { font-weight: 600; color: var(--text); }
.day-head {
  padding: 7px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 12.5px; font-weight: 500; color: var(--text-3);
}
.shop-block { padding: 16px; }
.shop-block h2 { font-size: 16px; font-weight: 600; }
.shop-block p { margin-top: 2px; font-size: 13.5px; color: var(--text-3); }

/* مفتاح / قيمة */
.kv-row {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 11px 14px; font-size: 14.5px;
}
.kv-row + .kv-row, .kv-row + .row, .row + .kv-row { border-top: 1px solid var(--line); }
.kv-k { color: var(--text-2); }
.kv-v { font-weight: 500; text-align: left; }
.kv-row.strong .kv-k, .kv-row.strong .kv-v { color: var(--text); font-weight: 600; }
.kv-row.total { background: var(--surface-2); border-top-color: var(--line-2); }
.kv-row.total .kv-k { color: var(--text); font-weight: 600; }
.kv-row.total .kv-v { font-size: 17px; font-weight: 700; }

.badge {
  display: inline-flex; align-items: center;
  height: 24px; padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  white-space: nowrap;
}
.badge-open { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary); }

/* الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--r);
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-press); }
.btn-primary:disabled { background: #9AA6B5; }
.btn-secondary { background: var(--surface); border-color: var(--line-2); color: var(--text); }
.btn-secondary:hover { border-color: var(--text-3); }
.btn-ghost { color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13.5px; }
.btn-row { display: flex; gap: 8px; padding: 12px 14px; }
.btn-row .btn { flex: 1; height: 44px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* النماذج */
.form-sec {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
}
.form-sec > * + *, .group.pad.flow > * + * { margin-top: 14px; }
.form-sec.invalid { border-color: var(--danger); }
.form-sec-head { display: flex; align-items: center; gap: 10px; }
.form-sec-head h2 { font-size: 15.5px; font-weight: 600; }
.step {
  width: 24px; height: 24px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-2); border-radius: 50%;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
}
.label { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.opt { margin-inline-start: 4px; font-size: 12.5px; font-weight: 400; color: var(--text-3); }
.input {
  width: 100%; height: 48px; padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r);
  outline: none; font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--primary); box-shadow: var(--focus); }
.input::placeholder { color: #A3ABB6; }
.input:disabled { background: var(--bg); color: var(--text-3); }
.textarea { height: auto; min-height: 76px; padding: 12px 14px; line-height: 1.6; resize: vertical; }
select.input {
  padding-left: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236F7988' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
}
.ltr-input { direction: ltr; text-align: right; }
.field.invalid .input { border-color: var(--danger); }
.field.invalid .label { color: var(--danger); }
.input-affix { position: relative; }
.input-affix .input { padding-left: 52px; }
.affix { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 14px; color: var(--text-3); pointer-events: none; }
.field-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 13px; color: var(--text-3); }
.hint b { color: var(--text); font-weight: 600; }
.field .hint { margin-top: 6px; }
#nr-match:empty { display: none; }
.note {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-line); border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--text-2);
}
.note svg { margin-top: 3px; color: var(--primary); }
.note b { color: var(--text); font-weight: 600; }

.seg {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r);
  overflow: hidden;
}
.seg button { flex: 1; height: 42px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.seg button + button { border-inline-start: 1px solid var(--line-2); }
.seg button.on { background: var(--primary); color: #fff; font-weight: 600; }

.add-btn {
  width: 100%; height: 48px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface);
  border: 1px dashed var(--line-2); border-radius: var(--r);
  font-size: 14.5px; font-weight: 600; color: var(--primary);
}
.add-btn:hover { border-color: var(--primary); }

/* الصور */
.capture {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 28px 16px;
  background: var(--bg);
  border: 1px dashed var(--line-2); border-radius: var(--r);
  color: var(--text-2);
}
.capture:hover { border-color: var(--primary); }
.capture b { font-size: 15px; color: var(--primary); }
.capture span { font-size: 13px; color: var(--text-3); }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo {
  position: relative; aspect-ratio: 1;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  overflow: hidden;
}
button.photo { padding: 0; cursor: zoom-in; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-x {
  position: absolute; top: 6px; left: 6px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(21, 28, 38, .75); color: #fff; border-radius: 50%;
}
.photo-add {
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: 1px dashed var(--line-2); border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 500; color: var(--primary);
}
.photo-full { display: block; width: 100%; border-radius: var(--r-sm); }

/* الاختيار */
.check {
  width: 22px; height: 22px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1.5px solid var(--line-2); border-radius: 5px;
  color: transparent;
}
.row-check.on .check, .ret-row.on .check { background: var(--primary); border-color: var(--primary); color: #fff; }
.ret-row + .ret-row { border-top: 1px solid var(--line); }
.ret-check { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: right; }
.ret-calc {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px 12px; padding-inline-start: 48px;
}
.ret-amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper {
  display: inline-flex; align-items: center;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  overflow: hidden;
}
.stepper button { width: 40px; height: 38px; font-size: 19px; color: var(--text-2); }
.stepper button:hover:not(:disabled) { background: var(--bg); }
.stepper button:disabled { color: var(--line-2); }
.stepper span {
  min-width: 76px; height: 38px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  border-inline: 1px solid var(--line-2);
  font-size: 14px; color: var(--text-2);
}
.stepper b { font-size: 15px; font-weight: 600; color: var(--text); }

/* الأشرطة السفلية */
.tabbar, .bar {
  position: fixed; bottom: 0; left: 50%; z-index: 30;
  width: 100%; max-width: 480px;
  transform: translateX(-50%);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar { display: flex; height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b); }
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11.5px; font-weight: 500; color: var(--text-3);
}
.tab.on { color: var(--primary); font-weight: 600; }
.tab-new { color: var(--text-2); }
.tab-new .tab-ic {
  width: 40px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; border-radius: var(--r-sm);
}
.bar { display: flex; align-items: center; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b)); }
.bar .btn { flex: 1; }
.bar-summary { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; color: var(--text-3); }
.bar-summary b { display: block; font-size: 15px; font-weight: 600; color: var(--text); }
.bar-summary + .btn { flex: none; min-width: 148px; }

/* النافذة السفلية */
.sheet-root { position: fixed; inset: 0; z-index: 50; }
.sheet-back { position: absolute; inset: 0; background: rgba(15, 21, 30, .45); }
.sheet {
  position: absolute; bottom: 0; left: 50%;
  width: 100%; max-width: 480px; max-height: 88vh; max-height: 88dvh;
  transform: translateX(-50%);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  padding-bottom: var(--safe-b);
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 8px 8px 16px; padding-inline-start: 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h3 { font-size: 16px; font-weight: 600; }
.sheet-body { flex: 1; padding: 16px; overflow: auto; }
.sheet-body > p { font-size: 14.5px; color: var(--text-2); }
.sheet-body.center { padding: 28px 16px 20px; text-align: center; }
.sheet-body.center h3 { font-size: 17px; font-weight: 600; }
.sheet-body.center p { margin-top: 4px; }
.sheet-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
.code-display {
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  direction: ltr; text-align: center;
  font: 600 19px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 1px;
}

/* الإشعار */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); z-index: 60;
  width: max-content; max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 10px 16px;
  background: #1B2330; color: #fff; border-radius: var(--r-sm);
  font-size: 14px;
}

/* الحالات */
.empty {
  padding: 28px 16px; text-align: center;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
}
.empty-t { font-weight: 600; color: var(--text-2); }
.empty-s { margin-top: 4px; font-size: 13.5px; color: var(--text-3); }
.done { padding: 16px 0 4px; text-align: center; }
.done-mark {
  width: 56px; height: 56px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--primary); border-radius: 50%;
  color: var(--primary);
}
.done h1 { font-size: 19px; font-weight: 600; }
.done-no { margin-top: 6px; color: var(--text-2); }
.done-no b { margin-inline-start: 6px; font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }

/* القفل */
.lock {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 64px 24px calc(28px + var(--safe-b));
  background: var(--surface);
}
.lock-top { text-align: center; }
.lock-mark {
  width: 52px; height: 52px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-2); border-radius: 50%;
  color: var(--primary);
}
.lock h1 { font-size: 18px; font-weight: 600; }
.lock p { margin-top: 6px; font-size: 14.5px; color: var(--text-2); }
.lock .err { color: var(--danger); }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin-top: 28px; }
.pin-dots span { width: 14px; height: 14px; border: 1.5px solid var(--line-2); border-radius: 50%; }
.pin-dots span.on { background: var(--primary); border-color: var(--primary); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 320px; margin: 0 auto; }
.keypad button {
  height: 60px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r);
  font-size: 22px; font-weight: 500;
}
.keypad button:active { background: var(--line); }
.lock-hint { margin-top: 16px; text-align: center; font-size: 12.5px; color: var(--text-3); }

/* الطباعة: رمز الاسترداد فقط */
@media print {
  #app, .sheet-back, .sheet-head, .sheet-foot, .note { display: none !important; }
  .sheet { position: static; transform: none; max-height: none; }
}
