:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1d2330; --muted: #6a7282; --line: #e1e4ea;
  --brand: #2f5d8a; --brand-2: #e8f0f8;
  --red: #c62828; --red-bg: #fdecec; --amber: #a86400; --amber-bg: #fff4dd; --green: #2e7d32; --green-bg: #e8f5e9;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Pretendard", "Malgun Gothic", system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.danger { background: var(--red); color: #fff; border-color: var(--red); }
button.big { padding: 14px 18px; font-size: 17px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; min-width: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--ink); font-size: 15px; }

header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; }
.scope { display: flex; align-items: center; gap: 6px; background: var(--brand-2); padding: 4px 6px 4px 10px; border-radius: 999px; flex-wrap: wrap; }
.scope-t { font-size: 13px; color: var(--brand); font-weight: 600; }
.scope b { color: var(--brand); }
.who.modeon { background: #fff4cc; color: #8a5a00; }
select.modeon { background: #fff4cc; border-color: #d9a400; font-weight: 600; }
.scope select { border-color: var(--brand); font-weight: 600; }
.spacer { flex: 1; }
.worker { display: flex; align-items: center; gap: 8px; }
.worker .who { background: var(--brand-2); color: var(--brand); padding: 6px 12px; border-radius: 999px; font-weight: 600; }
.worker .who.none { background: #eee; color: var(--muted); font-weight: 400; }
.worker .timer { color: var(--muted); font-size: 13px; }
.userbox { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }

nav { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
nav button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 14px; white-space: nowrap; }
nav button.on { border-bottom-color: var(--brand); color: var(--brand); font-weight: 700; }
nav .badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; margin-left: 4px; }

main { padding: 16px 24px; max-width: 1900px; margin: 0 auto; }  /* 12/1: 넓은 화면을 다 씀(옆으로 넘기지 않게) */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 160px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.stat { border-radius: 12px; padding: 14px; border: 1px solid var(--line); background: #fff; }
.stat b { display: block; font-size: 28px; }
.stat.red { background: var(--red-bg); color: var(--red); border-color: #f5c6c6; }
.stat.amber { background: var(--amber-bg); color: var(--amber); border-color: #f2dba8; }
.stat.blue { background: var(--brand-2); color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.note { background: var(--brand-2); color: var(--brand); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.warnbox { background: var(--amber-bg); color: var(--amber); padding: 10px 12px; border-radius: 8px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.cancelled td { color: #aaa; text-decoration: line-through; }
tr.batchrow td { background: var(--brand-2); }
tr.bchild td:first-child { padding-left: 14px; }
.tablewrap { overflow-x: auto; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.expired { background: var(--red); color: #fff; }
.pill.danger { background: var(--red-bg); color: var(--red); }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.none, .pill.gray { background: #eee; color: var(--muted); }
.pill.tt-in { background: var(--green-bg); color: var(--green); }
.pill.tt-out { background: var(--amber-bg); color: var(--amber); }
.pill.tt-cancel, .pill.tt- { background: #eee; color: var(--muted); }
.pill.tt-adjust { background: var(--brand-2); color: var(--brand); }
td.qty-in b { color: var(--green); }
td.qty-out b { color: var(--amber); }

.item-group { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.item-group > .head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: #fafbfc; gap: 8px; flex-wrap: wrap; }
.item-group > .head b { font-size: 16px; }
.item-group table td, .item-group table th { padding-left: 12px; }

.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 320px; overflow-y: auto; }
.pick button { text-align: left; padding: 12px; }
.pick button.sel { border-color: var(--brand); background: var(--brand-2); }
.pick button small { display: block; color: var(--muted); }

.modal { position: fixed; inset: 0; background: rgba(20, 25, 35, .45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; padding: 20px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.keypad button { font-size: 22px; padding: 14px 0; }
.pinview { font-size: 30px; letter-spacing: 12px; text-align: center; height: 44px; margin: 8px 0; }
.err { color: var(--red); min-height: 20px; font-size: 14px; margin-top: 6px; }
.leftafter { display: block; margin-top: 4px; color: var(--green); font-weight: 500; }
.leftafter .bad { color: var(--red); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #222; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 30; max-width: 90vw; }
.toast.bad { background: var(--red); }

.login-wrap { max-width: 440px; margin: 40px auto; }
.login-wrap .card { padding: 24px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.tabs2 { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs2 button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.right { text-align: right; }
.inline-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-actions button { padding: 4px 10px; font-size: 13px; }

@media (max-width: 640px) {
  main { padding: 10px; }
  .hide-sm { display: none; }
}
.mt { margin-top: 10px; }
header button { white-space: nowrap; }
.pinrow { display: flex; gap: 10px; align-items: flex-end; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.pinrow label { flex: 0 0 160px; }
.pin-input { font-size: 22px; letter-spacing: 8px; text-align: center; }
table.lines input, table.lines select { padding: 6px 8px; font-size: 14px; }
table.lines input.qty { width: 80px; }
table.lines td { vertical-align: middle; }
tr.warnrow td { background: var(--red-bg); }
details.excel { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; background: #fafbfc; }
details.excel summary { cursor: pointer; font-weight: 600; color: var(--brand); }
table.lines td:nth-child(2) { min-width: 150px; }
@media (max-width: 1000px) {
  table.lines tr:first-child { display: none; }
  table.lines, table.lines tbody { display: block; }
  table.lines tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
  table.lines td { display: block; border: 0; padding: 0; min-width: 0; }
  table.lines td[colspan] { grid-column: 1 / -1; }
  table.lines td:first-child { display: none; }
  table.lines td:nth-child(2) { grid-column: 1 / -1; }
  table.lines td[data-label]:not(:nth-child(2))::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
  table.lines select, table.lines input { width: 100%; }
}
button.stat { display: block; width: 100%; text-align: left; padding: 14px; }
button.stat:hover { filter: brightness(.97); }
/* 재고판 (2026-11-30) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip b { margin-left: 4px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip.hot:not(.on) { background: var(--red-bg); color: var(--red); border-color: #f5c6c6; }
button.link { border: 0; background: none; padding: 0; color: var(--ink); text-align: left; }
button.link:hover b { color: var(--brand); text-decoration: underline; }
.board td { vertical-align: middle; }
.board tr.open td { background: var(--brand-2); }
.board tr.detail td { background: #fafbfc; padding: 10px 12px 14px; }
.nowrap { flex-wrap: nowrap; white-space: nowrap; }
@media (max-width: 640px) {
  .board th:nth-child(3), .board td:nth-child(3) { display: none; }
  .board tr.detail td { display: table-cell; }
  .board .nowrap { flex-direction: column; gap: 4px; }
  .board .nowrap button { padding: 6px 0; width: 36px; font-size: 18px; }
  .board td:first-child { min-width: 120px; }
  .board th, .board td { padding: 8px 4px; }
  .card.board { padding: 8px; }
  .board td.num { white-space: normal; }
  .board td:first-child { min-width: 110px; }
}
tr.cancelled td b, tr.cancelled .pill { color: #aaa !important; background: #f3f3f3 !important; }
table.wide th, table.wide td { white-space: nowrap; }  /* 내역은 한 줄로 길게, 넘치면 가로 스크롤 */
#modalCard.wide { max-width: min(1100px, 96vw); width: 96vw; }
tr.batchrow { cursor: pointer; }
tr.batchrow:hover td { filter: brightness(0.97); }
.caret { display: inline-block; width: 1em; color: var(--brand); font-weight: 700; }
/* 전표 입력 모양 */
table.ledger { border-collapse: collapse; }
table.ledger th, table.ledger td { border: 1px solid var(--line); white-space: nowrap; }
table.ledger tr.blank td { height: 38px; background: #fafbfc; }
table.ledger input.itempick { width: 100%; min-width: 260px; }
table.ledger tr.sumrow td { background: #f3f5f8; font-weight: 700; }
/* 전표 입력: 넓게, 칸은 촘촘하게 */
table.ledger { width: 100%; }
table.ledger th, table.ledger td { padding: 6px 8px; }
table.ledger td:nth-child(2) { min-width: 0; }
table.ledger input.qty { width: 70px; }
table.ledger input[type=date] { width: 140px; }
table.ledger select { max-width: 170px; }
table.wide th, table.wide td { padding: 6px 7px; font-size: 14px; }
table.wide .pill { padding: 1px 6px; }
table.wide th, table.wide td { padding: 5px 6px; }
/* 12/1 표 정리: 글자 크기·줄 맞춤 통일 */
table.wide th, table.ledger th { text-align: center; vertical-align: middle; background: #f4f6f9; color: #4a5260; font-size: 13px; line-height: 1.3; }
table.wide td, table.ledger td { vertical-align: middle; font-size: 14px; line-height: 1.4; }
table.wide td.small, table.ledger td.small { font-size: 14px; }
table.wide td.num, table.ledger td.num { font-variant-numeric: tabular-nums; }
table.ledger input, table.ledger select { height: 34px; box-sizing: border-box; font-size: 14px; }
table.ledger input.itempick { width: 100%; min-width: 0; }
table.ledger td.rownum { width: 56px; text-align: center; color: var(--muted); white-space: nowrap; }
table.ledger button.x { margin-left: 6px; padding: 0 6px; height: 24px; font-size: 12px; color: var(--muted); }
table.ledger button.x:hover { color: var(--red); border-color: var(--red); }
table.ledger .leftafter { font-size: 12px; }
table.ledger tr.sumrow td { text-align: left; }
table.ledger tr.sumrow td.num { text-align: right; }
/* 12/1: 입력 칸이 칸 너비를 꽉 채우게(네모가 칸 안에 떠 보이지 않게) */
table.ledger td > input, table.ledger td > select { width: 100%; max-width: none; min-width: 90px; }
table.ledger td > input.qty { min-width: 70px; }
table.ledger td > input[type=date] { min-width: 130px; width: 100%; }
table.ledger td > input[data-f="procedure"] { min-width: 150px; }
table.ledger td > input[data-f="memo"], table.ledger td > input[data-f="customer"], table.ledger td > input[data-f="supplier"] { min-width: 120px; }
table.ledger td { padding: 5px 6px; }
table.ledger td > input.qty { width: 100%; text-align: right; }
/* 12/1: 칸 너비 고정(수량·단가가 쓸데없이 길어지지 않게). 남는 폭은 품목명·메모가 가짐 */
table.ledger.fixed { table-layout: fixed; min-width: 1200px; }
table.ledger.fixed td, table.ledger.fixed th { overflow: hidden; text-overflow: ellipsis; }
table.ledger.fixed td > input, table.ledger.fixed td > select { min-width: 0; }
table.ledger.fixed .leftafter { white-space: normal; }
/* 칸 너비(CSP 때문에 style 속성 대신 여기서). 12/1 반응형: 화면 폭에 비례(%)해서 늘고 줄어듦. 1000px 아래는 줄마다 카드 모양 */
table.ledger.fixed { width: 100%; min-width: 0; }
table.lg-in.cost col:nth-child(1) { width: 4%; }
table.lg-in.cost col:nth-child(2) { width: 16%; }
table.lg-in.cost col:nth-child(3) { width: 7%; }
table.lg-in.cost col:nth-child(4) { width: 8%; }
table.lg-in.cost col:nth-child(5) { width: 6%; }
table.lg-in.cost col:nth-child(6) { width: 10%; }
table.lg-in.cost col:nth-child(7) { width: 7%; }
table.lg-in.cost col:nth-child(8) { width: 8%; }
table.lg-in.cost col:nth-child(9) { width: 11%; }
table.lg-in.cost col:nth-child(10) { width: 12%; }
table.lg-in.cost col:nth-child(11) { width: 11%; }
table.lg-in:not(.cost) col:nth-child(1) { width: 5%; }
table.lg-in:not(.cost) col:nth-child(2) { width: 22%; }
table.lg-in:not(.cost) col:nth-child(3) { width: 9%; }
table.lg-in:not(.cost) col:nth-child(4) { width: 10%; }
table.lg-in:not(.cost) col:nth-child(5) { width: 8%; }
table.lg-in:not(.cost) col:nth-child(6) { width: 13%; }
table.lg-in:not(.cost) col:nth-child(7) { width: 16%; }
table.lg-in:not(.cost) col:nth-child(8) { width: 17%; }
table.lg-out col:nth-child(1) { width: 4%; }
table.lg-out col:nth-child(2) { width: 15%; }
table.lg-out col:nth-child(3) { width: 8%; }
table.lg-out col:nth-child(4) { width: 9%; }
table.lg-out col:nth-child(5) { width: 14%; }
table.lg-out col:nth-child(6) { width: 7%; }
table.lg-out col:nth-child(7) { width: 12%; }
table.lg-out col:nth-child(8) { width: 8%; }
table.lg-out col:nth-child(9) { width: 7%; }
table.lg-out col:nth-child(10) { width: 8%; }
table.lg-out col:nth-child(11) { width: 8%; }

/* 12/1 모든 표 통일: 내용 폭에 맞춤(화면 끝까지 늘리지 않음), 머리글 가운데·회색, 세로 가운데 */
@media (min-width: 641px) {
  /* 표는 화면 폭을 쓰되, 숫자·버튼 칸은 내용만큼(1%) 좁게, th.grow(품목명 등)가 남는 폭을 가짐 */
  .card table:not(.ledger) { width: 100%; min-width: 0; }
  /* 주 칸(th.grow)은 약 30%, 나머지 칸은 남는 폭을 고르게 나눔(넓은 모니터에서도 한 칸만 커지지 않게) */
  .card table:not(.ledger) th.grow { width: 30%; }
  .card table:not(.ledger) th:not(.grow) { min-width: 64px; }
  .card table:not(.ledger) td { font-size: 15px; }
  .card table:not(.ledger) th { font-size: 14px; }
  th { text-align: center; vertical-align: middle; background: #f4f6f9; color: #4a5260; font-size: 13px; white-space: nowrap; padding: 8px 12px; }
  td { vertical-align: middle; font-size: 14px; padding: 7px 12px; }
  td.small { font-size: 13px; }
  .card table:not(.ledger) td { white-space: nowrap; }
  .card table:not(.ledger) td.wrap { white-space: normal; max-width: 520px; }
  .board td:first-child { white-space: normal; min-width: 220px; }
}
/* 12/1 검색·필터 줄: 칸이 화면 폭만큼 늘어나지 않게(날짜 160, 선택 180, 글자 240) */
@media (min-width: 641px) {
  .row > label { flex: 0 0 auto; }
  .row > label > input[type=date] { width: 160px; }
  .row > label > select { width: 180px; }
  .row > label > input:not([type=date]):not([type=checkbox]) { width: 240px; }
  .row > button, .row > a > button { height: 40px; }
}
/* 표 칸(td)에 inline-actions 가 붙은 경우: 칸 모양을 유지하고 버튼은 한 줄로 */
td.inline-actions { display: table-cell; white-space: nowrap; }
td.inline-actions > * + * { margin-left: 6px; }
@media (min-width: 641px) { .card table.compact { width: auto; } }
td .inline-actions { flex-wrap: nowrap; }
td input.minq { width: 70px; }
table.ledger input.haslink::placeholder { color: var(--green); font-weight: 600; }
.otpkey { font: 600 20px/1.4 ui-monospace, Consolas, monospace; letter-spacing: 2px; background: #f4f6f9; border: 1px dashed var(--line); border-radius: 8px; padding: 12px; text-align: center; margin: 8px 0; word-break: break-all; }
