* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --primary: #0d6efd;
  --success: #198754;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #0dcaf0;
  --bg: #f4f6f9;
  --card: #fff;
  --text: #212529;
  --muted: #6c757d;
  --border: #e9ecef;
}
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, 'Cairo', 'Tajawal', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-size: 15px;
  user-select: none;
  -webkit-touch-callout: none;
}
.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.topbar {
  background: var(--primary);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.topbar .back { background: none; border: none; color: white; font-size: 22px; cursor: pointer; padding: 0 4px; }
.topbar h1 { margin: 0; font-size: 18px; flex: 1; }
.topbar .branch { font-size: 12px; opacity: 0.85; }
.content { flex: 1; padding: 16px; padding-bottom: 80px; }
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 640px; margin: 0 auto;
  background: white;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--border);
  z-index: 100;
}
.bottom-nav a {
  padding: 10px 4px;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a svg, .bottom-nav a i { font-size: 22px; }
.card-tile {
  background: white;
  padding: 18px;
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s;
}
.card-tile:active { transform: scale(0.98); }
.card-tile .icon-circle {
  width: 50px; height: 50px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: white;
  flex-shrink: 0;
}
.card-tile .info { flex: 1; }
.card-tile .info .label { font-weight: 600; font-size: 16px; }
.card-tile .info .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-tile .arrow { color: var(--muted); }

.btn {
  display: inline-block;
  padding: 14px 20px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
  width: 100%;
  text-align: center;
}
.btn:active { opacity: 0.85; }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: #000; }
.btn-light { background: white; color: var(--text); border: 1px solid var(--border); }

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--muted);
  font-weight: 500;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: white;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }

.scan-area {
  background: white;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 12px;
}
.scan-icon-big {
  font-size: 70px;
  text-align: center;
  color: var(--primary);
  margin: 10px 0;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.kpi {
  background: white;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.kpi .num { font-size: 22px; font-weight: 700; }
.kpi .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

.list-row {
  background: white;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.list-row .info { flex: 1; }
.list-row .info strong { display: block; font-size: 14px; }
.list-row .info small { color: var(--muted); font-size: 12px; }
.list-row .qty-ctrl { display: flex; align-items: center; gap: 6px; }
.list-row .qty-ctrl button {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  font-size: 16px;
}
.list-row .qty-ctrl button:active { background: var(--bg); }
.list-row .remove { color: var(--danger); border: none; background: none; font-size: 20px; padding: 0 4px; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; }
.alert-info { background: #cff4fc; color: #055160; }
.alert-success { background: #d1e7dd; color: #0a3622; }
.alert-warning { background: #fff3cd; color: #664d03; }
.alert-danger { background: #f8d7da; color: #58151c; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.badge-success { background: var(--success); color: white; }
.badge-danger { background: var(--danger); color: white; }
.badge-warning { background: var(--warning); color: #000; }

#scanner-container {
  background: black;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  aspect-ratio: 4/3;
  margin-bottom: 12px;
}
#scanner-container video { width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay {
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 70%; height: 30%;
  border: 2px solid #4ecdc4;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
}
.scanner-line {
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 70%; height: 2px;
  background: #ff6b6b;
  animation: scan 2s linear infinite;
}
@keyframes scan {
  0% { top: 35%; }
  50% { top: 65%; }
  100% { top: 35%; }
}

.spinner {
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  width: 30px; height: 30px;
  animation: spin 0.8s linear infinite;
  margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-container {
  position: fixed;
  top: 70px; left: 50%; transform: translateX(-50%);
  z-index: 9999;
  width: 90%;
  max-width: 400px;
}
.toast {
  background: var(--text);
  color: white;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideDown 0.3s;
}
.toast.success { background: var(--success); }
.toast.danger { background: var(--danger); }
.toast.warning { background: var(--warning); color: #000; }
@keyframes slideDown { from { transform: translateY(-30px); opacity: 0; } }

.install-prompt {
  position: fixed;
  bottom: 80px;
  left: 16px; right: 16px;
  background: var(--primary);
  color: white;
  padding: 14px;
  border-radius: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.install-prompt button { background: white; color: var(--primary); border: none; padding: 8px 14px; border-radius: 6px; font-weight: 600; }
.install-prompt .close { background: transparent; color: white; padding: 4px 8px; }
