:root {
  --bg: #f4f6f9; --panel: #fff; --line: #e1e5eb; --text: #1d2433; --muted: #6b7385;
  --primary: #1f4e78; --primary-2: #2e6aa3; --orig: #595959;
  --s-short: #dbe9f8; --s-ok: #e2efda; --s-over: #fff2cc; --s-bad: #f8d3c1;
  --up: #1a7f37; --down: #c0392b;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Pretendard", "Malgun Gothic", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
header { background: var(--primary); color: #fff; padding: 0 24px; display: flex; align-items: center; gap: 24px; height: 52px; }
header h1 { margin: 0; font-size: 17px; white-space: nowrap; }
header nav { display: flex; gap: 4px; }
header nav a { color: #d6e2ef; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-size: 13.5px; }
header nav a.on, header nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
header .right { margin-left: auto; font-size: 12.5px; opacity: .8; }
header .userbox { display: flex; gap: 10px; align-items: center; font-size: 12.5px; opacity: .9; white-space: nowrap; }
header .userbox a { color: #d6e2ef; text-decoration: none; border: 1px solid rgba(255,255,255,.3); border-radius: 5px; padding: 3px 8px; font-size: 12px; }
header .userbox a:hover { background: rgba(255,255,255,.14); color: #fff; }
header .userbox .adm { color: #ffd166; font-weight: 700; }
.auth-wrap { min-height: calc(100vh - 52px); display: flex; align-items: center; justify-content: center; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px 32px; width: 380px; display: grid; gap: 14px; }
.auth-card h2 { margin: 0; font-size: 18px; }
.auth-card input { height: 40px; }
.auth-card .btn-primary { width: 100%; height: 42px; }
main { padding: 18px 24px; display: grid; gap: 14px; }
main > * { min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; }
.field { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
input[type=number], input[type=text], input[type=date], select { height: 36px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; font-size: 14px; width: 100%; background: #fff; color: var(--text); }
button { height: 36px; border: 0; border-radius: 6px; padding: 0 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { background: #9aa6b8; cursor: default; }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: var(--text); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-danger { border-color: #d9534f; color: #c00; background: #fff5f5; }
.btn-danger:hover { background: #ffe5e5; }
.error { color: var(--down); font-weight: 600; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.chip { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: #fff; display: grid; gap: 2px; min-width: 100px; }
.chip b { font-size: 18px; }
.chip small { color: var(--muted); font-size: 11px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar label { font-size: 13px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.toolbar input[type=text], .toolbar select, .toolbar input[type=number] { height: 32px; width: auto; }
.seg { display: inline-flex; }
.seg button { height: 32px; padding: 0 12px; background: #fff; border: 1px solid var(--line); border-radius: 0; font-weight: 500; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button + button { margin-left: -1px; }
.seg button.on { background: var(--primary); color: #fff; border-color: var(--primary); }

.grid-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 12.5px; width: max-content; min-width: 100%; }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); border-right: 1px solid #eef0f4; white-space: nowrap; }
.grid th { position: sticky; top: 0; z-index: 2; color: #fff; font-weight: 600; text-align: center; cursor: pointer; user-select: none; background: var(--primary); }
.grid th.orig { background: var(--orig); }
.grid th .arrow { opacity: .7; font-size: 10px; margin-left: 4px; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.grid td.sticky, .grid th.sticky { position: sticky; left: 0; z-index: 1; background: #fff; box-shadow: 1px 0 0 var(--line); }
.grid th.sticky { z-index: 3; background: var(--primary); }
.grid tr:hover td { background: #f7f9fc; }
.grid tr.open td { background: #eef4fb; }
.grid td.rec { font-weight: 700; background: #f3f8fd; }
.neg, .down { color: var(--down); font-weight: 700; }
.up { color: var(--up); font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-weight: 700; font-size: 12px; }
.s-품귀 { background: var(--s-short); } .s-적정 { background: var(--s-ok); }
.s-과다 { background: var(--s-over); } .s-심각 { background: var(--s-bad); } .s-보류 { background: #e9e5f5; } .s-잔량 { background: #e4e6ea; }
.tag-slow { background: #fde8e8; color: #a12222; }
.empty { padding: 50px; text-align: center; color: var(--muted); }
a { color: var(--primary-2); }

.loading { position: fixed; inset: 0; background: rgba(20,30,45,.45); display: none; align-items: center; justify-content: center; z-index: 10; }
.loading.show { display: flex; }
.loading .box { background: #fff; border-radius: 12px; padding: 26px 32px; text-align: center; display: grid; gap: 10px; min-width: 320px; }
.spinner { width: 36px; height: 36px; border: 4px solid #dfe6ef; border-top-color: var(--primary); border-radius: 50%; margin: 0 auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 스타일 상세(펼침) */
.detail { display: grid; grid-template-columns: 1.1fr 1fr 1.2fr; gap: 16px; padding: 10px 6px; white-space: normal;
          position: sticky; left: 0; width: calc(100vw - 100px); max-width: 1100px; }
.detail h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); }
.detail table { border-collapse: collapse; font-size: 12px; width: 100%; }
.detail th, .detail td { padding: 4px 8px; border-bottom: 1px solid #eef0f4; text-align: right; white-space: nowrap; }
.detail th { color: var(--muted); font-weight: 600; background: #f7f9fc; }
.detail th:first-child, .detail td:first-child { text-align: left; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 70px; border-bottom: 1px solid var(--line); padding-bottom: 2px; }
.bars div { flex: 1; background: var(--primary-2); min-height: 1px; border-radius: 2px 2px 0 0; }
.bars div.neg { background: var(--down); }
