* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "맑은 고딕", sans-serif; background: #f3f5f8; color: #1a1d24; }
body { padding-bottom: env(safe-area-inset-bottom); }

/* 로그인 오버레이 */
.overlay { position: fixed; inset: 0; background: linear-gradient(135deg, #0b5fff 0%, #4a8bff 100%); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100; }
.overlay.hidden { display: none; }
.login-card { background: #fff; border-radius: 20px; padding: 40px 28px; width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; }
.login-logo { font-size: 56px; margin-bottom: 8px; }
.login-card h1 { margin: 8px 0 4px; font-size: 22px; }
.login-sub { color: #6b7280; margin: 4px 0 24px; font-size: 14px; }
.btn-google { width: 100%; background: #0b5fff; color: #fff; border: none; padding: 14px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn-google:hover { background: #0a52e0; }
.btn-google:disabled { opacity: .6; cursor: wait; }
.btn-primary { width: 100%; background: #0b5fff; color: #fff; border: none; padding: 12px; border-radius: 10px; font-weight: 600; margin-top: 8px; cursor: pointer; }
.warn { color: #d97706; font-size: 13px; margin: 16px 0 8px; }
.hint { color: #6b7280; font-size: 11px; margin: 8px 0 0; line-height: 1.5; }
.login-card label { display: block; text-align: left; font-size: 12px; color: #6b7280; margin: 12px 0 4px; }
.login-card input[type=text] { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 13px; }
.error { color: #dc2626; font-size: 13px; margin-top: 12px; white-space: pre-wrap; }

/* 상단바 */
.topbar { position: sticky; top: 0; background: #0b5fff; color: #fff; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,.1); padding-top: calc(14px + env(safe-area-inset-top)); }
.topbar h1 { margin: 0; font-size: 18px; }
.icon-btn { background: rgba(255,255,255,.15); border: none; color: #fff; width: 36px; height: 36px; border-radius: 50%; font-size: 18px; cursor: pointer; }

/* 메인 */
.main { padding: 16px; padding-bottom: 80px; max-width: 600px; margin: 0 auto; }

/* 카드 */
.card { background: #fff; border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card-label { display: block; font-size: 13px; font-weight: 600; color: #6b7280; margin-bottom: 10px; }

/* 바코드 입력 */
.barcode-row { display: flex; gap: 8px; }
#barcode-input { flex: 1; padding: 14px; border: 2px solid #e5e7eb; border-radius: 10px; font-size: 16px; font-family: ui-monospace, monospace; }
#barcode-input:focus { border-color: #0b5fff; outline: none; }
.btn-icon { background: #f3f4f6; border: none; width: 52px; border-radius: 10px; font-size: 22px; cursor: pointer; }
.btn-icon:active { background: #e5e7eb; }
#scanner-area { margin-top: 12px; }
#qr-reader { width: 100%; }
#qr-reader video { border-radius: 10px; }
.btn-secondary { width: 100%; background: #6b7280; color: #fff; border: none; padding: 10px; border-radius: 10px; margin-top: 8px; cursor: pointer; }
.product-info { margin-top: 12px; padding: 12px; background: #f0f7ff; border-left: 3px solid #0b5fff; border-radius: 6px; }
.pi-row { display: flex; gap: 10px; padding: 4px 0; font-size: 14px; }
.pi-label { color: #6b7280; min-width: 44px; font-size: 12px; }
.pi-row span:last-child { flex: 1; word-break: keep-all; }

/* 수량 */
.qty-row { display: flex; gap: 6px; align-items: center; }
.qty-btn { flex: 0 0 auto; background: #f3f4f6; border: none; padding: 12px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; min-width: 48px; }
.qty-btn:active { background: #d1d5db; }
#qty-input { flex: 1; text-align: center; font-size: 22px; font-weight: 600; padding: 10px; border: 2px solid #e5e7eb; border-radius: 8px; min-width: 0; }
#qty-input:focus { border-color: #0b5fff; outline: none; }

/* 입출고 토글 */
.toggle-row { display: flex; gap: 8px; }
.toggle-btn { flex: 1; background: #f3f4f6; border: 2px solid transparent; padding: 14px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; color: #6b7280; }
.toggle-btn.active[data-type="입고"] { background: #ecfdf5; border-color: #10b981; color: #047857; }
.toggle-btn.active[data-type="출고"] { background: #fef2f2; border-color: #ef4444; color: #b91c1c; }

/* 사유 */
.reason-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reason-btn { background: #f3f4f6; border: 2px solid transparent; padding: 12px; border-radius: 10px; font-size: 14px; cursor: pointer; }
.reason-btn.active { background: #eff6ff; border-color: #0b5fff; color: #0b5fff; font-weight: 600; }
.reason-custom { width: 100%; margin-top: 10px; padding: 12px; border: 2px solid #0b5fff; border-radius: 8px; font-size: 15px; }
.reason-custom:focus { outline: none; box-shadow: 0 0 0 3px rgba(11,95,255,.15); }

/* 작업자 */
.worker-row { display: flex; gap: 8px; }
#worker-select, #worker-input { flex: 1; padding: 12px; border: 2px solid #e5e7eb; border-radius: 8px; font-size: 14px; min-width: 0; }
#worker-select:focus, #worker-input:focus { border-color: #0b5fff; outline: none; }

/* 저장 버튼 */
.btn-save { width: 100%; background: #0b5fff; color: #fff; border: none; padding: 18px; border-radius: 14px; font-size: 17px; font-weight: 700; cursor: pointer; margin: 8px 0; box-shadow: 0 4px 12px rgba(11,95,255,.3); }
.btn-save:active { background: #0a52e0; transform: translateY(1px); }
.btn-save:disabled { background: #9ca3af; box-shadow: none; cursor: not-allowed; }
.save-msg { text-align: center; font-size: 13px; margin: 4px 0 16px; min-height: 18px; }
.save-msg.ok { color: #047857; }
.save-msg.err { color: #dc2626; }

/* 최근 기록 */
.recent-list { list-style: none; padding: 0; margin: 0; }
.recent-item { padding: 10px 0; border-bottom: 1px solid #f3f4f6; font-size: 13px; }
.recent-item:last-child { border-bottom: none; }
.recent-meta { color: #6b7280; font-size: 11px; }
.recent-empty { color: #9ca3af; font-size: 13px; text-align: center; padding: 16px; }

/* 토스트 */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 12px 20px; border-radius: 24px; font-size: 14px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 90%; }

@media (min-width: 600px) { .main { padding: 24px; } }
