/* Tekstor — mobile-first, high-contrast, big tap targets for warehouse speed. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --text: #16191d;
  --muted: #6b7280;
  --border: #d7dbe0;
  --primary: #2563eb;
  --primary-press: #1d4ed8;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --danger-press: #b91c1c;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --tap: 56px;
  --maxw: 720px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --border: #2b313a;
    --primary: #3b82f6;
    --primary-press: #2563eb;
    --danger: #ef4444;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  line-height: 1.4;
}
button { font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: 17px; margin: 5px; }

.app { max-width: var(--maxw); margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: .3px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 24px; cursor: pointer;
}
.icon-btn:active { transform: scale(.96); }

/* Content */
.content { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 16px; }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 0 18px; margin: 8px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font-size: 17px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn-primary:active { background: var(--primary-press); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:active { background: var(--danger-press); }
.btn-block { width: 100%; }
.btn-lg { min-height: 64px; font-size: 19px; }

/* Cards / fields */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 13px; color: var(--danger); }
input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); min-height: var(--tap);
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.toggle input { width: 26px; height: 26px; }

/* Keypad */
.keypad { display: flex; flex-direction: column; gap: 12px; }
.keypad-display {
  text-align: center; font-size: 40px; font-weight: 800; letter-spacing: 2px;
  padding: 14px; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  min-height: 72px; font-variant-numeric: tabular-nums;
}
.keypad-status { text-align: center; font-size: 14px; color: var(--muted); min-height: 20px; }
.keys { display: grid; gap: 10px; }
.keys-letters { grid-template-columns: repeat(4, 1fr); }
.keys-digits { grid-template-columns: repeat(3, 1fr); }
.key {
  min-height: 64px; font-size: 26px; font-weight: 700;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.key:active { background: var(--surface-2); transform: scale(.97); }
.key.dim { opacity: .38; }
.key.wide { grid-column: span 1; }
.key-ok { background: var(--ok); color: #fff; border-color: transparent; }
.key-back { background: var(--surface-2); }

/* Item list */
.list { display: flex; flex-direction: column; gap: 10px; }
.item-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.item-row:active { background: var(--surface-2); }
.badge {
  font-weight: 800; font-size: 15px; padding: 6px 10px; border-radius: 10px;
  background: var(--primary); color: #fff; min-width: 54px; text-align: center; font-variant-numeric: tabular-nums;
}
.item-row .meta { flex: 1; min-width: 0; }
.item-row .meta .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .meta .sub { font-size: 13px; color: var(--muted); }
.item-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }

/* Detail: big qty */
.detail-id { font-size: 34px; font-weight: 800; letter-spacing: 1px; }
.qty-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.qty-btn {
  width: 92px; height: 92px; border-radius: 20px; border: none; color: #fff;
  font-size: 48px; font-weight: 800; cursor: pointer; line-height: 1;
}
.qty-minus { background: var(--danger); }
.qty-plus { background: var(--ok); }
.qty-btn:active { transform: scale(.95); }
.qty-value { font-size: 60px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; flex: 1; }
.qty-na { font-size: 30px; color: var(--muted); font-weight: 700; }

.detail-img { width: 100%; max-height: 260px; object-fit: contain; border-radius: var(--radius); background: var(--surface-2); }
.barcode-preview { width: 100%; background: #fff; border-radius: var(--radius); padding: 10px; }

/* Save indicator */
.saved-flag { font-size: 13px; color: var(--ok); font-weight: 600; opacity: 0; transition: opacity .2s; }
.saved-flag.show { opacity: 1; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center;
  z-index: 50; padding: 0;
}
.modal {
  background: var(--surface); width: 100%; max-width: var(--maxw); border-radius: 18px 18px 0 0;
  padding: 18px; max-height: 92dvh; overflow-y: auto;
}
.modal h2 { margin: 0 0 12px; font-size: 20px; }
.img-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.img-grid img { width: 100%; height: 130px; object-fit: cover; border-radius: 10px; border: 2px solid transparent; cursor: pointer; background: var(--surface-2); }
.img-grid img.sel { border-color: var(--primary); }

/* Scanner */
.scanner-video { width: 100%; border-radius: var(--radius); background: #000; max-height: 60dvh; }
.scan-hint { text-align: center; color: var(--muted); font-size: 14px; margin-top: 8px; }

/* Toasts */
.toast-stack {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); z-index: 80;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  width: max-content; max-width: 92vw; pointer-events: none;
}
.toast {
  pointer-events: auto; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 10px 16px 10px 12px;
  border-radius: 14px; font-size: 15px; font-weight: 500;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 5px solid var(--muted);
  box-shadow: 0 8px 24px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.12);
  opacity: 0; transform: translateY(14px) scale(.98);
  transition: opacity .22s ease, transform .22s cubic-bezier(.2,.8,.2,1);
  max-width: 92vw;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast-msg { line-height: 1.3; }
.toast-icon {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff; font-style: normal;
}
.toast-success { border-left-color: var(--ok); }
.toast-success .toast-icon { background: var(--ok); }
.toast-error   { border-left-color: var(--danger); }
.toast-error   .toast-icon { background: var(--danger); }
.toast-warning { border-left-color: var(--warn); }
.toast-warning .toast-icon { background: var(--warn); }
.toast-info    { border-left-color: var(--primary); }
.toast-info    .toast-icon { background: var(--primary); }

/* Login wizard */
.wizard-steps { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 18px; }
.wizard-dot {
  width: 30px; height: 6px; border-radius: 3px; background: var(--surface-2);
  transition: background .2s;
}
.wizard-dot.active { background: var(--primary); }
.wizard-dot.done { background: var(--ok); }
.wizard-who {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  color: var(--muted); font-size: 14px; margin-bottom: 14px;
}
.wizard-who strong { color: var(--text); }
.otp-input {
  text-align: center; font-size: 30px; font-weight: 800;
  letter-spacing: 10px; font-variant-numeric: tabular-nums; padding-left: 10px;
}
.link-btn {
  background: none; border: none; color: var(--primary); font-size: 15px;
  cursor: pointer; padding: 10px; min-height: var(--tap); width: 100%;
}

/* Login */
.login-wrap { max-width: 380px; margin: 8dvh auto; padding: 0 16px; width: 100%; }
.login-wrap h1 { text-align: center; font-size: 28px; margin-bottom: 8px; }
.login-wrap p { text-align: center; color: var(--muted); margin-top: 0; }

@media (min-width: 640px) {
  .keys-digits { max-width: 420px; margin: 0 auto; width: 100%; }
  .modal { border-radius: 18px; margin-bottom: 5dvh; }
  .modal-backdrop { align-items: center; }
  .img-grid { grid-template-columns: repeat(3, 1fr); }
}
