:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #e3e6ea;
  --line-2: #d0d5db;
  --text: #111827;
  --sub: #5b6470;
  --faint: #8a929c;
  --pri: #1f4fd8;
  --pri-bg: #eef3ff;
  --warn: #b45309;
  --warn-bg: #fff7e8;
  --bad: #c2261c;
  --bad-bg: #fdeeed;
  --ok: #157347;
  --ok-bg: #eaf6ef;
  --new: #fffbe6;
  --r: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 14px; line-height: 1.5;
  word-break: keep-all; overflow-wrap: anywhere;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1280px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 28px; height: 56px; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; color: var(--sub); font-weight: 600; white-space: nowrap; }
.tab:hover { background: var(--bg); }
.tab.on { color: var(--text); background: var(--bg); }
main { max-width: 1280px; margin: 0 auto; padding: 20px; }

.btn { border: 1px solid var(--line-2); background: var(--card); padding: 7px 12px; border-radius: 8px; font-weight: 600; white-space: nowrap; min-height: 36px; }
.btn:hover { background: var(--bg); }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: #1a43b8; }
.btn.sm { padding: 4px 9px; min-height: 30px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: none; color: var(--sub); }
.btn.ghost:hover { background: var(--bg); color: var(--text); }
.btn:disabled { opacity: .45; cursor: default; }

.guide { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin-bottom: 16px; }
.guide b { font-size: 15px; }
.guide p { margin: 2px 0 0; color: var(--sub); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat:hover { border-color: var(--line-2); }
.stat.on { border-color: var(--pri); background: var(--pri-bg); }
.stat .k { color: var(--sub); font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.bar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.search { flex: 1 1 260px; min-width: 0; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 12px; background: var(--card); min-height: 38px; }
.search:focus, .inp:focus, select:focus, textarea:focus { outline: 2px solid var(--pri); outline-offset: -1px; border-color: var(--pri); }
.count { color: var(--sub); font-size: 13px; }

.tbl-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; max-height: calc(100vh - 290px); min-height: 280px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: middle; }
th { position: sticky; top: 0; background: #fafbfc; font-weight: 600; color: var(--sub); font-size: 13px; z-index: 1; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #fafbfd; }
td.num { font-variant-numeric: tabular-nums; }
th.newcol, td.newcol { background: var(--new); }
tbody tr:hover td.newcol { background: #fff6cc; }
.muted { color: var(--faint); }
.biz { font-variant-numeric: tabular-nums; }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 999px; border: 1px solid transparent; margin-left: 6px; white-space: nowrap; }
.chip.warn { color: var(--warn); background: var(--warn-bg); border-color: #f5dfb5; }
.chip.bad { color: var(--bad); background: var(--bad-bg); border-color: #f4c9c5; }
.chip.ok { color: var(--ok); background: var(--ok-bg); border-color: #c4e5d2; }
.chip.info { color: var(--pri); background: var(--pri-bg); border-color: #cfdcff; }
.chip.gray { color: var(--sub); background: var(--bg); border-color: var(--line); }
.chip:first-child { margin-left: 0; }

.cards { display: none; }
.mo-only { display: none; }
.imp-cards { display: none; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: flex-end; background: rgba(17, 24, 39, .28); }
.drawer[hidden] { display: none; }
.panel { width: min(720px, 100%); height: 100%; background: var(--bg); overflow-y: auto; box-shadow: -8px 0 24px rgba(0,0,0,.08); }
.panel-head { position: sticky; top: 0; z-index: 2; background: var(--card); border-bottom: 1px solid var(--line); padding: 14px 20px; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head .sub { color: var(--sub); font-size: 13px; margin-top: 2px; }
.panel-body { padding: 16px 20px 40px; display: grid; gap: 12px; }
.sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.sec h3 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.sec h3 .h-l { display: flex; align-items: center; gap: 4px; }
.sec .note { color: var(--sub); font-size: 13px; margin: -4px 0 10px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.fld { display: grid; gap: 4px; min-width: 0; }
.fld.full { grid-column: 1 / -1; }
.fld label { font-size: 12px; color: var(--sub); font-weight: 600; }
.inp, select.inp, textarea.inp { width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; background: #fff; min-height: 36px; }
.fld.newcol .inp { background: var(--new); }
.docs { display: flex; flex-wrap: wrap; gap: 8px; }
.doc { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; background: #fff; user-select: none; }
.doc input { margin: 0; width: 16px; height: 16px; }
.doc.miss { border-color: #f4c9c5; background: var(--bad-bg); }
.regs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; }
.reg { display: flex; align-items: center; gap: 8px; padding: 4px 0; min-width: 0; }
.reg .nm { flex: 1; min-width: 0; }
.reg input[type=checkbox] { width: 16px; height: 16px; margin: 0; }
.reg input[type=date] { width: 140px; border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 6px; min-height: 30px; }
.grp-t { grid-column: 1 / -1; font-size: 12px; color: var(--sub); font-weight: 600; margin-top: 6px; }
.grp-t:first-child { margin-top: 0; }
.list { display: grid; gap: 0; }
.li { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .d { color: var(--sub); font-variant-numeric: tabular-nums; width: 88px; flex: none; }
.li .t { font-weight: 600; width: 92px; flex: none; }
.li .m { color: var(--sub); flex: 1; min-width: 0; }
.addrow { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.addrow .inp { flex: 1 1 120px; width: auto; }
.addrow .inp.date { flex: 0 0 150px; }
.hist { border: 1px dashed var(--line-2); border-radius: 8px; padding: 10px 12px; color: var(--sub); }
.hist + .hist { margin-top: 8px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* settings */
.set-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.set-col { display: grid; gap: 16px; }
.items { display: grid; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item:last-child { border-bottom: 0; }
.item .nm { flex: 1; min-width: 120px; font-weight: 600; }
.item .nm input { width: 100%; }
.item.hid .nm { color: var(--faint); font-weight: 500; text-decoration: line-through; }
.item .meta { color: var(--sub); font-size: 13px; }
.kind { display: inline-block; font-size: 12px; color: var(--sub); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }

/* import */
.imp-grid { display: grid; gap: 16px; }
.imp-grid > *, .set-col > *, .panel-body > * { min-width: 0; }
.samples { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.drop { border: 1px dashed var(--line-2); border-radius: var(--r); padding: 18px; text-align: center; color: var(--sub); background: #fff; }
.drop label { color: var(--pri); font-weight: 600; cursor: pointer; }
.map { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.map-i { display: grid; grid-template-columns: 7.5em 14px minmax(0, 1fr); align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; min-width: 0; }
.map-i .src { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-i .arrow { color: var(--faint); }
.map-i select { flex: 1; min-width: 0; border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 6px; min-height: 30px; background: #fff; }
.map-i.unk { border-color: #f5dfb5; background: var(--warn-bg); }
.kinds { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
td .diff { color: var(--warn); font-weight: 600; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(17, 24, 39, .35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.dlg { background: var(--card); border-radius: 12px; width: min(480px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px 20px; box-shadow: 0 12px 32px rgba(0,0,0,.18); }
.dlg h3 { margin: 0 0 4px; font-size: 17px; }
.dlg .note { color: var(--sub); margin: 0 0 14px; font-size: 13px; }
.dlg .fld { margin-bottom: 12px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line-2); border-radius: 999px; padding: 2px 4px 2px 10px; background: #fff; font-size: 13px; }
.opt button { border: 0; background: none; color: var(--faint); padding: 0 4px; font-size: 15px; line-height: 1; }
.seg { display: flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 7px 0; font-weight: 600; color: var(--sub); }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--pri-bg); color: var(--pri); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 80; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.print-area { display: none; }
@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; color: #000; font-size: 12pt; }
  .print-area h1 { text-align: center; font-size: 20pt; margin: 0 0 18pt; }
  .print-area table { width: 100%; border-collapse: collapse; }
  .print-area th, .print-area td { border: 1px solid #000; padding: 6pt 8pt; white-space: normal; position: static; background: none; color: #000; }
  .print-area th { width: 28%; }
  .print-area .sign { margin-top: 36pt; display: flex; justify-content: space-between; }
}

@media (max-width: 900px) {
  .set-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  main { padding: 14px 16px; }
  .top-in { padding: 0 16px; gap: 12px; height: auto; flex-direction: column; align-items: stretch; padding-top: 10px; }
  .brand { font-size: 15px; }
  .tabs { margin: 0 -4px; padding-bottom: 6px; }
  .guide { flex-direction: column; align-items: stretch; }
  .guide .btn { width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat .v { font-size: 19px; }
  .tbl-wrap.main-tbl { display: none; }
  .cards { display: grid; gap: 8px; }
  .mo-only { display: block; }
  .imp-tbl { display: none; }
  .imp-cards { display: grid; gap: 8px; }
  .icard { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: grid; gap: 4px; font-size: 13px; }
  .icard .nm { font-weight: 700; font-size: 14px; }
  .icard .diff { display: block; color: var(--warn); font-weight: 600; }
  .btn, .btn.sm, .fchip, .tab, .sm-sel { min-height: 44px; }
  .opt button { padding: 12px; }
  .item .nm { flex-basis: auto; }
  .top { position: static; }
  .reg input[type=date] { min-height: 40px; }
  .opt button { padding: 8px; }
  .reg { min-height: 44px; }
  .doc { min-height: 40px; }
  .mcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; text-align: left; width: 100%; }
  .mcard .r1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
  .mcard .nm { font-weight: 700; font-size: 15px; }
  .mcard .r2 { color: var(--sub); font-size: 13px; margin-top: 2px; }
  .mcard .r3 { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
  .mcard .r3 .chip { margin-left: 0; }
  .mcard .cx { margin-top: 8px; font-size: 13px; background: var(--new); border-radius: 6px; padding: 4px 8px; }
  .form, .regs { grid-template-columns: 1fr; }
  .panel-head { padding: 12px 16px; }
  .panel-body { padding: 12px 16px 40px; }
  .li { flex-wrap: wrap; gap: 2px 10px; }
  .li .m { flex-basis: 100%; }
  .addrow .inp.date { flex: 1 1 140px; }
}

/* 거르기 단추 */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.fchip { border: 1px solid var(--line-2); background: var(--card); border-radius: 999px; padding: 6px 12px; min-height: 36px; font-size: 14px; color: var(--sub); }
.fchip b { color: var(--text); font-variant-numeric: tabular-nums; margin-left: 2px; }
.fchip:hover { background: var(--bg); }
.fchip.on { border-color: var(--pri); color: var(--pri); background: var(--pri-bg); }
.fchip.on b { color: var(--pri); }
/* 정상 값은 칩 없이 */
.plain { color: var(--faint); font-size: 13px; }
/* 글자만 있는 단추는 링크처럼 */
.btn.ghost { color: var(--pri); text-decoration: underline; text-underline-offset: 2px; }
/* 키보드로 고른 줄 */
tbody tr:focus-visible td { background: var(--pri-bg); }
tbody tr:focus-visible { outline: 2px solid var(--pri); outline-offset: -2px; }
.btn:focus-visible, .fchip:focus-visible { outline: 2px solid var(--pri); outline-offset: 2px; }
/* 가맹점 화면 요약 줄과 접는 기본 정보 */
.panel-head .sum { margin-top: 6px; font-size: 13px; color: var(--sub); line-height: 1.8; }
.panel-head .sum .chip { margin-left: 2px; }
details.base > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; }
details.base > summary::-webkit-details-marker { display: none; }
details.base .base-sum { flex: 1; min-width: 0; font-size: 13px; font-weight: 400; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.base .base-open { font-size: 13px; color: var(--pri); text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }
details.base[open] .base-open { display: none; }
details.base[open] > summary { margin-bottom: 10px; }
.sm-sel { min-height: 30px; font-size: 13px; padding: 3px 8px; border-radius: 6px; }
@media (prefers-reduced-motion: no-preference) {
  .panel { animation: slidein .18s ease-out; }
  @keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}
.panel:focus { outline: none; }

.hist { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.reg input[type=date].off { opacity: .35; }
.mcard .r3 > span { font-size: 13px; color: var(--sub); }
.sec h3 .btn.ghost { padding-right: 0; font-size: 13px; }
.map-i select { width: 100%; }
td .sm-sel { display: block; margin-top: 6px; width: auto; max-width: 100%; }
.icard .sm-sel { width: 100%; }
.hist-t { flex: 1; min-width: 0; }
.hist-t b { white-space: nowrap; }
.item .btn.ghost { color: var(--sub); text-decoration: none; }
.item .btn.ghost:hover, .item .btn.ghost:focus-visible { color: var(--pri); text-decoration: underline; }
.note .btn.ghost { padding: 0; min-height: auto; vertical-align: baseline; }
.tab:focus-visible { outline: 2px solid var(--pri); outline-offset: 2px; }
.panel-head .sum > span { white-space: nowrap; }
.rules { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 2px; }
.nw { white-space: nowrap; }
