@font-face {
    font-family: 'Cairo';
    src: url('fonts/cairo-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+08A0-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
    font-weight: 400 700;
    font-display: swap;
}
@font-face {
    font-family: 'Cairo';
    src: url('fonts/cairo-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122;
    font-weight: 400 700;
    font-display: swap;
}

:root {
    --bg: #f3f1ea;
    --card: #ffffff;
    --ink: #16211c;
    --muted: #6d7871;
    --line: #e5e1d6;
    --green: #0b5d3b;
    --green-2: #0f7a4d;
    --green-soft: #e7f1eb;
    --amber: #a9701a;
    --amber-soft: #fbf0dc;
    --red: #a02a20;
    --red-soft: #fbe9e6;
    --shadow: 0 1px 2px rgba(22, 33, 28, .06), 0 8px 24px rgba(22, 33, 28, .06);
    --r: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
    line-height: 1.5;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.3; }
p { margin: 0; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.amt { direction: ltr; unicode-bidi: isolate; display: inline-block; }

#app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* الشريط العلوي */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px 12px;
    background: rgba(243, 241, 234, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .tb-title { font-weight: 700; font-size: 17px; }
.topbar .tb-sub { font-size: 12.5px; color: var(--muted); }
.topbar .tb-spacer { flex: 1; }
.iconbtn {
    border: 1px solid var(--line); background: var(--card); color: var(--ink);
    width: 40px; height: 40px; border-radius: 12px;
    display: grid; place-items: center; padding: 0;
}
.iconbtn:active { transform: scale(.97); }
.iconbtn.warn { border-color: #efd9a8; background: var(--amber-soft); color: var(--amber); }

/* المحتوى */
.view { flex: 1; padding: 4px 16px 108px; max-width: 760px; width: 100%; margin: 0 auto; }
@media (min-width: 900px) { .view { padding-bottom: 40px; max-width: 880px; } }

/* البطاقات */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.section { margin-top: 18px; }
.section-head { display: flex; align-items: center; gap: 8px; margin: 0 2px 8px; }
.section-head h2 { font-size: 14.5px; color: var(--muted); font-weight: 600; }
.section-head .more { margin-inline-start: auto; font-size: 13px; color: var(--green); background: none; border: 0; padding: 4px; }

/* بطاقة الخزنة */
.hero {
    background: linear-gradient(150deg, #0b5d3b 0%, #0a4a30 100%);
    color: #fff; border-radius: 20px; padding: 20px; position: relative; overflow: hidden;
    box-shadow: 0 12px 30px rgba(11, 93, 59, .22);
}
.hero::after {
    content: ''; position: absolute; inset-inline-start: -40px; top: -60px;
    width: 190px; height: 190px; border-radius: 50%; background: rgba(255, 255, 255, .06);
}
.hero .h-label { font-size: 13px; opacity: .85; }
.hero .h-value { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin-top: 2px; }
.hero .h-value small { font-size: 15px; font-weight: 400; opacity: .8; margin-inline-start: 4px; }
.hero .h-row { display: flex; gap: 18px; margin-top: 12px; font-size: 13px; position: relative; }
.hero .h-row div span { display: block; opacity: .78; font-size: 12px; }
.hero .h-row div b { font-weight: 600; }

/* شبكة الأرقام */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.grid2 .cell { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.grid2 .cell span { display: block; font-size: 12.5px; color: var(--muted); }
.grid2 .cell b { font-size: 19px; font-weight: 700; }
.grid2 .cell.neg b { color: var(--red); }
.grid2 .cell small { font-size: 11.5px; color: var(--muted); }

/* أزرار */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--line); background: var(--card); color: var(--ink);
    border-radius: 12px; padding: 11px 14px; font-weight: 600; font-size: 14.5px;
    min-height: 46px;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:disabled { opacity: .55; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--red-soft); border-color: #f2cfc9; color: var(--red); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.quick .qbtn {
    background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 600; color: var(--ink); box-shadow: var(--shadow);
}
.quick .qbtn svg.ic { width: 24px; height: 24px; color: var(--green); }
.quick .qbtn.sell svg.ic { color: var(--green-2); }
.quick .qbtn.buy svg.ic { color: var(--amber); }

/* قوائم */
.rows { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row {
    display: flex; align-items: center; gap: 12px; padding: 13px 14px;
    border-bottom: 1px solid var(--line); background: var(--card); width: 100%; text-align: start;
    border-inline: 0; border-top: 0;
}
.row:last-child { border-bottom: 0; }
.row .r-main { flex: 1; min-width: 0; display: block; }
.row .r-title { display: block; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r-sub { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.row .r-end { text-align: end; flex-shrink: 0; }
.row .r-end b { font-size: 15px; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.row .r-end span { display: block; font-size: 12px; color: var(--muted); }
.row .r-end .in { color: var(--green-2); }
.row .r-end .out { color: var(--red); }
.row .avatar {
    width: 38px; height: 38px; border-radius: 11px; background: var(--green-soft); color: var(--green);
    display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.row .avatar.amber { background: var(--amber-soft); color: var(--amber); }

.chip {
    display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
    padding: 2px 9px; font-size: 11.5px; font-weight: 600; background: #eef1ee; color: var(--muted);
}
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 14px; }
.empty svg.ic { width: 34px; height: 34px; opacity: .5; margin-bottom: 6px; }

/* شريط التنقل */
.tabbar {
    position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: rgba(255, 255, 255, .96); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
    border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0; border-radius: 10px;
}
.tabbar button.on { color: var(--green); }
.tabbar button.on svg.ic { stroke-width: 2.1; }
.tabbar .fab {
    color: #fff; background: var(--green); border-radius: 16px; margin: -14px 8px 2px;
    padding: 10px 0 6px; box-shadow: 0 8px 18px rgba(11, 93, 59, .3);
}
.tabbar .fab.on { color: #fff; }
@media (min-width: 900px) { .tabbar { display: none; } }

/* الشريط الجانبي */
.side { display: none; }
@media (min-width: 900px) {
    .side {
        display: flex; flex-direction: column; width: 236px; flex-shrink: 0;
        background: #0b3d29; color: #dfeee6; padding: 18px 12px; gap: 4px;
        position: sticky; top: 0; height: 100vh;
    }
    .side .brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
    .side .brand b { font-size: 16px; color: #fff; }
    .side .brand span { font-size: 11.5px; color: #9dc3b0; display: block; }
    .side .logo { width: 38px; height: 38px; border-radius: 11px; background: rgba(255,255,255,.12); display: grid; place-items: center; color: #ffd894; }
    .side button {
        display: flex; align-items: center; gap: 10px; border: 0; background: none;
        color: #cfe3d8; padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; text-align: start;
    }
    .side button.on { background: rgba(255, 255, 255, .13); color: #fff; }
    .side .side-foot { margin-top: auto; font-size: 11.5px; color: #8fb4a2; padding: 10px 12px; }
}

/* نماذج */
.form-card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input, select.input, textarea.input {
    width: 100%; border: 1px solid var(--line); background: #fbfaf6; border-radius: 12px;
    padding: 12px; min-height: 48px; outline: none;
}
.input:focus { border-color: var(--green-2); background: #fff; box-shadow: 0 0 0 3px rgba(15, 122, 77, .1); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #6d7871 50%), linear-gradient(135deg, #6d7871 50%, transparent 50%); background-position: calc(0% + 14px) 22px, calc(0% + 19px) 22px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-inline-start: 34px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; align-items: end; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.err { color: var(--red); font-size: 13px; margin-top: 8px; font-weight: 600; }

.line {
    display: grid; grid-template-columns: 1fr 1fr 34px; gap: 8px; align-items: center;
    grid-template-areas: "item item del" "qty price del" "tot tot tot";
    padding: 12px 0; border-bottom: 1px dashed var(--line);
}
.line select[data-f="item"] { grid-area: item; }
.line input[data-f="qty"] { grid-area: qty; }
.line input[data-f="price"] { grid-area: price; }
.line .del { grid-area: del; align-self: start; margin-top: 4px; }
.line .lt { grid-area: tot; }
@media (min-width: 620px) {
    .line { grid-template-columns: 1fr 92px 100px 34px; grid-template-areas: "item qty price del" "tot tot tot tot"; }
}
.line select.input, .line input.input { min-height: 44px; padding: 8px 10px; font-size: 14px; }
.line .del { border: 0; background: none; color: var(--muted); padding: 4px; display: grid; place-items: center; }
.line .lt { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); padding-top: 2px; }
.totals { margin-top: 14px; background: #f7f5ef; border-radius: 12px; padding: 12px; }
.totals .tr { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.totals .tr.total b { font-size: 20px; }
.totals .tr.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.paidrow { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; margin-top: 10px; }

/* بطاقات ملخص */
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv b { font-weight: 700; }

/* الرسم البياني */
.bars { display: flex; align-items: flex-end; justify-content: space-around; gap: 6px; height: 110px; margin-top: 10px; }
.bars .bar { flex: 1; max-width: 46px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.bars .bar i { display: block; width: 100%; background: linear-gradient(180deg, #14875a, #0b5d3b); border-radius: 5px 5px 2px 2px; min-height: 3px; }
.bars .bar u { font-size: 10px; color: var(--muted); text-decoration: none; }

/* شيت */
.overlay {
    position: fixed; inset: 0; background: rgba(16, 24, 20, .45); z-index: 50;
    display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
@media (min-width: 640px) { .overlay { align-items: center; padding: 20px; } }
.sheet {
    background: var(--bg); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto;
    animation: up .18s ease-out;
}
@media (min-width: 640px) { .sheet { border-radius: 20px; padding-bottom: 20px; } }
@keyframes up { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .handle { width: 40px; height: 4px; border-radius: 4px; background: #d6d2c6; margin: 6px auto 10px; }
.sheet h3 { font-size: 17px; margin-bottom: 12px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet .actions .btn { flex: 1; }

/* توست */
.toast {
    position: fixed; inset-inline: 16px; bottom: 84px; z-index: 60; margin: 0 auto; max-width: 460px;
    background: #16211c; color: #fff; border-radius: 14px; padding: 12px 14px;
    display: flex; align-items: center; gap: 10px; box-shadow: 0 12px 30px rgba(0, 0, 0, .25);
    font-size: 14px;
}
.toast button { margin-inline-start: auto; background: none; border: 0; color: #ffd894; font-weight: 700; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* صفحة الصنف */
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.back { border: 0; background: none; color: var(--green); display: inline-flex; align-items: center; gap: 4px; font-weight: 600; padding: 6px 0; }
.back svg.ic { width: 18px; height: 18px; transform: scaleX(-1); }
.badge-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.sticky-cta { position: sticky; bottom: 78px; padding-top: 12px; }
@media (min-width: 900px) { .sticky-cta { bottom: 0; } }
.demo-banner {
    background: var(--amber-soft); border: 1px solid #f0dcb4; color: #7a5312;
    border-radius: 14px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; margin-top: 12px;
}
.demo-banner p { font-size: 13px; flex: 1; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 2px; margin: 8px 0 2px; }
.tabs button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--green); border-color: var(--green); color: #fff; }

[hidden] { display: none !important; }
