:root {
  --bg0: #0e151c;
  --bg1: #15202b;
  --bg2: #1c2a38;
  --card: #1a2734;
  --text: #f2f5f8;
  --muted: #8fa0b3;
  --accent: #3d9a7a;
  --accent-dim: color-mix(in srgb, var(--accent) 22%, transparent);
  --accent-2: #c4a35a;
  --danger: #c45c5c;
  --ok: #3d9a7a;
  --warn: #d4a017;
  --bad: #c45c5c;
  --border: rgba(255, 255, 255, 0.09);
  --radius: 16px;
  --radius-sm: 12px;
  --header-h: 56px;
  --bottom-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: "Segoe UI", "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, sans-serif;
  --touch: 44px;
}

[data-theme="light"] {
  --bg0: #f4f7fa;
  --bg1: #e8eef4;
  --bg2: #ffffff;
  --card: #ffffff;
  --text: #13202c;
  --muted: #5a6b7c;
  --border: rgba(15, 30, 45, 0.1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 85% -15%, #1f3d4a 0%, transparent 55%),
    radial-gradient(800px 420px at 0% 10%, #2a2418 0%, transparent 45%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 45%, #101820);
  -webkit-tap-highlight-color: transparent;
}
body { padding-left: var(--safe-l); padding-right: var(--safe-r); }
body.scanner-open {
  overflow: hidden;
  touch-action: none;
}
body.scanner-open .bottom-nav,
body.scanner-open .app-header,
body.scanner-open .desktop-tabs,
body.scanner-open #offline-banner {
  visibility: hidden;
  pointer-events: none;
}

.hidden { display: none !important; }
.view { min-height: 100dvh; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: #ffb4b4; margin: 0.4rem 0; }
.msg { margin-top: 0.75rem; }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: left; }

/* Offline banner — only applies safe-top when header is not showing it */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.45rem 1rem;
  text-align: center;
  background: color-mix(in srgb, var(--bad) 85%, #000);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
}
#view-login .offline-banner,
body:not(:has(#view-app:not(.hidden))) .offline-banner {
  padding-top: calc(0.45rem + var(--safe-t));
}

/* Login */
.login-shell {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 1.5rem;
  padding-top: calc(1.5rem + var(--safe-t));
  padding-bottom: calc(1.5rem + var(--safe-b));
  gap: 1.25rem;
}
.brand { text-align: center; }
.brand-logo {
  width: 88px; height: 88px;
  border-radius: 22px;
  object-fit: cover;
  box-shadow: 0 14px 40px rgba(61, 154, 122, 0.28);
  margin-bottom: 0.85rem;
}
.brand h1 { margin: 0; font-size: 1.75rem; font-weight: 750; letter-spacing: 0.02em; }
.brand p { margin: 0.4rem 0 0; color: var(--muted); }

.login-card, .panel, .cards > * {
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
}
.login-card {
  width: min(400px, 100%);
  padding: 1.25rem;
  display: grid;
  gap: 0.85rem;
}
label { display: grid; gap: 0.35rem; font-size: 0.92rem; }
.check-row {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  grid-template-columns: none;
}
input, select, button {
  font: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.7rem 0.85rem;
  min-height: var(--touch);
  background: var(--bg2);
  color: var(--text);
}
button {
  cursor: pointer;
  background: linear-gradient(145deg, var(--accent), #2f7d63);
  border: none;
  font-weight: 650;
}
button.ghost { background: transparent; border: 1px solid var(--border); }
button.linkish {
  background: none;
  border: none;
  color: var(--accent, #2563eb);
  padding: 0.15rem 0.25rem;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}
.ppm-name-tools label { display: block; }
#ppm-tr-msg { min-height: 1.1rem; margin: 0.15rem 0 0.35rem; }
button.danger { background: linear-gradient(145deg, var(--danger), #8f3d3d); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.install-btn { width: min(400px, 100%); }
.install-hint { max-width: 360px; text-align: center; line-height: 1.5; }

/* App header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: 0.5rem 0.85rem;
  padding-top: calc(0.5rem + var(--safe-t));
  background: color-mix(in srgb, var(--bg0) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.header-brand { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.header-logo { border-radius: 9px; object-fit: cover; flex-shrink: 0; }
.header-titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.app-name { font-size: 0.95rem; }
.user-name { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.conn-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 9.5rem;
  min-width: 0;
}
.conn-label {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.icon-btn {
  position: relative;
  width: var(--touch);
  height: var(--touch);
  min-height: var(--touch);
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1.1rem;
}
.badge {
  position: absolute;
  top: 4px; left: 4px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid; place-items: center;
}

.conn-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent);
  flex-shrink: 0;
}
.conn-dot.online {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}
.conn-dot.degraded {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 25%, transparent);
}
.conn-dot.offline {
  background: var(--bad);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent);
}

/* Desktop tabs */
.desktop-tabs, .ws-tabs, .mode-tabs, .row {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
}
.desktop-tabs {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
}
.desktop-tabs button,
.ws-tabs button,
.mode-tabs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.5rem 0.8rem;
  min-height: var(--touch);
  white-space: nowrap;
}
.desktop-tabs button.active,
.ws-tabs button.active,
.mode-tabs button.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.app-main {
  padding: 1rem;
  padding-bottom: calc(1rem + var(--bottom-h) + var(--safe-b) + 0.5rem);
  max-width: 1100px;
  margin: 0 auto;
}
.tab { display: none; animation: fade 0.22s ease; }
.tab.active { display: block; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}
@media (min-width: 360px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
.cards > * { padding: 1rem; }
.cards .label { color: var(--muted); font-size: 0.85rem; }
.cards .value {
  font-size: 1.35rem; font-weight: 700; margin-top: 0.35rem;
  font-variant-numeric: tabular-nums; direction: ltr; text-align: right;
}

.panel { padding: 1rem; margin-top: 0.75rem; }
.stack { display: grid; gap: 0.75rem; max-width: 420px; }
.results { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.5rem; }
.results li {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
}
.arm-status { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.pill {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  min-height: 32px;
  display: inline-flex; align-items: center;
}
.pill.on { background: var(--accent-dim); color: #b8f0d8; }
.pill.off { opacity: 0.7; }
.danger-zone { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }

.input-with-action {
  display: flex; gap: 0.4rem; align-items: stretch;
}
.input-with-action input { flex: 1; min-width: 0; }
.cam-btn { width: var(--touch); flex-shrink: 0; padding: 0; font-size: 1.15rem; }

/* Price card */
.price-card .price-hero {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
  color: #7de0b8;
  margin: 0.35rem 0 0.75rem;
}
.price-meta {
  display: grid;
  gap: 0.45rem;
  font-size: 0.92rem;
}
.price-meta .row-kv {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}
.price-meta .k { color: var(--muted); }

/* Cashier live */
.cashier-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.cashier-card + .cashier-card { margin-top: 0.5rem; }
.cashier-head {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.cashier-head h3 { margin: 0; font-size: 1.05rem; }
.status-pill {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
}
.status-pill.live { background: var(--accent-dim); color: #9ff0d0; }
.status-pill.stale { background: color-mix(in srgb, var(--warn) 25%, transparent); color: #ffd666; }
.status-pill.off { background: color-mix(in srgb, var(--bad) 25%, transparent); color: #ffb0b0; }
.cashier-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.75rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.cashier-stats .lab { color: var(--muted); display: block; font-size: 0.78rem; }
.cashier-total {
  font-size: 1.4rem; font-weight: 800;
  font-variant-numeric: tabular-nums; direction: ltr; text-align: right;
  margin: 0.25rem 0 0.75rem;
}
.line-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.line-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}
.line-list .line-meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.78rem;
  direction: ltr;
  text-align: right;
}
.warnings { margin: 0.5rem 0 0; color: #ffd666; font-size: 0.85rem; }

/* Cash drawer history */
.drawer-alert-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, #c41e1e 88%, #000);
  border: 1px solid #ff6b6b;
  color: #fff;
  font-size: 0.92rem;
  box-shadow: 0 0 0 2px color-mix(in srgb, #ff3b3b 35%, transparent);
  animation: drawer-alert-pulse 1.4s ease-in-out 2;
}
.drawer-alert-banner.hidden { display: none; }
.drawer-alert-banner strong { font-size: 1rem; }
.drawer-alert-banner .ghost {
  margin-inline-start: auto;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}
@keyframes drawer-alert-pulse {
  0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, #ff3b3b 35%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, #ff3b3b 55%, transparent); }
}

.drawer-summary {
  margin-bottom: 0.85rem;
}
.drawer-summary .card .lab {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}

.drawer-filters {
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
  align-items: flex-end;
}
.drawer-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.drawer-filters select {
  min-width: 7.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
}

.drawer-event-list {
  display: grid;
  gap: 0.55rem;
}
.drawer-event-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 0.75rem 0.85rem;
  display: grid;
  gap: 0.35rem;
}
.drawer-event-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.drawer-event-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.88rem;
}
.drawer-event-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.8rem;
}
.drawer-err {
  color: #ffb0b0;
  font-size: 0.82rem;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 45;
  display: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 0;
  min-height: calc(var(--bottom-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg0) 92%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
}
.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  min-height: var(--bottom-h);
  min-width: 0;
  padding: 0.35rem 0.15rem;
  line-height: 1.15;
}
.bottom-nav button span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.bottom-nav button.active {
  color: #9ff0d0;
  position: relative;
}
.bottom-nav button.active::after {
  content: "";
  position: absolute;
  top: 4px;
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
}
.bottom-nav .nav-ico { font-size: 1.2rem; line-height: 1; }

.scan-hero-btn {
  width: 100%;
  max-width: 420px;
  min-height: 52px;
  font-size: 1.05rem;
  margin: 0.35rem 0 0.85rem;
  letter-spacing: 0.01em;
}
.scan-lead { margin: 0 0 0.35rem; }
.scan-form-compact { margin-top: 0.5rem; }

.cashier-panel.both {
  display: grid;
  gap: 0.65rem;
}
@media (min-width: 720px) {
  .cashier-panel.both {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}
.cashier-card.compact .cashier-stats { font-size: 0.82rem; }
.cashier-card.compact .cashier-total { font-size: 1.2rem; }
.cashier-card.compact .line-list li { padding: 0.4rem 0.5rem; font-size: 0.82rem; }

/* Sheet */
.sheet {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.sheet-panel {
  position: relative;
  width: min(480px, 100%);
  max-height: min(85dvh, 640px);
  overflow: auto;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 0.75rem 1rem calc(1rem + var(--safe-b));
  animation: sheetUp 0.22s ease;
}
@keyframes sheetUp {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
.sheet-handle {
  width: 40px; height: 4px; border-radius: 999px;
  background: var(--border); margin: 0.15rem auto 0.75rem;
}
.sheet-panel h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.sheet-actions { display: grid; gap: 0.45rem; }
.sheet-actions button { width: 100%; text-align: center; }
.sheet-close { width: 100%; margin-top: 0.75rem; }

/* Full-screen scanner */
.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
}
.scanner-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.scanner-stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0a0a0a;
}
.scanner-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}
.scanner-top,
.scanner-bottom {
  pointer-events: auto;
}
.scanner-top {
  display: flex;
  gap: 0.4rem;
  justify-content: space-between;
  padding: calc(0.55rem + var(--safe-t)) 0.65rem 0.55rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0.72), transparent);
}
.scanner-chip {
  flex: 1;
  min-height: 42px;
  padding: 0.45rem 0.4rem;
  font-size: 0.82rem;
  border-radius: 12px;
  background: rgba(20, 28, 36, 0.72);
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(8px);
}
.scanner-chip.ghost { background: rgba(0,0,0,0.35); }
.scanner-chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: #9ff0d0;
}
.scanner-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(78vw, 300px);
  height: min(52vw, 200px);
  transform: translate(-50%, -58%);
  border: 2px solid rgba(125, 224, 184, 0.9);
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.42);
  overflow: hidden;
  pointer-events: none;
}
.scan-line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #7de0b8, transparent);
  animation: scanSweep 1.8s ease-in-out infinite;
}
@keyframes scanSweep {
  0% { top: 12%; opacity: 0.35; }
  50% { top: 78%; opacity: 1; }
  100% { top: 12%; opacity: 0.35; }
}
.scanner-bottom {
  padding: 0.65rem 0.75rem calc(0.75rem + var(--safe-b));
  background: linear-gradient(to top, rgba(8,12,16,0.92) 55%, rgba(8,12,16,0.35));
  display: grid;
  gap: 0.5rem;
}
.scanner-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.scanner-modes button {
  min-height: 44px;
  background: rgba(255,255,255,0.06);
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.88rem;
}
.scanner-modes button.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent-dim);
}
.scanner-send-opts {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 0.4rem;
}
.scanner-send-opts select,
.scanner-send-opts input {
  min-height: 44px;
  background: rgba(20,28,36,0.9);
}
.scanner-decoded {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: #9ff0d0;
  letter-spacing: 0.04em;
}
.scanner-error {
  margin: 0;
  text-align: center;
  background: color-mix(in srgb, var(--bad) 82%, #000);
  color: #fff;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  font-size: 0.88rem;
}
.scanner-error-actions,
.scanner-bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.scanner-error-actions:has(> :only-child),
.scanner-bottom-actions:has(> .hidden:first-child:last-child) {
  grid-template-columns: 1fr;
}
.scanner-bottom-actions button,
.scanner-error-actions button {
  min-height: 44px;
}

/* Skeleton */
.skeleton {
  border-radius: 12px;
  background: linear-gradient(90deg, var(--bg2) 25%, var(--card) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease infinite;
  min-height: 72px;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (max-width: 720px) {
  .desktop-tabs { display: none !important; }
  .bottom-nav { display: grid; }
  .app-main {
    padding: 0.85rem;
    padding-bottom: calc(1.1rem + var(--bottom-h) + var(--safe-b));
  }
  .app-header { gap: 0.45rem; padding-inline: 0.7rem; }
  .user-name { max-width: 42vw; }
  .conn-label { max-width: 5.5rem; font-size: 0.62rem; }
  .ws-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
  .ws-tabs button { width: 100%; justify-content: center; padding-inline: 0.35rem; font-size: 0.82rem; }
}

@media (max-width: 360px) {
  .bottom-nav button { font-size: 0.6rem; padding-inline: 0.05rem; }
  .bottom-nav .nav-ico { font-size: 1.05rem; }
  .app-name { font-size: 0.88rem; }
  .scanner-chip { font-size: 0.72rem; padding-inline: 0.25rem; }
}

@media (min-width: 721px) {
  .app-main { padding-bottom: 1.5rem; }
  .bottom-nav { display: none; }
  .conn-label { max-width: 12rem; }
}

@media (orientation: landscape) and (max-height: 480px) {
  .scanner-frame {
    width: min(42vw, 260px);
    height: min(58vh, 180px);
    transform: translate(-50%, -52%);
  }
  .scanner-bottom { padding-block: 0.4rem; }
  .scan-hero-btn { min-height: 46px; }
}

/* ══════════════════════════════════════════════════════════════════════
   Purchase entry (داخڵکردنی کاڵا)
   ══════════════════════════════════════════════════════════════════════ */

.small { font-size: 0.8rem; }
#purchase-draft-status { margin: -0.35rem 0 0.75rem; min-height: 1.1em; }

.purchase-type-tabs { margin-bottom: 0.85rem; }
.purchase-type-tabs button { flex: 1; justify-content: center; text-align: center; }

.purchase-header-card {
  display: grid;
  gap: 0.85rem;
  margin-top: 0;
}
.purchase-field-group { display: grid; gap: 0.5rem; }

.row2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
@media (min-width: 620px) {
  .row2 { grid-template-columns: 1fr 1fr; }
}

.field-label { font-size: 0.92rem; display: block; margin-bottom: 0.3rem; }
.pay-type-field .mode-tabs { margin: 0; }
.pay-type-field .mode-tabs button { flex: 1; justify-content: center; text-align: center; }

.link-btn {
  justify-self: start;
  width: auto;
  padding: 0.45rem 0.2rem;
  min-height: 2rem;
  background: transparent !important;
  border: none !important;
  color: #7de0b8;
  font-weight: 650;
  font-size: 0.88rem;
}
.danger-text { color: #ffb0b0; }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  z-index: 20;
  inset-inline: 0;
  top: calc(100% + 0.3rem);
  max-height: min(50vh, 320px);
  overflow-y: auto;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  padding: 0.3rem;
  display: grid;
  gap: 0.15rem;
}
.autocomplete-list button {
  width: 100%;
  text-align: start;
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 500;
  padding: 0.6rem 0.65rem;
  min-height: var(--touch);
  border-radius: 10px;
  display: grid;
  gap: 0.1rem;
}
.autocomplete-list button:hover,
.autocomplete-list button:focus-visible { background: var(--accent-dim); }
.autocomplete-list .ac-sub { color: var(--muted); font-size: 0.78rem; font-weight: 400; }
.autocomplete-list .ac-empty,
.autocomplete-list .ac-loading {
  padding: 0.6rem 0.65rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.selected-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  font-size: 0.9rem;
}
.selected-chip button {
  width: auto;
  min-height: 1.9rem;
  padding: 0.2rem 0.65rem;
  background: transparent;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.fx-box {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
}
.fx-box p { margin: 0 0 0.5rem; }

.purchase-scan-btn { margin-top: 1rem; }
.purchase-manual-row { margin-bottom: 0.5rem; }

.notfound-box { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); }
.notfound-box p { margin: 0 0 0.5rem; }

.purchase-lines-wrap { margin-top: 1.1rem; }
.purchase-lines-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.purchase-lines-head h3 { margin: 0; font-size: 1.02rem; }
.purchase-lines-head button { min-height: 2.2rem; padding: 0.4rem 0.7rem; font-size: 0.85rem; }

.purchase-lines-list {
  display: grid;
  gap: 0.6rem;
  /* Room so the sticky summary bar never covers the last card. */
  padding-bottom: calc(6.5rem + var(--safe-b));
}
@media (min-width: 721px) {
  .purchase-lines-list { padding-bottom: 1rem; }
}
.empty-hint { padding: 1.25rem 0.5rem; text-align: center; }

.purchase-line-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 0.75rem 0.85rem;
  display: grid;
  gap: 0.4rem;
}
.purchase-line-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
}
.purchase-line-name { font-weight: 650; }
.purchase-line-barcode { direction: ltr; text-align: left; color: var(--muted); font-size: 0.78rem; }
.purchase-line-total { font-weight: 750; font-size: 1.05rem; white-space: nowrap; }
.purchase-line-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.85rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.purchase-line-meta .ltr { direction: ltr; }
.purchase-line-actions { display: flex; gap: 0.5rem; margin-top: 0.15rem; }
.purchase-line-actions button {
  flex: 1;
  min-height: 2.3rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.86rem;
}
.purchase-line-card.pending {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--warn) 60%, var(--border));
}

.purchase-summary-bar {
  position: sticky;
  bottom: calc(var(--bottom-h) + var(--safe-b) + 0.5rem);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.7rem 0.85rem;
  margin-top: 0.75rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg1) 92%, transparent);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.purchase-summary-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.85rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.purchase-summary-stats strong { color: var(--text); font-variant-numeric: tabular-nums; }
.purchase-sum-total { font-size: 1rem; }
.purchase-post-btn {
  min-width: 9rem;
  min-height: 3rem;
  font-size: 0.98rem;
}
@media (min-width: 721px) {
  .purchase-summary-bar { bottom: 0.85rem; }
}

/* Centered modal overlays for item / product / party creation */
.p-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(0, 0, 0, 0.55);
}
@media (min-width: 621px) {
  .p-modal-overlay { align-items: center; padding: 1.25rem; }
}
.p-modal-card {
  width: min(520px, 100%);
  max-height: min(92dvh, 720px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 1.1rem 1.1rem calc(1.1rem + var(--safe-b));
  display: grid;
  gap: 0.75rem;
  animation: sheetUp 0.22s ease;
}
@media (min-width: 621px) {
  .p-modal-card { border-radius: var(--radius); padding: 1.25rem; }
}
.p-modal-card-lg { width: min(600px, 100%); }
.p-modal-card h3 { margin: 0; font-size: 1.15rem; }
.p-modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}
.p-modal-actions button { flex: 1; min-width: 8rem; }
.pim-name { font-weight: 700; font-size: 1.05rem; margin: 0; }

.ppm-advanced { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.6rem 0.75rem; }
.ppm-advanced summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.ppm-advanced[open] summary { margin-bottom: 0.65rem; }
.ppm-advanced .row2 { margin-top: 0.6rem; }
.ppm-advanced .row2:first-of-type { margin-top: 0; }

.purchase-confirm-body { display: grid; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.92rem; }
.purchase-confirm-body .row-kv {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}
.purchase-confirm-body .row-kv .k { color: var(--muted); }
.purchase-confirm-body .row-kv .ltr { direction: ltr; }


/* ----------------------------------------------------------------------
   Mobile-first polish (320�430px) � 2.51
   ---------------------------------------------------------------------- */

.app-main {
  width: 100%;
  max-width: 100%;
  padding-inline: max(0.85rem, var(--safe-l), var(--safe-r));
  padding-bottom: calc(var(--bottom-h) + var(--safe-b) + 1.25rem);
  overflow-x: hidden;
}
@media (min-width: 721px) {
  .app-main { max-width: 1100px; margin-inline: auto; padding-bottom: 1.5rem; }
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  width: 100%;
}
label > input,
label > select,
label > textarea {
  width: 100%;
  min-height: var(--touch);
  font-size: 1rem;
}

button, .scan-hero-btn, .purchase-post-btn {
  min-height: var(--touch);
}

.purchase-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
  font-size: 0.72rem;
  color: var(--muted);
}
.purchase-steps li {
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg2);
}
.purchase-section { margin-bottom: 1.1rem; }
.purchase-sec-title {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.purchase-line-card {
  display: grid;
  gap: 0.65rem;
  padding: 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  overflow: hidden;
}
.purchase-line-name { font-weight: 700; word-break: break-word; }
.purchase-line-barcode { color: var(--muted); font-size: 0.82rem; }
.purchase-qty-row {
  display: grid;
  gap: 0.35rem;
}
.qty-stepper {
  display: grid;
  grid-template-columns: var(--touch) 1fr var(--touch);
  gap: 0.4rem;
  align-items: center;
}
.qty-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  font-size: 1.25rem;
  font-weight: 700;
}
.qty-input {
  width: 100%;
  min-height: var(--touch);
  text-align: center;
  font-size: 1.05rem;
}
.purchase-price-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}
@media (min-width: 360px) {
  .purchase-price-grid { grid-template-columns: 1fr 1fr; }
}
.purchase-line-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}
.purchase-line-actions button { width: 100%; }

.purchase-summary-bar {
  position: sticky;
  bottom: calc(var(--bottom-h) + var(--safe-b) + 0.35rem);
  z-index: 30;
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px);
}
.purchase-post-btn {
  width: 100%;
  font-size: 1.05rem;
  font-weight: 750;
}

.debts-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: end;
  margin: 0.75rem 0;
}
.debts-search-label { margin: 0; }
.debts-list { display: grid; gap: 0.65rem; }
.debt-card {
  padding: 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  display: grid;
  gap: 0.5rem;
}
.debt-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: start;
}
.debt-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.debt-card-amounts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  font-size: 0.82rem;
}
.debt-card-amounts .k { display: block; color: var(--muted); font-size: 0.72rem; }
.debt-card-amounts .v { font-weight: 700; }
.debt-details summary {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 650;
}
.debt-details-body { display: grid; gap: 0.35rem; font-size: 0.88rem; padding-top: 0.35rem; }

.sheet-panel label { margin-bottom: 0.5rem; }
.sheet-panel select, .sheet-panel input { width: 100%; min-height: var(--touch); }

.scan-hero-btn {
  width: 100%;
  max-width: none;
  min-height: 52px;
  font-size: 1.08rem;
  font-weight: 750;
}

/* Prevent horizontal overflow on tiny phones */
#view-app, .tab, .panel, .purchase-line-card, .debt-card {
  max-width: 100%;
}
img, video, canvas { max-width: 100%; height: auto; }

[data-theme="light"] .error { color: #a12828; }
[data-theme="light"] .danger-text { color: #a12828; }
[data-theme="light"] .link-btn { color: #1f7a5a; }
[data-theme="light"] .bottom-nav button.active { color: #1f7a5a; }

@media (max-width: 360px) {
  .bottom-nav button { font-size: 0.58rem; }
  .app-header .user-name { max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ── Mobile permissions + consent modals ─────────────────────────────── */
.permissions-card { margin-bottom: 1rem; }
.permissions-card h3 { margin: 0 0 0.65rem; font-size: 1rem; }
.perm-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.45rem;
  font-size: 0.92rem;
}
.perm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}
.perm-actions button {
  flex: 1 1 auto;
  min-height: 44px;
  min-width: 8.5rem;
}
.perm-consent-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 12, 18, 0.62);
  box-sizing: border-box;
}
.perm-consent-modal.hidden { display: none !important; }
.perm-consent-card {
  width: min(100%, 22rem);
  max-height: min(90vh, 28rem);
  overflow: auto;
  border-radius: 14px;
  padding: 1.15rem 1rem 1rem;
  background: var(--surface, #121a22);
  color: var(--text, #f2f5f8);
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
.perm-consent-card h3 { margin: 0 0 0.55rem; font-size: 1.05rem; }
.perm-consent-card p { margin: 0 0 1rem; line-height: 1.55; color: var(--muted, #9aa8b8); }
.perm-consent-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.perm-consent-actions button {
  min-height: 46px;
  width: 100%;
}
@media (min-width: 420px) {
  .perm-consent-actions {
    flex-direction: row;
  }
  .perm-consent-actions button { flex: 1; }
}
html[data-theme="light"] .perm-consent-card,
body.theme-light .perm-consent-card {
  background: #fff;
  color: #13202b;
  border-color: rgba(0,0,0,0.1);
}
html[data-theme="light"] .perm-consent-card p,
body.theme-light .perm-consent-card p {
  color: #5a6b7a;
}
