:root {
  --bg: #f5f6f8; --panel: #fff; --line: #e3e6eb; --text: #1f2430; --muted: #6b7280;
  --blue: #2563eb; --blue-soft: #e8efff; --green: #15803d; --green-soft: #e7f6ec;
  --red: #c62828; --red-soft: #fdecec; --amber: #b45309; --amber-soft: #fff4e0;
  --order: #2563eb; --inbound: #0f766e; --pack: #7c3aed;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Malgun Gothic", "Apple SD Gothic Neo", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
a { color: var(--blue); text-decoration: none; }

/* 레이아웃 */
.shell { display: grid; grid-template-columns: 196px 1fr; height: 100vh; }
.side { background: #1e293b; color: #cbd5e1; display: flex; flex-direction: column; }
.side .brand { padding: 18px 16px 14px; color: #fff; font-weight: 700; font-size: 15px; line-height: 1.3; }
.side .brand small { display: block; font-weight: 400; color: #94a3b8; font-size: 12px; }
.side nav a { display: block; padding: 9px 16px; color: #cbd5e1; border-left: 3px solid transparent; }
.side nav a:hover { background: #273449; color: #fff; }
.side nav a.on { background: #273449; color: #fff; border-left-color: #60a5fa; }
.side .foot { margin-top: auto; padding: 12px 16px; font-size: 12px; color: #94a3b8; border-top: 1px solid #334155; }
.side .foot button { background: none; border: 1px solid #475569; color: #cbd5e1; border-radius: 4px; padding: 2px 8px; cursor: pointer; margin: 6px 4px 0 0; }
.main { overflow: auto; padding: 14px 18px 12px; min-width: 0; }
h1 { font-size: 20px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; }

/* 공통 요소 */
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.bar .grow { flex: 1; }
input[type=text], input[type=search], input[type=date], input[type=month], input[type=number], input[type=password], select, textarea {
  border: 1px solid #cfd5dd; border-radius: 6px; padding: 6px 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93b4f7; border-color: var(--blue); }
.btn { border: 1px solid #cfd5dd; background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f8; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); border-color: #f0b4b4; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid #cfd5dd; border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 6px 11px; cursor: pointer; border-right: 1px solid #e5e7eb; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.tabs button.on { background: #1e293b; color: #fff; border-color: #1e293b; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .s { color: var(--muted); font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.pill.draft { background: var(--amber-soft); color: var(--amber); }
.pill.sent { background: var(--green-soft); color: var(--green); }
.pill.disc { background: #eceff3; color: #6b7280; }
.muted { color: var(--muted); }
.neg { color: var(--red); }
.warn { color: var(--amber); }
.ok { color: var(--green); }
.section { margin: 22px 0 10px; font-size: 15px; font-weight: 700; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* 표 */
.tablewrap { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: calc(100vh - 210px); }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.t th, table.t td { padding: 5px 8px; border-bottom: 1px solid #eef0f3; white-space: nowrap; }
table.t th { position: sticky; top: 0; background: #f8fafc; z-index: 2; text-align: left; font-weight: 600; color: #374151; border-bottom: 1px solid var(--line); font-size: 12px; }
table.t th.n, table.t td.n { text-align: right; font-variant-numeric: tabular-nums; }
table.t tbody tr:hover td { background: #f8fbff; }
table.t tr.disc td { color: #9ca3af; }
table.t tr.hl td { background: #fffbea; }
table.t td.prod { white-space: normal; min-width: 220px; max-width: 360px; }
table.t td.prod .m { font-weight: 600; }
table.t td.prod .d { color: var(--muted); font-size: 12px; }
table.t tfoot td { position: sticky; bottom: 0; background: #f8fafc; font-weight: 700; border-top: 1px solid var(--line); }
table.t td.in { padding: 2px 4px; }
table.t td.in input { width: 76px; text-align: right; padding: 4px 6px; border-radius: 4px; }
table.t td.in input.has { background: var(--blue-soft); border-color: #9db7f5; font-weight: 600; }
table.t td.in input.saving { background: #fff8db; }
table.t td.in input.saved { background: var(--green-soft); border-color: #86c79c; }
table.t td.in input.err { background: var(--red-soft); border-color: var(--red); }
table.t .rec { color: var(--blue); font-weight: 600; cursor: pointer; }
table.t .rec:hover { text-decoration: underline; }
.k-order { color: var(--order); } .k-inbound { color: var(--inbound); } .k-pack { color: var(--pack); }
table.grid th.day { text-align: center; border-left: 1px solid var(--line); }
table.grid td.d0 { border-left: 1px solid var(--line); }
table.grid th.sticky, table.grid td.sticky { position: sticky; left: 0; z-index: 1; background: #fff; }
table.grid th.sticky { z-index: 3; background: #f8fafc; }
.more { text-align: center; padding: 10px; }

/* 업로드 */
.drops { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.drop { border: 2px dashed #c3cbd6; border-radius: 10px; padding: 16px; background: #fff; cursor: pointer; transition: .15s; position: relative; min-height: 170px; display: flex; flex-direction: column; }
.drop:hover { border-color: var(--blue); }
.drop.over { border-color: var(--blue); background: var(--blue-soft); }
.drop.busy { opacity: .6; pointer-events: none; }
.drop .title { font-weight: 700; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.drop .tag { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.drop .hint { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }
.drop .last { margin-top: auto; background: #f8fafc; border-radius: 6px; padding: 8px 10px; font-size: 12.5px; }
.drop .last .fn { font-weight: 600; word-break: break-all; }
.drop .last .nums { display: flex; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.drop .last .nums b { font-size: 14px; }
.drop .last.fresh { background: var(--green-soft); }
.drop.all { grid-column: 1 / -1; min-height: 110px; align-items: center; justify-content: center; text-align: center; }
.drop.all .title { justify-content: center; }

/* 모달 / 토스트 */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 10px; padding: 20px; width: min(640px, 94vw); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
.form { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; align-items: center; }
.form label { color: #374151; font-size: 13px; }
.form input, .form select { width: 100%; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#toast div { background: #1e293b; color: #fff; padding: 9px 16px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 80vw; }
#toast div.err { background: var(--red); }

/* 로그인 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 340px; padding: 28px; }
.login h1 { margin-bottom: 18px; }
.login input { width: 100%; margin-bottom: 10px; padding: 9px 11px; }
.login .btn { width: 100%; padding: 9px; }

.legend { font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side nav { display: flex; flex-wrap: wrap; }
  .side .foot { margin: 0; border: 0; }
  .main { padding: 14px; }
}

/* 현황표 — 엑셀 '전 월 재고 / 현 월 총계 현황' 모양 */
table.status thead tr th { height: 30px; }
table.status thead tr.h1 th { top: 0; }
table.status thead tr.h2 th { top: 30px; }
table.status thead tr.h3 th { top: 60px; }
table.status thead tr.h4 th { top: 90px; }
table.status thead th.c { text-align: center; font-size: 13px; }
table.status thead tr.sub th { font-weight: 700; color: var(--text); font-size: 13px; }
table.status thead th.subl { color: var(--red); text-align: right; }
table.status thead th.red { color: var(--red); }
table.status .g-prev { background-color: #f3f7ec; }
table.status .g-month { background-color: #f5f2fa; }
table.status .g-ship { background-color: #fdf3ea; }
table.status thead th.g-prev { background: #e7f0d9; }
table.status thead th.g-month { background: #e9e2f4; }
table.status thead th.g-ship { background: #fbe6d4; }
table.status .dash { color: #c0c4cc; }
table.status .g-ord { background-color: #eef4ff; }
table.status thead th.g-ord { background: #dbe7fd; }
.fillbox { display: inline-flex; }
.fillbox select { border-radius: 6px 0 0 6px; border-right: 0; max-width: 170px; }
.fillbox .btn { border-radius: 0 6px 6px 0; }

/* 사용자 권한 / 작업 기록 */
label.perm { display: inline-flex; align-items: center; gap: 3px; margin: 2px 10px 2px 0; font-size: 12.5px; white-space: nowrap; }
table.users td { vertical-align: middle; }
.act { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: #eef1f5; white-space: nowrap; }
.act-login, .act-logout { background: #e8f0fe; color: #1d4ed8; }
.act-login_fail { background: var(--red-soft); color: var(--red); font-weight: 600; }
.act-entry, .act-fill { background: #eef4ff; color: var(--order); }
.act-po_send { background: var(--green-soft); color: var(--green); }
.act-po_reopen, .act-po_delete { background: var(--amber-soft); color: var(--amber); }
.act-user_add, .act-user_update, .act-settings, .act-password { background: #f3e8ff; color: #7c3aed; }

/* 작업 화면 넓게: 메뉴 접기 */
.shell { transition: grid-template-columns .15s; }
.shell.collapsed { grid-template-columns: 0 1fr; }
.shell.collapsed .side { overflow: hidden; }
.sideclose { float: right; background: none; border: 1px solid #475569; color: #cbd5e1; border-radius: 4px; cursor: pointer; padding: 0 7px; font-size: 14px; line-height: 20px; }
.sideclose:hover { background: #334155; color: #fff; }
.sideopen { display: none; position: fixed; left: 8px; bottom: 10px; z-index: 40; width: 34px; height: 34px; border-radius: 8px; border: 0; background: #1e293b; color: #fff; font-size: 16px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.shell.collapsed .sideopen { display: block; }
h1.inline { margin: 0 10px 0 0; font-size: 18px; }
.bar { margin-bottom: 8px; }
.tabs { margin-bottom: 8px; }

/* 줄 구분 명확하게 */
table.t tbody td { border-bottom: 1px solid #d3d9e1; }
table.t tbody tr:nth-child(even) td { background-color: #fafbfd; }
table.t tbody tr:hover td { background-color: #eef4ff; }
table.status tbody tr:nth-child(even) td.g-prev { background-color: #ecf2e3; }
table.status tbody tr:nth-child(even) td.g-month { background-color: #efebf6; }
table.status tbody tr:nth-child(even) td.g-ship { background-color: #f9ece0; }
table.status tbody tr:nth-child(even) td.g-ord { background-color: #e6eefc; }
/* 입력 중인 줄은 노랗게 */
table.t tbody tr:focus-within td { background-color: #fff3bf !important; }
table.t tbody tr:focus-within td.prod .m { color: #92400e; }
table.t td.in input:focus { outline: 2px solid #f59e0b; border-color: #f59e0b; background: #fff; }
table.t td.prod { padding-top: 6px; padding-bottom: 6px; }

/* 단가표 */
.btn.sm { padding: 2px 8px; font-size: 12px; }
table.ptable th, table.ptable td { padding: 3px 6px; }
table.ptable td.in input { width: 72px; padding: 3px 5px; }
table.ptable td.in input.w2 { width: 110px; }
table.ptable td.in input.w3 { width: 170px; }
table.ptable td.in input.tl, input.tl { text-align: left; }
table.ptable td.in select { padding: 3px 4px; max-width: 150px; font-size: 12.5px; }
table.ptable td.pcode { min-width: 250px; max-width: 300px; }
table.ptable td.pcode .m { font-size: 12px; color: var(--muted); font-weight: 500; }
table.ptable td.pcode input.pname { width: 100%; border: 1px solid transparent; background: transparent; padding: 1px 3px; font-weight: 600; border-radius: 4px; }
table.ptable td.pcode input.pname:hover { border-color: #cfd5dd; background: #fff; }
table.ptable td.pcode input.pname:focus { border-color: #f59e0b; background: #fff; outline: none; }
table.ptable td.sticky, table.ptable th.sticky { position: sticky; left: 0; z-index: 1; background: #fff; box-shadow: 1px 0 0 var(--line); }
table.ptable thead th.sticky { z-index: 3; background: #f8fafc; }
table.ptable tr.pg th { top: 0; text-align: center; font-size: 12px; }
table.ptable tr.ph th { top: 27px; font-size: 11.5px; white-space: normal; min-width: 64px; vertical-align: bottom; line-height: 1.25; }
table.ptable thead .pg-info { background: #f1f5f9; } table.ptable thead .pg-cny { background: #fff4d6; }
table.ptable thead .pg-box { background: #e7f0d9; } table.ptable thead .pg-tariff { background: #fde8e8; }
table.ptable thead .pg-pack { background: #e9e2f4; } table.ptable thead .pg-cost { background: #dbe7fd; }
table.ptable thead .pg-sales { background: #d9f2e3; } table.ptable thead .pg-whole { background: #fbe6d4; } table.ptable thead .pg-etc { background: #f1f5f9; }
table.ptable td.fixed { background-color: #f3e8ff !important; color: #6b21a8; cursor: pointer; box-shadow: inset 0 0 0 1px #c4b5fd; }
.fixed-swatch { display: inline-block; width: 12px; height: 12px; background: #f3e8ff; border: 1px solid #c4b5fd; vertical-align: -2px; }
table.ptable tr.flash td { background-color: #dcfce7 !important; transition: background-color .6s; }
.psgrid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr); gap: 12px; }
@media (max-width: 900px) { .psgrid { grid-template-columns: 1fr; } }
