:root {
  --navy: #12263f;
  --navy2: #1b3556;
  --accent: #e8711a;
  --blue: #2563eb;
  --bg: #f3f5f8;
  --line: #dde3ea;
  --text: #1f2937;
  --muted: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea8a0c;
  --purple: #7c3aed;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Pretendard', 'Malgun Gothic', '맑은 고딕', -apple-system, sans-serif;
  font-size: 13px; color: var(--text); background: var(--bg);
  display: flex; overflow: hidden;
}
a { color: inherit; text-decoration: none; }

/* ---------- 사이드바 ---------- */
.side { width: 220px; background: var(--navy); color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand .logo { font-size: 22px; font-weight: 800; color: #fff; letter-spacing: 2px; }
.brand .logo::after { content: ''; display: inline-block; width: 8px; height: 8px; background: var(--accent); margin-left: 4px; border-radius: 2px; }
.brand .sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }
#menu { flex: 1; overflow-y: auto; padding: 8px 0; }
.m1 { display: block; padding: 10px 18px; font-weight: 600; color: #e2e8f0; cursor: pointer; user-select: none; }
.m1:hover { background: rgba(255,255,255,.05); }
.m1.on { background: var(--navy2); border-left: 3px solid var(--accent); padding-left: 15px; color: #fff; }
.m1.grp::after { content: '▸'; float: right; color: #64748b; transition: transform .15s; }
.m1.grp.open::after { transform: rotate(90deg); }
.m2 { display: none; padding-bottom: 4px; }
.m1.grp.open + .m2 { display: block; }
.m2 a { display: block; padding: 7px 18px 7px 40px; color: #94a3b8; font-size: 12.5px; }
.m2 a:hover { color: #fff; }
.m2 a.on { color: #fff; background: var(--navy2); border-left: 3px solid var(--accent); padding-left: 37px; }
.side-foot { padding: 12px 18px; font-size: 11px; color: #64748b; border-top: 1px solid rgba(255,255,255,.08); }

/* ---------- 메인 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top { height: 50px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; }
.crumb { color: var(--muted); }
.crumb span:last-child { color: var(--text); font-weight: 700; }
.crumb i { font-style: normal; margin: 0 8px; color: #cbd5e1; }
.top-right { display: flex; align-items: center; gap: 14px; color: var(--muted); }
.content { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 14px; gap: 12px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.panel h3 .sub { font-weight: 400; color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 14px; }
.row > * { flex: 1; min-width: 0; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols-3 { display: grid; grid-template-columns: 340px 1fr; gap: 14px; }

/* ---------- 버튼/입력 ---------- */
.btn { border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 6px; cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f8fafc; border-color: #c7d0db; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea { font: inherit; border: 1px solid #cfd6df; border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
input[type=number] { text-align: right; }
.form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.form.c3 { grid-template-columns: repeat(3, 1fr); }
.form.c4 { grid-template-columns: repeat(4, 1fr); }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form label.full { grid-column: 1 / -1; }
.form label.chk { flex-direction: row; align-items: center; gap: 6px; }
.req::after { content: ' *'; color: var(--red); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.filters label { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- 그리드 ---------- */
.grid-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.grid-search { width: 220px; }
.grid-count { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.grid-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 6px; max-height: 62vh; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
.grid th { position: sticky; top: 0; background: #f1f4f8; color: #475569; font-weight: 700; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; }
.grid td { padding: 7px 10px; border-bottom: 1px solid #eef1f5; white-space: nowrap; }
.grid tr.click { cursor: pointer; }
.grid tbody tr:hover td { background: #f8fbff; }
.grid tfoot td { background: #f8fafc; font-weight: 700; border-top: 2px solid var(--line); }
.grid .r { text-align: right; }
.grid .c { text-align: center; }
.grid td.empty { text-align: center; color: var(--muted); padding: 30px; }
.grid input, .grid select { padding: 3px 6px; }
.grid-pager { display: flex; gap: 4px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.pg { border: 1px solid var(--line); background: #fff; min-width: 28px; padding: 3px 6px; border-radius: 4px; cursor: pointer; }
.pg.on { background: var(--blue); color: #fff; border-color: var(--blue); }
table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { padding: 6px 8px; border-bottom: 1px solid #eef1f5; text-align: left; }
table.simple th { background: #f1f4f8; color: #475569; white-space: nowrap; }
table.simple .r { text-align: right; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 700; }
.b-gray { background: #eef1f5; color: #475569; }
.b-blue { background: #dbeafe; color: #1d4ed8; }
.b-green { background: #dcfce7; color: #15803d; }
.b-orange { background: #ffedd5; color: #c2410c; }
.b-red { background: #fee2e2; color: #b91c1c; }
.b-purple { background: #ede9fe; color: #6d28d9; }
.neg { color: var(--red); }
.pos { color: var(--green); }
.muted { color: var(--muted); }
.code { font-family: Consolas, monospace; font-size: 12px; color: #334155; }
.link { color: var(--blue); cursor: pointer; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---------- 대시보드 ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; cursor: pointer; }
.kpi:hover { border-color: var(--blue); }
.kpi .k { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 800; margin-top: 6px; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.kpi.alert .v { color: var(--red); }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding: 10px 4px 0; border-bottom: 1px solid var(--line); }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar .fill { width: 70%; background: linear-gradient(180deg, #3b82f6, #2563eb); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bar .val { font-size: 11px; font-weight: 700; margin-bottom: 3px; }
.bar-x { display: flex; gap: 10px; padding: 4px; }
.bar-x span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
.flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.flow .step { background: #f1f5f9; border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; font-weight: 700; cursor: pointer; }
.flow .step:hover { border-color: var(--blue); color: var(--blue); }
.flow .arr { color: #94a3b8; }

/* ---------- BOM / 로케이션 ---------- */
.list { border: 1px solid var(--line); border-radius: 6px; max-height: 66vh; overflow-y: auto; }
.list .li { padding: 9px 12px; border-bottom: 1px solid #eef1f5; cursor: pointer; }
.list .li:hover { background: #f8fbff; }
.list .li.on { background: #eff6ff; border-left: 3px solid var(--blue); }
.list .li .t { font-weight: 700; }
.list .li .s { color: var(--muted); font-size: 12px; }
.loc-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.loc-cell { border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; cursor: pointer; min-height: 62px; }
.loc-cell:hover { border-color: var(--blue); }
.loc-cell.on { outline: 2px solid var(--blue); }
.loc-cell .lc { font-weight: 700; font-family: Consolas, monospace; font-size: 12px; }
.loc-cell .ln { font-size: 11px; color: var(--muted); margin-top: 4px; }
.loc-cell.l1 { background: #eff6ff; }
.loc-cell.l2 { background: #dbeafe; }
.loc-cell.l3 { background: #bfdbfe; }
.loc-cell.empty { background: #fafafa; color: #9ca3af; }
.tree { font-size: 13px; }
.tree .node { padding: 5px 0 5px calc(var(--d) * 22px); border-bottom: 1px dashed #eef1f5; display: flex; gap: 8px; align-items: center; }
.tree .node .q { margin-left: auto; font-weight: 700; }

/* ---------- 모달 ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 50px 20px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 620px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: 1080px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; max-height: 72vh; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 6px; }
.modal-foot .left { margin-right: auto; }
.lines td input[type=number] { width: 90px; }
.info-grid { display: grid; grid-template-columns: repeat(4, auto 1fr); gap: 6px 12px; margin-bottom: 12px; font-size: 13px; }
.info-grid b { color: var(--muted); font-weight: 600; }
.note { background: #f8fafc; border: 1px solid var(--line); border-left: 3px solid var(--blue); padding: 10px 12px; border-radius: 6px; color: #475569; margin-bottom: 12px; }
.note.warn { border-left-color: var(--orange); background: #fffbeb; }
.note.err { border-left-color: var(--red); background: #fef2f2; }

.toast { position: fixed; right: 24px; bottom: 24px; background: #111827; color: #fff; padding: 12px 18px; border-radius: 8px; opacity: 0; transform: translateY(10px); transition: all .25s; z-index: 200; max-width: 480px; }
.toast.show { opacity: 1; transform: none; }
.toast.t-err { background: var(--red); }
.timeline { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 16px; }
.timeline .ev { position: relative; padding: 6px 0 10px; }
.timeline .ev::before { content: ''; position: absolute; left: -22px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.timeline .ev.ship::before { background: var(--red); }
.timeline .ev .d { color: var(--muted); font-size: 12px; }
.cols-3 > *, .cols-2 > * { min-width: 0; }
.x-scroll { overflow-x: auto; }
.lines td input[type=number].qty, .lines td input[type=number].sq { width: 72px; }

/* ---------- 2D/3D 전환 & 3D 뷰어 ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 14px; font: inherit; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--navy); color: #fff; }
.v3-wrap { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.v3 { width: 100%; height: 560px; cursor: grab; }
.v3 canvas { display: block; }
.v3-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.v3-legend { position: absolute; left: 10px; top: 10px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; display: flex; gap: 12px; font-size: 12px; }
.v3-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.v3-help { position: absolute; left: 10px; bottom: 10px; background: rgba(18,38,63,.85); color: #e2e8f0; border-radius: 6px; padding: 5px 10px; font-size: 11.5px; }
.v3-tip { position: absolute; display: none; pointer-events: none; background: #111827; color: #fff; padding: 7px 10px; border-radius: 6px; font-size: 12px; line-height: 1.5; max-width: 240px; z-index: 5; }
.v3-tip .muted { color: #9ca3af; }

/* ---------- QR 라벨 ---------- */
.lbl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.lbl-pick { display: flex; align-items: center; gap: 8px; cursor: pointer; border-radius: 8px; padding: 4px; }
.lbl-pick.on { background: #eff6ff; outline: 2px solid var(--blue); }
.lbl { flex: 1; display: flex; align-items: center; gap: 10px; border: 1px solid #94a3b8; border-radius: 6px; padding: 8px; background: #fff; min-width: 0; }
.lbl-qr img { width: 92px; height: 92px; image-rendering: pixelated; display: block; }
.lbl-txt { min-width: 0; flex: 1; }
.lbl-k { font-size: 10px; color: var(--muted); letter-spacing: 1px; }
.lbl-big { font-size: 16px; font-weight: 800; font-family: Consolas, monospace; margin: 2px 0; }
.lbl-s { font-size: 11.5px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 모바일 현장 ---------- */
.mob-layout { display: flex; gap: 20px; align-items: flex-start; }
.phone { width: 380px; height: 760px; background: #0f172a; border-radius: 44px; padding: 14px; position: relative; flex-shrink: 0; box-shadow: 0 20px 40px rgba(15,23,42,.25); }
.phone-notch { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: 120px; height: 24px; background: #0f172a; border-radius: 0 0 14px 14px; z-index: 2; }
.phone-screen { background: #f1f5f9; height: 100%; border-radius: 32px; overflow: hidden; display: flex; flex-direction: column; font-size: 14px; }
.m-head { display: flex; align-items: center; justify-content: space-between; background: var(--navy); color: #fff; padding: 34px 14px 12px; }
.m-head b { font-size: 15px; }
.m-back { background: none; border: 0; color: #fff; font-size: 26px; line-height: 1; cursor: pointer; width: 30px; text-align: left; }
.m-user { font-size: 11px; color: #94a3b8; }
.m-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.m-hello { color: var(--muted); font-size: 12px; }
.m-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.m-tile { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 8px; font: inherit; font-weight: 700; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.m-tile span { font-size: 28px; }
.m-tile.wide { grid-column: 1 / -1; flex-direction: row; justify-content: center; padding: 14px; }
.m-tile.wide span { font-size: 20px; }
.m-tile:active, .m-item:active { transform: scale(.98); }
.m-list { display: flex; flex-direction: column; gap: 6px; }
.m-list.small .m-row { padding: 6px 10px; font-size: 12px; }
.m-item { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.m-item span { color: var(--muted); font-size: 12px; }
.m-row { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; gap: 8px; align-items: center; }
.m-row span { flex: 1; color: #475569; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-row em { font-style: normal; font-weight: 700; }
.m-row.on { border-color: var(--blue); background: #eff6ff; }
.m-row.done { opacity: .55; }
.m-row.col { flex-direction: column; align-items: stretch; gap: 3px; }
.m-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.m-card.big { border: 2px solid var(--blue); }
.m-step { font-weight: 800; color: var(--blue); }
.m-loc { font-family: Consolas, monospace; font-size: 26px; font-weight: 800; color: var(--navy); }
.m-big { font-size: 18px; }
.m-qty input { width: 110px; font-size: 16px; padding: 6px; }
.m-btn { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 13px; font: inherit; font-weight: 800; font-size: 15px; cursor: pointer; margin-top: 4px; }
.m-btn:disabled { background: #cbd5e1; cursor: not-allowed; }
.m-scan { display: flex; gap: 10px; align-items: center; background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 12px; }
.m-scan-icon { font-size: 26px; width: 40px; height: 40px; border: 2px dashed #60a5fa; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #60a5fa; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.m-scan-t { font-weight: 800; font-size: 12px; color: #60a5fa; }
.m-scan-h { font-size: 13px; }
.m-msg { border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.m-msg.ok { background: #dcfce7; color: #166534; }
.m-msg.err { background: #fee2e2; color: #991b1b; animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.m-prog { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
.m-prog div { height: 100%; background: var(--green); }
.m-empty { text-align: center; color: var(--muted); padding: 30px 0; }
.sim { flex: 1; min-width: 0; }
.sim-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.sim-qr { display: flex; gap: 10px; align-items: center; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; font: inherit; }
.sim-qr:hover { border-color: var(--blue); background: #f8fbff; }
.sim-qr img { width: 72px; height: 72px; image-rendering: pixelated; }
@media (max-width: 760px) { .mob-layout { flex-direction: column; } .phone { width: 100%; height: 80vh; border-radius: 0; padding: 0; } .phone-screen { border-radius: 0; } }

/* ---------- 로그인 ---------- */
body.login-mode .side, body.login-mode .main { filter: blur(3px); pointer-events: none; }
#login { position: fixed; inset: 0; background: rgba(18,38,63,.55); display: flex; align-items: center; justify-content: center; z-index: 300; }
.login-card { background: #fff; border-radius: 14px; padding: 30px 32px; width: 340px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card .logo { font-size: 26px; font-weight: 800; letter-spacing: 2px; color: var(--navy); text-align: center; }
.login-card .logo span { color: var(--accent); }
.login-card .sub { text-align: center; color: var(--muted); margin-top: -8px; margin-bottom: 6px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.login-card input { padding: 10px; font-size: 14px; }
.login-card .btn { padding: 11px; font-size: 15px; }
.login-err { color: var(--red); font-size: 13px; }
