:root {
  --bg: #faf7f2; --panel: #fff; --ink: #1f2328; --muted: #6b6f76; --line: #e6e0d6; --line2: #f1ece4;
  --brand: #b45309; --brand-ink: #fff; --brand-soft: #fef3c7;
  --red: #b91c1c; --red-soft: #fee2e2; --orange: #c2410c; --orange-soft: #ffedd5;
  --yellow: #a16207; --yellow-soft: #fef9c3; --green: #15803d; --green-soft: #dcfce7;
  --blue: #1d4ed8; --blue-soft: #dbeafe; --gray-soft: #f3f4f6;
  --radius: 10px; --tap: 44px;
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
.hidden { display: none !important; }
a { color: var(--brand); }
h2 { margin: 0 0 14px; font-size: 22px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
h2 small { font-size: 14px; color: var(--muted); font-weight: 500; }
h3 { margin: 0 0 10px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* 레이아웃 */
.app { display: flex; min-height: 100vh; }
.side { width: 208px; background: #2b2118; color: #f5ede3; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-head { padding: 18px 18px 12px; font-weight: 700; font-size: 17px; }
.side nav a { display: flex; align-items: center; gap: 8px; padding: 10px 18px; color: #e9dccd; text-decoration: none; font-size: 14.5px; min-height: 40px; }
.side nav a:hover { background: #3a2d21; }
.side nav a.active { background: var(--brand); color: #fff; }
.side nav .sep { height: 1px; background: #463729; margin: 6px 12px; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 8px 16px; }
.scan { flex: 1; max-width: 420px; }
.scan input { width: 100%; }
.who { display: flex; flex-direction: column; line-height: 1.15; font-size: 14px; }
.who small { color: var(--muted); font-size: 12px; }
.alert-pill { text-decoration: none; background: var(--gray-soft); color: var(--ink); padding: 6px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
.alert-pill.on { background: var(--red-soft); color: var(--red); }
.icon-btn { display: none; border: 0; background: none; font-size: 22px; min-width: var(--tap); min-height: var(--tap); cursor: pointer; }
main { padding: 20px; max-width: 1500px; width: 100%; }

/* 폼 요소 */
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid #d6cfc3; border-radius: 8px; background: #fff; min-height: var(--tap); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
input[type=checkbox] { min-height: auto; width: 20px; height: 20px; accent-color: var(--brand); }
textarea { min-height: 70px; width: 100%; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: #3d3f44; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 14px; align-items: end; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.req::after { content: ' *'; color: var(--red); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.filters label { font-size: 12.5px; }

.btn { font: inherit; font-weight: 600; border: 1px solid #d6cfc3; background: #fff; color: var(--ink); border-radius: 8px; padding: 9px 16px; min-height: var(--tap); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f7f3ec; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #9a4708; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.btn.xs { min-height: 30px; padding: 3px 8px; font-size: 12.5px; }
.btn.big { min-height: 52px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* 카드 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.error { border-color: var(--red); color: var(--red); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 .full { grid-column: 1 / -1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.warn { border-color: #fdba74; background: var(--orange-soft); }
.kpi.danger { border-color: #fca5a5; background: var(--red-soft); }
.bar-row { display: grid; grid-template-columns: 120px 1fr 90px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13.5px; }
.bar { height: 12px; background: var(--line2); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

/* 탭 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

/* 표 */
.table-tools { display: flex; justify-content: flex-end; gap: 6px; margin-bottom: 6px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line2); text-align: left; vertical-align: middle; }
th { background: #f7f3ec; font-weight: 700; position: sticky; top: 0; z-index: 1; white-space: nowrap; font-size: 12.5px; color: #4b4f55; }
tbody tr:hover { background: #fffbf3; }
tr.clickable { cursor: pointer; }
td.empty { text-align: center; color: var(--muted); padding: 24px; }
tr.total td { font-weight: 700; background: #f7f3ec; }
tr.sub td { background: #fcfaf6; }
td input { min-height: 36px; padding: 5px 8px; width: 110px; }

/* 일일 재고현황 (시트 스타일) */
.sheet th, .sheet td { border: 1px solid #e3ddd2; padding: 5px 7px; font-size: 13px; }
.sheet th.grp { text-align: center; background: #efe8dc; }
.sheet td.brand { font-weight: 700; background: #fffdf7; }
.sheet td.item { font-weight: 600; }
.sheet td.total-col { background: #fef9c3; font-weight: 700; }
.sheet td.zero { color: #c9c3b8; }
.sheet tr.item-start td { border-top: 2px solid #d9d1c3; }
.sheet .out { color: var(--blue); }
.sheet .in { color: var(--green); }

/* 배지 */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--gray-soft); color: #374151; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.lotlabel { font-family: ui-monospace, Consolas, monospace; font-weight: 700; }

/* 알림·결과 */
.notice { padding: 12px 14px; border-radius: 8px; background: var(--blue-soft); color: #1e3a8a; margin: 10px 0; }
.notice.warn { background: var(--orange-soft); color: #7c2d12; }
.notice.ok { background: var(--green-soft); color: #14532d; }
.notice.err { background: var(--red-soft); color: #7f1d1d; }

/* 모달 */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 14, 8, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 980px; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 600; }

/* 추적 트리 */
.tree, .tree ul { list-style: none; margin: 0; padding-left: 20px; }
.tree { padding-left: 0; }
.tree li { position: relative; padding: 4px 0 4px 14px; border-left: 2px solid var(--line); }
.tree .node { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13.5px; }
.tree .ship { color: var(--blue); font-size: 13px; }

/* 토스트 */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2328; color: #fff; padding: 12px 16px; border-radius: 8px; max-width: 420px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 14px; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }

/* 로그인 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; margin: 0; text-align: center; }
.brand-mark { font-size: 40px; text-align: center; }
.loading { color: var(--muted); padding: 30px; }

/* 반응형 */
@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .side { position: fixed; left: -230px; z-index: 40; transition: left .2s; }
  .side.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .icon-btn { display: block; }
  .who { display: none; }
  main { padding: 14px 16px; }
  .form-grid .wide { grid-column: auto; }
}
@media (max-width: 560px) {
  .top { flex-wrap: wrap; }
  .scan { order: 5; max-width: none; flex-basis: 100%; }
  dl.kv { grid-template-columns: 100px 1fr; }
}
@media print {
  .side, .top, .table-tools, .filters, .tabs, .no-print, .btn { display: none !important; }
  main { padding: 0; max-width: none; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
  .card { border: 0; padding: 0; }
  body { background: #fff; }
  .sheet th, .sheet td { font-size: 10.5px; padding: 3px 4px; }
}
