:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #dfe4ea;
  --text: #1f2933;
  --muted: #616e7c;
  --primary: #1b6b45;
  --primary-hover: #145335;
  --cold: #0b7285;
  --cold-bg: #e7f5ff;
  --warn-bg: #fff9db;
  --warn-border: #fab005;
  --err-bg: #fff5f5;
  --err-border: #fa5252;
  --radius: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
button, input, select, textarea { font-family: inherit; }
button { touch-action: manipulation; }

.topbar {
  background: #14281d;
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  border-bottom: 3px solid var(--primary);
}
.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 26px; }
.brand h1 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.subtitle { margin: 2px 0 0; font-size: 12px; color: #c8ded1; }
.badge-proto {
  font-size: 11px;
  background: rgba(255,255,255,0.16);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.header-right { display: flex; align-items: center; gap: 8px; }
.privacy-pill {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.28);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.icon-lock-btn {
  height: 32px;
  width: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}

.stepper {
  max-width: 1480px;
  margin: 12px auto 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.step-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,0.1);
  color: #c8ded1;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
}
.step-pill .num {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
}
.step-pill.active { background: #2b8a5c; color: #fff; font-weight: 700; }
.step-pill.done { background: #1e4d35; color: #d8f5a2; }
.step-arrow { color: #7fa590; font-size: 12px; }

.container {
  max-width: 1480px;
  margin: 18px auto 64px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; font-size: 16px; }
.hint { font-size: 12px; color: var(--muted); }

.dropzone {
  border: 2px dashed #9fb3c8;
  border-radius: var(--radius);
  background: #f8fafc;
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  background: #ebfbee;
  border-color: var(--primary);
}
.dropzone-sm { padding: 20px 16px; flex: 1; }
.drop-icon { font-size: 28px; margin-bottom: 6px; }
.drop-title { font-weight: 700; font-size: 14px; }
.drop-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.selected-files {
  margin-top: 12px;
  padding: 10px 12px;
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.selected-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; }
.file-chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.file-chip {
  background: #fff;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.file-chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #829ab1;
  font-weight: 700;
  padding: 0 2px;
}

.import-controls {
  margin-top: 14px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
}
.field input, .field select { height: 38px; padding: 0 10px; }
.field-sm input { width: 110px; }
.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  font-size: 13px;
  cursor: pointer;
}

.btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-lg { min-height: 42px; padding: 0 20px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #334e68; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #243b53; }
.btn-cold { background: var(--cold-bg); color: var(--cold); border-color: #74c0fc; }
.btn-cold:hover:not(:disabled) { background: #d0ebff; }
.btn-ghost { background: #fff; color: var(--text); border-color: #cbd2d9; }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; }
.btn-link { border: none; background: transparent; color: #d64545; cursor: pointer; font-size: 12px; }

.alert { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert-error { background: var(--err-bg); border: 1px solid var(--err-border); color: #c92a2a; }
.alert-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: #8c5a00; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.kpi-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi-card:hover { border-color: #7b8794; }
.kpi-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(27,107,69,0.18);
  background: #f3faf6;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 19px; }
.kpi-cold .kpi-val { color: var(--cold); }
.kpi-pack .kpi-val { color: #b45309; }
.kpi-ship .kpi-val { color: var(--primary); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.input-temp { width: 68px; height: 36px; padding: 0 8px; border: 1px solid #cbd2d9; border-radius: 6px; }
.input-search {
  width: 290px;
  max-width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  font-size: 13px;
}
.toolbar select {
  height: 36px;
  padding: 0 8px;
  border: 1px solid #cbd2d9;
  border-radius: 6px;
  background: #fff;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 560px;
}
.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 1180px;
}
.order-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef2f6;
  color: #334e68;
  font-weight: 700;
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.order-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #edf2f7;
  vertical-align: top;
}
.order-table tr.row-held { opacity: 0.62; background: #f8f9fa; }
.order-table tr.row-packing { background: #fffdf0; }
.order-table tr.row-cold { background: #f4faff; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-smartstore { background: #d3f9d8; color: #186429; }
.badge-coupang { background: #ffe3e3; color: #a61e4d; }
.badge-toss { background: #d0ebff; color: #1864ab; }
.badge-cold { background: #d0ebff; color: #0c5480; border: 1px solid #74c0fc; }
.badge-ok-temp { background: #f1f3f5; color: #495057; }
.badge-flag { background: #fff3bf; color: #8c5a00; }
.badge-dup { background: #e5dbff; color: #5f3dc4; }

.cell-input, .cell-select {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid #d9e2ec;
  border-radius: 5px;
  font-size: 12px;
  background: #fff;
  color: var(--text);
}
.cell-input:focus, .cell-select:focus { outline: none; border-color: var(--primary); }
.cell-qty { width: 58px; text-align: center; }
.cell-qty.multi { background: #fff4e6; border-color: #fd7e14; font-weight: 700; }
.cell-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.addr-cell { max-width: 240px; word-break: keep-all; }

/* Mobile order cards (hidden on desktop) */
.mobile-order-list { display: none; flex-direction: column; gap: 10px; }
.mcard {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mcard.row-held { opacity: 0.68; background: #f8f9fa; }
.mcard.row-packing { background: #fffdf0; border-color: #ffe066; }
.mcard.row-cold { background: #f4faff; border-color: #a5d8ff; }
.mcard-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.mcard-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mcard-status { width: auto; min-width: 105px; height: 32px; font-weight: 600; }
.mcard-recip { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.mcard-tel { color: var(--primary); text-decoration: none; font-size: 12.5px; font-weight: 600; }
.mcard-addr { font-size: 12.5px; color: #334e68; word-break: keep-all; }
.mcard-prod { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mcard-qty-pill { background: #fff4e6; color: #d9480f; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; }
.mcard-memo {
  background: #fff9db;
  border-left: 3px solid #fab005;
  padding: 6px 8px;
  font-size: 12.5px;
  border-radius: 4px;
}
.mcard-msg { font-size: 12px; color: var(--muted); }
.mcard-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.export-bar {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.export-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.reverse-controls { display: flex; gap: 14px; align-items: stretch; flex-wrap: wrap; }
.courier-box { min-width: 220px; display: flex; align-items: center; }

.result-kpi-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
}
.result-kpi {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.result-kpi strong { font-size: 22px; }
.result-kpi.ok { background: #ebfbee; border-color: #69db7c; color: #1b6b45; }
.result-kpi.neutral { background: #f8f9fa; }
.result-kpi.warn { background: #fff9db; border-color: #ffd43b; color: #8c5a00; }

.download-box { margin-top: 16px; }
.download-box h3 { margin: 0 0 10px; font-size: 14px; }
.download-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* Bottom mobile nav (hidden on desktop) */
.mobile-nav { display: none; }

/* Bottom sheet editor */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 800;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: 560px;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -8px 28px rgba(0,0,0,0.2);
}
.modal-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #cbd2d9;
  margin: 0 auto 12px;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  border: none;
  background: #f1f3f5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
}
.sheet-form { display: flex; flex-direction: column; gap: 10px; }
.sheet-row-2 { display: grid; grid-template-columns: 1fr 90px; gap: 10px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 16px; }

/* Full-screen PIN lock overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: linear-gradient(160deg, #0f1f16 0%, #14281d 60%, #1b4332 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pin-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.pin-card.shake { animation: pinShake 0.32s ease-in-out; }
@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
.pin-icon { font-size: 40px; }
.pin-title { font-size: 20px; font-weight: 700; }
.pin-msg { font-size: 13px; color: #c8ded1; min-height: 20px; }
.pin-msg.err { color: #ffa8a8; font-weight: 600; }
.pin-dots { display: flex; gap: 12px; margin: 4px 0 8px; min-height: 16px; }
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.45);
  background: transparent;
  transition: background 0.12s, transform 0.12s;
}
.pin-dot.filled {
  background: #69db7c;
  border-color: #69db7c;
  transform: scale(1.1);
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 12px;
  margin-top: 6px;
}
.pin-key {
  height: 62px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
}
.pin-key:active { background: rgba(255,255,255,0.28); }
.pin-key.fn { font-size: 16px; background: rgba(255,255,255,0.05); color: #c8ded1; }
.pin-text-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.pin-text-wrap input {
  height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.12);
  color: #fff;
  padding: 0 12px;
  font-size: 16px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 20px;
  background: #1f2933;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 999;
}

.hidden { display: none !important; }

/* Mobile layout (<= 820px) */
@media (max-width: 820px) {
  body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .subtitle, .stepper { display: none; }
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  .brand h1 { font-size: 15.5px; }
  .container { margin: 12px auto 16px; padding: 0 10px; }
  .card { padding: 14px; }

  /* Show only active mobile tab */
  body[data-mobile-tab="1"] .step-section:not([data-step="1"]),
  body[data-mobile-tab="2"] .step-section:not([data-step="2"]),
  body[data-mobile-tab="3"] .step-section:not([data-step="3"]) {
    display: none !important;
  }

  .import-controls { flex-direction: column; align-items: stretch; }
  .field-sm input { width: 100%; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { padding: 10px; }
  .toolbar-search-row { width: 100%; }
  .input-search { width: 100%; }
  .toolbar select { flex: 1; }

  /* Swap wide table for touch cards */
  .table-wrap { display: none; }
  .mobile-order-list { display: flex; }

  .export-bar { flex-direction: column; align-items: stretch; }
  .export-actions { flex-direction: column; }
  .export-actions .btn, .download-buttons .btn { width: 100%; }
  .reverse-controls { flex-direction: column; }
  .courier-box { width: 100%; }
  .courier-box .field { width: 100%; }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 700;
    background: #14281d;
    border-top: 1px solid #2b4c3b;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    gap: 4px;
  }
  .mnav-btn {
    border: none;
    background: transparent;
    color: #a9c7b6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 2px;
    border-radius: 8px;
    cursor: pointer;
  }
  .mnav-btn.active { background: #1b6b45; color: #fff; }
  .mnav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
  .mnav-ico { font-size: 16px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); right: 12px; left: 12px; text-align: center; }
}
