/* 디자인 교회 창고 및 재고 관리 — 모바일 우선 스타일 */
:root {
  --primary: #1e3a8a;
  --primary-d: #152a63;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --nav-h: 60px;
  --header-h: 52px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
}
.hidden { display: none !important; }

/* 헤더 */
#app-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--primary); color: #fff; display: flex; align-items: center;
  padding: 0 12px; z-index: 50; gap: 8px;
  padding-top: env(safe-area-inset-top);
}
#header-title { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-user { font-size: 12px; opacity: .9; }
.header-link { color: #fff; font-size: 13px; text-decoration: none; opacity: .95; padding: 4px 6px; white-space: nowrap; flex: 0 0 auto; }
.header-link:active { opacity: .7; }
.icon-btn { background: none; border: none; color: #fff; font-size: 28px; line-height: 1; padding: 0 6px; cursor: pointer; }

/* 메인 */
#view {
  padding: 14px;
  padding-top: calc(var(--header-h) + 14px + env(safe-area-inset-top));
  padding-bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; min-height: 100vh;
}
/* 인증 화면은 헤더/네비 없이 풀스크린 */
body.auth-mode #view { padding-top: 24px; }

/* 하단 네비 */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; z-index: 50; padding-bottom: env(safe-area-inset-bottom);
}
#bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px;
}
#bottom-nav a .ico { font-size: 20px; }
#bottom-nav a.active { color: var(--primary); font-weight: 600; }

/* 카드 */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.card.tappable:active { background: #fafafa; }

/* 통계 그리드 */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.alert .num { color: var(--danger); }

/* 리스트 아이템 */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: none; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; }
.list-item .li-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-item .li-right { text-align: right; white-space: nowrap; }

/* 뱃지 */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.qty { background: #eef2ff; color: var(--primary-d); }
.badge.low { background: #fef2f2; color: var(--danger); }
.badge.ok { background: #f0fdf4; color: var(--success); }
.badge.tag { background: #f3f4f6; color: #374151; margin-right: 4px; }
.badge.in { background: #f0fdf4; color: var(--success); }
.badge.out { background: #fef2f2; color: var(--danger); }
.badge.pending { background: #fffbeb; color: var(--warn); }
.badge.approved { background: #f0fdf4; color: var(--success); }
.badge.rejected { background: #f3f4f6; color: var(--muted); }
.badge.warn { background: #fffbeb; color: var(--warn); }       /* 유통기한 임박(주의) */
.badge.expired { background: #fef2f2; color: var(--danger); }  /* 유통기한 만료(경고) */
.list-item.exp-warn { border-left: 3px solid var(--warn); padding-left: 9px; }
.list-item.exp-expired { border-left: 3px solid var(--danger); padding-left: 9px; }
/* 재고 실사 */
.list-item.st-changed { border-left: 3px solid var(--warn); padding-left: 9px; }
.st-input-wrap { display: flex; align-items: center; gap: 6px; }
.st-input-wrap .st-input { width: 72px; text-align: center; }

/* 물품 상세페이지 재고량 강조 */
.qty-wrap { display: inline-flex; align-items: baseline; gap: 6px; }
.qty-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.qty-lg { display: inline-flex; align-items: baseline; gap: 4px; padding: 6px 16px; border-radius: 14px; font-size: 30px; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.qty-lg .unit { font-size: 15px; font-weight: 600; opacity: 0.85; }
.qty-lg.low { background: #fef2f2; color: var(--danger); }
.qty-lg.ok { background: #f0fdf4; color: var(--success); }

/* 폼 */
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; background: #fff; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input.input-invalid { border-color: var(--danger); background: #fff7f7; }
input.input-invalid:focus { border-color: var(--danger); }
.field-hint { margin-top: 4px; }
/* 휴대폰번호 010- 고정 접두어 */
.phone-field { display: flex; }
.phone-field input { flex: 1; min-width: 0; margin: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.phone-prefix { display: flex; align-items: center; padding: 0 12px; font-size: 16px; color: var(--text); background: #f3f4f6; border: 1px solid var(--border); border-right: none; border-radius: 10px 0 0 10px; white-space: nowrap; }
/* 비밀번호 표시/숨김 토글 */
.pw-field { position: relative; }
.pw-field input { padding-right: 46px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; padding: 0; margin: 0; border: none; background: none; font-size: 18px; line-height: 1; cursor: pointer; }
/* 폼 안내문 */
.form-intro {
  background: #eef2ff; border: 1px solid #dbe4ff; color: #334155;
  font-size: 12.5px; line-height: 1.55; padding: 10px 12px; border-radius: 10px; margin-bottom: 6px;
}
.field-desc { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 3px 0 2px; }
.btn {
  display: block; width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; margin-top: 16px; text-align: center; text-decoration: none;
  white-space: nowrap;
}
.btn:active { background: var(--primary-d); }
.btn.secondary { background: #f3f4f6; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.sm { width: auto; display: inline-block; padding: 8px 14px; font-size: 14px; margin: 0; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { margin-top: 0; }

/* 검색바 */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { margin: 0; }

/* 입출고 이력 필터 */
.filter-card { padding: 12px; }
.filter-card .chip-row { margin-top: 0; }
.filter-card .search-bar { margin-bottom: 0; }
.filter-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.filter-row input[type="date"] { margin: 0; flex: 1; min-width: 0; }
.filter-sep { flex: 0 0 auto; color: var(--muted); }

/* 인증 화면 */
.auth-wrap { max-width: 380px; margin: 8vh auto 0; padding: 0 8px; }
.auth-logo { text-align: center; font-size: 40px; margin-bottom: 8px; }
.auth-wrap h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.auth-wrap .sub { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 14px; }
.auth-switch a { color: var(--primary); font-weight: 600; text-decoration: none; }

/* 기타 */
.muted { color: var(--muted); }
.center { text-align: center; }
.spacer { height: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.err-text { color: var(--danger); font-size: 13px; margin-top: 8px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 20px 0 8px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.scan-box { aspect-ratio: 1; background: #000; border-radius: var(--radius); overflow: hidden; position: relative; margin-bottom: 12px; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; }
/* 스캔 인식 결과 목록 */
.scan-results { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.scan-hint { font-size: 13px; padding: 6px 0; }
.scan-result-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.scan-result-code { font-weight: 600; font-family: ui-monospace, monospace; word-break: break-all; }
.scan-result-row .btn.sm { flex: 0 0 auto; }

/* 통계: 탭 + 막대그래프 */
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; padding: 9px; border: 1px solid var(--border); background: #fff; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 200px; overflow-x: auto; padding-top: 6px; }
.bar-col { flex: 1 0 auto; min-width: 22px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-val { font-size: 11px; color: var(--muted); height: 15px; line-height: 15px; }
.bar-track { flex: 1; width: 70%; max-width: 30px; display: flex; align-items: flex-end; }
.bar-fill { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-fill.out { background: var(--danger); }
.bar-label { font-size: 10px; color: var(--muted); margin-top: 5px; white-space: nowrap; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: #fff; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
/* 링크로 동작하는 태그/필터 칩 (밑줄 제거, 클릭 가능 표시) */
a.badge.tag, a.chip { text-decoration: none; cursor: pointer; }
/* 토글 스위치 (on = 초록, off = 회색) + 현재 상태 텍스트 */
.switch-wrap { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.switch-state { font-size: 12px; color: var(--muted); min-width: 56px; text-align: right; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; cursor: pointer; transition: background .18s; }
.switch .slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s; }
.switch input:checked + .slider { background: #22c55e; }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(34,197,94,.35); }

/* 토스트 */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px;
  z-index: 100; max-width: 90%; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }

/* 모달 */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; display: flex; align-items: flex-end; }
.modal { position: relative; background: #fff; width: 100%; max-width: 640px; margin: 0 auto; border-radius: 18px 18px 0 0; padding: 20px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 12px; padding-right: 30px; }
/* 레이어팝업 닫기(X): 작고 눈에 거슬리지 않게 우상단 */
.modal-x { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; padding: 0; border: none; background: transparent; color: var(--muted); font-size: 19px; line-height: 30px; text-align: center; cursor: pointer; border-radius: 8px; }
.modal-x:hover { background: #f3f4f6; color: var(--text); }

@media (min-width: 480px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }

/* QR 라벨 시트 */
.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.qr-label {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 8px; text-align: center;
  background: #fff; break-inside: avoid; page-break-inside: avoid;
}
.qr-label .qr-img { display: flex; justify-content: center; align-items: center; aspect-ratio: 1; }
.qr-label .qr-img svg { width: 100%; height: auto; max-width: 150px; }
.qr-label .qr-code { font-weight: 700; font-size: 14px; margin-top: 6px; letter-spacing: .04em; }
.qr-label .qr-type { font-size: 11px; color: var(--muted); }
.qr-label .qr-title { font-size: 13px; font-weight: 600; margin-top: 2px; }
.qr-label .qr-sub { font-size: 11px; color: var(--muted); }
/* QR 라벨 선택 UI (화면 전용) */
.qr-label { position: relative; cursor: pointer; }
.qr-pick { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; padding: 0; margin: 0; z-index: 2; cursor: pointer; }
.qr-label.unselected { opacity: .35; }
/* QR 라벨 배치(위치 지정) 모드 */
.place-cell { min-height: 150px; }
.place-no { position: absolute; top: 4px; right: 6px; font-size: 11px; font-weight: 700; color: var(--muted); }
.place-cell.qr-blank { background: repeating-linear-gradient(45deg,#fafafa,#fafafa 6px,#f0f0f0 6px,#f0f0f0 12px); }
.cell-pick { margin-top: 6px; font-size: 13px; padding: 6px 8px; }
.qr-thumb svg { width: 56px; height: 56px; display: block; }
/* QR 라벨 문구 묶음 + 배치/문구표시 화면 미리보기 (인쇄는 qrprint.js 의 specCss 가 mm 단위로 처리) */
.qr-label .qr-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.qr-scr-id { position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; letter-spacing: .04em; color: var(--muted);
  background: #f3f4f6; border-radius: 4px; padding: 0 5px; display: none;
  max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; z-index: 2; }
/* 가로 배치: QR 왼쪽(고정) · 문구는 남은 폭 채움 → 행마다 QR 위치 동일 */
.qr-sheet.orient-h .qr-label { flex-direction: row; justify-content: flex-start; align-items: center; gap: 8px; text-align: left; }
.qr-sheet.orient-h .qr-img { width: 46%; flex: 0 0 auto; }
.qr-sheet.orient-h .qr-text { flex: 1 1 auto; text-align: left; }
/* 문구 비노출: QR만 크게 + 식별용 코드 칩 표시 */
.qr-sheet.no-text .qr-text { display: none; }
.qr-sheet.no-text .qr-img { width: 82%; }
.qr-sheet.no-text .qr-scr-id { display: block; }

/* 도움말 페이지 */
.help-sec { background: var(--card); border-radius: 12px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06); overflow: hidden; }
.help-sec > summary { padding: 14px 16px; font-weight: 600; cursor: pointer; list-style: none; font-size: 15px; }
.help-sec > summary::-webkit-details-marker { display: none; }
.help-sec > summary::after { content: '▾'; float: right; color: var(--muted); }
.help-sec[open] > summary::after { content: '▴'; }
.help-body { padding: 0 16px 14px; font-size: 14px; color: #374151; line-height: 1.6; }
.help-body ul { margin: 4px 0; padding-left: 18px; }
.help-body li { margin: 5px 0; }
.help-body p { margin: 8px 0; }
.help-body code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.help-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-table th, .help-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.help-table th { background: #f8fafc; }
.help-table th:nth-child(n+2), .help-table td:nth-child(n+2) { text-align: center; width: 64px; }

/* 인쇄 */
@media print {
  /* 라벨 규격(@page 여백·칸 크기·글자 크기)은 '라벨 인쇄' 화면에서 선택한 규격에 따라
     런타임으로 <style> 주입된다(public/js/views/qrprint.js). 여기에는 규격 무관 공통 규칙만 둔다. */
  #app-header, #bottom-nav, #toast, .no-print { display: none !important; }
  body { background: #fff; }
  #view { padding: 0 !important; max-width: none; }

  .qr-sheet { display: grid; gap: 0; justify-content: center; }
  .qr-label.unselected { display: none !important; }  /* 선택 안 한 라벨은 인쇄 제외 */
  .qr-label {
    box-sizing: border-box; border: none; border-radius: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    overflow: hidden; break-inside: avoid; page-break-inside: avoid;
  }
  .qr-label .qr-img { aspect-ratio: 1; }
  .qr-label .qr-img svg { width: 100%; height: 100%; max-width: none; }
  .qr-label.qr-blank { background: none !important; border: none !important; }  /* 빈칸은 아무것도 인쇄하지 않음 */
}
