/* ═══ واجهة زجاجية حسب design-system.md ═══
   كل الألوان والزوايا من tokens.css. لتغيير اللون الأساسي: غيّر --primary و --primary-light هناك فقط. */

:root {
  --tint-panel: .42;   /* لوح عادي */
  --tint-field: .55;   /* حقل / زر ثانوي */
  --tint-modal: .72;   /* نافذة منبثقة */
  --blur: 22px;
  --primary-10: color-mix(in srgb, var(--primary) 10%, transparent);
  --primary-88: color-mix(in srgb, var(--primary) 88%, transparent);
  --alert-88: color-mix(in srgb, var(--alert) 88%, transparent);
  --alert-06: color-mix(in srgb, var(--alert) 6%, transparent);
  --press: transform 140ms ease;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--splash-bg); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
/* الصورة الخلفية تعبّي الشاشة وثابتة */
body::before {
  content: ''; position: fixed; top: 0; left: 0; right: 0; height: var(--bg-h, 100lvh); z-index: -1;
  background: var(--splash-bg) url(../img/bg.webp) center / cover no-repeat;
}
body.locked #app { visibility: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ── الأيقونات: ملفات SVG كما هي، تاخذ لون النص ── */
.ic { display: inline-block; flex: none; width: 22px; height: 22px; background: currentColor;
  -webkit-mask: var(--ic) center / contain no-repeat; mask: var(--ic) center / contain no-repeat; }
.ic-add-circle { --ic: url(../icons/ui/add-circle.svg); }
.ic-back { --ic: url(../icons/ui/back.svg); }
.ic-calendar { --ic: url(../icons/ui/calendar.svg); }
.ic-caret-down { --ic: url(../icons/ui/caret-down.svg); }
.ic-categories { --ic: url(../icons/ui/categories.svg); }
.ic-expenses { --ic: url(../icons/ui/expenses.svg); }
.ic-expiry { --ic: url(../icons/ui/expiry.svg); }
.ic-package { --ic: url(../icons/ui/package.svg); }
.ic-plus { --ic: url(../icons/ui/plus.svg); }
.ic-purchases { --ic: url(../icons/ui/purchases.svg); }
.ic-sales { --ic: url(../icons/ui/sales.svg); }
.ic-scan { --ic: url(../icons/ui/scan.svg); }
.ic-search { --ic: url(../icons/ui/search.svg); }
.ic-settings { --ic: url(../icons/ui/settings.svg); }
.ic-stock { --ic: url(../icons/ui/stock.svg); }

/* ── اللوح الزجاجي ── */
.glass, .appbar, .homebar, .card, .item-row, .empty, .totals, .stock-hero, .quick-search, .segmented, .chip,
.btn-ghost, .btn-soft, .pick, .unit-card, .sheet, .dialog, .pin-box, .toast, .tile, .today, .fatal, .note {
  position: relative;
  background-color: rgba(255, 255, 255, var(--tint-panel));
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .30), rgba(255, 255, 255, 0) 55%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.15);
  backdrop-filter: blur(var(--blur)) saturate(1.15);
  border: 0;
  box-shadow: 0 10px 30px -18px rgba(16, 35, 27, .35);
}
/* الحافة اللامعة 1px بتدرج مائل 75% ← 10% ← 41% */
.glass::after, .appbar::after, .homebar::after, .card::after, .item-row::after, .empty::after, .totals::after, .stock-hero::after,
.segmented::after, .chip::after, .btn-ghost::after, .btn-soft::after, .pick::after, .unit-card::after, .sheet::after, .dialog::after,
.pin-box::after, .tile::after, .today::after, .quick-search::after, .note::after, .fatal::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, .75), rgba(255, 255, 255, .10) 50%, rgba(255, 255, 255, .41));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
/* بديل عند عدم دعم backdrop-filter: نفس الصورة المغبّشة كخلفية ثابتة */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .appbar, .homebar, .card, .item-row, .empty, .totals, .stock-hero, .tile, .today, .sheet, .dialog, .pin-box {
    background-image: linear-gradient(180deg, rgba(255, 255, 255, .30), rgba(255, 255, 255, 0) 55%), url(../img/bg-blur.webp);
    background-size: auto, cover; background-attachment: scroll, fixed;
  }
}

/* ── الهيكل ── */
#app { max-width: 760px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) var(--pad-screen) calc(24px + env(safe-area-inset-bottom)); }
.native #app { padding-top: max(calc(10px + env(safe-area-inset-top)), 34px); }
.view { outline: none; }
.view.enter { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } }

/* الشريط العلوي بالشاشات الداخلية: رجوع + عنوان + إضافة */
.appbar {
  position: sticky; top: calc(10px + env(safe-area-inset-top)); z-index: 30;
  height: 60px; border-radius: var(--r-card); display: flex; align-items: center; gap: 10px; padding: 0 8px; margin-bottom: var(--gap);
}
.native .appbar { top: max(calc(10px + env(safe-area-inset-top)), 34px); }
.appbar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 600; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-btn {
  width: 44px; height: 44px; border-radius: var(--r-icon); display: grid; place-items: center; flex: none; padding: 0;
  background: rgba(255, 255, 255, var(--tint-field)); color: var(--primary); text-decoration: none; border: 0; cursor: pointer; transition: var(--press);
}
.bar-btn:active { transform: scale(.965); }
.bar-btn .ic { width: 22px; height: 22px; }

/* الرئيسية */
.homebar { height: 72px; border-radius: var(--r-card); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 18px; }
.homebar .shop { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.homebar .shop strong { font-size: 19px; font-weight: 600; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.homebar .shop small, .homebar .date { font-size: 12px; color: var(--muted); }
.homebar .date { flex: none; white-space: nowrap; }
.home { display: flex; flex-direction: column; gap: var(--gap); }
.quick-search { height: 50px; border-radius: var(--r-search); display: flex; align-items: center; gap: 10px; padding: 0 18px; background-color: rgba(255, 255, 255, var(--tint-field)); }
.quick-search .ic { color: var(--muted); }
.quick-search input { flex: 1; height: 100%; border: 0; background: none; font-size: 15px; outline: none; min-width: 0; }
.quick-results { display: flex; flex-direction: column; gap: 8px; }
.quick-results:empty { display: none; }
.big-action {
  height: 118px; border-radius: var(--r-sheet); display: flex; align-items: center; gap: 16px; padding: 0 22px;
  background: var(--primary-88); color: #fff; text-decoration: none; font-size: 19px; font-weight: 600;
  box-shadow: 0 14px 30px -16px var(--primary); transition: var(--press);
}
.big-action:active { transform: scale(.965); }
.big-action .ring { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .22); flex: none; }
.big-action .ring .ic { width: 30px; height: 30px; }
.big-action small { display: block; font-size: 12px; font-weight: 400; opacity: .85; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.tile { min-height: 104px; border-radius: var(--r-card); padding: 16px; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px;
  text-decoration: none; color: var(--ink); font-size: 15px; font-weight: 500; transition: var(--press); }
.tile:active { transform: scale(.965); }
.tile .icon-box { margin-bottom: auto; }
.icon-box { width: 42px; height: 42px; border-radius: var(--r-tile-icon); display: grid; place-items: center; background: var(--primary-10); color: var(--primary); flex: none; }
.today { border-radius: var(--r-card); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; column-gap: 18px; padding: 14px 18px; }
.today > div { display: flex; flex-direction: column; }
.today .sep { width: 1px; height: 36px; background: rgba(16, 35, 27, .12); }
.today small { font-size: 12px; color: var(--muted); }
.today strong { font-size: 19px; font-weight: 600; color: var(--primary); }
.today .label { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

/* ── رأس الصفحة (ما يبقى بعد نقل العنوان للشريط) ── */
.page-head { margin: 0 4px var(--gap); }
.page-head:empty { display: none; }
.page-head .sub { margin: 0 0 6px; color: var(--muted); font-size: 12px; }

/* ── الألواح ── */
.stack { display: flex; flex-direction: column; gap: var(--gap); margin-bottom: var(--gap); }
.stack-sm { display: flex; flex-direction: column; gap: var(--gap); }
.card { border-radius: var(--r-card); padding: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--primary); flex: 1; }
.card-num { display: none; }

/* ── الحقول: عنوان صغير فوق والقيمة تحته داخل نفس المربع (64) ── */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid.three { grid-template-columns: 1fr 1fr 1fr; }
.field { position: relative; display: flex; flex-direction: column; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
@media (max-width: 420px) { .grid { grid-template-columns: 1fr; } .grid.three { grid-template-columns: 1fr 1fr; } }
label { font-size: 12px; font-weight: 500; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.field > label { margin: 0 4px 6px; }
.field:has(> input, > select) > label { position: absolute; top: 9px; inset-inline-start: 16px; inset-inline-end: 16px; margin: 0; z-index: 2; pointer-events: none; white-space: nowrap; overflow: hidden; }
.field > input, .field > select, .inline-form input, .toolbar-row select {
  width: 100%; height: 64px; border-radius: var(--r-field); padding: 24px 16px 6px; border: 0; outline: none;
  background-color: rgba(255, 255, 255, var(--tint-field)); font-size: 17px; font-weight: 500; color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
.field > select, .toolbar-row select { background-image: url(../icons/ui/caret-down.svg); background-repeat: no-repeat; background-size: 16px; background-position: left 16px center; padding-inline-end: 40px; }
.inline-form input, .toolbar-row select { height: 56px; padding-top: 0; padding-bottom: 0; font-size: 15px; }
.field > input:focus, .field > select:focus, .inline-form input:focus { box-shadow: inset 0 0 0 1.5px var(--primary); }
input[dir="ltr"] { text-align: right; }
.field:has([aria-invalid="true"]) > label { color: var(--alert); }
input[aria-invalid="true"], select[aria-invalid="true"] { box-shadow: inset 0 0 0 100px var(--alert-06), inset 0 0 0 1.5px var(--alert) !important; }
.err { color: var(--alert); font-size: 12px; margin: 4px 6px 0; }
.err:empty { display: none; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 6px 0; }
.hint.lead { margin: 0 0 10px; }
.opt { font-size: 11px; color: var(--muted); opacity: .85; font-weight: 400; }
.opt::before { content: '· '; }
.toolbar-row { display: flex; gap: 8px; align-items: stretch; }
.toolbar-row select { flex: 1; }

/* ── الأزرار (56) ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; padding: 0 20px;
  border-radius: var(--r-btn); border: 0; font-size: 17px; font-weight: 600; cursor: pointer; text-decoration: none; transition: var(--press);
}
.btn:active { transform: scale(.965); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary-88); color: #fff; }
.btn-danger { background: var(--alert-88); color: #fff; }
.btn-ghost, .btn-soft { background-color: rgba(255, 255, 255, var(--tint-field)); color: var(--primary); }
.danger-text { color: var(--alert) !important; }
.btn-block { width: 100%; }
.sticky-save { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5; }
.sticky-save.two { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.action-bar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px var(--gap); scrollbar-width: none; }
.action-bar .btn { flex: none; min-height: 48px; font-size: 15px; }
.icon-btn { min-width: 40px; height: 40px; border-radius: var(--r-icon); border: 0; background: rgba(255, 255, 255, var(--tint-field)); display: inline-grid; place-items: center; cursor: pointer; padding: 0 12px; font-size: 13px; font-weight: 600; color: var(--primary); transition: var(--press); }
.icon-btn:active { transform: scale(.965); }

/* ── بحث ورقائق ── */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: var(--gap); }
.search { position: relative; }
.search .ic { position: absolute; inset-inline-start: 18px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; z-index: 2; }
.search input {
  width: 100%; height: 50px; border-radius: var(--r-search); border: 0; outline: none; padding: 0 18px; padding-inline-start: 50px; font-size: 15px;
  background-color: rgba(255, 255, 255, var(--tint-field)); -webkit-backdrop-filter: blur(var(--blur)); backdrop-filter: blur(var(--blur));
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px var(--gap); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--r-search); font-size: 14px; font-weight: 500; cursor: pointer; color: var(--ink); }
.chip-n { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--primary-10); color: var(--primary); font-size: 12px; display: grid; place-items: center; }
.chip.on { background: var(--primary-88); color: #fff; }
.chip.on .chip-n { background: rgba(255, 255, 255, .22); color: #fff; }
.chip.alert:not(.on) .chip-n { background: var(--alert); color: #fff; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; border-radius: var(--r-btn); }
.segmented.two { grid-template-columns: 1fr 1fr; }
.segmented button, .segmented a { min-height: 46px; border: 0; border-radius: 14px; background: none; display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer; text-decoration: none; transition: var(--press); }
.segmented button.on, .segmented a.on { background: var(--primary-88); color: #fff; }

/* ── القوائم ── */
.item-list { display: flex; flex-direction: column; gap: 10px; }
.item-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--r-card); color: var(--ink); text-decoration: none; transition: var(--press); }
.item-row:active { transform: scale(.965); }
.item-row.off { opacity: .55; }
.item-main { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.item-main strong { font-size: 15px; font-weight: 500; }
.item-main small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-qty { display: flex; flex-direction: column; align-items: flex-end; text-align: end; flex: none; }
.item-qty .num { font-weight: 600; font-size: 15px; color: var(--primary); }
.item-qty small { color: var(--muted); font-size: 12px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.badges:empty { display: none; }
.badge { font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 10px; }
.badge-bad { background: var(--alert-06); color: var(--alert); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--alert) 25%, transparent); }
.badge-warn { background: rgba(255, 255, 255, .6); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(16, 35, 27, .15); }
.badge-ok { background: var(--primary-10); color: var(--primary); }
.badge-muted { background: rgba(255, 255, 255, .5); color: var(--muted); }
.empty { border-radius: var(--r-card); display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 36px 16px; text-align: center; color: var(--muted); }
.empty .icon-box { width: 64px; height: 64px; border-radius: 18px; }
.empty .icon-box .ic { width: 30px; height: 30px; }
.empty p { margin: 0; }

.stock-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); border-radius: var(--r-card); margin-bottom: var(--gap); overflow: hidden; }
.stock-hero > div { padding: 14px 18px; display: flex; flex-direction: column; }
.stock-hero > div + div { border-inline-start: 1px solid rgba(16, 35, 27, .08); }
.stock-hero small { font-size: 12px; color: var(--muted); }
.stock-hero strong { font-size: 19px; font-weight: 600; color: var(--primary); line-height: 1.35; }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid rgba(16, 35, 27, .12); white-space: nowrap; }
.tbl td { padding: 10px 8px; border-bottom: 1px solid rgba(16, 35, 27, .06); white-space: nowrap; }
.tbl td small { color: var(--muted); }
.tbl tr:last-child td { border-bottom: 0; }

.batch-list, .moves { display: flex; flex-direction: column; }
.batch, .move { display: grid; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(16, 35, 27, .07); text-decoration: none; color: inherit; }
.batch { grid-template-columns: 1fr auto auto; }
.move { grid-template-columns: auto 1fr auto; }
.batch:last-child, .move:last-child { border-bottom: 0; }
.batch > div, .move > div { display: flex; flex-direction: column; min-width: 0; }
.batch small, .move small { color: var(--muted); font-size: 12px; }
.batch .num { font-weight: 600; }
.move-ic { width: 10px; height: 10px; border-radius: 50%; }
.move-ic.in { background: var(--primary); }
.move-ic.out { background: var(--alert); }
.move-qty { align-items: flex-end; text-align: end; }
.move-qty .num { font-weight: 600; direction: ltr; unicode-bidi: isolate; }

.totals { display: flex; flex-direction: column; gap: 4px; padding: 14px 18px; border-radius: var(--r-card); margin-top: var(--gap); }
.totals > div { display: flex; justify-content: space-between; gap: 10px; }
.totals .grand { font-size: 19px; font-weight: 600; color: var(--primary); }
.line-total { text-align: end; font-weight: 600; margin-top: 8px; color: var(--primary); }

.units { display: flex; flex-direction: column; gap: var(--gap); }
.unit-card { border-radius: var(--r-card); padding: 12px 14px 14px; }
.unit-head { display: flex; justify-content: space-between; align-items: center; min-height: 40px; margin-bottom: 4px; }
.unit-tag { font-size: 12px; font-weight: 500; color: var(--primary); }
.add-unit { width: 100%; }
.pick-results { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.pick-results:empty { display: none; }
.pick { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 56px; padding: 10px 16px; border-radius: var(--r-field); border: 0; text-align: start; cursor: pointer; color: var(--ink); text-decoration: none; transition: var(--press); }
.pick:active { transform: scale(.965); }
.pick small { color: var(--muted); font-size: 12px; }
.pick:disabled { opacity: .5; cursor: not-allowed; }

.status-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pill { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 12px; font-weight: 500; font-size: 13px; }
.pill-on { background: var(--primary-10); color: var(--primary); }
.pill-off { background: rgba(255, 255, 255, .55); color: var(--muted); }
.note { display: block; margin: 12px 0 0; padding: 12px 14px; border-radius: var(--r-field); font-size: 13px; color: var(--ink); }
.money-preview { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--r-field); background: rgba(255, 255, 255, var(--tint-field)); }
.money-preview .lbl { color: var(--muted); font-size: 12px; }
.money-preview .num { font-size: 19px; font-weight: 600; color: var(--primary); direction: ltr; unicode-bidi: isolate; }

/* مفتاح تشغيل */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 15px; font-weight: 500; color: var(--ink); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 50px; height: 30px; border-radius: 15px; background: rgba(16, 35, 27, .18); position: relative; transition: background .2s; flex: none; }
.switch-ui::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s ease; }
.switch input:checked + .switch-ui { background: var(--primary-88); }
.switch input:checked + .switch-ui::after { transform: translateX(-20px); }

.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.inline-form input { flex: 1; }
.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list li { display: flex; align-items: center; gap: 6px; padding: 8px 0; border-bottom: 1px solid rgba(16, 35, 27, .07); }
.cat-list li span { flex: 1; font-weight: 500; }

/* ── النوافذ المنبثقة: ستارة داكنة + لوح زجاجي + تكبير من 94% ── */
.sheet-overlay, .overlay, .pin-overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: var(--scrim); animation: fadeIn .18s ease; }
.sheet-overlay.closing { opacity: 0; transition: opacity .16s; }
.sheet, .dialog {
  width: min(520px, 100%); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--r-sheet); background-color: rgba(255, 255, 255, var(--tint-modal)); animation: pop .2s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px 6px; }
.sheet-head h3 { margin: 0; font-size: 17px; font-weight: 600; color: var(--primary); }
.sheet-body { padding: 8px 18px 20px; overflow-y: auto; }
.dialog { width: min(380px, 100%); padding: 22px; text-align: center; }
.dialog h3 { margin: 4px 0; font-size: 19px; font-weight: 600; color: var(--primary); }
.dialog.danger h3 { color: var(--alert); }
.dialog p { margin: 0 0 18px; color: var(--muted); }
.dialog-actions { display: grid; gap: 8px; }

/* ── التنبيه ── */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 90; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 12px 18px; border-radius: var(--r-field); font-weight: 500; font-size: 14px; color: var(--ink); background-color: rgba(255, 255, 255, var(--tint-modal)); transition: .2s ease; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { color: var(--alert); }

/* ── القفل ── */
.pin-overlay { z-index: 100; }
.pin-overlay.full { background: transparent; }
.pin-overlay.full::before { content: ''; position: fixed; inset: 0; z-index: -1; background: var(--splash-bg) url(../img/bg.webp) center / cover no-repeat; }
.pin-box { width: min(340px, 100%); text-align: center; border-radius: var(--r-sheet); padding: 24px 20px 20px; background-color: rgba(255, 255, 255, var(--tint-modal)); animation: pop .2s ease; }
.pin-title { margin: 0; font-size: 19px; font-weight: 600; color: var(--primary); }
.pin-sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 20px 0 6px; direction: ltr; }
.pin-dots .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent); transition: .15s; }
.pin-dots .dot.optional { opacity: .5; }
.pin-dots .dot.on { background: var(--primary); box-shadow: none; opacity: 1; }
.pin-msg { min-height: 20px; color: var(--alert); font-size: 13px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; direction: ltr; }
.key { height: 56px; border-radius: var(--r-btn); border: 0; background: rgba(255, 255, 255, var(--tint-field)); font-size: 22px; font-weight: 500; cursor: pointer; display: grid; place-items: center; color: var(--ink); transition: var(--press); }
.key:active { transform: scale(.965); }
.key-fn { font-size: 14px; color: var(--muted); }
.key-ok { background: var(--primary-88); color: #fff; font-size: 15px; font-weight: 600; }
.key-ok:disabled { opacity: .4; }
.pin-cancel { margin-top: 12px; width: 100%; }
.pin-box.shake { animation: shake .35s; }
.pin-box.busy { opacity: .7; }
@keyframes shake { 25%, 75% { transform: translateX(-6px); } 50% { transform: translateX(6px); } }

.fatal { max-width: 520px; margin: 15vh auto; padding: 24px; border-radius: var(--r-card); text-align: center; }
.fatal h1 { color: var(--alert); font-size: 19px; }
.fatal small { color: var(--muted); display: block; margin-top: 12px; }

@media (min-width: 900px) { #app { padding-top: 20px; } .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* الطباعة: تظهر صور صفحات الفاتورة فقط */
@media screen { #print-root { display: none; } }
@media print {
  body::before { display: none; }
  body { background: #fff !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root img { display: block; page-break-after: always; break-after: page; }
  #print-root img:last-child { page-break-after: auto; break-after: auto; }
}

.appbar[hidden] { display: none; }
.bar-slot { display: flex; gap: 8px; }
.tbl a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* ═══ شاشة التفعيل (نفس أسلوب شاشة القفل) ═══ */
.act-overlay { overflow-y: auto; align-items: start; padding-top: max(24px, env(safe-area-inset-top)); }
.act-box { width: min(440px, 100%); text-align: start; display: flex; flex-direction: column; gap: var(--gap); }
.act-box .pin-title, .act-box .pin-sub { text-align: center; }
.act-device { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px; border-radius: var(--r-field); background: rgba(255, 255, 255, var(--tint-field)); }
.act-device small { font-size: 12px; color: var(--muted); }
.act-device strong { font-size: 26px; font-weight: 600; color: var(--primary); letter-spacing: .06em; }
.act-row { justify-content: center; }
.act-box textarea { width: 100%; border: 0; outline: none; resize: vertical; border-radius: var(--r-field); padding: 14px 16px; font-size: 14px; background: rgba(255, 255, 255, var(--tint-field)); font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
.act-box textarea:focus { box-shadow: inset 0 0 0 1.5px var(--primary); }
.act-box textarea[aria-invalid="true"] { box-shadow: inset 0 0 0 100px var(--alert-06), inset 0 0 0 1.5px var(--alert); }
.act-dev { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid rgba(16, 35, 27, .1); text-align: center; }
.act-dev strong { color: var(--primary); font-size: 15px; }
.act-dev small { color: var(--muted); font-size: 12px; }
.act-phone { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; }
.act-phone .btn { min-height: 44px; font-size: 14px; padding: 0 14px; }
.act-phone .num { font-size: 15px; font-weight: 500; text-align: start; }
.locked-field { opacity: .75; }

/* عن التطبيق */
.about-credits { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.about-credits li { display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; border-top: 1px solid rgba(16, 35, 27, .08); }
.about-credits li .hint { margin: 0; }

/* ── المساعد B1 (زر عائم + محادثة). صورة B1 تُضاف لما توصل من صاحب البرنامج ── */
.b1-fab { position: fixed; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 60; width: 60px; height: 60px; padding: 0; border-radius: var(--r-btn); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(16, 35, 27, .25); }
body.locked .b1-fab { display: none; }
/* B1 = روبي (bot/R1.svg من bot-kit تبع صاحب البرنامج، اختياره B1 بالمرجع). حركاته جوّا الملف نفسه */
.b1-face { width: 46px; height: 46px; background: url(../img/b1.svg) center / contain no-repeat; }
.b1-sheet { width: min(560px, 100%); }
.b1-panel { display: flex; flex-direction: column; gap: 10px; }
.b1-log { display: flex; flex-direction: column; gap: 8px; max-height: min(60vh, 520px); min-height: 160px; overflow-y: auto; padding: 2px; }
.b1-msg { max-width: 88%; padding: 8px 12px; border-radius: var(--r-field); }
.b1-msg p { margin: 0 0 4px; }
.b1-msg p:last-child { margin-bottom: 0; }
.b1-msg.bot { align-self: flex-start; background: rgba(255, 255, 255, .7); }
.b1-msg.me { align-self: flex-end; background: var(--primary-88); color: #fff; }
.b1-msg .b1-list { margin: 6px 0 2px; }
.b1-msg .pick { min-height: 44px; padding: 8px 12px; }
.b1-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.b1-form input { min-width: 0; height: 48px; padding: 0 14px; border-radius: var(--r-field); border: 1px solid rgba(16, 35, 27, .15); background: rgba(255, 255, 255, .8); }
.b1-bubble { position: fixed; left: 84px; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 61; padding: 10px 14px; border-radius: var(--r-field); font-size: 14px; max-width: 460px; }
.b1-bubble[hidden] { display: none; }
.b1-raise .b1-fab { bottom: calc(84px + env(safe-area-inset-bottom)); }
.b1-raise .b1-bubble { bottom: calc(84px + env(safe-area-inset-bottom)); }
/* مساحة تحت آخر الشاشة حتى ما يغطّي زر B1 آخر سطر */
#view::after { content: ''; display: block; height: 72px; }
