/* ===== لوحة مخزون Lava Gifts ===== */
:root {
    --bg: #f6f6fa;
    --card: #ffffff;
    --text: #1d2033;
    --muted: #6d7088;
    --line: #ececf3;
    --line-strong: #dcdce7;
    --hover: #f6f5fa;

    --accent: #be185d;
    --accent-2: #db2777;
    --accent-soft: #fce7f1;

    --in: #15803d;       --in-bg: #e6f6ec;
    --out: #dc2626;      --out-bg: #fdecec;
    --transfer: #2563eb; --transfer-bg: #e8efff;
    --adjust: #b45309;   --adjust-bg: #fdf3e1;

    --loc1: #7c3aed;     --loc1-bg: #f1ebfe;
    --loc2: #0d9488;     --loc2-bg: #e2f5f3;

    --warn: #b45309;     --warn-bg: #fdf3e1;
    --danger: #dc2626;   --danger-bg: #fdecec;

    --radius: 14px;
    --shadow: 0 1px 2px rgba(25, 22, 45, .04), 0 6px 20px rgba(25, 22, 45, .045);
    --mtop-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
    font-family: 'Tajawal', Tahoma, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-weight: 400; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.req { color: var(--accent); }

/* عناصر خاصة بالجوال — مخفية على الشاشات الكبيرة */
.mtop, .bnav, .grab, .filter-toggle, .m-only { display: none; }

/* ===== الهيكل ===== */
.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }

.side {
    position: sticky; top: 0; height: 100vh;
    background: var(--card);
    border-inline-end: 1px solid var(--line);
    padding: 22px 16px;
    display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 4px; }
.brand .logo {
    width: 44px; height: 44px; border-radius: 13px; flex: none;
    display: grid; place-items: center; color: #fff;
    background: linear-gradient(140deg, var(--accent), #f472b6);
    box-shadow: 0 6px 16px rgba(190, 24, 93, .28);
}
.brand .logo .i { width: 22px; height: 22px; }
.brand b { display: block; font-size: 16px; font-weight: 800; line-height: 1.3; }
.brand small { color: var(--muted); font-size: 12.5px; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 10px;
    color: var(--muted); font-weight: 500;
    transition: background .15s, color .15s;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.side-actions { display: grid; gap: 8px; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 8px; }
.side-title { font-size: 12px; color: var(--muted); font-weight: 700; padding: 0 4px; }
.side-loc { display: flex; align-items: center; gap: 8px; padding: 0 4px; font-size: 13.5px; }
.side-loc span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { padding: 28px 32px 56px; width: 100%; max-width: 1340px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.top > div:first-child { min-width: 0; }
.top h1 { font-size: 25px; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.top .sub { color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== الأزرار ===== */
.btn {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: 10px;
    border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
    font: inherit; font-weight: 700; font-size: 14px; line-height: 1.3;
    cursor: pointer; white-space: nowrap; touch-action: manipulation;
    transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(190, 24, 93, .22); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger { color: var(--danger); border-color: #f5c9c9; }
.btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn.sm .i { width: 16px; height: 16px; }
.btn.icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.btn.icon .i { width: 17px; height: 17px; }
.btn.a-in:hover       { background: var(--in-bg);       color: var(--in);       border-color: transparent; }
.btn.a-out:hover      { background: var(--out-bg);      color: var(--out);      border-color: transparent; }
.btn.a-transfer:hover { background: var(--transfer-bg); color: var(--transfer); border-color: transparent; }
.btn.a-adjust:hover   { background: var(--adjust-bg);   color: var(--adjust);   border-color: transparent; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.link { color: var(--accent); font-weight: 700; font-size: 13.5px; }
.link:hover { text-decoration: underline; }
.dotn { position: absolute; top: -6px; inset-inline-end: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }

/* ===== البطاقات ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 800; }
.card-head h2 .i { color: var(--muted); }
.h2 { font-size: 16px; font-weight: 800; margin-bottom: 14px; }
.h2.mt { margin-top: 8px; }
.stack { display: grid; gap: 16px; align-content: start; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-form { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.narrow { max-width: 760px; }

.welcome { display: flex; align-items: center; gap: 18px; padding: 22px; margin-bottom: 16px; background: linear-gradient(120deg, #fff 40%, var(--accent-soft)); }
.welcome h2 { font-size: 19px; font-weight: 800; }
.welcome p { margin: 4px 0 0; color: var(--muted); }
.welcome-ic { width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.welcome-ic .i { width: 28px; height: 28px; }

/* ===== الإجراءات السريعة ===== */
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.qa {
    display: flex; align-items: center; gap: 13px; text-align: start;
    padding: 15px 16px; border-radius: var(--radius);
    background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
    font: inherit; color: inherit; cursor: pointer; touch-action: manipulation;
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.qa:active { transform: scale(.97); }
.qa b { display: block; font-size: 15px; font-weight: 800; }
.qa small { display: block; color: var(--muted); font-size: 12.5px; }
.qa-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.qa-ic .i { width: 21px; height: 21px; stroke-width: 2.4; }
.qa-in .qa-ic       { background: var(--in-bg);       color: var(--in); }
.qa-out .qa-ic      { background: var(--out-bg);      color: var(--out); }
.qa-transfer .qa-ic { background: var(--transfer-bg); color: var(--transfer); }
.qa-adjust .qa-ic   { background: var(--adjust-bg);   color: var(--adjust); }
@media (hover: hover) {
    .qa:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(25, 22, 45, .09); }
    .qa-in:hover { border-color: #b7e4c7; } .qa-out:hover { border-color: #f7c1c1; }
    .qa-transfer:hover { border-color: #bcd0fb; } .qa-adjust:hover { border-color: #f1d6a8; }
}

/* ===== المؤشرات ===== */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
a.kpi-link { color: inherit; transition: border-color .15s, box-shadow .15s; }
a.kpi-link:hover { border-color: #b7e4c7; box-shadow: 0 10px 26px rgba(25, 22, 45, .08); }
.c-sales { background: var(--in-bg); color: var(--in); }
.kpi { display: flex; align-items: center; gap: 14px; padding: 16px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.kpi > div { min-width: 0; }
.kpi > div > span { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi b { display: block; font-size: 24px; font-weight: 800; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.kpi-ic .i { width: 21px; height: 21px; }
.c-accent { background: var(--accent-soft); color: var(--accent); }
.c-loc1 { background: var(--loc1-bg); color: var(--loc1); }
.c-loc2 { background: var(--loc2-bg); color: var(--loc2); }
.c-value { background: #e9f4fd; color: #0369a1; }
.c-warn { background: #f1f1f5; color: var(--muted); }
.kpi.is-warn { border-color: #f6dcae; background: linear-gradient(120deg, #fff 45%, #fff8ec); }
.kpi.is-warn .c-warn { background: var(--warn-bg); color: var(--warn); }
.kpi.is-warn b { color: var(--warn); }

/* ===== توزيع المقرين ===== */
.split-card { margin-bottom: 16px; }
.split-head { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 14px; }
.split { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--line); gap: 3px; }
.split span { display: block; min-width: 4px; border-radius: 99px; transition: width .4s; }
.split .s1 { background: var(--loc1); }
.split .s2 { background: var(--loc2); }
.split-legend { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 10px; font-size: 13.5px; color: var(--muted); }
.split-legend span { display: inline-flex; align-items: center; gap: 7px; }
.split-legend b { color: var(--text); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; vertical-align: middle; }
.dot.loc1 { background: var(--loc1); }
.dot.loc2 { background: var(--loc2); }

/* ===== القوائم ===== */
.list { list-style: none; margin: 0; padding: 4px 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 20px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li small { display: block; font-size: 12.5px; }
.pname { font-weight: 700; }
.pname:hover { color: var(--accent); }
.mv-main { flex: 1; min-width: 0; }
.mv-main a { font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-main a:hover { color: var(--accent); }
.mv-main small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-end { text-align: end; flex: none; }
.mv-end small { color: var(--muted); font-size: 12px; }
.moves .badge { min-width: 52px; justify-content: center; }
.today { display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 10px 20px; background: #fafafd; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.today b { color: var(--text); }
.today .q-in b { color: var(--in); }
.today .q-out b { color: var(--out); }

/* ===== الشارات والكميات ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.b-in       { background: var(--in-bg);       color: var(--in); }
.b-out      { background: var(--out-bg);      color: var(--out); }
.b-transfer { background: var(--transfer-bg); color: var(--transfer); }
.b-adjust   { background: var(--adjust-bg);   color: var(--adjust); }
.st-ok  { background: #eff0f5; color: var(--text); }
.st-low { background: var(--warn-bg); color: var(--warn); }
.st-out { background: var(--danger-bg); color: var(--danger); }
td .badge.num { min-width: 46px; justify-content: center; font-size: 13.5px; }

.loc { display: inline-block; min-width: 46px; text-align: center; padding: 3px 10px; border-radius: 8px; font-weight: 700; }
.loc.loc1 { background: var(--loc1-bg); color: var(--loc1); }
.loc.loc2 { background: var(--loc2-bg); color: var(--loc2); }
.loc.zero { opacity: .4; }

.q { display: inline-block; direction: ltr; unicode-bidi: isolate; font-weight: 800; font-variant-numeric: tabular-nums; }
.q-in { color: var(--in); } .q-out { color: var(--out); } .q-tr { color: var(--transfer); } .q-adj { color: var(--adjust); }
.arrow { color: var(--muted); margin: 0 3px; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 7px; background: #f2f2f7; font-size: 13px; }
.code { font-size: 12px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.meta { font-size: 12px; color: var(--muted); }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 700; text-align: start; padding: 12px 16px; background: #fafafd; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th:first-child { border-start-start-radius: var(--radius); }
.table th:last-child { border-start-end-radius: var(--radius); }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fcfbfe; }
.table .c { text-align: center; }
.table .e { text-align: end; }
.acts { display: flex; gap: 5px; justify-content: flex-end; }
.acts .lbl { display: none; }
tr[data-href] { cursor: pointer; }
.foot-note { padding: 12px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; text-align: center; }

/* ===== الحقول ===== */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 240px; }
.log-filters .more, .log-filters .more-actions { display: contents; }
.input {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--line-strong); border-radius: 10px;
    background: #fff; color: inherit; font: inherit; font-size: 14.5px;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.auto { width: auto; }
select.input { cursor: pointer; }
.search { position: relative; }
.search > .i { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; width: 17px; height: 17px; }
.search .input { padding-inline-start: 38px; }
.mb8 { margin-bottom: 8px; }
.chk { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 500; cursor: pointer; padding: 0 4px; white-space: nowrap; }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.date-lbl { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }

.field { margin-bottom: 14px; flex: 1; min-width: 0; }
.field.grow2 { flex: 2; }
.field label { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; color: #3b3e55; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; min-height: 1em; }
.hint b { color: var(--text); }
.row { display: flex; gap: 12px; }
.form-foot { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--line); }

.stepper { display: flex; gap: 6px; }
.stepper .input { text-align: center; font-weight: 800; font-size: 17px; -moz-appearance: textfield; appearance: textfield; }
.stepper .input::-webkit-inner-spin-button,
.stepper .input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .btn.icon { width: 46px; height: auto; flex: none; border-radius: 10px; }
.stepper .btn.icon .i { width: 18px; height: 18px; stroke-width: 2.5; }

/* ===== صفحة المنتج ===== */
.sboxes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sbox { padding: 12px 14px; border-radius: 12px; min-width: 0; }
.sbox span { display: block; font-size: 12.5px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sbox b { display: block; font-size: 24px; font-weight: 800; line-height: 1.3; }
.sbox.loc1 { background: var(--loc1-bg); color: var(--loc1); }
.sbox.loc2 { background: var(--loc2-bg); color: var(--loc2); }
.danger-zone, .data-row { display: flex; align-items: center; gap: 14px; }
.danger-zone small, .data-row small { display: block; font-size: 13px; }
.data-row { padding: 12px 0; border-top: 1px solid var(--line); }
.data-row:first-of-type { border-top: 0; padding-top: 0; }

/* صفحة الفئات */
.cat-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.cat-row:first-of-type { border-top: 0; padding-top: 0; }
.cat-row .input { flex: 1; min-width: 0; }
.cat-row .input.changed { border-color: var(--accent); background: var(--accent-soft); }
.cat-row .btn:disabled { opacity: .45; cursor: default; pointer-events: none; }
.cat-count { min-width: 64px; text-align: center; white-space: nowrap; }
.cat-hint { margin: 16px 0 0; padding: 12px 18px 0 0; border-top: 1px solid var(--line); display: grid; gap: 4px; }

/* ===== الحالة الفارغة ===== */
.empty { text-align: center; color: var(--muted); padding: 30px 20px; }
.empty .i { width: 30px; height: 30px; opacity: .5; }
.empty p { margin: 8px 0 14px; }
.empty.big { padding: 56px 20px; }

/* ===== النافذة ===== */
dialog {
    border: 0; padding: 0; border-radius: 18px; color: inherit; background: var(--card);
    width: min(520px, calc(100vw - 24px));
    max-height: calc(100vh - 32px);
    overflow: auto; overscroll-behavior: contain;
    box-shadow: 0 30px 70px rgba(20, 16, 40, .28);
}
dialog::backdrop { background: rgba(28, 22, 44, .45); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 4px; }
.dlg-head h3 { font-size: 19px; font-weight: 800; }
.dlg-body { padding: 12px 20px 2px; }
.dlg-foot { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 14px 20px 20px; border-top: 1px solid var(--line); background: var(--card); }
.dlg-foot .btn.primary { flex: 1; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: #f1f1f6; border-radius: 12px; margin-bottom: 16px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 4px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; }
.seg span .i { width: 16px; height: 16px; stroke-width: 2.4; }
.seg span:hover { color: var(--text); }
.seg input:checked + span { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.seg input[value=in]:checked + span       { color: var(--in); }
.seg input[value=out]:checked + span      { color: var(--out); }
.seg input[value=transfer]:checked + span { color: var(--transfer); }
.seg input[value=adjust]:checked + span   { color: var(--adjust); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== صفحة الدخول ===== */
.auth-body {
    min-height: 100vh; min-height: 100dvh;
    display: grid; place-items: center;
    padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
    background:
        radial-gradient(900px 520px at 100% 0%, var(--accent-soft), transparent 60%),
        radial-gradient(800px 480px at 0% 100%, var(--loc1-bg), transparent 60%),
        var(--bg);
}
.auth { width: min(400px, 100%); }
.auth-card { padding: 30px 26px 26px; }
.auth-brand { display: grid; justify-items: center; gap: 4px; text-align: center; margin-bottom: 22px; }
.auth-brand .logo {
    width: 62px; height: 62px; margin-bottom: 8px; border-radius: 19px;
    display: grid; place-items: center; color: #fff;
    background: linear-gradient(140deg, var(--accent), #f472b6);
    box-shadow: 0 10px 26px rgba(190, 24, 93, .32);
}
.auth-brand .logo .i { width: 30px; height: 30px; }
.auth-brand b { font-size: 21px; font-weight: 800; }
.auth-brand small { color: var(--muted); font-size: 13px; }
.auth h1 { font-size: 18px; font-weight: 800; margin-bottom: 2px; }
.auth form > p { margin: 0 0 18px; font-size: 14px; }
.auth .btn.block { margin-top: 16px; }
.auth-remember { padding: 0; font-size: 13.5px; white-space: normal; }
.auth-alert { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 16px; border-radius: 10px; font-size: 14px; font-weight: 700; background: var(--in-bg); color: var(--in); }
.auth-alert.err { background: var(--danger-bg); color: var(--danger); }
.auth-alert.info { background: var(--transfer-bg); color: var(--transfer); }
.auth-help { margin-top: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.auth-help summary { cursor: pointer; font-weight: 700; }
.auth-help p { margin: 8px 0 0; line-height: 1.7; }
.auth-help code { background: #fff; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); }
.pass-wrap { position: relative; }
.pass-wrap .input { padding-inline-end: 48px; }
.pass-toggle { position: absolute; inset-inline-end: 5px; top: 50%; transform: translateY(-50%); }
.pass-toggle.on { color: var(--accent); }
.side-logout { margin-top: 4px; }
.side-logout .btn { width: 100%; justify-content: flex-start; color: var(--muted); }
.side-logout .btn:hover { color: var(--danger); background: var(--danger-bg); }
.h2 .i { vertical-align: -3px; margin-inline-end: 4px; color: var(--muted); }

/* ===== التكلفة والربح ===== */
.sub-cost { font-size: 12px; color: var(--muted); font-weight: 500; }
.margin-hint { margin: -6px 0 14px; padding: 8px 12px; border-radius: 10px; background: #fafafd; color: var(--muted); font-size: 13px; }
.margin-hint b { font-weight: 800; }
.margin-hint.pos { background: var(--in-bg); color: var(--in); }
.margin-hint.neg { background: var(--danger-bg); color: var(--danger); }
.p-pos { color: var(--in); font-weight: 800; }
.p-neg { color: var(--danger); font-weight: 800; }
.c-profit { background: var(--in-bg); color: var(--in); }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.k4 .kpi { flex-direction: column; align-items: flex-start; gap: 10px; }
.kpis.k4 .kpi > div { width: 100%; }
.kpi b .p-pos, .kpi b .p-neg { font-weight: 800; }
.inv-list tr.is-cancelled .ic-profit span { text-decoration: line-through; opacity: .6; }
.inv-internal { border-style: dashed; background: #fcfcfe; }
.ii-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ii-head .i { color: var(--muted); }
.ii-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ii-grid > div { padding: 10px 12px; border-radius: 10px; background: #fff; border: 1px solid var(--line); min-width: 0; }
.ii-grid > div > span { display: block; font-size: 12px; color: var(--muted); }
.ii-grid b { font-size: 17px; font-weight: 800; }
.ii-note { display: block; margin-top: 10px; line-height: 1.7; }

/* ===== واجهة الزبائن (في لوحة التحكم) ===== */
textarea.input { resize: vertical; min-height: 84px; line-height: 1.7; }
.store-chk { display: flex; padding: 0; margin: 2px 0 14px; white-space: normal; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; min-width: 0; color: var(--muted); background: #fafafd; }
.tag-hidden { display: inline-block; margin-inline-start: 6px; padding: 0 8px; border-radius: 6px; background: #f1f1f5; color: var(--muted); font-size: 11.5px; font-weight: 700; vertical-align: 2px; }
.nav a .i + span + .i { width: 14px; height: 14px; margin-inline-start: auto; opacity: .6; }

/* ===== صور المنتجات ===== */
.pimg { flex: none; border-radius: 10px; background: #f1f1f6; overflow: hidden; }
img.pimg { display: block; object-fit: cover; }
img.pimg[data-full] { cursor: zoom-in; }
.pimg.ph { display: grid; place-items: center; font-weight: 800; line-height: 1; user-select: none; }
.pimg-sm { width: 42px; height: 42px; font-size: 17px; }
.pimg-md { width: 48px; height: 48px; border-radius: 11px; font-size: 19px; }
.ph-0 { background: #fce7f1; color: #be185d; }
.ph-1 { background: #ede9fe; color: #6d28d9; }
.ph-2 { background: #e0f2fe; color: #0369a1; }
.ph-3 { background: #dcfce7; color: #15803d; }
.ph-4 { background: #fef3c7; color: #b45309; }
.ph-5 { background: #ccfbf1; color: #0f766e; }
.pcell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pcell > div { min-width: 0; }
#mvStock:not(:empty) { display: flex; align-items: center; gap: 10px; }

.img-field { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.img-preview {
    width: 112px; height: 112px; flex: none; overflow: hidden; cursor: pointer;
    display: grid; place-items: center; border-radius: 16px;
    background: #fafafd; border: 2px dashed var(--line-strong);
    transition: border-color .15s, background .15s;
}
.img-preview:hover { border-color: var(--accent); background: var(--accent-soft); }
.img-preview.has-img { border-style: solid; border-color: var(--line); }
.img-preview img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .2s, filter .2s; }
.img-preview.removing img { opacity: .25; filter: grayscale(1); }
.img-empty { display: grid; justify-items: center; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }
.img-empty .i { width: 26px; height: 26px; }
.img-actions { display: grid; gap: 7px; justify-items: start; min-width: 0; }
.img-actions small { font-size: 12.5px; }
.sm-chk { font-size: 13.5px; padding: 0; }

.lightbox { padding: 0; background: transparent; box-shadow: none; width: fit-content; max-width: 94vw; overflow: visible; }
.lightbox::backdrop { background: rgba(15, 12, 25, .78); backdrop-filter: blur(4px); }
.lightbox img { display: block; max-width: 94vw; max-height: 86vh; border-radius: 16px; background: #fff; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); cursor: zoom-out; }
.lb-close {
    position: absolute; top: -14px; inset-inline-start: -14px;
    width: 38px; height: 38px; display: grid; place-items: center;
    border: 0; border-radius: 50%; background: #fff; color: var(--text); cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}

/* ===== الفاتورة داخل نافذة الحركة ===== */
.inv-box { padding: 12px 14px 4px; margin-bottom: 12px; border-radius: 12px; background: #fafafd; border: 1px dashed var(--line-strong); }
.inv-box-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.inv-box-head .chk { padding: 0; font-weight: 700; }
.inv-box-head .link { font-size: 13px; }
.inv-box .field { margin-bottom: 8px; }
.inv-box-total { font-size: 13.5px; color: var(--muted); padding-bottom: 8px; }
.inv-box-total b { color: var(--in); font-size: 15px; }

/* ===== قائمة الفواتير ===== */
.inv-no { font-weight: 800; color: var(--accent); }
.inv-link { color: var(--accent); font-weight: 700; }
.inv-link:hover { text-decoration: underline; }
.inv-list tr.is-cancelled .ic-total b { text-decoration: line-through; color: var(--muted); }
.cancel-note { display: flex; align-items: center; gap: 10px; color: var(--danger); background: var(--danger-bg); border-color: #f5c9c9; }

/* ===== فاتورة جديدة ===== */
.inv-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(290px, 1fr); gap: 16px; align-items: start; }
.inv-side { position: sticky; top: 20px; }
.seg.seg-locs { grid-template-columns: repeat(2, 1fr); margin-bottom: 0; }
.seg.seg-locs span { gap: 8px; }
.seg-locs input[value="1"]:checked + span { color: var(--loc1); }
.seg-locs input[value="2"]:checked + span { color: var(--loc2); }
.inv-search-wrap { position: relative; }
.suggest {
    position: absolute; inset-inline: 0; top: 100%; z-index: 25; margin-top: 4px; padding: 4px;
    max-height: 340px; overflow: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 18px 44px rgba(25, 22, 45, .16);
}
.sug { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 12px; border: 0; border-radius: 9px; background: none; font: inherit; color: inherit; text-align: start; cursor: pointer; }
.sug b { display: block; }
.sug small { display: block; color: var(--muted); font-size: 12px; }
.sug .num { font-weight: 700; color: var(--accent); white-space: nowrap; }
.sug.on, .sug:hover { background: var(--accent-soft); }
.sug.none small { color: var(--danger); }
.sug-empty { padding: 16px; text-align: center; color: var(--muted); }
.cart { display: grid; gap: 8px; }
.cline {
    display: grid; grid-template-columns: minmax(0, 1fr) 116px 88px 84px 30px;
    grid-template-areas: "info qty price total del";
    align-items: center; gap: 10px; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 12px; background: #fcfcfe;
    animation: drop .2s ease-out;
}
.cline.over { border-color: #f5c2c2; background: #fff7f7; }
.cline.over .cl-av { color: var(--danger); font-weight: 800; }
.cl-info { grid-area: info; min-width: 0; display: flex; align-items: center; gap: 10px; }
.cl-txt { min-width: 0; }
.cl-info b { display: block; overflow-wrap: anywhere; line-height: 1.35; }
.cl-info small { color: var(--muted); font-size: 12px; }
.cl-step { grid-area: qty; }
.cl-price { grid-area: price; }
.cl-t { grid-area: total; text-align: end; white-space: nowrap; }
.cl-del { grid-area: del; }
.cline .input { padding: 8px 10px; font-size: 15px; }
.cline .stepper { gap: 4px; }
.cline .stepper .btn.icon { width: 32px; }
.cline .cl-del { width: 30px; height: 30px; }
.cline .stepper .input { padding: 8px 2px; font-size: 15px; }
.totals .trow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; }
.totals .trow + .trow { border-top: 1px dashed var(--line-strong); }
.totals .trow > span, .totals .trow > label { color: var(--muted); font-weight: 600; }
.totals .disc { width: 130px; text-align: center; padding: 8px 10px; }
.totals .grand { font-size: 21px; font-weight: 800; }
.totals .grand > span { color: var(--text); }
.totals .grand b { color: var(--accent); }
.btn.block { width: 100%; margin-top: 12px; padding: 13px; font-size: 15.5px; }
.hint.c { text-align: center; }
.hint.err { color: var(--danger); font-weight: 700; }
.mb0 { margin-bottom: 0; }

/* ===== الفاتورة (عرض وطباعة) ===== */
.inv-wrap { max-width: 780px; display: grid; gap: 16px; }
.invoice-paper { position: relative; overflow: hidden; padding: 28px 30px; }
.ip-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 18px; border-bottom: 2px dashed var(--line-strong); }
.ip-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ip-brand .logo { width: 48px; height: 48px; border-radius: 14px; flex: none; display: grid; place-items: center; color: #fff; background: linear-gradient(140deg, var(--accent), #f472b6); }
.ip-brand .logo .i { width: 24px; height: 24px; }
.ip-brand b { display: block; font-size: 20px; font-weight: 800; line-height: 1.3; }
.ip-brand small { color: var(--muted); font-size: 13px; }
.ip-no { text-align: end; flex: none; }
.ip-no span { display: block; color: var(--muted); font-size: 12.5px; }
.ip-no b { font-size: 26px; font-weight: 800; color: var(--accent); line-height: 1.2; }
.ip-info { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 16px 0; }
.ip-info span { display: block; font-size: 12px; color: var(--muted); }
.ip-info b { font-weight: 700; }
.ip-info b[dir=ltr] { display: block; text-align: right; }
.ip-info small { display: block; color: var(--muted); text-align: right; }
.ip-items { width: 100%; border-collapse: collapse; }
.ip-items th { background: #fafafd; font-size: 12.5px; color: var(--muted); font-weight: 700; padding: 10px 12px; text-align: start; border-block: 1px solid var(--line); white-space: nowrap; }
.ip-items td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ip-items .c { text-align: center; }
.ip-items .e { text-align: end; }
.ip-sum { width: min(320px, 100%); margin-inline-start: auto; padding-top: 14px; display: grid; gap: 6px; }
.ip-sum > div { display: flex; justify-content: space-between; gap: 12px; font-size: 14.5px; }
.ip-sum span { color: var(--muted); }
.ip-sum .grand { margin-top: 6px; padding: 12px 16px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-size: 19px; font-weight: 800; }
.ip-sum .grand span { color: inherit; }
.ip-note { margin: 18px 0 0; padding: 12px 14px; border-radius: 10px; background: #fafafd; font-size: 14px; }
.ip-foot { margin-top: 22px; padding-top: 16px; border-top: 2px dashed var(--line-strong); text-align: center; color: var(--muted); font-size: 14.5px; }
.ip-stamp {
    position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%) rotate(-16deg);
    padding: 6px 30px; border: 5px solid var(--danger); border-radius: 16px;
    color: var(--danger); font-size: 52px; font-weight: 800; letter-spacing: 3px;
    opacity: .3; pointer-events: none;
}

/* ===== التنبيهات ===== */
.toasts { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(460px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: #1d2033; color: #fff; font-weight: 500; box-shadow: 0 12px 30px rgba(20, 16, 40, .25); animation: drop .25s ease-out; transition: opacity .3s, transform .3s; }
.toast.ok .i { color: #4ade80; }
.toast.info .i { color: #93c5fd; }
.toast.err { background: #b91c1c; }
.toast > span { flex: 1; }
.toast-link { flex: none; padding: 5px 12px; border-radius: 8px; background: rgba(255, 255, 255, .16); color: #fff; font-weight: 800; font-size: 13.5px; white-space: nowrap; }
.toast-link:hover { background: rgba(255, 255, 255, .26); }
.toast.hide { opacity: 0; transform: translateY(-8px); }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }


/* ================================================================
   الشاشات المتوسطة
   ================================================================ */
@media (max-width: 1280px) {
    /* الفاتورة الجديدة: السلة بكامل العرض والعميل والمجموع بجانب بعضهما تحتها */
    .inv-grid { grid-template-columns: minmax(0, 1fr); }
    .inv-side { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}
@media (max-width: 1150px) {
    .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpis.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
    .grid2 { grid-template-columns: minmax(0, 1fr); }
    .inv-side { grid-template-columns: minmax(0, 1fr); }
    /* صفحة المنتج: الرصيد أولاً ثم النموذج ثم الحركات */
    .grid-form { display: flex; flex-direction: column; align-items: stretch; }
    .grid-form > .stack { display: contents; }
    .stock-card { order: -1; }
}

/* ================================================================
   الجوال والأجهزة اللوحية الصغيرة — شريط علوي + تنقل سفلي
   ================================================================ */
@media (max-width: 860px) {
    .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    .side, .hide-m { display: none; }

    /* الشريط العلوي */
    .mtop {
        display: flex; align-items: center; justify-content: space-between; gap: 10px;
        position: sticky; top: 0; z-index: 30;
        height: calc(var(--mtop-h) + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 16px 0;
        background: rgba(255, 255, 255, .92);
        -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
        border-bottom: 1px solid var(--line);
    }
    .mtop .brand { padding: 0; gap: 10px; min-width: 0; }
    .mtop .brand .logo { width: 36px; height: 36px; border-radius: 11px; box-shadow: 0 4px 10px rgba(190, 24, 93, .25); }
    .mtop .brand .logo .i { width: 19px; height: 19px; }
    .mtop .brand b { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .mtop-stock { display: flex; gap: 6px; flex: none; }
    .chip { display: flex; flex-direction: column; align-items: center; min-width: 54px; max-width: 96px; padding: 3px 10px; border-radius: 10px; line-height: 1.2; }
    .chip small { max-width: 100%; font-size: 10.5px; font-weight: 700; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .chip b { font-size: 14.5px; font-weight: 800; }
    .chip.loc1 { background: var(--loc1-bg); color: var(--loc1); }
    .chip.loc2 { background: var(--loc2-bg); color: var(--loc2); }
    .mtop-gear { width: 38px; height: 38px; color: var(--muted); }
    .mtop-gear .i { width: 20px; height: 20px; }
    .mtop-gear.active { color: var(--accent); background: var(--accent-soft); }

    /* التنقل السفلي */
    .bnav {
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center;
        position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .94);
        -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
        border-top: 1px solid var(--line);
        box-shadow: 0 -6px 24px rgba(25, 22, 45, .06);
    }
    .bnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; color: var(--muted); font-size: 11.5px; font-weight: 700; touch-action: manipulation; }
    .bnav a .i { width: 52px; height: 30px; padding: 4px 15px; border-radius: 15px; transition: background .15s; }
    .bnav a.active { color: var(--accent); }
    .bnav a.active .i { background: var(--accent-soft); stroke-width: 2.3; }
    .bnav-fab {
        justify-self: center; width: 56px; height: 56px; margin-top: -30px;
        display: grid; place-items: center; border: 4px solid var(--bg); border-radius: 20px;
        background: linear-gradient(140deg, var(--accent), #ec4899); color: #fff;
        box-shadow: 0 10px 24px rgba(190, 24, 93, .38); cursor: pointer; touch-action: manipulation;
        transition: transform .12s;
    }
    .bnav-fab:active { transform: scale(.92); }
    .bnav-fab .i { width: 26px; height: 26px; stroke-width: 2.6; }

    .main { padding: 16px 16px calc(104px + env(safe-area-inset-bottom)); }
    .top { flex-wrap: nowrap; margin-bottom: 14px; gap: 10px; }
    .top > div:first-child { flex: 1; }
    .top h1 { font-size: 21px; }
    .top .sub { font-size: 12.5px; }
    .top-actions { flex: none; flex-wrap: nowrap; }

    /* حجم 16px يمنع التكبير التلقائي في iPhone عند الكتابة */
    .input { font-size: 16px; padding: 11px 12px; }

    /* شريط البحث ثابت أثناء التمرير */
    .toolbar.sticky-m {
        position: sticky; top: calc(var(--mtop-h) + env(safe-area-inset-top) + 8px); z-index: 10;
        box-shadow: 0 6px 18px rgba(25, 22, 45, .07), 0 -9px 0 var(--bg);
    }
    .toolbar .search { flex-basis: 100%; }
    .toolbar select.input.auto { flex: 1; }

    /* فلاتر السجل قابلة للطي */
    .filter-toggle { display: inline-flex; flex: none; width: 46px; height: 46px; }
    .log-filters .search { flex: 1 1 0; }
    .log-filters .more { display: none; }
    .log-filters.open .more { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
    .log-filters .more .input.auto { width: 100%; }
    .log-filters .date-lbl { display: flex; min-width: 0; }
    .log-filters .date-lbl .input { flex: 1; min-width: 0; }
    .log-filters .more-actions { display: flex; gap: 8px; grid-column: 1 / -1; }
    .log-filters .more-actions .btn { flex: 1; }

    dialog .input { font-size: 16px; }
}

/* ================================================================
   الأجهزة اللوحية والهاتف — المنتجات كبطاقات بدل الجدول
   ================================================================ */
@media (max-width: 860px) {
    .m-only { display: inline; }

    .cards-sm { background: none; border: 0; box-shadow: none; }
    .cards-sm .table-wrap { overflow: visible; }
    .cards-sm .table { display: block; }
    .cards-sm tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .cards-sm thead { display: none; }
    .cards-sm tbody tr {
        display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
        grid-template-areas: "name name name" "l1 l2 tot" "acts acts acts";
        padding: 14px;
        background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    }
    .cards-sm tbody td { display: block; padding: 0; border: 0; background: none !important; text-align: start; }
    .cards-sm .hide-sm { display: none; }
    .cards-sm .cell-name { grid-area: name; padding-bottom: 2px; }
    .cards-sm .cell-l1 { grid-area: l1; }
    .cards-sm .cell-l2 { grid-area: l2; }
    .cards-sm .cell-tot { grid-area: tot; }
    .cards-sm .cell-acts { grid-area: acts; }
    .cards-sm .pname { font-size: 16px; }
    .cards-sm .pimg-sm { width: 54px; height: 54px; border-radius: 12px; font-size: 21px; }
    .cards-sm .loc, .cards-sm .cell-tot .badge {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
        width: 100%; min-width: 0; padding: 7px 6px; border-radius: 11px;
        font-size: 19px; font-weight: 800; line-height: 1.25;
    }
    .cards-sm .cell-tot .badge.st-ok { background: #f1f1f6; }
    .cards-sm [data-label]::before {
        content: attr(data-label); max-width: 100%;
        font-size: 11.5px; font-weight: 700; opacity: .8;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .cards-sm .loc.zero { opacity: .55; }
    .cards-sm .acts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 2px; }
    .cards-sm .acts .btn.icon { width: auto; height: 40px; gap: 5px; font-size: 13px; }
    .cards-sm .acts .lbl { display: inline; }
    .cards-sm .acts .a-in       { color: var(--in); }
    .cards-sm .acts .a-out      { color: var(--out); }
    .cards-sm .acts .a-transfer { color: var(--transfer); }
    .cards-sm .acts .btn .lbl { color: var(--text); }
}

/* ================================================================
   الهاتف — بطاقة واحدة في الصف، والسجل كقائمة
   ================================================================ */
@media (max-width: 700px) {
    .cards-sm tbody { grid-template-columns: minmax(0, 1fr); gap: 10px; }

    /* السجل كقائمة */
    .list-sm .table, .list-sm tbody { display: block; }
    .list-sm thead { display: none; }
    .list-sm tbody tr {
        display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "type prod qty" "type place date" "type note note";
        column-gap: 12px; row-gap: 1px; padding: 12px 16px; border-bottom: 1px solid var(--line);
    }
    .list-sm tbody tr:last-child { border-bottom: 0; }
    .list-sm tbody td { display: block; padding: 0; border: 0; background: none !important; }
    .list-sm .lc-type { grid-area: type; padding-top: 2px; }
    .list-sm .lc-type .badge { min-width: 50px; justify-content: center; }
    .list-sm .lc-prod { grid-area: prod; min-width: 0; }
    .list-sm .lc-prod .code { display: none; }
    .list-sm .lc-qty { grid-area: qty; text-align: end; }
    .list-sm .lc-place { grid-area: place; font-size: 12.5px; color: var(--muted); white-space: normal; }
    .list-sm .lc-date { grid-area: date; text-align: end; font-size: 12px; }
    .list-sm .lc-note { grid-area: note; display: block; font-size: 12.5px; }
    .list-sm .lc-note:empty { display: none; }

    /* الفواتير كقائمة */
    .inv-list .table, .inv-list tbody { display: block; }
    .inv-list thead { display: none; }
    .inv-list tbody tr {
        display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "no cust total" "no date st";
        column-gap: 12px; row-gap: 2px; align-items: center;
        padding: 12px 16px; border-bottom: 1px solid var(--line);
    }
    .inv-list tbody tr:last-child { border-bottom: 0; }
    .inv-list tbody td { display: block; padding: 0; border: 0; background: none !important; }
    .inv-list .ic-no { grid-area: no; align-self: center; }
    .inv-list .ic-no .inv-no { display: grid; place-items: center; min-width: 48px; height: 44px; padding: 0 8px; border-radius: 11px; background: var(--accent-soft); font-size: 14px; }
    .inv-list .ic-cust { grid-area: cust; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .inv-list .ic-total { grid-area: total; text-align: end; }
    .inv-list .ic-date { grid-area: date; font-size: 12px; }
    .inv-list .ic-st { grid-area: st; text-align: end; }
    .inv-list .ic-st .badge { font-size: 11.5px; padding: 1px 8px; }
    .inv-list .ic-loc, .inv-list .ic-pcs, .inv-list .ic-profit { display: none; }
}

/* ================================================================
   الهاتف الصغير
   ================================================================ */
@media (max-width: 600px) {
    .dt { display: none; }
    .btn.icon-m { width: 44px; height: 44px; padding: 0; }
    .btn.sm.icon-m { width: 36px; height: 36px; }
    .btn { padding: 10px 14px; }

    .row:not(.keep) { flex-direction: column; gap: 0; }
    .card.pad { padding: 16px; }
    .card-head { padding: 14px 16px; }
    .list li { padding: 11px 16px; gap: 10px; }
    .today { padding: 9px 16px; }

    /* الإجراءات السريعة والمؤشرات */
    .quick { gap: 10px; margin-bottom: 12px; }
    .qa { padding: 11px 12px; gap: 10px; }
    .qa-ic { width: 38px; height: 38px; border-radius: 11px; }
    .qa-ic .i { width: 19px; height: 19px; }
    .qa b { font-size: 14px; }
    .qa small { display: none; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
    /* الأيقونة فوق الرقم ليأخذ المبلغ مع العملة كامل عرض البطاقة */
    .kpi { flex-direction: column; align-items: flex-start; padding: 12px; gap: 8px; }
    .kpi > div { width: 100%; }
    .kpi-ic { width: 34px; height: 34px; border-radius: 10px; }
    .kpi-ic .i { width: 18px; height: 18px; }
    .kpi b { font-size: 19px; }
    .kpi > div > span { font-size: 12px; }
    .kpi small { font-size: 11px; }
    .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .split-card { margin-bottom: 12px; }
    .welcome { flex-direction: column; align-items: stretch; text-align: center; }
    .welcome-ic { margin: 0 auto; }

    /* صفحة المنتج */
    .sboxes { gap: 6px; }
    .sbox { padding: 10px; }
    .sbox b { font-size: 20px; }
    .btn-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .btn-row .btn { padding: 9px 4px; }
    .form-foot .btn { flex: 1; }
    .form-foot .btn.primary { flex: 1 1 100%; }
    .danger-zone, .data-row { flex-wrap: wrap; }
    .cat-row { gap: 6px; }
    .cat-count { min-width: 0; font-size: 12.5px; }

    .img-preview { width: 96px; height: 96px; }
    .ii-grid { gap: 6px; }
    .ii-grid > div { padding: 8px; }
    .ii-grid b { font-size: 15px; }
    .copy-row { flex-wrap: wrap; }
    .copy-row .input { flex-basis: 100%; }
    .copy-row .btn { flex: 1; }
    dialog.lightbox { width: fit-content; max-width: 94vw; margin: auto; border-radius: 0; max-height: none; }
    .lb-close { top: 8px; inset-inline-start: 8px; }
    .lightbox[open] { animation: pop .18s ease-out; }

    /* النافذة تصبح لوحة سفلية */
    dialog {
        width: 100%; max-width: 100%;
        margin: auto 0 0; border-radius: 22px 22px 0 0;
        max-height: 92vh; max-height: 92dvh;
    }
    dialog[open] { animation: sheet .26s cubic-bezier(.2, .8, .2, 1); }
    .grab { display: block; width: 42px; height: 5px; margin: 8px auto 0; border-radius: 9px; background: var(--line-strong); }
    .dlg-head { padding: 6px 16px 0; }
    .dlg-body { padding: 10px 16px 0; }
    .dlg-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
    .dlg-foot .btn { padding: 13px 16px; font-size: 15px; }
    .seg span { flex-direction: column; gap: 2px; padding: 8px 2px; font-size: 13px; }
    .seg.seg-locs span { flex-direction: row; font-size: 14px; padding: 10px 4px; }

    /* سطر الفاتورة الجديدة على الهاتف */
    .cline {
        grid-template-columns: minmax(0, 1fr) minmax(0, .8fr) auto;
        grid-template-areas: "info info del" "qty price total";
        row-gap: 8px; padding: 10px;
    }
    .cl-t { font-size: 15px; }

    /* الفاتورة على الهاتف */
    .invoice-paper { padding: 18px 16px; }
    .ip-brand b { font-size: 17px; }
    .ip-no b { font-size: 21px; }
    .ip-info { grid-template-columns: 1fr 1fr; }
    .ip-items th, .ip-items td { padding: 9px 6px; }
    .ip-items .ip-n { display: none; }
    .ip-stamp { font-size: 38px; }
}
@keyframes sheet { from { transform: translateY(100%); } }

/* ================================================================
   الطباعة — الفاتورة فقط
   ================================================================ */
@media print {
    @page { margin: 12mm; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    body { background: #fff; }
    .side, .mtop, .bnav, .top, .toasts, .no-print, dialog { display: none !important; }
    .app { display: block; }
    .main { padding: 0 !important; max-width: none; }
    .inv-wrap { max-width: none; }
    .card { box-shadow: none !important; }
    .invoice-paper { border: 0; padding: 0; overflow: visible; }
    .table-wrap { overflow: visible; }
}
