/* =============================================================================================
   보세창고 모바일 시스템 - 화면 스타일
   - 색 · 글꼴 · 상태색(ok / warn / danger)은 웹시스템(bonded-wms/public/style.css)과 같은 값 사용
   - 휴대폰 기준(세로 320 ~ 480px)으로 만들고, 넓은 화면(가로 모드 · 태블릿)은 카드 2열 + 가운데 정렬
   - 글자 크기는 화면 폭에 따라 14 ~ 17px 사이에서 자동 조절 (clamp), 손가락 터치 영역 44px 이상
   - 노치 · 하단 제스처 영역은 env(safe-area-inset-*) 만큼 비움
   ============================================================================================= */
:root {
  --bg: #e6ecf0;
  --panel: #ffffff;
  --line: #cfd8df;
  --line-strong: #9fadb9;
  --text: #17212b;
  --muted: #5b6875;
  --brand: #0f6e74;
  --brand-dark: #0a4f54;
  --brand-soft: #dff0f1;
  --hover: #e3f2f3;
  --sel: #ffe28a;
  --sel-line: #e07b00;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #2f855a;
  --req: #fffbe6;          /* 필수 입력 배경 (웹시스템 req 와 같은 연노랑) */
  --radius: 10px;
  --ctl-h: 48px;           /* 입력 · 버튼 높이 (장갑 · 현장 작업 고려) */
  --tb-h: 54px;            /* 상단바 높이 */
  --gap: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Noto Sans KR", Roboto, Arial, sans-serif;
  font-size: clamp(14px, 3.9vw, 17px);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { overscroll-behavior-y: none; }
/* 입력칸 글자 16px 이상 : iOS 에서 입력칸을 누를 때 화면이 확대되는 것 방지 */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: max(16px, 1rem); }
[hidden] { display: none !important; }

/* ---------- 버튼 · 입력 ---------- */
.btn { min-height: var(--ctl-h); padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; white-space: nowrap; font-weight: 700; touch-action: manipulation; }
.btn:active { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-block { display: block; width: 100%; }
.btn.icon { width: var(--ctl-h); padding: 0; flex: none; font-size: 1.15rem; }
.btn.icon.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn { flex: none; width: 44px; height: 44px; border: 0; background: transparent; color: inherit; font-size: 22px; cursor: pointer; padding: 0; border-radius: 50%; }
.icon-btn:active { background: rgba(255,255,255,.15); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin-top: 10px; }
.field:first-child { margin-top: 0; }
.field > label { font-size: .86rem; color: var(--muted); font-weight: 700; }
.field > label.req::after { content: " *"; color: var(--danger); }
.field input, .field select, .codeinput input, .searchbox input {
  height: var(--ctl-h); width: 100%; min-width: 0; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; background: #fff;
}
.field select { padding: 0 8px; }
input:focus, select:focus { outline: 2px solid rgba(15,110,116,.3); border-color: var(--brand); }
.req input, select.req, input.req { background: var(--req); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 10px; }
.field-row > .field { margin-top: 10px; }
.chk { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; cursor: pointer; }
.chk input { width: 22px; height: 22px; accent-color: var(--brand); }

/* 코드 입력 (코드 + ✕ + 🔍, 아래에 명칭) */
.codeinput .row { display: flex; gap: 6px; }
.codeinput input { flex: 1; font-weight: 700; letter-spacing: .3px; }
.codeinput .ghost { display: none; }
.codeinput.has-value .ghost { display: block; }
.code-name { min-height: 0; color: var(--brand-dark); font-weight: 700; font-size: .92rem; padding: 0 2px; }
.code-name:not(:empty) { margin-top: 4px; }

/* 수량 입력 (− 숫자 +) */
.qtyinput { display: flex; align-items: stretch; flex: 1; min-width: 0; }
.qtyinput .btn { border-radius: 0; font-size: 1.4rem; }
.qtyinput .btn:first-child { border-radius: 8px 0 0 8px; }
.qtyinput .btn:last-child { border-radius: 0 8px 8px 0; }
.qtyinput .qty { flex: 1; min-width: 56px; width: 0; height: var(--ctl-h); border: 1px solid var(--line-strong); border-left: 0; border-right: 0; text-align: center; font-weight: 800; font-size: 1.15rem; background: var(--req); }

/* 검색창 */
.searchbox { display: flex; gap: 8px; }
.searchbox input { flex: 1; }
.searchbox .btn { flex: none; min-width: 76px; }

/* ---------- 로그인 ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); }
.login-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 22px; box-shadow: 0 8px 28px rgba(15, 40, 60, .12); }
.login-logo img { width: 56px; height: 56px; display: block; margin-bottom: 12px; }
.login-card h1 { margin: 0 0 4px; font-size: 1.45rem; color: var(--brand-dark); }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: .92rem; }
.login-card > label:not(.chk) { display: block; margin: 14px 0 6px; font-weight: 700; }
.login-card input:not([type=checkbox]), .login-card select { width: 100%; height: var(--ctl-h); border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; background: #fff; }
.login-card .chk { margin-top: 6px; }
.login-card .btn { margin-top: 14px; font-size: 1.05rem; }
.login-note { margin-top: 14px; font-size: .8rem; color: var(--muted); }

/* ---------- 레이아웃 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  height: calc(var(--tb-h) + var(--safe-t)); padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(6px + var(--safe-l));
  background: var(--brand-dark); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topbar .back { font-size: 34px; line-height: 1; padding-bottom: 4px; }
.topbar .back[hidden] + .tb-title { padding-left: 8px; }
.tb-title { flex: 1; min-width: 0; font-size: 1.08rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 접속 환경 표시 : 운영은 차분하게, 개발은 눈에 띄게 (웹시스템과 같은 규칙) */
.env-badge { flex: none; padding: 3px 9px; border-radius: 12px; font-size: .75rem; font-weight: 800; white-space: nowrap; background: rgba(255,255,255,.18); color: #fff; }
.env-badge.env-DEV { background: #f59e0b; color: #1f2937; }
.wh-chip { flex: 0 1 auto; max-width: 38vw; min-height: 36px; padding: 0 10px; border: 1px solid rgba(255,255,255,.5); border-radius: 18px; background: transparent; color: #fff; font-size: .8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.main {
  max-width: 760px; margin: 0 auto;
  padding: var(--gap) calc(var(--gap) + var(--safe-r)) calc(24px + var(--safe-b)) calc(var(--gap) + var(--safe-l));
}

/* ---------- 홈 ---------- */
.user-card { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 3px rgba(15, 40, 60, .07); }
.uc-main { flex: 1; min-width: 0; }
.uc-name { font-size: 1.1rem; font-weight: 800; color: var(--brand-dark); }
.uc-name small { font-size: .8rem; color: var(--muted); font-weight: 600; }
.uc-sub { margin-top: 3px; font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.menu-group h3 { display: flex; align-items: center; gap: 6px; margin: 18px 2px 8px; font-size: .9rem; color: var(--brand-dark); letter-spacing: .5px; }
.menu-group h3::before { content: ""; width: 4px; height: 14px; border-radius: 2px; background: var(--brand); }
.tiles { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tile { display: flex; align-items: center; gap: 14px; min-height: 72px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; box-shadow: 0 1px 3px rgba(15, 40, 60, .07); }
.tile:active { background: var(--hover); border-color: var(--brand); }
.ti-icon { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; background: var(--brand-soft); font-size: 1.5rem; }
.ti-text { display: flex; flex-direction: column; min-width: 0; }
.ti-text b { font-size: 1.05rem; }
.ti-text small { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.tile::after { content: "›"; margin-left: auto; font-size: 1.6rem; color: var(--line-strong); }
.home .logout { margin-top: 24px; color: var(--muted); }

/* ---------- 화면 구역 ---------- */
.sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: var(--gap); box-shadow: 0 1px 3px rgba(15, 40, 60, .07); }
.sec-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sec-head h3 { margin: 0; font-size: .95rem; color: var(--brand-dark); }
.sec-head .right { margin-left: auto; display: flex; gap: 6px; }
.more { margin-top: 10px; }
.more summary { display: flex; align-items: center; min-height: 40px; color: var(--brand); font-weight: 700; cursor: pointer; list-style: none; font-size: .92rem; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "▾"; margin-left: 6px; transition: transform .15s; }
.more[open] summary::after { transform: rotate(180deg); }
.more-body { padding-top: 4px; }
.list-info { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 2px 4px 8px; font-size: .86rem; font-weight: 700; color: var(--muted); }
.list-info:empty { display: none; }
.list-info .sum { color: var(--brand-dark); }
.sec .list-info { margin: 0 0 8px; }

/* ---------- 카드 목록 ---------- */
.cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
.card { display: block; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 3px rgba(15, 40, 60, .07); min-width: 0; }
.sec .card { box-shadow: none; }
.card.tap, .card .c-tap { cursor: pointer; }
.card.tap:active, .card .c-tap:active { background: var(--hover); }
.card .c-tap { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 0; margin: 0; }
.card.picked { border-color: var(--sel-line); box-shadow: 0 0 0 2px var(--sel) inset; background: #fffdf3; }
.card.empty-loc { background: #f5f8fa; }
.c-head { display: flex; align-items: flex-start; gap: 10px; }
.c-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.c-title b { font-size: 1.02rem; overflow-wrap: anywhere; }
.c-title b.loc { font-size: 1.15rem; color: var(--brand-dark); letter-spacing: .3px; }
.c-title small, .c-prod small { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.c-qty { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 1.35rem; font-weight: 800; color: var(--brand-dark); line-height: 1.1; }
.c-qty small { font-size: .72rem; font-weight: 700; color: var(--muted); }
.c-qty.muted { font-size: .9rem; color: var(--muted); }
.c-prod { display: flex; flex-direction: column; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.c-sub { margin-top: 2px; color: var(--muted); font-size: .85rem; font-weight: 600; }
.c-kvs { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: .86rem; }
.kv { display: inline-flex; gap: 5px; min-width: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 700; overflow-wrap: anywhere; }
.kv.warn .v { color: var(--warn); }
.badges, .chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: .74rem; font-weight: 700; background: #eef2f5; color: #98a4af; }
.badge.on { background: var(--brand-soft); color: var(--brand-dark); }
.chip { padding: 3px 9px; border-radius: 12px; font-size: .78rem; font-weight: 700; background: #eef2f5; }
.chip.ok { background: #e3f4ea; color: var(--ok); }
.chip.warn { background: #fdf1dc; color: var(--warn); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.stat { display: flex; flex-direction: column; align-items: center; padding: 6px 2px; border-radius: 8px; background: #f2f6f8; min-width: 0; }
.stat span { font-size: .72rem; color: var(--muted); font-weight: 700; white-space: nowrap; }
.stat b { font-size: .98rem; overflow-wrap: anywhere; }
.stat.warn b { color: var(--warn); }
.c-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; margin-top: 10px; font-size: .78rem; color: var(--muted); }
.c-more { color: var(--brand); font-weight: 700; }
.card.open .c-more { color: var(--brand-dark); }
.c-move { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.c-move .lbl { flex: none; font-size: .82rem; font-weight: 700; color: var(--muted); }
.c-move > .btn { flex: none; padding: 0 12px; }
.c-locs { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.loc-head { font-size: .78rem; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.loc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "loc qty" "info qty"; gap: 0 10px; width: 100%; min-height: 52px; padding: 6px 8px; margin-top: 4px; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: #f8fafb; cursor: pointer; }
.loc-row:active { background: var(--hover); }
.lr-loc { grid-area: loc; min-width: 0; }
.lr-loc b { color: var(--brand-dark); margin-right: 6px; }
.lr-loc small { color: var(--muted); }
.lr-info { grid-area: info; font-size: .78rem; color: var(--muted); }
.lr-qty { grid-area: qty; align-self: center; font-weight: 800; font-size: 1.05rem; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: .92rem; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.c-locs .empty, .sec .empty { padding: 16px 8px; }
.more-btn { margin-top: 2px; }

/* ---------- 하단 고정 처리 바 (재고 이동 등) ---------- */
.screen.has-actionbar { padding-bottom: calc(76px + var(--safe-b)); }
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; gap: 10px;
  padding: 10px calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(15, 40, 60, .1);
}
.actionbar .ab-sum { flex: 1; min-width: 0; font-weight: 800; color: var(--brand-dark); font-size: .92rem; }
.actionbar .btn { flex: none; min-width: 120px; font-size: 1.05rem; }

/* ---------- 시트 (아래에서 올라오는 팝업) ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(15, 25, 35, .45); animation: fade .15s ease-out; }
.sheet { width: 100%; max-width: 760px; max-height: 85vh; max-height: 85dvh; display: flex; flex-direction: column; background: #fff; border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.25); animation: up .18s ease-out; }
.sheet.full { height: 92vh; height: 92dvh; max-height: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; background: var(--brand-dark); color: #fff; border-radius: 16px 16px 0 0; }
.sheet-head h3 { flex: 1; min-width: 0; margin: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 14px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 14px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
.sheet:not(:has(.sheet-foot)) .sheet-body { padding-bottom: calc(14px + var(--safe-b)); }
.confirm-msg { white-space: pre-line; line-height: 1.65; font-size: 1rem; padding: 4px 0 8px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sheet-body > .pick-list:first-child { margin-top: 0; }
.pick { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 10px; min-height: 52px; padding: 8px 12px; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.pick:active, .pick.active { background: var(--brand-soft); border-color: var(--brand); }
.pick b { color: var(--brand-dark); }
.pick em { margin-left: auto; font-style: normal; font-size: .8rem; color: var(--muted); }
.kv-list { display: flex; flex-direction: column; }
.kv-item { display: grid; grid-template-columns: minmax(96px, 38%) minmax(0, 1fr); gap: 10px; padding: 9px 2px; border-bottom: 1px solid #edf1f4; font-size: .92rem; }
.kv-k { color: var(--muted); font-weight: 700; overflow-wrap: anywhere; }
.kv-v { overflow-wrap: anywhere; font-weight: 600; }
.kv-v.num { font-weight: 800; }

/* ---------- 알림 ---------- */
#toast-area { position: fixed; left: 12px; right: 12px; bottom: calc(86px + var(--safe-b)); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { max-width: 520px; width: 100%; padding: 12px 14px; border-radius: 10px; color: #fff; background: #34495e; box-shadow: 0 4px 14px rgba(0,0,0,.25); line-height: 1.45; font-weight: 700; white-space: pre-line; pointer-events: auto; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); } .toast.warn { background: var(--warn); }

/* ---------- 작은 휴대폰 (폭 360px 미만) ---------- */
@media (max-width: 359px) {
  :root { --ctl-h: 44px; --gap: 8px; }
  .field-row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .env-badge { display: none; }
  .actionbar .btn { min-width: 100px; }
}
/* ---------- 넓은 화면 (가로 모드 · 폴더블 · 태블릿) : 카드 · 메뉴 2열 ---------- */
@media (min-width: 600px) {
  .tiles, .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards > .empty, .cards > .more-btn { grid-column: 1 / -1; }
  .sheet-back { align-items: center; padding: 16px; }
  .sheet { border-radius: 16px; max-height: 88vh; }
  .sheet.full { height: 86vh; }
  .sheet-foot { padding-bottom: 10px; }
  .actionbar { margin: 0 auto; max-width: 760px; border-radius: 14px 14px 0 0; }
}
/* 가로 모드로 높이가 낮을 때 : 상단바 낮춤 */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --tb-h: 46px; --ctl-h: 42px; }
}
