:root {
  --brand: #e5582a; --brand-dark: #c4441b; --accent: #f3e22e;
  --bg: #faf7f3; --card: #fff; --line: #e6dfd6; --text: #2a2420; --muted: #857a70;
  --ok: #2f8f4e; --warn: #b7791f; --info: #2b6cb0;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--card);
  border-bottom: 1px solid var(--line); }
.top img { height: 34px; }
.top .who { font-weight: 700; margin-left: auto; }
.top .who small { font-weight: 400; color: var(--muted); margin-right: 6px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 14px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: #b3261e; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 14px; }

.tabs { display: flex; gap: 2px; padding: 0 12px; background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto; position: sticky; top: 0; z-index: 5; }
.tabs button { border: 0; background: none; padding: 12px 12px; white-space: nowrap; color: var(--muted);
  border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 170px; }
main.wide { max-width: 1100px; }
h2 { font-size: 15px; margin: 22px 0 6px; color: var(--muted); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.datebar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.datebar .lbl { color: var(--muted); font-size: 14px; }
.datebar input[type=date] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; background: var(--card); }
.datebar .dow { font-weight: 700; font-size: 18px; }
.datebar .nav { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }

.banner { border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: #fff7e0; border: 1px solid #f0dfa8; font-size: 15px; }
.banner.ok { background: #eaf6ee; border-color: #bfe0c9; }
.banner.lock { background: #f1eeea; border-color: var(--line); }
.banner.err { background: #fdecea; border-color: #f3c1bc; }

.tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; align-items: center; }
.tools input[type=search], .tools select, .tools input[type=date] { border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: var(--card); min-width: 0; }
.tools input[type=search] { flex: 1 1 140px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip small { opacity: .8; margin-left: 4px; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); min-height: 56px; }
.row:first-child { border-top: 0; }
.row.on { background: #fff4ec; }
.row .nm { flex: 1; min-width: 0; font-weight: 600; }
.row .nm small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.step { display: flex; align-items: center; gap: 4px; }
.step button { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 20px; }
.step button.ten { width: 50px; font-size: 15px; font-weight: 700; color: var(--brand-dark); }
.step input { width: 64px; height: 42px; text-align: center; border: 1px solid var(--line); border-radius: 10px; font-weight: 700; background: var(--card); }
.row.on .step input { border-color: var(--brand); color: var(--brand-dark); }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }

.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-left: 6px;
  background: #eee9e2; color: var(--muted); vertical-align: 1px; }
.tag.s-submitted { background: #e3effb; color: var(--info); }
.tag.s-shipped { background: #fff0cf; color: var(--warn); }
.tag.s-received { background: #e2f3e7; color: var(--ok); }
.tag.s-none { background: #f1eeea; }

.foot { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); z-index: 6; }
.foot .in { max-width: 728px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.foot .cnt { flex: 1; color: var(--muted); }
.foot .cnt b { color: var(--text); font-size: 18px; }
.foot .btn { padding: 12px 22px; }

.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
thead th { border-top: 0; font-size: 13px; color: var(--muted); white-space: nowrap; background: #fbf9f6; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.tot { font-weight: 700; }
tr.cat td { background: #f6f2ec; font-size: 13px; font-weight: 700; color: var(--muted); padding: 5px 10px; }
td input[type=number], td input[type=text], td select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px;
  background: var(--card); width: 100%; min-width: 0; }
td input[type=number] { width: 84px; text-align: right; }
td select { min-width: 92px; }
td.diff input { border-color: var(--warn); background: #fff8e6; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.hist { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none;
  padding: 12px; border-top: 1px solid var(--line); }
.hist:first-child { border-top: 0; }
.hist b { min-width: 86px; }

.form { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.form input[type=text], .form input[type=time] { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); }
.form .days { display: flex; gap: 10px; flex-wrap: wrap; color: var(--text); }

.pick { max-width: 420px; margin: 8vh auto 0; padding: 0 16px; text-align: center; }
.pick img { width: 240px; max-width: 80%; }
.pick p { color: var(--muted); }
.pick .btn { display: block; width: 100%; padding: 14px; margin-top: 10px; font-size: 17px; font-weight: 600; }
.pick .note { font-size: 13px; margin-top: 18px; }

.sheet { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.sheet h1 { text-align: center; letter-spacing: .4em; margin: 0 0 14px; font-size: 24px; }
.sheet .meta { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 14px; }
.sheet .meta b { font-size: 16px; }
.sheet table th, .sheet table td { border: 1px solid #cfc7bc; font-size: 14px; }
.sheet .rem { color: var(--muted); font-size: 12px; }
.sheet tfoot td { font-weight: 700; background: #fbf9f6; }
.sheet .grand td { font-size: 16px; background: #fff4ec; }
.sheet .bank { margin-top: 12px; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #2a2420; color: #fff;
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
  max-width: 90vw; text-align: center; }
#toast.show { opacity: .95; }
#toast.err { background: #b3261e; }

@media (max-width: 520px) {
  .top img { height: 28px; }
  .sheet { padding: 12px; }
}
@media print {
  .noprint, .tabs, .top, .foot, #toast { display: none !important; }
  body { background: #fff; }
  main, main.wide { max-width: none; padding: 0; }
  .sheet, .tablewrap { border: 0; padding: 0; }
}

.chip .del { border: 0; background: none; color: var(--muted); padding: 0 0 0 6px; font-size: 13px; }
.chip .del:hover { color: #b3261e; }
details.banner summary { cursor: pointer; }
.foot .in { flex-wrap: wrap; }

.btn.pickbtn { white-space: nowrap; }
.btn.pickbtn.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }

/* 자동 발주 표: 품목 칸은 넓게, 숫자 칸은 내용만큼만 */
table.auto th, table.auto td { padding: 7px 6px; }
table.auto td:first-child { min-width: 150px; padding-left: 10px; }
table.auto td.n, table.auto th.n { width: 1%; }
table.auto td:last-child { width: 1%; padding-left: 4px; }
table.auto td input[type=number] { width: 68px; padding: 6px 6px; }
table.auto .note { color: var(--warn); }

/* 현황판 */
.flow { display: flex; align-items: stretch; gap: 6px; margin: 4px 0 12px; }
.flow .fstep { flex: 1 1 0; min-width: 0; display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; border-top: 4px solid var(--line); }
.flow .fstep.done { border-top-color: var(--ok); }
.flow .fstep.warn { border-top-color: #e0a526; }
.flow .fstep.act { border-top-color: var(--brand); background: #fff4ec; }
.flow .k { font-size: 13px; color: var(--muted); font-weight: 700; }
.flow .v { font-size: 22px; font-weight: 800; line-height: 1.3; }
.flow .v small { font-size: 13px; font-weight: 400; color: var(--muted); }
.flow .s { font-size: 13px; color: var(--muted); }
.flow .up { display: inline-block; margin-top: 6px; cursor: pointer; }
.flow .arrow { align-self: center; color: var(--muted); font-size: 20px; }
.lv { font-weight: 700; }
.lv.low { color: #b3261e; }
.lv.ok { color: var(--ok); }
table.board td .why { margin-top: 4px; width: 100%; min-width: 0; font-size: 13px; padding: 4px; }
table.board td input[type=number] { width: 74px; }
input[type=month] { border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; background: var(--card); }
@media (max-width: 560px) {
  .flow { flex-direction: column; }
  .flow .arrow { transform: rotate(90deg); align-self: center; line-height: 1; }
}

table.auto tr.cmt td { border-top: 0; padding-top: 0; padding-bottom: 10px; color: var(--muted); }

/* 손익계산서 */
.pnl h3 { margin: 18px 0 6px; font-size: 16px; display: flex; justify-content: space-between; gap: 10px; border-bottom: 2px solid var(--text); padding-bottom: 4px; }
.pnl h3 .sub { font-weight: 700; color: var(--brand-dark); font-size: 15px; }
.prow { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dotted var(--line); flex-wrap: wrap; }
.prow label, .prow .clabel { flex: 1 1 150px; min-width: 0; }
.prow input.amt { width: 150px; text-align: right; border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; background: var(--card); font-variant-numeric: tabular-nums; }
.prow .clabel { border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; background: var(--card); }
.prow .share { width: 52px; text-align: right; color: var(--muted); font-size: 13px; }
.prow .del { width: 52px; border: 0; background: none; color: var(--muted); }
.prow .sug { font-size: 12px; padding: 4px 8px; color: var(--info); }
.pnl textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; }
.pnl section > .btn { margin-top: 6px; }
.psum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.psum .tile { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fbf9f6; min-width: 0; }
.psum .tile .k { font-size: 12px; color: var(--muted); font-weight: 700; }
.psum .tile .v { font-size: 18px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.psum .tile .s { font-size: 12px; color: var(--muted); }
.psum .tile.pos .v { color: var(--ok); }
.psum .tile.neg .v { color: #b3261e; }
@media (max-width: 560px) { .psum { grid-template-columns: repeat(2, 1fr); } .prow input.amt { width: 120px; } }
@media print { .prow input, .pnl textarea { border: 0 !important; } .prow .sug, .prow .del { display: none; } }

/* 로그인 */
.form input[type=password] { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); }
.pick .form { margin-top: 12px; }
.pick .banner { text-align: left; }
@media (max-width: 520px) { .top .who small { display: none; } .top { gap: 6px; padding: 8px 10px; } }

a.btn { text-decoration: none; display: inline-block; }
a.btn, td .btn { white-space: nowrap; }

/* 본사: 역할 바꾸기 */
.viewas { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--card); font-size: 14px; max-width: 150px; }
.viewas.on { border-color: var(--brand); background: #fff4ec; color: var(--brand-dark); font-weight: 700; }
.top { flex-wrap: wrap; }

.form label.remember { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 15px; }
.form label.remember input { width: 18px; height: 18px; }

/* 선결제 장부 */
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; color: #fff; }
.badge.neg { background: #b3261e; }
.badge.low { background: #d9911a; }
.pp { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 12px; align-items: start; }
.ppside { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: auto; max-height: 72vh; position: sticky; top: 56px; }
.ppside h3 { margin: 0; padding: 9px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); background: #fbf9f6; position: sticky; top: 0; }
.ppitem { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; padding: 9px 12px; }
.ppitem:first-of-type { border-top: 0; }
.ppitem.on { background: #fff4ec; box-shadow: inset 3px 0 0 var(--brand); font-weight: 700; }
.ppitem .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ppitem .bal { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.ppitem.off { opacity: .5; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #c9c1b7; }
.dot.neg { background: #b3261e; } .dot.low { background: #d9911a; } .dot.ok { background: var(--ok); }
.tag.p-neg { background: #fdecea; color: #b3261e; } .tag.p-low { background: #fff0cf; color: var(--warn); } .tag.p-ok { background: #e2f3e7; color: var(--ok); }
.banner.low { background: #fff7e0; border-color: #f0dfa8; }
.banner .lnk { border: 0; background: none; padding: 0; text-decoration: underline; color: inherit; font-weight: 700; }
.pphead { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pphead h2 { margin: 0; font-size: 22px; color: var(--text); }
.pphead .big { margin-left: auto; text-align: right; }
.pphead .big b { font-size: 28px; font-variant-numeric: tabular-nums; }
.pphead .big.neg b { color: #b3261e; } .pphead .big.low b { color: var(--warn); } .pphead .big.ok b { color: var(--ok); }
.ppform { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 12px; }
.ppform input[type=text], .ppform input[type=date] { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--card); min-width: 0; }
.ppform .amt { width: 130px; text-align: right; font-weight: 700; }
.ppform .memo { flex: 1 1 140px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 8px 14px; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 700; }
.tacc { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.tacc .ttitle { text-align: center; font-weight: 800; padding: 9px; border-bottom: 3px solid var(--text); }
.tacc .tcols { display: grid; grid-template-columns: 1fr 1fr; }
.tacc .tcol + .tcol { border-left: 3px solid var(--text); }
.tacc .tcol h4 { margin: 0; padding: 7px 10px; font-size: 13px; color: var(--muted); background: #fbf9f6; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.tacc .te { display: flex; gap: 6px; align-items: baseline; padding: 6px 10px; border-bottom: 1px dotted var(--line); font-size: 14px; }
.tacc .te .d { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tacc .te .m { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tacc .te .a { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.tacc .te .x { border: 0; background: none; color: var(--muted); padding: 0 2px; font-size: 12px; }
.tacc .te.void { opacity: .45; text-decoration: line-through; }
.tacc .tnone { padding: 14px 10px; color: var(--muted); font-size: 13px; text-align: center; }
.tacc .tsum { display: grid; grid-template-columns: 1fr 1fr; border-top: 2px solid var(--text); font-weight: 800; }
.tacc .tsum div { padding: 8px 10px; text-align: right; font-variant-numeric: tabular-nums; }
.tacc .tsum div + div { border-left: 3px solid var(--text); }
.tacc .tbal { padding: 10px; text-align: right; border-top: 1px solid var(--line); background: #fbf9f6; }
tr.click { cursor: pointer; } tr.click:hover td { background: #fff9f4; }
@media (max-width: 620px) {
  .pp { grid-template-columns: 1fr; }
  .ppside { position: static; max-height: 210px; }
}
@media print { .ppside, .ppform { display: none; } .pp { display: block; } }
.tag { white-space: nowrap; }
