/* Moda ERP phone app. Colours from the desktop Theme: primary #2B579A, background #E9ECEF, warning #FFD666. */
:root {
  --primary: #2B579A;
  --primary-dark: #1E4478;
  --primary-soft: #DBE6F4;
  --bg: #E9ECEF;
  --surface: #FFFFFF;
  --surface-alt: #F5F6F7;
  --text: #222222;
  --muted: #5F6368;
  --border: #D2D6DC;
  --line: #E3E6EA;
  --good: #1E6B33;
  --good-soft: #E3F1E6;
  --bad: #C62828;
  --bad-soft: #FDE4E4;
  --warn: #FFD666;
  --warn-soft: #FFF3CD;
  --warn-text: #8A5A00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .07);
  --tabbar-h: 62px;
  --font: "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
[hidden] { display: none !important; }

.app { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; position: relative; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  padding-inline-start: max(12px, env(safe-area-inset-right));
  padding-inline-end: max(12px, env(safe-area-inset-left));
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.topbar .titles { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .updated { font-size: 12px; opacity: .85; min-height: 16px; }
.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, .16); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Content */
.view {
  padding: 14px 12px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  padding-inline-start: max(12px, env(safe-area-inset-right));
  padding-inline-end: max(12px, env(safe-area-inset-left));
  outline: none;
}
.view > * + * { margin-top: 12px; }
.section-title { margin: 18px 4px 8px; font-size: 15px; font-weight: 700; color: var(--muted); }
.stack > * + * { margin-top: 12px; }
.stack > .section-title { margin: 18px 4px 8px; }
.stack > .section-title:first-child { margin-top: 2px; }
.row .t.wrap { white-space: normal; }
small.cur { font-size: 12px; font-weight: 600; color: var(--muted); margin-inline-start: 3px; }
.hero small.cur { color: inherit; font-size: 17px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.card.flush { padding: 0; overflow: hidden; }

/* Today hero */
.hero {
  background: linear-gradient(135deg, #2B579A 0%, #3A6DB8 100%);
  color: #fff; border-radius: 18px; padding: 16px; box-shadow: 0 6px 18px rgba(43, 87, 154, .35);
}
.hero .label { font-size: 14px; opacity: .9; }
.hero .big { font-size: 38px; font-weight: 800; line-height: 1.15; margin: 4px 0 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero .big small { font-size: 17px; font-weight: 600; opacity: .9; margin-inline-start: 4px; }
.hero .date { font-size: 13px; opacity: .85; }
.hero .compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.chip {
  background: rgba(255, 255, 255, .14); border-radius: 12px; padding: 8px 10px; min-width: 0;
}
.chip .k { font-size: 12px; opacity: .9; }
.chip .v { display: flex; align-items: center; gap: 4px; font-weight: 700; font-size: 16px; }
.chip .v svg { width: 16px; height: 16px; flex: none; }
.chip.up .v { color: #B7F5C5; }
.chip.down .v { color: #FFC4C4; }
.chip.none .v { color: #fff; opacity: .8; font-weight: 600; font-size: 14px; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; min-width: 0; }
.stat .k { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .k i { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex: none; }
.stat .v { font-size: 21px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.3; }
.stat .v small { font-size: 12px; font-weight: 600; color: var(--muted); margin-inline-start: 3px; }
.stat.good .k i { background: var(--good); }
.stat.bad .k i { background: var(--bad); }
.stat.warn .k i { background: #E0A800; }
.stat.wide { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stat.wide .v { margin: 0; }
.stat.net { background: var(--primary-soft); box-shadow: none; }
.stat.net .v { color: var(--primary-dark); }

/* Chart */
.chart svg { width: 100%; height: auto; }
.chart .bar { fill: var(--primary); }
.chart .bar.max { fill: #1E4478; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { font-family: var(--font); fill: var(--muted); font-size: 11px; }
.chart text.val { fill: var(--text); font-weight: 700; font-size: 10.5px; }

/* Lists */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; min-height: 56px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
a.row:active, button.row:active { background: var(--surface-alt); }
button.row { width: 100%; border: 0; background: none; text-align: start; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: end; flex: none; font-variant-numeric: tabular-nums; }
.row .end .t { font-size: 16px; }
.chev { width: 18px; height: 18px; flex: none; fill: none; stroke: #9AA0A6; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rank {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; font-size: 14px;
}
.rank.gold { background: var(--warn); color: #5B4300; }
.meter { height: 6px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }

/* Branch cards on home */
.branch-cards { display: grid; gap: 10px; }
.branch-card { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.branch-card:active { background: var(--surface-alt); }
.branch-card .main { flex: 1; min-width: 0; }
.branch-card .name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-card .net { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.branch-card .net small { font-size: 12px; color: var(--muted); font-weight: 600; margin-inline-start: 3px; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.stale { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.sync.stale { color: var(--bad); }

/* Controls */
.toolbar { display: grid; gap: 10px; }
.seg { display: flex; background: #DDE1E6; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; min-width: 0; border: 0; background: transparent; border-radius: 9px; padding: 8px 4px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); padding-inline-start: 2px; }
.input, .field input, .field select {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  font-size: 15px; outline: none;
}
.field input:focus, .field select:focus, .input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(43, 87, 154, .18); }
.search { display: flex; gap: 8px; }
.search .input { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 15px; white-space: nowrap;
}
.btn:active { background: var(--primary-dark); }
.btn.ghost { background: var(--surface); color: var(--primary); border: 1px solid var(--primary-soft); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn[disabled] { opacity: .6; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Tables (stock grid, receipt lines) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 8px 10px; text-align: start; border-top: 1px solid var(--line); white-space: nowrap; }
table.grid th { background: var(--surface-alt); color: var(--muted); font-weight: 600; font-size: 12.5px; border-top: 0; }
table.grid td.n, table.grid th.n { text-align: center; }
table.grid td.zero { color: #B0B5BB; }
table.grid tr.total td { font-weight: 800; background: var(--surface-alt); }
.model-head { display: flex; align-items: baseline; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.model-head .no { font-weight: 800; font-size: 16px; color: var(--primary-dark); direction: ltr; unicode-bidi: isolate; }
.model-head .nm { color: var(--muted); font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-head .thumb { width: 56px; height: 56px; flex: none; align-self: center; border-radius: 8px; object-fit: cover; background: var(--surface-alt); border: 1px solid var(--line); }
.model-head .thumb.none { display: grid; place-items: center; color: var(--border); }
.model-head .thumb.none svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-alt); color: var(--muted); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn-text); }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* Receipt */
.receipt-line { display: flex; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.receipt-line:first-child { border-top: 0; }
.receipt-line .main { flex: 1; min-width: 0; }
.receipt-line .t { font-weight: 700; }
.receipt-line .s { font-size: 13px; color: var(--muted); }
.receipt-line .end { text-align: end; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.receipt-line.ret .end { color: var(--bad); }
.totals .row { min-height: 44px; padding: 8px 14px; }
.totals .row.net { background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; font-size: 17px; }

/* Alerts */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-top: 1px solid var(--line); }
.alert:first-child { border-top: 0; }
.alert .ic { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; }
.alert .ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.alert .t { font-weight: 600; overflow-wrap: anywhere; }
.alert .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.alert.stale .ic { background: var(--bad-soft); color: var(--bad); }
.alert.problem .ic { background: #FDEBD8; color: #B25E00; }
.alert.dayOpen .ic { background: var(--warn-soft); color: var(--warn-text); }
.alert.discount .ic, .alert.return .ic { background: var(--primary-soft); color: var(--primary); }

/* Reports */
.report-frame { width: 100%; min-height: 160px; border: 0; display: block; background: #fff; }

/* States */
.skeleton { background: linear-gradient(90deg, #DDE1E6 25%, #ECEEF1 50%, #DDE1E6 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-hero { height: 168px; border-radius: 18px; }
.sk-row { height: 74px; }
.sk-chart { height: 190px; }
.state { text-align: center; padding: 36px 18px; color: var(--muted); }
.state svg { width: 52px; height: 52px; margin: 0 auto 10px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.state .t { font-weight: 700; color: var(--text); font-size: 16px; }
.state .s { font-size: 14px; margin: 4px 0 16px; overflow-wrap: anywhere; }
.state.error svg { color: var(--bad); }
.state.ok svg { color: var(--good); }
.empty { text-align: center; color: var(--muted); padding: 22px 14px; font-size: 14px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary); animation: spin .8s linear infinite; margin: 28px auto; }

/* Login */
body.login .topbar, body.login .tabbar { display: none; }
body.login .view { padding-bottom: calc(env(safe-area-inset-bottom) + 14px); }
.login-wrap { min-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; justify-content: center; padding: 24px 6px; }
.login-wrap .logo { width: 76px; height: 76px; margin: 0 auto 12px; border-radius: 20px; box-shadow: 0 8px 20px rgba(43, 87, 154, .35); }
.login-wrap h2 { text-align: center; margin: 0; font-size: 24px; color: var(--primary-dark); }
.login-wrap p { text-align: center; margin: 4px 0 20px; color: var(--muted); }
.login-card { display: grid; gap: 14px; }
.form-error { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-weight: 600; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 520px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, .97);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(16, 24, 40, .06);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: #6B7178; font-size: 11px; font-weight: 600; min-width: 0;
}
.tabbar a span { white-space: nowrap; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--primary); }
.tabbar a.on::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }
.badge {
  position: absolute; top: 6px; inset-inline-end: calc(50% - 22px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

/* Print: only the report itself (the phone's share / save as PDF). */
@media print {
  body { background: #fff; }
  .topbar, .tabbar, .no-print { display: none !important; }
  .view { padding: 0; }
  .card { box-shadow: none; padding: 0; }
  .report-frame { min-height: 0; }
}
