:root {
  --bg: #eef3f9;
  --ink: #1c2430;
  --muted: #5b7394;
  --line: #c9d8ea;
  --panel: #ffffff;
  --brand: #1d4f91;
  --brand-dark: #163e74;
  --brand-soft: #e8f1fb;
  --brand-mid: #2f6fbd;
  --ok: #1a7a4c;
  --ok-bg: #e8f6ee;
  --warn: #b86a00;
  --warn-bg: #fff7e8;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(29, 79, 145, 0.07);
  --font: "Tajawal", Tahoma, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(29, 79, 145, 0.1), transparent 55%),
    var(--bg);
}

.page {
  width: min(1000px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1.5rem 0 2.5rem;
}

/* Icons */
.ico {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.ico.lg {
  width: 2.4rem;
  height: 2.4rem;
  color: var(--brand-mid);
}

.ico.ok { color: var(--ok); }
.ico.warn { color: var(--warn); }

/* Header */
.topbar {
  margin-bottom: 1.25rem;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.95rem 1.1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background-image: linear-gradient(180deg, #f5f9ff 0%, #ffffff 70%);
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  flex-shrink: 0;
}

.brand {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.1;
  color: #143a6b;
}

.tagline {
  margin: 0.2rem 0 0;
  color: #8b1a1a;
  font-size: 0.95rem;
}

/* Search */
.search-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.search-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: linear-gradient(180deg, #f3f8ff 0%, #eaf2fc 100%);
  border-bottom: 1px solid var(--line);
}

.search-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #143a6b;
}

.search-head p {
  margin: 0.15rem 0 0;
  color: #c62828;
  font-size: 0.88rem;
}

.search-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--brand);
}

.field label .ico {
  color: var(--brand-mid);
}

.warehouse-field { flex: 0 0 130px; }
.query-field { flex: 1; min-width: 0; }

.query-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.query-row input {
  flex: 1;
  min-width: 0;
}

.btn-scan {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 49px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
  cursor: pointer;
}

.btn-scan:hover {
  background: #d9e9fb;
  border-color: #a8c5e8;
}

.btn-scan .ico {
  width: 1.25rem;
  height: 1.25rem;
}

.search-form input,
.search-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
  font: inherit;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
}

.search-form input:focus,
.search-form select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29, 79, 145, 0.15);
}

.btn-primary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  border: 0;
  padding: 0.8rem 1.2rem;
  color: #fff;
  background: var(--brand);
  white-space: nowrap;
}

.btn-primary:hover { background: var(--brand-dark); }

.btn-ghost {
  border: 1px solid #c5daf5;
  padding: 0.55rem 0.9rem;
  color: var(--brand);
  background: var(--brand-soft);
  font-size: 0.92rem;
}

.btn-ghost:hover { background: #d9e9fb; }

#sync-btn {
  color: #c62828;
}

#sync-btn .ico {
  color: var(--ok);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin: 0;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  background: #f8fbff;
}

.sync-form {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.sync-secret-input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  min-width: 130px;
  background: #fff;
}

.cache-meta {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid #c5daf5;
  background: var(--brand-soft);
  color: #143a6b;
  font-size: 0.88rem;
  font-weight: 600;
}

.cache-meta .ico { color: var(--brand); }
.cache-meta.is-ready {
  color: #c62828;
}
.cache-meta.is-ready .ico { color: var(--ok); }
.cache-meta.is-empty {
  background: var(--warn-bg);
  border-color: #f0d5a0;
  color: #8a5a00;
}
.cache-meta.is-empty .ico { color: var(--warn); }

/* Alerts */
.alert {
  margin-top: 0.9rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f3c2bf;
}

.alert-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #b7dfc8;
}

/* Results */
.results {
  margin-top: 1.1rem;
  display: grid;
  gap: 0.9rem;
}

.match-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  padding: 0;
}

.match-head {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  padding: 1rem 1.1rem;
  background: linear-gradient(180deg, #f3f8ff 0%, #eaf2fc 100%);
  border-bottom: 1px solid var(--line);
}

.match-top {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  padding: 1rem 1.1rem 0.2rem;
}

.match-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.match-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.match-copy {
  min-width: 0;
}

.match-label {
  margin: 0;
  color: var(--brand-mid);
  font-size: 0.9rem;
  font-weight: 700;
}

.match-code {
  margin: 0.2rem 0 0;
  font-family: var(--mono);
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  font-weight: 700;
  line-height: 1.15;
  color: #c62828;
}

.match-name {
  margin: 0.35rem 0 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: #000;
}

.match-meta {
  margin: 0;
  padding: 0.85rem 1.1rem 1.05rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: #f8fbff;
  border-top: 1px solid var(--line);
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #c5daf5;
  color: #143a6b;
  font-size: 0.86rem;
  font-weight: 500;
}

.meta-pill svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: var(--brand);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.meta-pill strong {
  font-weight: 800;
  color: var(--brand);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background-image: linear-gradient(180deg, #f3f8ff 0%, #ffffff 100%);
}

.section-title .panel-ico {
  margin: 0;
}

.section-title h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #143a6b;
}

.section-title p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-blue .panel-head {
  background: linear-gradient(180deg, #f3f8ff 0%, #eaf2fc 100%);
  border-bottom: 1px solid var(--line);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.7rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}

.panel-ico {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  flex-shrink: 0;
}

.panel-ico svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: #143a6b;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  margin-inline-start: auto;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.table-wrap::after {
  content: "مرّر الجدول أفقياً لرؤية كل الأعمدة ←";
  display: block;
  padding: 0.45rem 1rem 0.7rem;
  color: #5b7394;
  font-size: 0.82rem;
  font-weight: 600;
  background: #f8fbff;
  border-top: 1px solid #e4ecf5;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 920px;
}

.data-table th,
.data-table td {
  padding: 0.85rem 1rem;
  text-align: right;
  border-bottom: 1px solid #e4ecf5;
  vertical-align: middle;
}

.data-table th {
  font-size: 0.78rem;
  color: var(--brand);
  background: #f5f9ff;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

.data-table th .th-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  margin-inline-end: 0.28rem;
  vertical-align: -0.2rem;
  color: var(--brand-mid);
}

.data-table th .th-ico svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.data-table tbody tr:nth-child(even) td {
  background: #f8fbff;
}

.data-table tbody tr:hover td {
  background: #eef5ff;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.9em;
}

.highlight-code {
  font-weight: 700;
  color: #c62828;
}

.name-cell {
  color: #000;
  font-weight: 600;
}

.gcode-cell {
  color: var(--brand);
  font-weight: 700;
}

.chip {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: #fdecea;
  color: #c62828;
  border: 1px solid #f3c2bf;
  font-size: 0.86rem;
  font-weight: 700;
}

.chip-group {
  background: #e8f6ee;
  color: #1a7a4c;
  border-color: #b7dfc8;
}

.price-cell { font-weight: 700; color: #143a6b; }
.qty-cell { font-weight: 700; color: #0d5c38; }

.empty-state {
  text-align: center;
  padding: 2.2rem 1.25rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background-image: linear-gradient(180deg, #f5f9ff 0%, #ffffff 55%);
}

.empty-title {
  margin: 0.55rem 0 0.25rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: #143a6b;
}

.empty-state p:last-child {
  margin: 0;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 720px) {
  .search-form {
    flex-direction: column;
    align-items: stretch;
  }
  .warehouse-field { flex: 1 1 auto; }
  .btn-primary { width: 100%; }
  .match-top,
  .match-head { flex-direction: column; }
}

/* —— Sync progress overlay —— */
.sync-progress {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(15, 35, 65, 0.45);
  backdrop-filter: blur(4px);
}

.sync-progress[hidden] {
  display: none !important;
}

.sync-progress-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(20, 58, 107, 0.22);
  padding: 1.6rem 1.4rem 1.35rem;
  text-align: center;
}

.sync-progress-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
}

.sync-progress-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: sync-spin 1.1s linear infinite;
}

.sync-progress.is-done .sync-progress-icon {
  background: #e6f6ea;
  color: #1b7a3d;
}

.sync-progress.is-done .sync-progress-icon svg {
  animation: none;
}

.sync-progress.is-error .sync-progress-icon {
  background: #fdecea;
  color: #c62828;
}

.sync-progress.is-error .sync-progress-icon svg {
  animation: none;
}

.sync-progress-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: #143a6b;
}

.sync-progress-status {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 1.4em;
}

.sync-progress-track {
  height: 12px;
  border-radius: 999px;
  background: #e8eef6;
  overflow: hidden;
  border: 1px solid #d5e2f2;
}

.sync-progress-fill {
  height: 100%;
  width: 1%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1d4f91, #3a7bd5);
  transition: width 0.28s ease;
}

.sync-progress.is-done .sync-progress-fill {
  background: linear-gradient(90deg, #1b7a3d, #3cb371);
}

.sync-progress.is-error .sync-progress-fill {
  background: linear-gradient(90deg, #c62828, #e57373);
}

.sync-progress-label {
  margin: 0.65rem 0 0;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.15rem;
  color: #143a6b;
  font-variant-numeric: tabular-nums;
}

.sync-progress #sync-progress-close {
  margin-top: 1rem;
}

@keyframes sync-spin {
  to { transform: rotate(-360deg); }
}

/* —— Barcode camera scanner —— */
.barcode-scanner {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(15, 35, 65, 0.55);
  backdrop-filter: blur(4px);
}

.barcode-scanner[hidden] {
  display: none !important;
}

.barcode-scanner-card {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(20, 58, 107, 0.22);
  padding: 1.1rem 1.1rem 1.25rem;
  overflow: hidden;
}

.barcode-scanner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.barcode-scanner-head h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: #143a6b;
}

.barcode-scanner-status {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.92rem;
  min-height: 1.35em;
}

.barcode-scanner-status.is-error {
  color: var(--danger);
  font-weight: 600;
}

.barcode-scanner-status.is-ok {
  color: var(--ok);
  font-weight: 700;
}

.barcode-scanner-viewport {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #0b1a2e;
  min-height: 320px;
}

.zebra-viewport {
  aspect-ratio: 3 / 4;
  max-height: min(65vh, 560px);
}

.zebra-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.zebra-laser {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  height: 3px;
  margin-top: -1px;
  background: linear-gradient(90deg, transparent, #ff1a1a 15%, #ff3b3b 50%, #ff1a1a 85%, transparent);
  box-shadow: 0 0 12px 2px rgba(255, 40, 40, 0.85);
  animation: zebra-laser 1.4s ease-in-out infinite;
  pointer-events: none;
  z-index: 2;
}

.zebra-guide {
  position: absolute;
  inset: 38% 5%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 1;
}

.zebra-hint {
  margin: 0.75rem 0 0;
  text-align: center;
  color: #5b7394;
  font-size: 0.88rem;
  font-weight: 600;
}

@keyframes zebra-laser {
  0%, 100% { transform: translateY(-28px); opacity: 0.55; }
  50% { transform: translateY(28px); opacity: 1; }
}

@media (max-width: 720px) {
  .btn-scan { width: 49px; }
}

