:root {
  --bg: #f4f6f9; --card: #fff; --line: #dfe3ea; --line2: #eef1f5;
  --ink: #1d2433; --sub: #5b6475; --mute: #8a92a3;
  --navy: #1f3a5f; --navy2: #2d5286; --accent: #2d6cdf;
  --in: #2d6cdf; --pack: #1f8a5b; --out: #d0661b;
  --red: #c62828; --orange: #e07a00; --yellow: #b58900; --green: #2e7d32; --gray: #7a8394;
  --r: 10px;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", sans-serif;
  font-size: 15px; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.boot { padding: 40px; text-align: center; color: var(--sub); }

/* ── 상단 ── */
header.top { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top); }
.top-row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; max-width: 1280px; margin: 0 auto; }
.top-row h1 { font-size: 17px; margin: 0; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { font-size: 13px; opacity: .9; white-space: nowrap; }
.who .role { background: rgba(255,255,255,.18); border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.top-row .btn-ghost { color: #fff; border-color: rgba(255,255,255,.4); }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; max-width: 1280px; margin: 0 auto;
  scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { color: #cfdbec; text-decoration: none; padding: 9px 12px 10px; white-space: nowrap; font-size: 14px;
  border-bottom: 3px solid transparent; }
nav.tabs a.on { color: #fff; border-bottom-color: #8fb8ff; font-weight: 700; }

main { max-width: 1280px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; color: var(--sub); }

/* ── 카드 · 폼 ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.grid .wide { grid-column: 1 / -1; }
.f label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.f .hint { font-size: 12px; color: var(--mute); margin-top: 3px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=search], select {
  width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input:focus, select:focus { outline: 2px solid #9cc0ff; outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; vertical-align: middle; }
.check { display: flex; align-items: center; gap: 6px; height: 40px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; height: 40px; }
.seg button { flex: 1; border: 0; background: #fff; cursor: pointer; font-weight: 600; color: var(--sub); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { color: #fff; background: var(--navy2); }
.seg button.on[data-v="입고"] { background: var(--in); }
.seg button.on[data-v="포장"] { background: var(--pack); }
.seg button.on[data-v="출고"] { background: var(--out); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.btn { height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--navy2); background: var(--navy2); color: #fff;
  font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--navy2); border: 1px solid var(--line); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; font-weight: 500; }
.btn-danger { background: transparent; color: var(--red); border-color: #f0c7c7; }
.info { background: #f5f8fd; border: 1px solid #e1e9f7; border-radius: 8px; padding: 10px 12px; font-size: 14px; color: var(--sub);
  line-height: 1.6; }
.info b { color: var(--ink); }
.warn { color: var(--red); font-weight: 600; }

/* ── 필터 · 표 ── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 10px; }
.filters .f { min-width: 130px; flex: 0 1 170px; }
.filters .f.grow { flex: 1 1 200px; }
.sum { font-size: 14px; color: var(--sub); margin: 6px 0 8px; }
.sum b { color: var(--ink); }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); background: #fff; max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line2); text-align: left; white-space: nowrap; }
th { background: #f0f3f8; color: var(--sub); font-weight: 600; font-size: 13px; position: sticky; top: 0; z-index: 1; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; background: #fafbfd; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9fc; }
tr.detail td { background: #fbfcfe; padding: 0 10px 10px 28px; }
tr.detail table { width: auto; margin-top: 6px; border: 1px solid var(--line2); }
tr.inactive td { color: var(--mute); }
td.neg { color: var(--red); font-weight: 600; }
.empty { padding: 24px; text-align: center; color: var(--mute); }
.kind { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; color: #fff; }
.kind.입고 { background: var(--in); } .kind.포장 { background: var(--pack); } .kind.출고 { background: var(--out); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 13px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; }
.badge.재고없음 { background: #fde2e2; color: var(--red); }
.badge.발주필요 { background: #ffe9cc; color: #a35400; }
.badge.발주검토 { background: #fff5c2; color: #7a5c00; }
.badge.정상 { background: #e3f3e5; color: var(--green); }
.badge.사용이력없음, .badge.최근사용없음 { background: #eceef2; color: var(--gray); }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; min-width: 110px; cursor: pointer; }
.stat.on { border-color: var(--navy2); box-shadow: inset 0 0 0 1px var(--navy2); }
.stat .k { font-size: 12px; color: var(--sub); }
.stat .v { font-size: 20px; font-weight: 700; }
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.subtabs button { border: 1px solid var(--line); background: #fff; border-radius: 18px; padding: 6px 14px; cursor: pointer; }
.subtabs button.on { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ── 로그인 ── */
.login { max-width: 380px; margin: 9vh auto; padding: 0 16px; }
.login .card { padding: 24px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login p { color: var(--sub); font-size: 14px; margin: 0 0 18px; line-height: 1.5; }
.login .f { margin-bottom: 12px; }
.login .btn { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px 0; font-size: 14px; }

/* ── 팝업 · 알림 ── */
.modal-bg { position: fixed; inset: 0; background: rgba(20,28,40,.45); z-index: 50; display: flex; align-items: flex-start;
  justify-content: center; overflow-y: auto; padding: 5vh 12px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; padding: 18px; }
.modal h2 { margin-top: 0; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: #263246; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 4px 14px rgba(0,0,0,.2); }
#toast div.err { background: var(--red); }

@media (max-width: 640px) {
  :root { font-size: 15px; }
  main { padding: 12px 10px 40px; }
  .card { padding: 12px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid .half-m { grid-column: auto; }
  .grid .full-m { grid-column: 1 / -1; }
  .who .name { display: none; }
  .filters .f { flex: 1 1 140px; }
  th, td { padding: 6px 8px; }
}
@media print {
  header.top, .filters, .actions, .card.form { display: none !important; }
  .tbl-wrap { max-height: none; overflow: visible; border: 0; }
}
