/* نظام الكاشير: نمط واحد لشاشة البيع ولوحة الإدارة */
:root {
  --bg: #EEF1F4; --surface: #FFFFFF; --ink: #16202B; --muted: #5B6875; --line: #D5DBE1;
  --brand: #0B6E4F; --brand-deep: #0B4F3A; --amber: #B4690E; --danger: #B3261E; --ok: #1B7F4B;
  --r: 10px; --r-sm: 6px;
  --font: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
body.pos { overflow: hidden; user-select: none; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.3; }
h2 { font-size: 1.15rem; line-height: 1.35; }
a { color: var(--brand); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 3px solid #1F6FB2; outline-offset: 2px; }
.num, input[type=number], input[type=date] { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
td.num, th.num { text-align: left; }
.hint, small { color: var(--muted); font-size: .875rem; }
.empty { color: var(--muted); padding: 28px 12px; text-align: center; grid-column: 1 / -1; }
.neg { color: var(--danger); font-weight: 600; } .pos-n, span.pos { color: var(--ok); font-weight: 600; }

/* أزرار وحقول */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 9px 16px; min-height: 44px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-deep); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { min-height: 56px; font-size: 1.1rem; }
.btn.sm { min-height: 34px; padding: 4px 10px; font-size: .875rem; }
.link { border: 0; background: none; color: var(--brand); text-decoration: underline; padding: 0; direction: ltr; }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 9px 12px; min-height: 44px; background: #fff; width: 100%; }
input[type=color] { width: 64px; height: 44px; padding: 2px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; }
.big-input { font-size: 1.5rem !important; min-height: 60px !important; text-align: center; }
label { display: grid; gap: 4px; font-weight: 600; font-size: .95rem; }
label.check, .seg label, .multi label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--brand); }
.multi { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: #E4E9EE; color: var(--ink); white-space: nowrap; }
.tag.amber { background: #FBEBD0; color: #7A4505; } .tag.bad { background: #F9DEDC; color: #8C1D18; }
.tag.ok { background: #D8F0E2; color: #0B4F3A; } .tag.warn { background: #FFF1C2; color: #6B4E00; }
.note { border-radius: var(--r-sm); padding: 10px 14px; background: #E7EEF5; border-inline-start: 4px solid #1F6FB2; margin: 12px 0; }
.note.bad { background: #FBE9E7; border-color: var(--danger); } .note.ok { background: #E3F4EA; border-color: var(--ok); } .note.warn { background: #FFF6D6; border-color: #C99700; }
.note ul { margin: 6px 0 0; padding-inline-start: 20px; }

/* بطاقات الوسط: التفعيل والدخول */
.center-card { max-width: 440px; margin: 9vh auto 0; background: var(--surface); border-radius: var(--r); padding: 32px; display: grid; gap: 16px; box-shadow: 0 1px 0 var(--line); }
.login { height: 100%; display: grid; grid-template-rows: auto 1fr auto auto; gap: 20px; padding: 32px; max-width: 900px; margin: 0 auto; }
.login-head p { color: var(--muted); }
.users { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-content: start; overflow: auto; }
.user-tile { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r); padding: 22px 16px; text-align: start; display: grid; gap: 2px; min-height: 96px; }
.user-tile b { font-size: 1.2rem; } .user-tile span { color: var(--muted); font-size: .875rem; }
.user-tile.on { border-color: var(--brand); background: #E9F5EF; }
.login-form { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.login-foot { font-size: .9rem; color: var(--muted); }
.login-foot.warn { color: #6B4E00; } .login-foot.bad { color: var(--danger); }

/* شاشة البيع */
#app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.who { display: grid; line-height: 1.25; min-width: 120px; } .who span { color: var(--muted); font-size: .8rem; }
.top input[type=search] { flex: 1; max-width: 420px; }
.top-actions { display: flex; gap: 6px; margin-inline-start: auto; }
.pill { border: 0; border-radius: 99px; padding: 6px 14px; font-size: .85rem; font-weight: 700; min-height: 36px; white-space: nowrap; }
.pill.ok { background: #D8F0E2; color: #0B4F3A; } .pill.warn { background: #FFF1C2; color: #6B4E00; } .pill.bad { background: #F9DEDC; color: #8C1D18; }
.sale { flex: 1; min-height: 0; display: grid; grid-template-columns: 148px minmax(0, 1fr) 400px; }
.cats { overflow: auto; padding: 10px 10px; display: flex; flex-direction: column; gap: 6px; border-inline-end: 1px solid var(--line); }
.cats button { border: 0; border-inline-start: 6px solid var(--c, var(--muted)); background: var(--surface); border-radius: var(--r-sm); padding: 14px 10px; text-align: start; font-weight: 600; min-height: 56px; line-height: 1.3; }
.cats button.on { background: var(--ink); color: #fff; }
.items { overflow: auto; padding: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-auto-rows: 104px; gap: 8px; align-content: start; }
.item { border: 0; border-top: 5px solid var(--c); background: var(--surface); border-radius: var(--r-sm); padding: 10px 12px; display: flex; flex-direction: column; justify-content: space-between; text-align: start; }
.item:active { background: #E9F5EF; }
.item-name { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-meta { display: flex; justify-content: space-between; align-items: center; } .item-meta b { font-size: 1.1rem; }
.cart { background: var(--surface); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.cart-lines { flex: 1; overflow: auto; padding: 4px 12px; }
.cl { display: grid; grid-template-columns: minmax(0, 1fr) auto 76px 32px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cl-name { font-weight: 600; line-height: 1.3; } .cl-name small { display: block; font-weight: 400; text-align: start; }
.cl-qty { display: flex; align-items: center; gap: 4px; }
.cl-qty button { width: 40px; height: 40px; border: 1px solid var(--line); background: var(--bg); border-radius: var(--r-sm); font-size: 1.3rem; font-weight: 700; line-height: 1; }
.cl-qty b { min-width: 30px; text-align: center; font-size: 1.1rem; }
.cl-total { text-align: left; }
.cl-x { border: 0; background: none; color: var(--danger); font-size: 1.5rem; width: 32px; height: 40px; line-height: 1; }
.cart-foot { padding: 10px 12px 12px; border-top: 2px solid var(--ink); display: grid; gap: 3px; }
.t-row { display: flex; justify-content: space-between; color: var(--muted); font-size: .92rem; }
/* الإجمالي هو أبرز ما في الشاشة */
.grand { display: flex; justify-content: space-between; align-items: baseline; background: var(--brand-deep); color: #fff; border-radius: var(--r-sm); padding: 8px 14px; margin: 6px 0; }
.grand span { font-weight: 600; } .grand b { font-size: 2.5rem; line-height: 1.15; letter-spacing: -.01em; }
.cart-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pay { display: grid; grid-template-columns: 1.4fr 1.4fr 1fr; gap: 6px; margin-top: 6px; }
.pay .btn { min-height: 62px; font-size: 1.2rem; border: 0; color: #fff; }
.pay-cash { background: var(--brand); } .pay-card { background: #1F5E9C; } .pay-split { background: var(--ink); }

/* النوافذ */
.modal-wrap { position: fixed; inset: 0; background: rgba(22, 32, 43, .55); display: grid; place-items: center; padding: 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border-radius: var(--r); padding: 24px; width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; user-select: text; }
.modal.wide { width: min(760px, 100%); }
.modal-wrap.full { padding: 0; } .modal-wrap.full .modal { width: 100%; height: 100%; max-height: none; border-radius: 0; background: var(--bg); }
.modal form, .modal { display: grid; gap: 14px; align-content: start; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.stack { display: grid; gap: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg > button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 8px 14px; min-height: 44px; font-weight: 600; }
.seg > button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.seg label { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 14px; min-height: 44px; }
.due { display: flex; justify-content: space-between; align-items: baseline; background: var(--brand-deep); color: #fff; border-radius: var(--r-sm); padding: 10px 16px; }
.due b { font-size: 2rem; } .due.sub { background: var(--bg); color: var(--ink); } .due.sub b { font-size: 1.6rem; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { flex: 1; min-width: 80px; min-height: 48px; border: 1px solid var(--line); background: var(--bg); border-radius: var(--r-sm); font-weight: 700; font-variant-numeric: tabular-nums; }
.qty-in { width: 90px !important; text-align: center; }
#toasts { position: fixed; inset-inline: 0; bottom: 18px; display: grid; justify-items: center; gap: 8px; z-index: 80; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--r-sm); font-weight: 600; max-width: min(560px, 92vw); }
.toast.ok { background: var(--ok); } .toast.bad { background: var(--danger); }

/* الجداول والتقارير */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.tbl-wrap.tall { max-height: 56vh; }
.tbl { border-collapse: collapse; width: 100%; font-size: .93rem; }
.tbl th { text-align: start; font-weight: 700; background: #F4F6F8; position: sticky; top: 0; white-space: nowrap; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
.row-actions { white-space: nowrap; text-align: left; } .row-actions .btn { margin-inline-start: 4px; }
.bar { display: block; height: 10px; background: var(--brand); border-radius: 2px; min-width: 2px; }
.rep-head { display: flex; justify-content: space-between; align-items: center; } .rep-head span { color: var(--muted); }
.rep-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin: 12px 0; }
.rep-bar label { grid-auto-flow: column; align-items: center; gap: 6px; font-weight: 500; }
.rep-bar input, .rep-bar select { width: auto !important; }
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--ink); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 16px; font-weight: 600; min-height: 44px; white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; }
.tabs button.on { background: var(--ink); color: #fff; }
.rep-body { padding-top: 14px; }
.ledger { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 20px 14px; max-width: 560px; }
.ledger-row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px dotted var(--line); }
.ledger-row.strong { font-weight: 700; font-size: 1.25rem; border-bottom: 2px solid var(--ink); }
.ledger-sep { margin-top: 16px; font-weight: 700; color: var(--muted); font-size: .875rem; }
.inv-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.paper { background: #fff; width: 302px; padding: 12px; border: 1px solid var(--line); }

/* لوحة الإدارة */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--ink); color: #fff; display: flex; flex-direction: column; padding: 18px 10px; gap: 16px; position: sticky; top: 0; height: 100vh; }
.side-top { display: grid; padding: 0 10px; } .side-top span { opacity: .7; font-size: .85rem; }
.side nav { display: grid; gap: 2px; flex: 1; align-content: start; }
.side nav button { border: 0; background: none; color: #fff; text-align: start; padding: 11px 12px; border-radius: var(--r-sm); font-weight: 600; min-height: 44px; }
.side nav button.on { background: #fff; color: var(--ink); }
.badge { background: var(--danger); color: #fff; border-radius: 99px; padding: 0 8px; font-size: .78rem; }
.side-foot { display: grid; gap: 6px; } .side-foot .btn { color: var(--ink); }
.content { padding: 24px 28px 60px; max-width: 1200px; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.content > h2, .block h2 { margin: 18px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-inline-start: 6px solid var(--c); background: var(--surface); border-radius: var(--r-sm); padding: 8px 12px; font-weight: 600; min-height: 40px; }
.block { margin: 18px 0; } .block header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; } .block header h2 { margin: 0; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 1.1rem; letter-spacing: .12em; direction: ltr; unicode-bidi: isolate; background: #FFF1C2; padding: 2px 8px; border-radius: 4px; user-select: all; }
.alert { background: var(--surface); border: 1px solid var(--line); border-inline-start: 5px solid var(--line); border-radius: var(--r-sm); padding: 12px 16px; margin-bottom: 8px; }
.alert.new { border-inline-start-color: var(--danger); }
.alert header { display: flex; justify-content: space-between; gap: 12px; } .alert time { color: var(--muted); font-size: .85rem; direction: ltr; }
.alert pre { margin: 6px 0 0; font: inherit; white-space: pre-wrap; color: var(--muted); }
.form { display: grid; gap: 14px; max-width: 560px; } .form h2 { margin-top: 12px; }
.install { max-width: 620px; margin: 5vh auto; background: var(--surface); padding: 32px; border-radius: var(--r); display: grid; gap: 16px; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; font-size: .9rem; }
.checks .yes { color: var(--ok); } .checks .no { color: var(--danger); font-weight: 700; }

/* الإيصال (80 ملم) */
#print { display: none; }
.receipt { width: 72mm; max-width: 100%; margin: 0 auto; color: #000; font: 12px/1.45 var(--font); }
.r-head { text-align: center; } .r-co { font-size: 16px; font-weight: 700; }
.r-title { text-align: center; font-weight: 700; font-size: 13px; border-block: 1px dashed #000; padding: 4px 0; margin: 6px 0; }
.r-row { display: flex; justify-content: space-between; gap: 8px; }
.r-total { font-size: 15px; font-weight: 700; border-block: 1px solid #000; padding: 3px 0; margin: 4px 0; }
.r-lines { width: 100%; border-collapse: collapse; margin: 6px 0; border-block: 1px dashed #000; }
.r-lines th { font-weight: 700; text-align: start; border-bottom: 1px solid #000; padding: 2px 0; }
.r-lines td { padding: 2px 0; vertical-align: top; } .r-lines td.num, .r-lines th:not(:first-child) { text-align: left; padding-inline-start: 6px; white-space: nowrap; }
.r-qr { width: 44mm; margin: 8px auto 4px; } .r-qr svg { display: block; width: 100%; height: auto; }
.r-foot { text-align: center; font-size: 11px; }

@media (max-width: 1000px) {
  .sale { grid-template-columns: 110px minmax(0, 1fr) 320px; }
  .top-actions .btn { padding: 9px 10px; }
  .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; } .side nav { grid-auto-flow: column; overflow-x: auto; }
  .content { padding: 16px; }
}
@media (max-width: 720px) {
  body.pos { overflow: auto; } #app { height: auto; min-height: 100%; }
  .top { flex-wrap: wrap; } .top input[type=search] { order: 5; flex-basis: 100%; max-width: none; }
  .sale { grid-template-columns: 1fr; } .cats { flex-direction: row; border: 0; } .cats button { white-space: nowrap; }
  .items { max-height: 46vh; } .cart { border: 0; border-top: 1px solid var(--line); }
  .login-form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: no-preference) { .toast { animation: rise .18s ease-out; } @keyframes rise { from { transform: translateY(8px); opacity: 0; } } }
@media print {
  @page { size: 80mm auto; margin: 0; }
  html, body { height: auto; background: #fff; overflow: visible; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; padding: 2mm 4mm 6mm; }
}
