:root {
  --bg: #f3f4f7;
  --card: #fff;
  --text: #1b1e24;
  --muted: #6b7280;
  --line: #e2e5ea;
  --brand: #1f4fd1;
  --brand-soft: #e8eefc;
  --out: #1f4fd1;
  --in: #c2410c;
  --ok: #15803d;
  --bad: #dc2626;
  --warn: #b45309;
  --r: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Pretendard', 'Noto Sans KR', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* 헤더 */
header.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
header.top h1 { margin: 0; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 8px; }
header.top h1 .logo { width: 24px; height: 24px; border-radius: 7px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 13px; }
header.top .who { font-size: 12px; color: var(--muted); }
.wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px 110px; }
.wrap.wide { max-width: 1200px; }

/* 콩깍지 (세그먼트 토글) */
.pods { display: flex; gap: 4px; padding: 4px; background: #e6e8ee; border-radius: 999px; margin-bottom: 10px; }
.pods button { flex: 1; border: 0; background: transparent; padding: 10px 6px; border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; }
.pods button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pods.type button.on[data-v="out"] { background: var(--out); color: #fff; }
.pods.type button.on[data-v="in"] { background: var(--in); color: #fff; }
.pods.lg button { padding: 13px 6px; font-size: 16px; }

/* 카드 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 6px; }
.card h2 .cnt { color: var(--brand); }
.card h2 .sp { flex: 1; }

/* 입력/버튼 */
.row { display: flex; gap: 8px; align-items: center; }
.row > input, .row > .grow { flex: 1; min-width: 0; }
input[type=text], input[type=password], input[type=email], input[type=search], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 5px; }
.btn { border: 0; border-radius: 10px; padding: 11px 14px; min-height: 44px; font-weight: 600; cursor: pointer; background: #eceef2; white-space: nowrap; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.outline { background: #fff; border: 1px solid var(--line); }
.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn-grid .btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 4px; }
.btn-grid .btn .ic { font-size: 22px; }

/* 로그인 */
.login { max-width: 380px; margin: 70px auto; padding: 0 16px; }
.login .brand { text-align: center; margin-bottom: 26px; }
.login .brand .logo { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 26px; }
.login h1 { margin: 0; font-size: 23px; }
.login p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

/* 품목 */
.item { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.item:last-child { border-bottom: 0; }
.item .body { flex: 1; min-width: 0; }
.item .model { font-weight: 600; word-break: break-all; }
.item .serial { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; color: #374151; }
.item .holder { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item .x { border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer; padding: 0 4px; }
.item input[type=checkbox] { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; vertical-align: middle; margin-left: 3px; }
.tag.usim { background: #f3e8ff; color: #7e22ce; }
.tag.dev { background: var(--brand-soft); color: var(--brand); }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.ok { background: #dcfce7; color: #166534; }
.tag.bad { background: #fee2e2; color: #991b1b; }
.tag.gray { background: #f1f2f4; color: #4b5563; }
.tag.out { background: var(--out); color: #fff; }
.tag.in { background: var(--in); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 22px 0; font-size: 14px; }

/* 자동완성 */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 40; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.1); max-height: 240px; overflow: auto; }
.ac-list div { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f1f2f4; }
.ac-list div:hover, .ac-list div.on { background: var(--brand-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 11px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip .n { opacity: .7; margin-left: 3px; }

/* 판매점 */
.store-opt { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; cursor: pointer; }
.store-opt:hover { border-color: var(--brand); }
.store-opt .addr { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chosen { padding: 12px; border-radius: 10px; background: var(--brand-soft); border: 1px solid #c7d5f8; display: flex; gap: 8px; align-items: center; }
.chosen .name { flex: 1; font-weight: 600; }
.chosen .addr { font-weight: 400; font-size: 12px; color: var(--muted); }

/* 하단 바 */
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; justify-content: center; }
.bottom-bar .inner { max-width: 528px; width: 100%; display: flex; gap: 10px; align-items: center; }
.bottom-bar .count { flex: 1; font-weight: 600; font-size: 14px; }

/* 모달 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal { align-items: center; } .modal .sheet { border-radius: 16px; } .modal .sheet.wide { max-width: 900px; } }
.modal h3 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; }
.modal h3 .sp { flex: 1; }
.modal .actions { display: flex; gap: 8px; margin-top: 14px; }
.modal .actions .btn { flex: 1; }
.cam { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4/3; width: 100%; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-box { position: absolute; left: 5%; right: 5%; top: 25%; height: 50%; border: 2px solid rgba(255,255,255,.85); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; transition: border-color .15s; }
.scan-box.hit { border-color: #22c55e; }
.cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: #ddd; font-size: 14px; white-space: pre-line; }
.scan-log { font-size: 13px; margin-top: 10px; max-height: 160px; overflow: auto; }
.scan-log > div { padding: 5px 0; border-bottom: 1px dashed #eee; display: flex; gap: 6px; align-items: center; }
.scan-log > div > span { flex: 1; }

/* 서명 */
.sign-box { border: 2px dashed #c9ced8; border-radius: 12px; background: #fcfcfd; height: 170px; position: relative; }
.sign-box canvas { width: 100%; height: 100%; display: block; }
.sign-box .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #b4bac5; pointer-events: none; font-size: 14px; }
.link-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; word-break: break-all; font-size: 13px; }

/* 전표관리 목록 */
.slip-card { padding: 12px 0; border-bottom: 1px solid var(--line); }
.slip-card:last-child { border-bottom: 0; }
.slip-card .l1 { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.slip-card .l1 .name { font-weight: 600; flex: 1; min-width: 120px; }
.slip-card .l2 { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.slip-card .l3 { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.mismatch { font-size: 12px; color: var(--bad); margin-top: 4px; }

/* ===== 전표 양식 ===== */
.slip-wrap { background: #e9ecf1; padding: 10px; border-radius: 12px; }
.slip { position: relative; background: #fff; color: #111; width: 100%; max-width: 440px; margin: 0 auto; padding: 16px 14px 12px; font-size: 12.5px; line-height: 1.45; border: 1px solid #d5d9e0; overflow: hidden; }
.slip-head { display: flex; align-items: center; justify-content: center; position: relative; border-bottom: 3px double #333; padding-bottom: 8px; }
.slip-title { font-size: 21px; font-weight: 800; letter-spacing: 2px; }
.slip-type { position: absolute; right: 0; top: 2px; font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 4px; color: #fff; }
.slip-type.out { background: var(--out); }
.slip-type.in { background: var(--in); }
.slip-meta { display: flex; justify-content: space-between; margin: 7px 0; font-size: 11.5px; color: #333; }
.slip table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.slip th, .slip td { border: 1px solid #555; padding: 4px 5px; vertical-align: middle; word-break: break-all; }
.slip th { background: #f2f4f7; font-weight: 600; width: 58px; font-size: 11.5px; text-align: center; }
.party { margin-bottom: 6px; }
.party th.vert { width: 24px; background: #e7ebf2; font-size: 12px; line-height: 1.35; }
.seal-cell { position: relative; }
.seal { position: absolute; right: -8px; top: 50%; width: 50px; height: 50px; transform: translateY(-50%) rotate(-8deg); object-fit: contain; pointer-events: none; }
.items-title { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 13.5px; margin: 10px 0 4px; }
.items-title span:last-child { font-weight: 600; font-size: 12px; }
.slip table.items th { width: auto; }
.slip table.items td.c { text-align: center; }
.slip table.items td.mono { font-size: 12px; }
.phrase { text-align: center; font-weight: 700; font-size: 13.5px; margin: 12px 0 8px; padding: 8px; border: 1px solid #333; background: #fafafa; }
.slip table.sign th { width: 100px; }
.slip table.sign td { height: 58px; }
.slip .sign-name { width: 90px; text-align: center; font-weight: 700; font-size: 14px; }
.slip .sign-img { text-align: center; }
.slip .sign-img img { max-height: 52px; max-width: 100%; }
.slip .sign-ph { color: #aaa; }
.slip-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: #555; }
.slip.voided .void-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%,-50%) rotate(-18deg); border: 5px solid rgba(220,38,38,.75); color: rgba(220,38,38,.75); font-size: 46px; font-weight: 900; padding: 4px 26px; letter-spacing: 10px; }

/* 아이폰 이미지 저장 */
.img-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 100; overflow: auto; padding: 60px 12px 20px; }
.img-overlay img { width: 100%; max-width: 480px; display: block; margin: 0 auto; }
.img-overlay-bar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #111; color: #fff; font-size: 14px; }
.img-overlay-bar span { flex: 1; }

/* 관리자 표 */
.tabs { display: flex; gap: 4px; background: #e6e8ee; padding: 4px; border-radius: 10px; margin: 12px 0; flex-wrap: wrap; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 8px; color: var(--muted); font-weight: 600; cursor: pointer; }
.tabs button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar select, .toolbar input { width: auto; padding: 8px 10px; }
.toolbar input[type=search] { min-width: 180px; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid th { background: #f8f9fb; font-weight: 600; position: sticky; top: 0; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: #f8faff; }
.map-grid { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: center; margin: 10px 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; align-items: end; }

#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .25s; z-index: 200; max-width: 90vw; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--bad); }
#toast.ok { background: var(--ok); }
.spinner { width: 28px; height: 28px; border: 3px solid #e5e7eb; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
