:root {
  --bg: #f5f2ea; --card: #ffffff; --ink: #1c1917; --mute: #6b645b; --line: #e7e1d6;
  --pri: #0f766e; --pri-ink: #ffffff; --pri-soft: #e0f2ef; --acc: #ea580c;
  --good: #15803d; --good-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2;
  --r: 14px; --shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 4px 14px rgba(28, 25, 23, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f; --card: #1f1c18; --ink: #f3efe7; --mute: #a39b8f; --line: #34302a;
    --pri: #2dd4bf; --pri-ink: #062b27; --pri-soft: #123631; --acc: #fb923c;
    --good: #4ade80; --good-soft: #14321f; --warn: #fbbf24; --warn-soft: #3a2c0c; --bad: #f87171; --bad-soft: #3b1616;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif; font-size: 16px; line-height: 1.5; min-height: 100vh; }
a { color: var(--pri); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
#app { max-width: 760px; margin: 0 auto; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
main { padding: 12px 16px 88px; }
small { font-size: .75em; color: var(--mute); font-weight: 500; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top h1 { flex: 1; margin: 0; font-size: 1.15rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back { font-size: 1.4rem; line-height: 1; padding: 4px 8px; color: var(--ink); }
.logo { font-size: 1.4rem; }
.topbtn { background: var(--pri-soft); color: var(--pri); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: .9rem; white-space: nowrap; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; max-width: 152px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; color: var(--mute); font-size: .78rem; font-weight: 600; }
.tabs a span { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--pri); }
.tabs a.on span { filter: none; opacity: 1; }

.hero { background: var(--pri); color: var(--pri-ink); border-radius: 20px; padding: 18px 20px; box-shadow: var(--shadow); }
.hero.small { padding: 14px 18px; }
.hero small { color: inherit; opacity: .8; }
.hero-date { opacity: .85; font-size: .9rem; }
.hero-label { opacity: .9; margin-top: 6px; }
.hero-num { font-size: 2.3rem; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.hero-row { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: .92rem; opacity: .95; }
.hero-row span { background: rgba(255, 255, 255, .16); padding: 2px 10px; border-radius: 999px; }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 14px 0; }
.qbtn { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 8px; border-radius: var(--r); background: var(--card); color: var(--ink); font-weight: 700; border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center; }
.qbtn.primary { background: var(--acc); color: #fff; border-color: transparent; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; color: var(--ink); box-shadow: var(--shadow); }
.card.wide { grid-column: 1 / -1; }
.card.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.card-k { color: var(--mute); font-size: .85rem; }
.card-v { font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.card-s { font-size: .82rem; color: var(--mute); }
.card-s.bad, b.bad, .bad { color: var(--bad); }
.good { color: var(--good); }

.sec { margin: 20px 0 8px; font-size: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.row:last-child, .srow:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main span { color: var(--mute); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.row-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.more-link { display: block; text-align: center; padding: 10px; font-weight: 600; }
.empty { padding: 22px 16px; text-align: center; color: var(--mute); }
.sumline { color: var(--mute); margin: 4px 0 12px; }
.sumline b { color: var(--ink); }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.note { display: block; margin: 10px 0; padding: 10px 14px; border-radius: var(--r); font-size: .9rem; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.filebar { display: block; width: calc(100% - 32px); margin: 8px 16px 0; padding: 8px 12px; border-radius: 10px; background: var(--pri-soft); color: var(--pri); font-size: .85rem; border: 0; text-align: start; }
.filebar.warn { background: var(--warn-soft); color: var(--warn); cursor: pointer; }
.filebar button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; margin: 4px 2px 0; cursor: pointer; }

.search input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 1rem; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 6px 14px; border-radius: 999px; font-size: .88rem; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; padding-bottom: 90px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: start; padding: 12px; min-height: 96px; border-radius: var(--r); border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); cursor: pointer; }
.tile:active { transform: scale(.98); }
.tile.in { border-color: var(--pri); outline: 2px solid var(--pri); outline-offset: -2px; }
.tile-name { font-weight: 700; line-height: 1.3; }
.tile-price { font-weight: 800; color: var(--pri); font-variant-numeric: tabular-nums; margin-top: auto; }
.tile-stock { font-size: .75rem; color: var(--mute); }
.tile-stock.warn { color: var(--warn); } .tile-stock.bad { color: var(--bad); }
.tile-q { position: absolute; top: 8px; left: 8px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; background: var(--pri); color: var(--pri-ink); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }

#cart { position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 25; display: flex; justify-content: center; pointer-events: none; }
.cart { pointer-events: auto; width: 100%; max-width: 760px; margin: 0 8px; background: var(--card); border: 1px solid var(--line); border-radius: 18px 18px 14px 14px; box-shadow: 0 -6px 30px rgba(0, 0, 0, .14); overflow: hidden; }
.cart-head { display: flex; width: 100%; align-items: center; gap: 10px; padding: 14px 16px; border: 0; background: var(--pri); color: var(--pri-ink); cursor: pointer; font-size: 1rem; }
.cart-head b { margin-inline-start: auto; font-size: 1.15rem; }
.cart-body { display: none; padding: 10px 14px 14px; max-height: 58vh; overflow-y: auto; }
.cart.open .cart-body { display: block; }
.cline { display: grid; grid-template-columns: 1fr auto 72px 28px; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cline-name { font-weight: 600; line-height: 1.25; } .cline-name small { display: block; color: var(--acc); }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 34px; height: 36px; border: 0; background: var(--bg); font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 46px; height: 36px; border: 0; text-align: center; background: var(--card); }
.cline-price { width: 72px; height: 36px; border: 1px solid var(--line); border-radius: 10px; text-align: center; background: var(--card); }
.x { border: 0; background: none; color: var(--mute); cursor: pointer; font-size: 1rem; }
.seg { display: flex; margin: 12px 0 8px; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 10px; font-weight: 700; cursor: pointer; color: var(--mute); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.cart-actions { display: grid; grid-template-columns: auto 1fr; gap: 8px; margin-top: 12px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: .88rem; color: var(--mute); font-weight: 600; }
.field input, .field select, .catin { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 1rem; min-height: 48px; }
.field input:focus, .field select:focus, .search input:focus, .catin:focus { outline: 2px solid var(--pri); outline-offset: 0; border-color: transparent; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.check input { width: 20px; height: 20px; accent-color: var(--pri); }
.hint { font-size: .85rem; color: var(--mute); }
.calc { display: flex; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.calc b { font-variant-numeric: tabular-nums; }
.calc.total { background: var(--pri-soft); border-color: transparent; font-size: 1.08rem; }
.calc.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.calc.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.calc.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.calcs { display: flex; flex-direction: column; gap: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer; color: var(--ink); text-align: center; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.btn.primary { background: var(--pri); color: var(--pri-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.mini { font-size: .8rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; }

.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu a { display: flex; align-items: center; gap: 8px; padding: 14px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.about { margin-top: 18px; color: var(--mute); font-size: .9rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 4px; font-size: 1rem; }
.panel p { margin: 0 0 8px; color: var(--mute); font-size: .92rem; }
.meter { display: grid; grid-template-columns: 110px 1fr 96px; align-items: center; gap: 8px; font-size: .85rem; margin: 6px 0; }
.meter div { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--pri); }
.meter i.bad { background: var(--bad); }
.meter small { text-align: end; }

.welcome { max-width: 440px; margin: 0 auto; padding: 48px 20px; text-align: center; }
.welcome h1 { margin: 8px 0; font-size: 2rem; }
.welcome p { color: var(--mute); }
.welcome .small { font-size: .85rem; margin-top: 20px; }
.w-logo { font-size: 3.4rem; }

#toast { position: fixed; z-index: 60; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--acc); font-weight: 800; cursor: pointer; }
#busy { position: fixed; inset: 0; z-index: 70; display: none; place-items: center; background: rgba(0, 0, 0, .35); }
#busy.show { display: grid; }
#busy div { background: var(--card); padding: 18px 22px; border-radius: 14px; display: flex; align-items: center; gap: 12px; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--pri); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.splash { min-height: 80vh; display: grid; place-items: center; text-align: center; color: var(--mute); }
.splash .w-logo { margin-bottom: 8px; }
@media (min-width: 700px) { .cards { grid-template-columns: repeat(4, 1fr); } .card.wide { grid-column: span 4; } .menu { grid-template-columns: repeat(3, 1fr); } }

/* add / edit / delete from anywhere */
body.locked { overflow: hidden; }
.fab { position: fixed; z-index: 28; bottom: calc(74px + env(safe-area-inset-bottom)); left: max(16px, calc(50% - 364px)); width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--acc); color: #fff; font-size: 2.1rem; line-height: 1; font-weight: 400; cursor: pointer; box-shadow: 0 6px 20px color-mix(in srgb, var(--acc) 45%, transparent); display: grid; place-items: center; padding-bottom: 4px; }
.fab:active { transform: scale(.94); }
#sheet { position: fixed; inset: 0; z-index: 50; display: none; }
#sheet.show { display: block; }
.sh-back { position: absolute; inset: 0; background: rgba(0, 0, 0, .42); animation: shfade .15s ease-out; }
.sh-panel { position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 760px; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column; background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); animation: shup .22s cubic-bezier(.2, .8, .2, 1); padding-bottom: env(safe-area-inset-bottom); }
.sh-grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex: none; }
.sh-head { display: flex; align-items: center; gap: 10px; padding: 6px 16px 10px; border-bottom: 1px solid var(--line); flex: none; }
.sh-head h2 { flex: 1; margin: 0; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-x { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: .95rem; }
.sh-body { overflow-y: auto; padding: 14px 16px 18px; overscroll-behavior: contain; }
.sh-body .quick { margin: 0 0 4px; }
@keyframes shup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes shfade { from { opacity: 0; } }
@media (min-width: 700px) {
  .sh-panel { top: 50%; bottom: auto; left: 50%; right: auto; width: min(560px, calc(100% - 32px)); max-height: 86vh; transform: translate(-50%, -50%); border-radius: 20px; animation: shfade .15s ease-out; padding-bottom: 0; }
  .sh-grab { display: none; }
  .sh-head { padding-top: 14px; }
}
.formbar { position: sticky; bottom: -18px; display: flex; gap: 8px; margin: 6px -16px -18px; padding: 10px 16px 14px; background: var(--bg); border-top: 1px solid var(--line); }
.formbar .btn.primary { flex: 1; }
main .formbar { position: static; margin: 4px 0 0; padding: 0; border: 0; background: none; }
.addgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.addgrid a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; min-height: 96px; padding: 10px 6px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); color: var(--ink); box-shadow: var(--shadow); }
.addgrid a:first-child { background: var(--acc); color: #fff; border-color: transparent; }
.addgrid a:first-child small { color: #fff; opacity: .85; }
.addgrid .ic { font-size: 1.6rem; line-height: 1.2; }
.addgrid b { font-size: .92rem; line-height: 1.3; }
.addgrid small { font-size: .72rem; }
.srow { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); background: var(--card); }
.srow .row { position: relative; z-index: 1; background: var(--card); border-bottom: 0; transition: transform .2s ease-out; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.srow.drag .row { transition: none; }
.sacts { position: absolute; top: 0; bottom: 0; left: 0; display: flex; direction: ltr; flex-direction: row-reverse; }
.sacts button, .sacts a { display: flex; align-items: center; justify-content: center; min-width: 70px; padding: 0 10px; border: 0; cursor: pointer; font-weight: 700; font-size: .82rem; background: var(--pri-soft); color: var(--pri); white-space: nowrap; }
.sacts .del { background: var(--bad); color: #fff; }
.sacts .alt { background: var(--warn-soft); color: var(--warn); }

@media (hover: hover) and (pointer: fine) {
  .sacts { z-index: 2; top: 50%; bottom: auto; left: 128px; transform: translateY(-50%); gap: 4px; visibility: hidden; opacity: 0; transition: opacity .12s; }
  .sacts button, .sacts a { min-width: 0; height: 32px; padding: 0 10px; border-radius: 8px; box-shadow: var(--shadow); }
  .srow:hover .sacts, .srow:focus-within .sacts { visibility: visible; opacity: 1; }
  .srow:hover .row { background: color-mix(in srgb, var(--pri-soft) 40%, var(--card)); }
  .srow.open .row { transform: none !important; }
  .srow.open .sacts { visibility: visible; opacity: 1; }
}
.tipline { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; padding: 9px 12px; border-radius: 12px; background: var(--pri-soft); color: var(--pri); font-size: .86rem; }
.tipline span { flex: 1; }
.tipline button { border: 0; background: var(--card); color: var(--pri); font-weight: 700; padding: 4px 12px; border-radius: 999px; cursor: pointer; }
