/* Layout: one working column (max 1040px) with a tab row; plain panels for forms, scrollable tables for records. */
:root {
  --bg: #f4f3ef; --panel: #ffffff; --soft: #eeece6; --line: #e1ded6; --fg: #1d1c19; --muted: #5f5b53;
  --accent: #2440c8; --on-accent: #ffffff; --field: #ffffff; --field-line: #b9b4a9;
  --good: #1a7438; --good-bg: #e3f2e7; --bad: #b3301d; --bad-bg: #fae6e2; --warn: #7f4c00; --warn-bg: #fbefd7;
  --font: "IBM Plex Sans Arabic", -apple-system, "SF Arabic", "Segoe UI", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --panel: #1d1c1a; --soft: #262521; --line: #34322e; --fg: #f2f0ea; --muted: #aaa59b;
    --accent: #8ea2ff; --on-accent: #0c1333; --field: #171715; --field-line: #55524b;
    --good: #5cc985; --good-bg: #1a2e21; --bad: #ff8a77; --bad-bg: #3a1f1a; --warn: #ebb25c; --warn-bg: #352812;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --panel: #1d1c1a; --soft: #262521; --line: #34322e; --fg: #f2f0ea; --muted: #aaa59b;
  --accent: #8ea2ff; --on-accent: #0c1333; --field: #171715; --field-line: #55524b;
  --good: #5cc985; --good-bg: #1a2e21; --bad: #ff8a77; --bad-bg: #3a1f1a; --warn: #ebb25c; --warn-bg: #352812;
  color-scheme: dark;
}
body { background: var(--bg); color: var(--fg); font: 15px/1.6 var(--font); }
.wrap { max-width: 1040px; margin: 0 auto; padding-block: 20px 56px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 16px; }
h1 { margin: 0; font-size: 24px; line-height: 1.3; font-weight: 700; text-wrap: balance; }
h2 { margin: 0; font-size: 17px; line-height: 1.4; font-weight: 600; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }
p { margin: 0; }
.sub, .hint { color: var(--muted); }
.hint { font-size: 13.5px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 10px; background: var(--soft); }
.tabs button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 8px; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--panel); color: var(--fg); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
main { display: grid; gap: 16px; min-width: 0; }
.panel { display: grid; gap: 12px; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.sub-panel { display: grid; gap: 12px; padding: 12px; border-radius: 10px; background: var(--soft); min-width: 0; }
details.panel > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after { content: "+"; font-size: 20px; color: var(--muted); }
details.panel[open] > summary::after { content: "−"; }
.form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: grid; gap: 4px; flex: 1 1 150px; min-width: 0; }
.field.wide { flex-basis: 260px; }
.form.compact { justify-content: flex-start; }
.form.compact .field { flex: 0 1 220px; }
.form.compact .field.name { flex: 0 0 120px; }
.form.compact .field.tiny { flex: 0 1 140px; }
.field.tiny { flex: 0 1 110px; }
label, .label { font-size: 13px; color: var(--muted); }
input, select, textarea { box-sizing: border-box; width: 100%; min-height: 40px; padding: 6px 10px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--field); color: var(--fg); font: inherit; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
input[type="file"] { padding: 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 40px; padding: 0 16px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--panel); color: var(--fg); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.head .t { display: grid; gap: 2px; flex: 1 1 260px; min-width: 0; }
.list { display: grid; }
.li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li.off .main b, .li.off .amt { color: var(--muted); }
.li .main { display: grid; gap: 2px; flex: 1 1 220px; min-width: 0; }
.li .main small { color: var(--muted); font-size: 13px; }
.li .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list + .hint, h3 + .list, h3 + .hint { margin-top: -4px; }
.seg.lg button { min-height: 40px; padding: 0 18px; font-size: 14.5px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--fg); font: inherit; font-size: 13.5px; cursor: pointer; }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
.scroll { overflow-x: auto; min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 8px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12.5px; font-weight: 600; text-align: start; white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td select, td input { min-height: 34px; padding: 4px 8px; }
.n { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pill.way { background: var(--soft); color: var(--muted); }
.pill.ok { background: var(--good-bg); color: var(--good); }
.pill.ret { background: var(--bad-bg); color: var(--bad); }
.pill.new { background: var(--warn-bg); color: var(--warn); }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.stat .label { font-size: 13px; }
.stat b { font-size: 21px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 12.5px; }
.statement { display: grid; }
.statement div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.statement div:last-child { border-bottom: 0; }
.statement .total { font-weight: 700; border-top: 2px solid var(--fg); }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 14px; }
.note.ok { background: var(--good-bg); color: var(--good); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.empty { padding: 20px 8px; color: var(--muted); text-align: center; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 20; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: var(--fg); color: var(--bg); font-weight: 600; transform: translate(-50%, 8px); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------- app shell ---------- */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 22px; }
.brand .store { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkish { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 8px 4px; min-height: 40px; }
.sync { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); flex: none; }
.sync .dot.bad { background: var(--bad); }
.sync .dot.busy { background: var(--warn); }
.sync .main { flex: 1 1 220px; min-width: 0; }
.cs { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; white-space: nowrap; }
.review-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.review-row:last-child { border-bottom: 0; }
.review-row .who { flex: 1 1 160px; min-width: 0; display: grid; gap: 2px; }
.review-row .who small { color: var(--muted); }

/* ---------- sign in ---------- */
.auth { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; display: grid; gap: 16px; }
.auth .panel { gap: 14px; }
.auth .err { color: var(--bad); font-size: 14px; }

/* ---------- phones: each order becomes a three-line card ----------
   line 1: product ............ profit
   line 2: employee · date ...... price
   line 3: status ............... number
   line 4: actions, when the order has any */
@media (max-width: 640px) {
  .wrap { padding-block: 12px 48px; }
  .tabs { position: sticky; top: 0; z-index: 5; }
  .tabs button { flex: 1 1 0; padding: 0 6px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 18px; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "prod prod profit" "emp date price" "st st no" "acts acts acts"; gap: 4px 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.cards tbody tr:last-child { border-bottom: 0; }
  table.cards td { display: block; padding: 0; border: 0; min-width: 0; text-align: start; }
  table.cards td:nth-child(1) { grid-area: no; text-align: end; }
  table.cards td:nth-child(2) { grid-area: date; }
  table.cards td:nth-child(3) { grid-area: emp; }
  table.cards td:nth-child(4) { grid-area: prod; font-weight: 600; }
  table.cards td:nth-child(5) { grid-area: price; text-align: end; }
  table.cards td:nth-child(6) { grid-area: st; }
  table.cards td:nth-child(7) { grid-area: profit; text-align: end; font-weight: 700; }
  table.cards td:nth-child(8) { grid-area: acts; justify-self: end; }
  table.cards td:nth-child(-n+3), table.cards td:nth-child(5) { color: var(--muted); font-size: 13px; }
  table.cards td.empty { grid-area: auto; grid-column: 1 / -1; text-align: center; }
  table.cards .cs { display: inline; margin-inline-start: 6px; white-space: normal; }
  table.cards .row-actions { justify-content: flex-end; }
}
