:root {
  --bg: #f3f6f5; --surface: #ffffff; --surface-2: #eaf0ee; --text: #14201e; --muted: #5b6b68; --line: #dbe4e1;
  --primary: #0f766e; --primary-ink: #ffffff; --primary-soft: #cfe9e5;
  --good: #15803d; --good-bg: #dcf3e4; --warn: #9a5b00; --warn-bg: #fdecc8; --bad: #b42318; --bad-bg: #fde0dc; --info: #1d4ed8; --info-bg: #dbe7fd;
  --bar: #7fbab3; --bar-hi: #0f766e; --p-cash: #0f766e; --p-card: #d97706; --p-other: #64748b;
  --shadow: 0 1px 2px rgb(20 32 30 / 8%), 0 4px 14px rgb(20 32 30 / 6%);
  --radius: 16px; --gutter: 16px; --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514; --surface: #162120; --surface-2: #1d2b29; --text: #e7f0ee; --muted: #9bb0ac; --line: #263836;
    --primary: #2dd4bf; --primary-ink: #04201c; --primary-soft: #14403b;
    --good: #5ee09a; --good-bg: #143a27; --warn: #f5b84c; --warn-bg: #3d2d0b; --bad: #ff8d82; --bad-bg: #44191a; --info: #93b4ff; --info-bg: #16284f;
    --bar: #2c6d66; --bar-hi: #2dd4bf; --p-cash: #2dd4bf; --p-card: #f5a524; --p-other: #94a3b8;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; }
.app { max-width: 600px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.muted { color: var(--muted); font-size: 0.875rem; }
b { font-weight: 700; }
.boot { display: grid; place-items: center; min-height: 60dvh; padding: var(--gutter); }

/* header + status */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(12px + env(safe-area-inset-top)) var(--gutter) 8px; }
.top h1 { font-size: 1.25rem; line-height: 1.3; }
.top-actions { display: flex; gap: 6px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }
.ico { width: 22px; height: 22px; }
.spin .ico { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin .ico { animation: none; } }
.banner { margin: 4px var(--gutter) 8px; padding: 10px 12px; border-radius: 12px; font-size: 0.875rem; display: flex; gap: 10px; align-items: center; }
.banner.ok { background: var(--good-bg); color: var(--good); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.dot-live { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.banner.ok .dot-live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .banner.ok .dot-live { animation: none; } }

main { padding: 0 var(--gutter); outline: none; }
.view { display: grid; gap: 14px; }

/* cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 1rem; }
.empty { color: var(--muted); text-align: center; padding: 14px 0; font-size: 0.9375rem; }
.ok-card { text-align: center; color: var(--good); padding: 28px 14px; font-size: 1.125rem; }

/* hero */
.hero { background: linear-gradient(135deg, #0f766e, #115e59); color: #fff; border-radius: 20px; padding: 18px 16px 14px; box-shadow: var(--shadow); display: grid; gap: 4px; }
@media (prefers-color-scheme: dark) { .hero { background: linear-gradient(135deg, #0f5f59, #0b3d3a); border: 1px solid #1c5a54; } }
.hero-label { font-size: 0.875rem; opacity: 0.9; }
.hero-value { font-size: 2.25rem; line-height: 1.15; letter-spacing: -0.5px; }
.hero-sub { font-size: 0.9375rem; opacity: 0.95; }
.cmp-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.cmp { background: rgb(255 255 255 / 12%); border-radius: 12px; padding: 8px; display: grid; gap: 2px; font-size: 0.8125rem; align-content: start; }
.cmp-label { opacity: 0.85; font-size: 0.75rem; line-height: 1.25; }
.cmp b { font-size: 0.9375rem; }
.chip { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: rgb(255 255 255 / 18%); width: fit-content; }
.chip.up { color: #b7f7d1; } .chip.down { color: #ffd0cb; } .chip.flat { color: #e5e7eb; }
.card .chip { background: var(--surface-2); }
.card .chip.up { color: var(--good); } .card .chip.down { color: var(--bad); } .card .chip.flat { color: var(--muted); }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpis.tight { gap: 8px; margin-top: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 2px; align-content: start; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 0.8125rem; }
.kpi-value { font-size: 1.375rem; line-height: 1.25; }
.kpi-sub { font-size: 0.8125rem; color: var(--muted); }
.kpi.warn { background: var(--warn-bg); border-color: transparent; } .kpi.warn .kpi-value, .kpi.warn .kpi-sub { color: var(--warn); }

/* charts */
.chart-wrap { width: 100%; }
.chart { width: 100%; height: auto; max-height: 190px; display: block; }
.axis { stroke: var(--line); stroke-width: 1; }
.bar { fill: var(--bar); } .bar-hi { fill: var(--bar-hi); } .bar-zero { fill: var(--line); }
.chart-label { fill: var(--muted); font-size: 9px; }
.chart-value { fill: var(--text); font-size: 9px; font-weight: 700; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.stat-row > div { display: grid; gap: 2px; justify-items: start; }
.split { width: 100%; height: 14px; display: block; border-radius: 7px; }
.split-bg { fill: var(--surface-2); }
.p-cash { fill: var(--p-cash); background: var(--p-cash); } .p-card { fill: var(--p-card); background: var(--p-card); } .p-other { fill: var(--p-other); background: var(--p-other); }
.legend { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 0.9375rem; }
.legend .legend-label { flex: 1; }
.legend small { color: var(--muted); min-width: 38px; text-align: end; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* segmented */
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 10px; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.view > .seg { margin-bottom: 0; }

/* ranking */
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rank li { display: flex; gap: 10px; align-items: flex-start; }
.rank-n { width: 24px; height: 24px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 0.8125rem; font-weight: 700; flex: none; margin-top: 2px; }
.rank-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.rank-row { display: flex; justify-content: space-between; gap: 8px; }
.rank-name { overflow-wrap: anywhere; }
.rank-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.rank-fill { display: block; height: 100%; background: var(--primary); border-radius: 3px; }

/* lists */
.list, .orders, .alerts { list-style: none; margin: 0; padding: 0; }
.list > li, .orders > li { border-top: 1px solid var(--line); }
.list > li:first-child, .orders > li:first-child { border-top: 0; }
.order-row { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 2px; background: none; border: 0; cursor: pointer; text-align: start; min-height: 56px; }
.order-main, .order-side { display: grid; gap: 2px; }
.order-side { justify-items: end; }
.order-no { direction: ltr; unicode-bidi: plaintext; text-align: start; }
.tag { font-size: 0.75rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); width: fit-content; }
.tag.closed, .tag.ok { background: var(--good-bg); color: var(--good); }
.tag.cancelled, .tag.bad, .tag.missing { background: var(--bad-bg); color: var(--bad); }
.tag.open, .tag.warn { background: var(--warn-bg); color: var(--warn); }
.open-row { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; }
.open-side { display: grid; justify-items: end; gap: 2px; }
.shift-row { padding: 12px 0; display: grid; gap: 6px; }
.shift-top, .shift-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.shift-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 0.875rem; color: var(--muted); }
.shift-nums b { color: var(--text); }
.days summary { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 12px 0; cursor: pointer; list-style: none; min-height: 48px; }
.days summary::-webkit-details-marker { display: none; }
.day-detail { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0 0 12px; font-size: 0.875rem; color: var(--muted); }
.day-detail b { color: var(--text); }
.warn-text { color: var(--warn); }

/* alerts */
.alerts { display: grid; gap: 10px; }
.alert { border-radius: 14px; padding: 12px 14px; display: grid; gap: 4px; border-inline-start: 5px solid currentColor; }
.alert p { color: var(--text); font-size: 0.9375rem; }
.alert.bad { background: var(--bad-bg); color: var(--bad); } .alert.warn { background: var(--warn-bg); color: var(--warn); } .alert.info { background: var(--info-bg); color: var(--info); }

/* bottom navigation */
.tabs { position: fixed; inset-inline: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr); max-width: 600px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { position: relative; min-height: var(--nav-h); border: 0; background: none; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 0.75rem; cursor: pointer; }
.tabs button.on { color: var(--primary); font-weight: 700; }
.tabs button.on::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
.badge { position: absolute; top: 8px; inset-inline-start: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 0.6875rem; font-style: normal; font-weight: 700; display: grid; place-items: center; }

/* sheet */
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 50%); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { position: relative; background: var(--surface); width: 100%; max-width: 600px; max-height: 88dvh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px var(--gutter) calc(18px + env(safe-area-inset-bottom)); }
.sheet-close { position: absolute; inset-block-start: 8px; inset-inline-end: 8px; width: 44px; height: 44px; border: 0; background: var(--surface-2); border-radius: 50%; font-size: 1.5rem; cursor: pointer; }
.sheet-inner { padding-top: 6px; }
.sheet-body { display: grid; gap: 12px; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding-inline-end: 48px; }
.sheet-head h2 { direction: ltr; unicode-bidi: plaintext; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 0; }
.meta div { display: grid; } .meta dt { color: var(--muted); font-size: 0.8125rem; } .meta dd { margin: 0; font-weight: 600; }
.items { width: 100%; border-collapse: collapse; }
.items td { padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.9375rem; vertical-align: top; }
.items .num { text-align: end; white-space: nowrap; color: var(--muted); }
.items td.num:last-child { color: var(--text); font-weight: 700; }
.note { background: var(--surface-2); border-radius: 10px; padding: 10px; font-size: 0.9375rem; overflow-wrap: anywhere; }
.sheet-total { display: flex; justify-content: space-between; font-size: 1.125rem; padding-top: 6px; border-top: 2px solid var(--line); }

/* login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: var(--gutter); }
.login { width: 100%; max-width: 380px; display: grid; gap: 10px; background: var(--surface); padding: 22px; border-radius: 20px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.login h1 { font-size: 1.5rem; }
.login label { font-weight: 600; font-size: 0.9375rem; margin-top: 4px; }
.login input { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.login input:focus-visible, .btn:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn { min-height: 48px; margin-top: 8px; border: 0; border-radius: 12px; background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: 1rem; cursor: pointer; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; font-size: 0.9375rem; }

@media (min-width: 700px) { body { background: var(--surface-2); } .app { background: var(--bg); box-shadow: 0 0 0 1px var(--line); } }
