/* ==========================================================================
   KARA Packing Proof — Design System
   Modern, clean, mobile-first. Gradients + soft elevation + rounded corners.
   ========================================================================== */

:root {
  --brand-1: #6D5EF5;
  --brand-2: #9B6BF3;
  --brand-3: #4FD1C5;
  --brand-grad: linear-gradient(135deg, #6D5EF5 0%, #9B6BF3 55%, #B992F0 100%);
  --brand-grad-soft: linear-gradient(135deg, rgba(109,94,245,0.12) 0%, rgba(155,107,243,0.10) 100%);

  --bg: #F4F5FA;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, rgba(109,94,245,0.14), transparent 60%), #F4F5FA;
  --surface: #FFFFFF;
  --surface-2: #F8F8FC;
  --border: #E7E7F1;
  --text: #1C1B29;
  --text-muted: #6E6C82;
  --text-faint: #9997AC;

  --success: #21B573;
  --success-bg: #E7F9F1;
  --warning: #F5A623;
  --warning-bg: #FFF5E4;
  --danger: #EF4B5F;
  --danger-bg: #FDEAED;
  --info: #3B82F6;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --shadow-sm: 0 2px 8px rgba(28, 27, 41, 0.06);
  --shadow-md: 0 8px 24px rgba(28, 27, 41, 0.08);
  --shadow-lg: 0 16px 40px rgba(109, 94, 245, 0.18);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14131F;
    --bg-grad: radial-gradient(1200px 600px at 50% -10%, rgba(109,94,245,0.25), transparent 60%), #14131F;
    --surface: #1D1B2E;
    --surface-2: #24223A;
    --border: #322F4A;
    --text: #F1F0F8;
    --text-muted: #A9A7C0;
    --text-faint: #726F8C;
    --success-bg: rgba(33,181,115,0.14);
    --warning-bg: rgba(245,166,35,0.14);
    --danger-bg: rgba(239,75,95,0.14);
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.28);
    --shadow-md: 0 10px 28px rgba(0,0,0,0.34);
    --shadow-lg: 0 18px 44px rgba(109,94,245,0.30);
  }
}
:root[data-theme="dark"] {
  --bg: #14131F;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, rgba(109,94,245,0.25), transparent 60%), #14131F;
  --surface: #1D1B2E;
  --surface-2: #24223A;
  --border: #322F4A;
  --text: #F1F0F8;
  --text-muted: #A9A7C0;
  --text-faint: #726F8C;
  --success-bg: rgba(33,181,115,0.14);
  --warning-bg: rgba(245,166,35,0.14);
  --danger-bg: rgba(239,75,95,0.14);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-grad);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(78px + var(--safe-bottom));
}

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 14px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--brand-grad);
  font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-weight: 800; font-size: 15px; letter-spacing: 0.5px; }
.brand-subtitle { font-size: 11px; color: var(--text-muted); font-weight: 600; }

.topbar-status { display: flex; align-items: center; gap: 8px; }
.net-indicator {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700;
  padding: 5px 9px; border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.net-indicator .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.net-indicator.net-online .dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.net-indicator.net-offline .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.net-indicator.net-offline { color: var(--danger); }

.operator-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 5px 10px 5px 5px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  max-width: 130px;
}
.operator-chip .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 800;
  flex-shrink: 0;
}
#operator-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- Views ---------------- */
.views { flex: 1; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.view { display: none; flex-direction: column; gap: 16px; animation: viewIn 0.28s ease both; }
.view.is-active { display: flex; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Hero / Home ---------------- */
.hero-card {
  background: var(--brand-grad);
  border-radius: var(--radius-xl);
  padding: 26px 22px;
  color: #fff;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(120px 120px at 90% 0%, rgba(255,255,255,0.25), transparent 60%);
}
.hero-eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 700; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.6px; }
.hero-title { margin: 0 0 8px; font-size: 22px; font-weight: 800; line-height: 1.3; }
.hero-desc { margin: 0; font-size: 13px; opacity: 0.92; line-height: 1.5; }

.scan-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 16px;
}

.btn-scan { padding: 18px; font-size: 15px; }

.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-faint); font-size: 12px; font-weight: 600;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.manual-form { display: flex; flex-direction: column; gap: 12px; }

.quick-stats { display: flex; gap: 10px; }
.stat-pill {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-value { display: block; font-size: 20px; font-weight: 800; color: var(--brand-1); }
.stat-label { display: block; font-size: 10.5px; color: var(--text-muted); font-weight: 600; margin-top: 2px; }

/* ---------------- Fields & Inputs ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
input[type="text"], input[type="number"], input[type="url"], input[type="search"], select {
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 15px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--brand-1);
  box-shadow: 0 0 0 4px rgba(109,94,245,0.15);
}
.form-grid { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.btn-icon-only { flex: 0 0 auto; padding: 12px 14px; font-size: 17px; }

/* ---------------- Buttons ---------------- */
.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 14.5px;
  font-weight: 750;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease, filter 0.12s ease;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-icon { font-size: 17px; }

.btn-primary { background: var(--brand-grad); color: #fff; box-shadow: var(--shadow-lg); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px dashed var(--border); }
.btn-ghost-light { background: rgba(255,255,255,0.14); color: #fff; border: 1.5px solid rgba(255,255,255,0.4); }
.btn-success { background: linear-gradient(135deg, #21B573, #1B9E63); color: #fff; box-shadow: 0 10px 26px rgba(33,181,115,0.32); }
.btn-danger { background: var(--danger); color: #fff; }

.stack-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------------- Scanner ---------------- */
.view-scanner { position: fixed; inset: 0; z-index: 100; background: #000; padding: 0 !important; }
.view-scanner.is-active { display: flex; }
.scanner-wrap { position: relative; flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; }
#scanner-video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame {
  position: absolute; width: 78%; max-width: 320px; aspect-ratio: 1.6/1;
  border: 3px solid #fff; border-radius: 18px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,0.45);
}
.scanner-hint {
  position: absolute; bottom: 90px; left: 0; right: 0;
  text-align: center; color: #fff; font-size: 13px; font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.scanner-actions {
  display: flex; gap: 10px; padding: 16px calc(16px + var(--safe-bottom)) calc(20px + var(--safe-bottom));
  background: #000;
}
.scanner-actions .btn { flex: 1; }

/* ---------------- Cards / Alerts ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}
.card-eyebrow { margin: 0 0 4px; font-size: 11.5px; font-weight: 800; color: var(--brand-1); text-transform: uppercase; letter-spacing: 0.5px; }
.card h2 { margin: 0 0 4px; font-size: 19px; font-weight: 800; }
.card-desc { color: var(--text-muted); font-size: 13px; margin: 6px 0 16px; line-height: 1.5; }

.alert-card {
  border-radius: var(--radius-xl);
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.alert-card h2 { margin: 6px 0 4px; font-size: 20px; font-weight: 800; }
.alert-icon { font-size: 40px; line-height: 1; }
.alert-sub { color: var(--text-muted); font-size: 13.5px; margin: 0; }
.alert-warning { background: var(--warning-bg); border: 1px solid rgba(245,166,35,0.3); }
.alert-warning h2 { color: #A05A00; }
.alert-success { background: var(--success-bg); border: 1px solid rgba(33,181,115,0.3); }
.alert-success h2 { color: #0E7C4E; }

.info-list { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.info-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; background: var(--surface); border-radius: var(--radius-sm); padding: 10px 12px; }
.info-row span:first-child { color: var(--text-muted); font-weight: 600; }
.info-row span:last-child { font-weight: 700; text-align: right; }

.tracking-display { font-size: 19px; font-weight: 800; letter-spacing: 0.3px; margin: 4px 0 2px; word-break: break-all; }
.tracking-display-input {
  width: 100%; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 10px 12px;
}
.field-hint { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

/* ---------------- Packing screen ---------------- */
.packing-header {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.packing-header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.badge { font-size: 11px; font-weight: 800; padding: 4px 10px; border-radius: 999px; }
.badge-status { background: var(--warning-bg); color: #A05A00; }
.badge-status.is-done { background: var(--success-bg); color: #0E7C4E; }
.badge-status.is-check { background: var(--danger-bg); color: #B0233A; }
.sync-pill { font-size: 16px; color: var(--text-faint); }
.sync-pill.is-local { color: var(--warning); }
.sync-pill.is-synced { color: var(--success); }
.sync-pill.is-conflict { color: var(--danger); }
.packing-meta { color: var(--text-muted); font-size: 12.5px; margin: 0 0 14px; }

.progress-track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--brand-grad); border-radius: 999px; transition: width 0.35s ease; }
.progress-label { text-align: center; font-size: 12px; font-weight: 700; color: var(--text-muted); margin: 8px 0 0; }

.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-slot {
  aspect-ratio: 1/1;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; position: relative; overflow: hidden; cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.photo-slot:active { transform: scale(0.98); }
.photo-slot.is-filled { border-style: solid; border-color: var(--success); }
.photo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-slot .slot-icon { font-size: 26px; color: var(--text-faint); }
.photo-slot .slot-label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-align: center; padding: 0 6px; }
.photo-slot .slot-check {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--success); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.photo-slot .slot-retake {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55); color: #fff;
  font-size: 10.5px; font-weight: 700; text-align: center;
  padding: 5px 0;
}

/* ---------------- Checkbox ---------------- */
.checkbox-row {
  display: flex; align-items: center; gap: 12px;
  font-size: 14px; font-weight: 700;
  padding: 4px 0;
}
.checkbox-row input[type="checkbox"] {
  width: 22px; height: 22px; accent-color: var(--brand-1);
}
.handover-time { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }

/* ---------------- History ---------------- */
.history-toolbar { display: flex; gap: 8px; }
.history-toolbar input { flex: 1.4; }
.history-toolbar select { flex: 1; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  transition: transform 0.1s ease;
}
.history-item:active { transform: scale(0.98); }
.history-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.history-item-tracking { font-weight: 800; font-size: 13.5px; }
.history-item-sub { font-size: 12px; color: var(--text-muted); }
.history-empty { text-align: center; color: var(--text-faint); padding: 40px 10px; font-size: 13.5px; }

/* ---------------- Operator list ---------------- */
.operator-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.operator-pill {
  padding: 9px 14px; border-radius: 999px;
  background: var(--surface-2); border: 1.5px solid var(--border);
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.operator-pill.is-selected { background: var(--brand-grad); color: #fff; border-color: transparent; }

/* ---------------- Bottom nav ---------------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-width: 560px; margin: 0 auto;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + var(--safe-bottom));
}
.nav-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 700; color: var(--text-faint);
  padding: 6px 0; border-radius: 12px;
}
.nav-btn .nav-icon { font-size: 19px; }
.nav-btn.is-active { color: var(--brand-1); }

/* ---------------- Toasts ---------------- */
.toast-root {
  position: fixed; top: calc(10px + var(--safe-top)); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200; pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease both;
  max-width: 100%;
}
.toast.toast-success { background: var(--success); color: #fff; }
.toast.toast-error { background: var(--danger); color: #fff; }
.toast.toast-info { background: var(--brand-1); color: #fff; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Topbar sync button ---------------- */
.topbar-sync-btn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; font-size: 14px;
  box-shadow: var(--shadow-sm); cursor: pointer; color: var(--text-muted);
  flex-shrink: 0;
}
.topbar-sync-btn:active { transform: scale(0.92); }
.topbar-sync-btn.is-syncing { animation: spin 0.9s linear infinite; color: var(--brand-1); }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ---------------- Sync error / status text ---------------- */
.sync-error-text {
  font-size: 12px; font-weight: 600; color: var(--danger);
  background: var(--danger-bg); border-radius: var(--radius-sm);
  padding: 8px 10px; margin-top: 10px; line-height: 1.4;
}

.health-status { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.health-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.health-row .health-badge { font-size: 11.5px; font-weight: 800; padding: 3px 9px; border-radius: 999px; }
.health-badge.is-ok { background: var(--success-bg); color: #0E7C4E; }
.health-badge.is-bad { background: var(--danger-bg); color: #B0233A; }
.health-badge.is-checking { background: var(--warning-bg); color: #A05A00; }

.btn-sm { padding: 10px 14px; font-size: 13px; }
.btn-danger-outline {
  background: transparent; color: var(--danger);
  border: 1.5px solid var(--danger);
}

/* ---------------- Misc ---------------- */
::selection { background: rgba(109,94,245,0.25); }
