:root {
  --bg:        #0f0f1a;
  --surface:   #1a1a2e;
  --surface2:  #16213e;
  --accent:    #0f3460;
  --primary:   #e94560;
  --green:     #4caf50;
  --green-dim: rgba(76,175,80,0.12);
  --red-dim:   rgba(233,69,96,0.12);
  --text:      #eaeaea;
  --muted:     #888;
  --border:    #2a2a4a;
  --radius:    12px;
  --shadow:    0 4px 20px rgba(0,0,0,0.4);
  --nav-h:     62px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  font-size: 15px;
}

.hidden { display: none !important; }

/* ── Login ───────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--bg) 0%, #0d0d2b 100%);
}
.login-box {
  width: 100%; max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 10px; }
.login-title { font-size: 1.5rem; font-weight: 700; }
.login-sub { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.login-error { color: var(--primary); font-size: 0.82rem; min-height: 20px; margin-bottom: 8px; }
.pin-input {
  width: 100%; text-align: center; letter-spacing: 6px;
  font-size: 1.4rem; font-weight: 700;
}

/* ── App Shell ───────────────────────────────────────────── */
.app-shell {
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--surface) 0%, var(--accent) 100%);
  padding: 14px 16px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; }
.header-title { font-size: 1rem; font-weight: 700; }
.role-chip {
  font-size: 0.68rem; font-weight: 600;
  padding: 3px 10px; border-radius: 20px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
}

/* ── Main ────────────────────────────────────────────────── */
.main {
  flex: 1;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
  overflow-y: auto;
}

/* ── Pages ───────────────────────────────────────────────── */
.page { display: none; padding: 14px; }
.page.active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; } }

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.card-title {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); margin-bottom: 10px;
}

/* ── Form ────────────────────────────────────────────────── */
.form-group { margin-bottom: 12px; position: relative; }
label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 5px; }

select, input, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
select:focus, input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: none; height: 64px; }
input[type="number"] { font-size: 1rem; font-weight: 600; }

.qty-row { display: flex; align-items: center; gap: 10px; }
.qty-row input { flex: 1; }
.unit-label {
  font-size: 0.8rem; color: var(--muted);
  white-space: nowrap; min-width: 40px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  width: 100%; padding: 13px;
  border-radius: var(--radius); border: none;
  font-size: 0.93rem; font-weight: 700; cursor: pointer;
  transition: all 0.18s; font-family: inherit;
}
.btn-primary  { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(233,69,96,0.35); }
.btn-primary:active  { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-add-item {
  width: 100%; padding: 10px; border-radius: 8px;
  border: 1px dashed rgba(233,69,96,0.4);
  background: var(--red-dim); color: var(--primary);
  font-size: 0.83rem; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: all 0.15s;
}
.btn-add-item:active { background: rgba(233,69,96,0.2); }
.btn-approve { background: var(--green); color: #fff; flex: 1; }
.btn-reject  { background: var(--primary); color: #fff; flex: 1; }
.btn-clear {
  background: none; border: none; color: var(--muted);
  font-size: 1rem; cursor: pointer; padding: 2px 6px;
  border-radius: 4px; line-height: 1;
}
.btn-clear:active { color: var(--primary); }
.btn-icon-del {
  background: none; border: none;
  color: var(--muted); font-size: 1rem; cursor: pointer;
  padding: 4px 8px; border-radius: 6px; flex-shrink: 0;
}
.btn-icon-del:active { color: var(--primary); background: var(--red-dim); }

/* ── Bottom Nav ──────────────────────────────────────────── */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; z-index: 200;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; border: none; background: none;
  color: var(--muted); font-size: 0.62rem;
  cursor: pointer; padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.nav-ico { font-size: 1.3rem; line-height: 1; }
.nav-btn.active { color: var(--primary); }
.add-circle {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 1.6rem; margin-top: -10px;
  box-shadow: 0 4px 14px rgba(233,69,96,0.55);
  line-height: 1;
}
.nav-btn.add-btn { color: var(--primary); font-weight: 700; font-size: 0.66rem; }

/* ── Filter row (list page) ──────────────────────────────── */
.filter-row { display: flex; gap: 7px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 2px; }
.filter-btn {
  flex-shrink: 0; padding: 7px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 0.75rem; cursor: pointer;
  font-family: inherit; white-space: nowrap; transition: all 0.15s;
}
.filter-btn.active { border-color: var(--primary); color: var(--primary); background: var(--red-dim); }

/* ── Request cards ───────────────────────────────────────── */
.request-list { display: flex; flex-direction: column; gap: 8px; }
.req-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 13px;
  cursor: pointer; transition: border-color 0.15s, opacity 0.15s;
  display: flex; align-items: flex-start; gap: 11px;
}
.req-card:active { border-color: var(--primary); opacity: 0.78; }
.req-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.dot-pending  { background: #ffb74d; }
.dot-approved { background: var(--green); }
.dot-rejected { background: var(--primary); }
.req-info { flex: 1; min-width: 0; }
.req-no   { font-size: 0.72rem; color: var(--muted); margin-bottom: 2px; }
.req-type { font-size: 0.86rem; font-weight: 600; }
.req-meta { font-size: 0.7rem; color: var(--muted); margin-top: 3px; }
.req-status {
  font-size: 0.68rem; font-weight: 700;
  padding: 3px 8px; border-radius: 12px; white-space: nowrap;
}
.status-pending  { background: rgba(255,183,77,0.15); color: #ffb74d; }
.status-approved { background: var(--green-dim);      color: var(--green); }
.status-rejected { background: var(--red-dim);        color: var(--primary); }

/* ── Type tabs (create page) ─────────────────────────────── */
.type-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.type-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 10px 6px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface2);
  color: var(--muted); font-size: 0.72rem; cursor: pointer;
  font-family: inherit; transition: all 0.18s; line-height: 1.3;
}
.type-ico { font-size: 1.4rem; }
.type-tab.active { border-color: var(--primary); color: var(--primary); background: var(--red-dim); }
.type-tab-disabled {
  opacity: 0.35; cursor: not-allowed !important;
  pointer-events: none;
}

.type-form { display: none; }
.type-form.active { display: block; }

/* ── Direction tabs ──────────────────────────────────────── */
.dir-tabs { display: flex; gap: 8px; }
.dir-btn {
  flex: 1; padding: 9px; border-radius: 8px;
  border: 2px solid var(--border); background: var(--surface2);
  color: var(--muted); font-size: 0.82rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.dir-btn[data-dir="in"].active  { border-color: var(--green); color: var(--green); background: var(--green-dim); }
.dir-btn[data-dir="out"].active { border-color: var(--primary); color: var(--primary); background: var(--red-dim); }

/* ── Swap mode (ส่งสินค้าผิด) ────────────────────────────── */
.swap-box {
  border-radius: 10px; padding: 12px;
  margin-bottom: 4px; border: 1px solid var(--border);
}
.swap-box.out-box { background: rgba(233,69,96,0.06); border-color: rgba(233,69,96,0.25); }
.swap-box.in-box  { background: rgba(76,175,80,0.06);  border-color: rgba(76,175,80,0.25); }
.swap-label { font-size: 0.78rem; font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.swap-tag { font-size: 0.65rem; font-weight: 700; padding: 2px 7px; border-radius: 10px; }
.out-tag { background: rgba(233,69,96,0.15); color: var(--primary); }
.in-tag  { background: rgba(76,175,80,0.15);  color: var(--green); }
.swap-arrow-row {
  text-align: center; font-size: 0.78rem; color: var(--muted);
  padding: 6px 0; font-weight: 600;
}

/* ── Reason grid ─────────────────────────────────────────── */
.reason-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.reason-btn {
  padding: 9px 6px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.75rem; text-align: center;
  cursor: pointer; font-family: inherit; transition: all 0.15s; line-height: 1.3;
}
.reason-btn-wide { grid-column: span 2; }
.reason-btn.active { border-color: var(--primary); background: var(--red-dim); color: var(--primary); }

/* ── Search dropdown ─────────────────────────────────────── */
.search-dropdown {
  position: absolute; left: 0; right: 0; z-index: 100;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px; margin-top: 4px;
  max-height: 220px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.search-item {
  padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem; transition: background 0.12s;
}
.search-item:last-child { border-bottom: none; }
.search-item:active { background: rgba(233,69,96,0.1); }
.search-item .si-sku  { font-weight: 600; }
.search-item .si-name { color: var(--muted); font-size: 0.73rem; margin-top: 1px; }
.search-item .si-row  { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.si-sku-tag {
  font-size: 0.72rem; font-weight: 700;
  background: rgba(233,69,96,0.12); color: var(--primary);
  padding: 1px 7px; border-radius: 6px; white-space: nowrap; flex-shrink: 0;
}
.si-name-inline { font-size: 0.83rem; font-weight: 600; }
.si-stock { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

/* ── Selected tag ────────────────────────────────────────── */
.selected-tag {
  margin-top: 7px; padding: 8px 12px;
  background: rgba(233,69,96,0.1);
  border: 1px solid rgba(233,69,96,0.3);
  border-radius: 8px; font-size: 0.8rem;
}
.selected-preview {
  margin-top: 8px;
}
.selected-sku-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: rgba(233,69,96,0.1);
  border: 1px solid rgba(233,69,96,0.3);
  border-radius: 8px; font-size: 0.82rem;
}

/* ── Items preview ───────────────────────────────────────── */
.items-preview { margin-bottom: 10px; display: flex; flex-direction: column; gap: 7px; }
.item-chip {
  background: var(--surface); border-radius: 8px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
}
.item-chip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.item-chip-info { flex: 1; min-width: 0; }
.item-chip-name { font-size: 0.82rem; font-weight: 600; }
.item-chip-sub  { font-size: 0.7rem; color: var(--muted); margin-top: 1px; }
.item-chip-qty  { font-size: 0.88rem; font-weight: 700; white-space: nowrap; }
.item-chip-qty.in  { color: var(--green); }
.item-chip-qty.out { color: var(--primary); }
.stock-badge {
  display: inline-block; margin-top: 3px;
  font-size: 0.65rem; font-weight: 600;
  color: #7ecfff; background: rgba(126,207,255,0.1);
  border: 1px solid rgba(126,207,255,0.25);
  padding: 1px 7px; border-radius: 6px;
}

/* ── Pair info / repack preview ──────────────────────────── */
.pair-info {
  background: var(--surface2); border-radius: 8px;
  border: 1px solid var(--border);
  padding: 10px 12px; margin-bottom: 10px; font-size: 0.8rem;
}
.pair-arrow { color: var(--muted); margin: 0 8px; }
.repack-preview {
  background: var(--surface2); border-radius: 8px;
  border: 1px solid var(--border);
  padding: 12px; margin-top: 8px;
}
.repack-row { display: flex; justify-content: space-between; font-size: 0.82rem; padding: 4px 0; }
.repack-row .rr-lbl { color: var(--muted); }
.repack-row .rr-out { color: var(--primary); font-weight: 700; }
.repack-row .rr-in  { color: var(--green);   font-weight: 700; }

/* ── Settings tabs ───────────────────────────────────────── */
.settings-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.settings-tab {
  flex: 1; padding: 10px 8px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface2);
  color: var(--muted); font-size: 0.75rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.settings-tab.active { border-color: var(--primary); color: var(--primary); background: var(--red-dim); }

.stab { display: none; }
.stab.active { display: block; }

/* ── Item list (settings) ────────────────────────────────── */
.section-title {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); margin: 14px 0 8px;
}
.item-list { display: flex; flex-direction: column; gap: 7px; }
.list-item {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 12px 13px;
  display: flex; align-items: center; gap: 10px;
}
.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-size: 0.83rem; font-weight: 600; }
.list-item-sub  { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.pair-ratio-tag {
  font-size: 0.68rem; font-weight: 700;
  background: rgba(79,195,247,0.12);
  border: 1px solid rgba(79,195,247,0.3);
  color: #4fc3f7; padding: 2px 8px; border-radius: 10px;
  white-space: nowrap; flex-shrink: 0;
}

/* ── Detail sheet ────────────────────────────────────────── */
.detail-header { margin-bottom: 14px; }
.detail-no    { font-size: 0.72rem; color: var(--muted); }
.detail-type  { font-size: 1rem; font-weight: 700; margin: 4px 0; }
.detail-meta  { font-size: 0.75rem; color: var(--muted); }
.detail-items { margin: 12px 0; display: flex; flex-direction: column; gap: 7px; }
.detail-note  { font-size: 0.8rem; color: var(--muted); margin-top: 10px; padding: 10px 12px; background: var(--surface2); border-radius: 8px; }
.detail-reject { font-size: 0.8rem; color: var(--primary); margin-top: 8px; padding: 10px 12px; background: var(--red-dim); border-radius: 8px; border: 1px solid rgba(233,69,96,0.3); }
.approve-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ── Overlay / Sheet ─────────────────────────────────────── */
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.75); z-index: 300;
  align-items: flex-end; justify-content: center;
  pointer-events: none;
}
.overlay.show { display: flex; pointer-events: auto; }
.sheet {
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.22s ease; pointer-events: auto;
}
.handle { width: 38px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 14px; }
.sheet-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 14px; }
.sheet-sm { max-height: 70vh; }
.pin-input-sm {
  text-align: center; letter-spacing: 4px;
  font-size: 1.2rem; font-weight: 700;
}

/* ── Edit item overlay ───────────────────────────────────── */
.item-chip.editable { cursor: pointer; transition: border-color 0.15s; }
.item-chip.editable:active { border-color: var(--primary); }
.item-chip-edit-hint {
  font-size: 0.62rem; color: var(--muted);
  margin-top: 2px; opacity: 0.7;
}
.edit-item-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom,0px));
  left: 50%; transform: translateX(-50%) translateY(14px);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 10px 18px; border-radius: 22px;
  font-size: 0.83rem; opacity: 0;
  pointer-events: none; transition: all 0.28s; z-index: 400;
  white-space: nowrap; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--primary); color: var(--primary); }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-ico   { font-size: 2.5rem; display: block; margin-bottom: 10px; }

/* ── Loading ─────────────────────────────────────────────── */
.loading { text-align: center; padding: 30px; color: var(--muted); }
.spinner {
  width: 24px; height: 24px; margin: 0 auto 8px;
  border: 2px solid rgba(233,69,96,0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
