/* ══════════════════════════════════════════
   LGM System — 공통 스타일
   (변수, 리셋, 헤더, 푸터, 공유 컴포넌트)
   ══════════════════════════════════════════ */

/* ── RESET ── */
*, *::before, *::after {
    box-sizing: border-box; margin: 0; padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* ── DESIGN TOKENS ── */
:root {
    --bg: #F2F4F6;
    --surface: #FFFFFF;
    --surface2: #F9FAFB;
    --border: #E8ECEF;
    --border-hover: #C9D0DC;
    --text: #191F28;
    --text-dim: #B0B8C1;
    --text-mid: #8B95A1;
    --accent: #0064FF;
    --accent-dim: rgba(0, 100, 255, 0.08);
    --accent-glow: rgba(0, 100, 255, 0.16);
    --accent-dk: #0050CC;
    --error: #F04452;
    --error-bg: rgba(240, 68, 82, 0.06);
    --warn: #F5A623;
    --warn-bg: rgba(245, 166, 35, 0.08);
    --ok: #00B493;
    --ok-bg: rgba(0, 180, 147, 0.08);
    --blue: #3D80F5;
    --blue-bg: rgba(61, 128, 245, 0.08);
    --mono: 'DM Mono', 'Noto Sans KR', monospace;
    --sans: 'DM Mono', 'Noto Sans KR', monospace;
    --title-font: 'Noto Sans KR', sans-serif;
    --page-max-wide: 1520px;
    --page-gutter: 32px;
    --page-top: 36px;
    --app-font-size: 14px;
    --table-font-size: 12px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ── BASE ── */
/* overflow-y: scroll — 세로 스크롤바 자리를 항상 확보해, 탭/페이지 전환 시
   스크롤바 유무로 가운데 정렬 콘텐츠가 ~15px 좌우로 흔들리는 현상 방지
   (scrollbar-gutter:stable 보다 호환성·확실성 우위) */
html { font-size: 16px; color-scheme: light; overflow-y: scroll; }
body {
    background: var(--bg); color: var(--text);
    font-family: var(--mono); font-size: var(--app-font-size); -webkit-text-size-adjust: 100%;
}
button { font-family: var(--mono); }

/* ── 굵기 표준 (번짐 방지) ──
   본문 폰트(DM Mono / Noto Sans KR)는 500까지만 로드한다. 600·700을 요청하면
   브라우저가 가짜 굵기(faux-bold)를 합성해 글자가 번져 보이므로:
   ① 합성을 꺼 가장 가까운 실제 굵기로 렌더 ② 강조 표준 굵기를 500으로 고정.
   새 컴포넌트의 강조는 500을 쓴다(600·700 금지). (sms는 Pretendard 독립 — 영향 없음) */
* { font-synthesis-weight: none; }
b, strong { font-weight: 500; }

/* ── HEADER ── */
header {
    display: flex; align-items: center; justify-content: space-between; gap: 24px;
    padding: 0 32px; height: 56px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--surface); z-index: 100;
}
.app-header-left { display: flex; align-items: center; gap: 34px; min-width: 0; }
.app-header-right { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-left: auto; flex-shrink: 0; }
.logo { flex-shrink: 0; font-family: var(--mono); font-size: 12px; color: var(--text-mid); letter-spacing: 0.08em; text-decoration: none; }
.logo span { color: var(--accent); }
.header-nav { display: flex; gap: 4px; min-width: 0; }
.header-nav a {
    font-family: var(--mono); font-size: 11px; color: var(--text-mid);
    text-decoration: none; padding: 6px 12px; border-radius: 6px;
    letter-spacing: 0.06em; transition: color 0.15s, background 0.15s;
}
.header-nav a:hover { color: var(--text); background: var(--bg); }
.header-nav a.active { color: var(--accent); background: var(--accent-dim); font-weight: 500; }
.hamburger { display: none; flex-direction: column; gap: 5px; background: none; border: none; cursor: pointer; padding: 4px; }
.hamburger span { display: block; width: 20px; height: 1.5px; background: var(--text-mid); border-radius: 2px; transition: all 0.2s; }
.mobile-menu {
    display: none; flex-direction: column; padding: 12px 16px 16px;
    border-bottom: 1px solid var(--border); background: var(--surface); gap: 2px;
    position: fixed; top: 56px; left: 0; right: 0; z-index: 190; box-shadow: var(--shadow-md);
}
.mobile-menu.open { display: flex; }
.mobile-menu a {
    font-family: var(--mono); font-size: 13px; color: var(--text-mid);
    text-decoration: none; padding: 11px 14px; border-radius: 8px;
    letter-spacing: 0.04em; transition: color 0.15s, background 0.15s;
}
.mobile-menu a:hover { color: var(--text); background: var(--bg); }
.mobile-menu a.active { color: var(--accent); background: var(--accent-dim); font-weight: 500; }
@media (max-width: 640px) {
    header { padding: 0 16px; }
    .app-header-left { gap: 0; }
    .header-nav { display: none; }
    .hamburger { display: flex; }
}

/* ── FOOTER ── */
footer { padding: 20px 32px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--surface); }
.footer-left { font-family: var(--mono); font-size: 11px; color: var(--text-dim); letter-spacing: 0.05em; }
.footer-right { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── PAGE TITLE ── */
.page-title { margin-bottom: 40px; font-family: var(--title-font); }
.page-title .eyebrow {
    font-family: var(--title-font); font-size: 11px; color: var(--accent);
    letter-spacing: 0.12em; text-transform: uppercase; display: block; margin-bottom: 10px;
}
.page-title h1 { font-size: 2rem; font-weight: 500; letter-spacing: -0.02em; line-height: 1.28; color: var(--text); }
.page-title p { margin-top: 10px; font-size: 0.95rem; color: var(--text-mid); line-height: 1.7; }

/* ── PAGE LAYOUT ── */
.page-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.page-wrap {
    flex: 1;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 32px 20px 80px;
}
.page-wrap-center {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}
.page-wrap-narrow {
    max-width: 640px;
}
.page-wrap-wide {
    max-width: var(--page-max-wide);
    padding-left: var(--page-gutter);
    padding-right: var(--page-gutter);
}
.page-wrap .page-title {
    margin-bottom: 28px;
}

/* ── APP SHELL (하단탭 기반 페이지 공통) ── */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 100;
}
.nav-btn {
    flex: 1; display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 12px; font-weight: 500;
    letter-spacing: 0.04em; font-family: var(--mono); padding: 8px 0; transition: color 0.15s;
}
.nav-btn.active { color: var(--accent); }
.page { display: none; padding: 24px 16px 80px; max-width: 640px; margin: 0 auto; width: 100%; }
.page.active { display: block; }
@media (min-width: 641px) { .page { padding: 36px 32px 80px; max-width: 760px; } }
@media (min-width: 641px) {
    .page.page-wide,
    .page.app-wide {
        max-width: calc(var(--page-max-wide) + (var(--page-gutter) * 2));
        padding: var(--page-top) var(--page-gutter) 80px;
    }
}
.page > .page-title { margin-bottom: 24px; }
.page > main { max-width: 680px; width: 100%; margin: 0 auto; flex: none; }
.page.app-wide > main,
.page.page-wide > main {
    max-width: var(--page-max-wide);
}

/* ── SUB TABS ── */
.sub-tabs { display: flex; gap: 0; margin-bottom: 20px; border-bottom: 1.5px solid var(--border); }
.sub-tab {
    flex: 1; padding: 11px 0; background: none; border: none;
    font-size: 0.85rem; font-weight: 500; color: var(--text-dim); cursor: pointer;
    border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
    transition: all 0.15s; font-family: var(--mono);
}
.sub-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.sub-tab.hf-error-tab.active { color: var(--error); border-bottom-color: var(--error); }
.sub-tab.hf-error-tab { display: flex; align-items: center; justify-content: center; gap: 4px; }
.hf-error-badge {
    display: inline-block; min-width: 16px; padding: 0 5px;
    font-size: 0.7rem; line-height: 16px; font-weight: 500; text-align: center;
    color: #fff; background: var(--error); border-radius: 8px;
}

/* ── CARD ── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }

/* ── INPUTS ── */
input[type=text], input[type=date], input[type=number], select, textarea {
    width: 100%; padding: 14px 16px;
    border: 1.5px solid var(--border); border-radius: 10px;
    font-size: 1rem; background: var(--surface); color: var(--text);
    outline: none; -webkit-appearance: none;
    transition: border-color 0.15s, box-shadow 0.15s; font-family: var(--mono);
}
input[type=date] { padding-left: 16px; text-indent: 0; }
textarea { font-family: var(--mono); font-size: 0.875rem; resize: vertical; min-height: 140px; line-height: 1.8; }
input[type=text]:focus, input[type=date]:focus, input[type=number]:focus, select:focus, textarea:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input.upper { text-transform: uppercase; }
input.upper::placeholder { text-transform: none; color: var(--text-dim); }

/* ── BUTTONS ── */
.btn { padding: 14px 16px; border-radius: 10px; border: none; font-size: 1rem; font-weight: 500; cursor: pointer; transition: all 0.15s; font-family: var(--mono); }
.btn:active { transform: scale(0.97); }
.btn-accent { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.btn-accent:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn-outline { background: var(--surface); color: var(--text-mid); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--border-hover); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-mid); border: none; font-size: 0.9rem; }
.btn-full { width: 100%; display: block; text-align: center; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-primary {
    width: 100%; padding: 16px 24px; background: var(--accent); color: #fff;
    border: 1px solid var(--accent); border-radius: 10px; font-family: var(--mono);
    font-size: 1rem; font-weight: 500; cursor: pointer; transition: all 0.2s; margin-bottom: 32px;
}
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── SECTION LABEL ── */
.section-label {
    font-family: var(--mono); font-size: 11px; color: var(--text-mid);
    letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 8px; padding-left: 2px;
}
.input-label {
    font-family: var(--mono); font-size: 11px; color: var(--text-mid);
    letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 10px; padding-left: 2px;
}

/* ── BADGES ── */
.badge { font-family: var(--mono); font-size: 11px; font-weight: 500; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-low { background: var(--warn-bg); color: var(--warn); }
.badge-out { background: var(--error-bg); color: var(--error); }
.badge-scan { background: var(--accent); color: #fff; }
.text-accent { color: var(--accent); }
.text-error { color: var(--error); }
.text-mid { color: var(--text-mid); }
.text-strong { color: var(--text); }

/* ── FILTER BAR ── */
.filter-bar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; flex-wrap: wrap; border-bottom: 1px solid var(--border); background: var(--surface2); }
.filter-btn {
    font-size: 0.78rem; font-weight: 500; padding: 5px 12px; border-radius: 20px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-mid);
    cursor: pointer; font-family: var(--mono); transition: all 0.15s;
}
.filter-btn.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* ── STATES ── */
.empty-state { text-align: center; padding: 48px 0; color: var(--text-dim); font-size: 0.9rem; }
.error-card { background: var(--error-bg); border: 1px solid rgba(240, 68, 82, 0.15); border-radius: var(--radius); padding: 16px; text-align: center; color: var(--error); font-size: 0.875rem; margin-bottom: 12px; }
.loading { text-align: center; padding: 48px 0; color: var(--text-dim); font-size: 0.9rem; }
.spinner { display: inline-block; width: 24px; height: 24px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; margin-bottom: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ── */
.toast {
    position: fixed; bottom: calc(60px + 14px); left: 50%; transform: translateX(-50%);
    background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 24px;
    font-size: 0.875rem; font-weight: 500; opacity: 0; transition: opacity 0.2s;
    pointer-events: none; z-index: 999; white-space: nowrap; box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; }

/* ── MODAL ── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(25, 31, 40, 0.5); z-index: 200;
    align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal-box { background: var(--surface); border-radius: 16px; padding: 28px 24px; max-width: 480px; width: 100%; box-shadow: var(--shadow-md); }
.modal-icon { font-size: 1.5rem; margin-bottom: 14px; }
.modal-title { font-size: 1.05rem; font-weight: 500; margin-bottom: 10px; }
.modal-body { font-size: 0.9rem; color: var(--text-mid); line-height: 1.7; margin-bottom: 24px; }

/* ── COPY BUTTON ── */
.copy-btn { font-family: var(--mono); font-size: 0.75rem; font-weight: 500; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface2); color: var(--text-mid); cursor: pointer; transition: all 0.15s; }
.copy-btn.copied { background: var(--accent-dim); color: var(--accent); border-color: rgba(0, 100, 255, 0.3); }

/* ── PRODUCT ITEM (공통 상품 행, scanner·inventory 공유) ── */
.product-item { display: flex; align-items: flex-start; gap: 8px; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.product-item:last-child { border-bottom: none; }
.pi-info { flex: 1; min-width: 0; }
.pi-name { font-size: 0.78rem; font-weight: 500; color: var(--text); line-height: 1.4; word-break: keep-all; }
.pi-option { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-top: 2px; }
.pi-meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.pi-bc { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.pi-loc { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.pi-order { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.pi-right { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pi-qty { font-family: var(--mono); font-size: 0.88rem; font-weight: 500; }

/* ── PROGRESS ── */
.progress-wrap { background: var(--border); border-radius: 4px; height: 4px; overflow: hidden; margin-top: 10px; }
.progress-bar { height: 4px; background: var(--accent); border-radius: 4px; transition: width 0.3s; }

/* ── UTILITY ── */
/* 강제 숨김 유틸 — .btn-primary.btn-compact 등 2-class 셀렉터(우선순위 0,2,0)가
   display 를 덮어쓰는 걸 막기 위해 !important (편집모드 전용 버튼 등이 항상 보이던 버그 수정) */
.is-hidden { display: none !important; }

/* ── 작업 진행 모달 (LGMProgress) ── */
.lgm-prog-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: none; align-items: center; justify-content: center;
    padding: 20px;
    background: rgba(25, 31, 40, 0.45);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.lgm-prog-overlay.open { display: flex; }
.lgm-prog-box {
    width: 100%; max-width: 480px; max-height: 82vh;
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-md);
    overflow: hidden;
    animation: lgmProgIn 0.18s ease;
}
@keyframes lgmProgIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.lgm-prog-head {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.lgm-prog-title { font-family: var(--title-font); font-size: 15px; font-weight: 500; color: var(--text); flex: 1; }
.lgm-prog-x {
    border: none; background: transparent; color: var(--text-dim);
    font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 6px; line-height: 1;
}
.lgm-prog-x:hover { background: var(--surface2); color: var(--text); }

/* 진행 중 영역 */
.lgm-prog-working {
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    padding: 40px 24px;
}
.lgm-prog-spinner {
    width: 38px; height: 38px; border-radius: 50%;
    border: 3px solid var(--accent-dim); border-top-color: var(--accent);
    animation: lgmProgSpin 0.8s linear infinite;
}
@keyframes lgmProgSpin { to { transform: rotate(360deg); } }
.lgm-prog-status { font-size: 13px; color: var(--text-mid); text-align: center; line-height: 1.6; }
.lgm-prog-status strong { color: var(--text); }

/* 완료 영역 (기본 숨김 → is-done 시 표시) */
.lgm-prog-done { display: none; flex-direction: column; min-height: 0; padding: 16px 18px 4px; }
.lgm-prog-foot { display: none; padding: 14px 18px 18px; }
.lgm-prog-overlay.is-done .lgm-prog-working { display: none; }
.lgm-prog-overlay.is-done .lgm-prog-done { display: flex; }
.lgm-prog-overlay.is-done .lgm-prog-foot { display: flex; justify-content: flex-end; }
.lgm-prog-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.lgm-prog-summary:empty { display: none; }
.lgm-prog-list { overflow-y: auto; min-height: 0; }
.lgm-prog-close { margin-left: auto; }
.lgm-prog-errbox {
    background: var(--error-bg); color: var(--error);
    border: 1px solid var(--error); border-radius: 8px;
    padding: 12px 14px; font-size: 13px; line-height: 1.6; word-break: break-word;
}
