:root {
  --c: #1f4e79; --c2: #2e75b6; --bg: #f3f5f8; --line: #dde2e8; --text: #1d2733; --muted: #6b7785;
  --ok: #1e8e3e; --warn: #b26a00; --bad: #c62828; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
a { color: var(--c2); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.3; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }

/* 상단 · 하단 메뉴 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--c); color: #fff; }
.top a, .top .link { color: #fff; }
.brand { font-weight: 700; font-size: 1.05rem; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { padding: 4px 10px; border-radius: 6px; opacity: .85; }
.topnav a.on { background: rgba(255,255,255,.18); opacity: 1; }
.who { font-size: .9rem; opacity: .9; }
.link { background: none; border: 0; cursor: pointer; font: inherit; padding: 0; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; padding-bottom: 90px; }
.bottomnav { display: none; }

@media (max-width: 760px) {
  .topnav, .who { display: none; }
  .top { justify-content: space-between; }
  main { padding: 10px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: #fff;
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 0; color: var(--muted); font-size: .75rem; }
  .bottomnav a b { font-size: 1.3rem; font-weight: normal; }
  .bottomnav a.on { color: var(--c); }
}

/* 카드 · 버튼 · 입력 */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--c2); }
.btn.primary { background: var(--c); border-color: var(--c); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.big { padding: 14px 18px; font-size: 1.05rem; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd6ef; border-color: var(--c2); }
label { display: block; font-size: .85rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--text); font-size: 15px; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.chk { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--text); margin: 10px 0; }
.chk input { width: auto; margin: 0; }

/* 로그인 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }

/* 올리기 */
.up { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.staged { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.thumb { position: relative; width: 84px; height: 84px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #fafbfc; display: flex; align-items: center; justify-content: center; font-size: .75rem; text-align: center; padding: 2px; word-break: break-all; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1; }

/* 목록 */
.list { display: grid; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
.row:hover { border-color: var(--c2); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 600; white-space: nowrap; }
.mini { width: 46px; height: 46px; border-radius: 6px; object-fit: cover; background: #eef1f4; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: .7rem; color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; background: #eef2f7; color: var(--c); white-space: nowrap; }
.tag.ok { background: #e6f4ea; color: var(--ok); }
.tag.warn { background: #fff4e0; color: var(--warn); }
.tag.bad { background: #fdecea; color: var(--bad); }
.tag.off { background: #f1f3f5; color: #9aa4ae; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 99px; background: var(--c2); color: #fff; font-size: .8rem; text-align: center; }
.filters { display: grid; gap: 8px; grid-template-columns: 2fr 1fr 1fr; margin-bottom: 10px; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters .q { grid-column: 1 / -1; } }

/* 문서 확인 화면 */
.doc { display: grid; gap: 14px; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
.preview { position: sticky; top: 64px; }
.preview img { width: 100%; border-radius: 6px; border: 1px solid var(--line); display: block; margin-bottom: 8px; cursor: zoom-in; }
.preview iframe { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 6px; }
@media (max-width: 960px) {
  .doc { grid-template-columns: 1fr; }
  .preview { position: static; }
  .preview iframe { height: 60vh; }
}
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: .92rem; }
.alert.warn { background: #fff8e6; border: 1px solid #f3d38a; }
.alert.bad { background: #fdecea; border: 1px solid #f5b5ae; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.typesel { display: flex; flex-wrap: wrap; gap: 6px; }
.typesel label { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px;
  color: var(--text); font-size: .95rem; cursor: pointer; }
.typesel input { width: auto; margin: 0; }
.typesel label.on { background: var(--c); border-color: var(--c); color: #fff; }

/* 품목 */
.items { display: grid; gap: 6px; }
.item, .item-head { display: grid; gap: 4px; align-items: center;
  grid-template-columns: 96px minmax(120px, 2fr) minmax(70px, 1fr) 56px 64px 92px 104px 88px minmax(60px, 1fr) 30px; }
.item-head { font-size: .78rem; color: var(--muted); padding: 0 2px; }
.item input { padding: 6px; font-size: 14px; }
.item .num { text-align: right; }
.item .del { border: 0; background: none; color: var(--bad); cursor: pointer; font-size: 1.1rem; }
.item label { display: none; }
.items-wrap { overflow-x: auto; }
@media (max-width: 1100px) {
  .item-head { display: none; }
  .item { grid-template-columns: 1fr 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; padding: 8px; position: relative; }
  .item label { display: block; }
  .item .f-name { grid-column: 1 / -1; padding-right: 28px; }
  .item .f-note { grid-column: 1 / -1; }
  .item .del { position: absolute; top: 4px; right: 4px; }
}
.sumcheck { font-size: .88rem; margin-top: 6px; }

/* 거래 */
.slots { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.slot { border: 1px dashed var(--line); border-radius: 8px; padding: 10px; background: #fff; }
.slot.have { border-style: solid; border-color: #b7dfc3; background: #f6fbf7; }
.slot.need { border-color: #f1b8b2; background: #fff8f7; }
.slot h4 { margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; }
.slot .d { display: block; padding: 6px 0; border-top: 1px solid var(--line); color: var(--text); font-size: .9rem; }
.opt { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; color: var(--text); font-size: .95rem; }
.opt > input[type=radio] { width: auto; margin-top: 4px; }
.opt .grow { flex: 1; min-width: 0; }
table.cmp { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.cmp th, table.cmp td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
table.cmp th:first-child, table.cmp td:first-child { text-align: left; }
.diff { color: var(--bad); font-weight: 600; }

/* 기타 */
.spinner { width: 42px; height: 42px; margin: 10px auto 16px; border: 4px solid #dbe6f1; border-top-color: var(--c2); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 50; max-width: 90vw; }
#toast div { background: #263238; color: #fff; padding: 10px 16px; border-radius: 8px; margin-top: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
#toast div.bad { background: var(--bad); }
.actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 0 4px; display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 760px) { .actions { bottom: calc(58px + env(safe-area-inset-bottom)); } }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 100; overflow: auto; cursor: zoom-out; }
.lightbox img { display: block; max-width: none; width: 100%; }
@media (min-width: 900px) { .lightbox img { width: auto; max-width: 160%; margin: 0 auto; } }

/* 공급사 자동완성 */
label.acwrap { position: relative; }
.ac { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 280px; overflow: auto; margin-top: 2px; }
.ac button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; font: inherit; color: var(--text); cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.ac button:hover, .ac button:focus { background: #eef5fc; }
.ac .muted { font-size: .82rem; }
.supstate { font-size: .88rem; margin: 6px 0 2px; }
.newdeal { display: grid; gap: 8px; grid-template-columns: 2fr 2fr auto; margin-bottom: 12px; }
@media (max-width: 760px) { .newdeal { grid-template-columns: 1fr; } }
.bizimg { max-width: 100%; max-height: 420px; border: 1px solid var(--line); border-radius: 6px; display: block; margin: 6px 0; cursor: zoom-in; }

/* 매입·매출 */
.tag.buy { background: #e8f0fb; color: #1f4e79; }
.tag.sales { background: #fdf0e6; color: #b45309; }
.filters { grid-template-columns: 2fr 1fr 1fr 1fr; }
.newdeal { grid-template-columns: 2fr 1fr 2fr auto; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .newdeal { grid-template-columns: 1fr; } }

/* 관리자 */
.adminlink { padding: 4px 10px; border-radius: 6px; background: rgba(255,255,255,.16); white-space: nowrap; }
@media (max-width: 760px) { .adminlink { margin-left: auto; margin-right: 10px; } }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 14px; }
.kpi { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .sw { position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; }
.kl { font-size: .82rem; color: var(--muted); }
.kv { font-size: 1.45rem; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.ks { font-size: .78rem; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: .85rem; color: var(--text); margin-bottom: 4px; }
.legend i, .tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .ax { font-size: 11px; fill: #6b7785; }
.tip { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .85rem;
  box-shadow: 0 6px 16px rgba(0,0,0,.12); pointer-events: none; min-width: 150px; color: var(--text); }
.two { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.two .card { margin-bottom: 0; } .two { margin-bottom: 14px; }
.hbars { display: grid; gap: 6px; }
.hb { display: grid; grid-template-columns: minmax(80px, 1.3fr) 2fr auto; gap: 8px; align-items: center; font-size: .88rem; }
.hn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ht { background: #f1f3f6; border-radius: 4px; height: 14px; overflow: hidden; }
.hf { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.hv { white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats-f { grid-template-columns: 1fr 1fr 1fr 1.4fr; }
@media (max-width: 760px) { .stats-f { grid-template-columns: 1fr 1fr; } }

/* 수정 이력 */
details > summary { cursor: pointer; padding: 4px 0; }
.hist { display: grid; gap: 8px; margin-top: 8px; }
.hist .h { border-left: 3px solid var(--line); padding: 4px 0 4px 10px; }
.hist .hh { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hch, .hitems { margin: 4px 0 0; padding-left: 18px; font-size: .88rem; }
.hitems { font-size: .84rem; color: var(--muted); }
