:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #5f6672;
  --line: #e3e6eb;
  --brand: #1f4fd6;
  --brand-ink: #ffffff;
  --brand-soft: #eaf0ff;
  --warn-bg: #fff6e5;
  --warn-ink: #8a5a00;
  --err: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1a1d23;
    --ink: #eceef2;
    --muted: #a0a7b3;
    --line: #2c313a;
    --brand: #6b8cff;
    --brand-ink: #0b0d12;
    --brand-soft: #1e2740;
    --warn-bg: #3a2e14;
    --warn-ink: #f3c56b;
    --err: #ff7b7b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Pretendard, -apple-system, "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-inner { display: flex; justify-content: space-between; align-items: center; height: 56px; }
.brand { font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; }
.brand span { color: var(--brand); }
.tel { color: var(--muted); text-decoration: none; font-weight: 600; }

.hero { padding: 40px 0 24px; }
.hero h1 { font-size: clamp(24px, 5vw, 32px); margin: 0 0 8px; letter-spacing: -0.02em; }
.hero p { margin: 0 0 20px; color: var(--muted); }
.find { display: flex; gap: 8px; }
.find input { flex: 1; min-width: 0; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
button {
  padding: 11px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
button.ghost { background: var(--brand-soft); color: var(--brand); }
button:disabled { opacity: .55; cursor: progress; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 16px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: 13px; }

.product { display: flex; gap: 20px; }
.product img { width: 160px; height: 160px; object-fit: contain; border-radius: 12px; background: #fff; border: 1px solid var(--line); flex: none; }
.product-info { min-width: 0; flex: 1; }
.product h2 { font-size: 20px; margin: 2px 0 4px; }
.code, .sub { margin: 0; color: var(--muted); font-size: 14px; }
.sub a { color: var(--brand); }
.tiers-scroll, .lines-scroll { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
.tiers th, .tiers td { border: 1px solid var(--line); padding: 6px 8px; text-align: right; white-space: nowrap; }
.tiers th { background: var(--bg); text-align: center; font-weight: 600; }
.tiers td.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.grid label.wide { grid-column: 1 / -1; }
.grid em { color: var(--err); font-style: normal; }
.hp { position: absolute; left: -9999px; }

.lines th, .lines td { padding: 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.lines th { color: var(--muted); font-weight: 600; font-size: 13px; }
.lines th:first-child, .lines td:first-child { text-align: left; white-space: normal; }
.lines td.text { color: var(--muted); }
.total { display: flex; justify-content: space-between; align-items: baseline; margin-top: 16px; padding-top: 12px; border-top: 2px solid var(--ink); }
.total span { color: var(--muted); font-size: 14px; }
.total strong { font-size: 26px; letter-spacing: -0.02em; }

.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 12px 14px; border-radius: 10px; margin: 0 0 12px; font-size: 14px; }
.msg { margin: 10px 0 0; font-size: 14px; color: var(--err); }
.msg.ok { color: var(--brand); font-weight: 600; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.fine { color: var(--muted); font-size: 13px; margin: 10px 0 0; text-align: right; }

dialog { width: min(900px, 100vw - 16px); height: min(92vh, 1200px); padding: 0; border: 0; border-radius: 14px; overflow: hidden; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog[open] { display: flex; flex-direction: column; }
.preview-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; background: var(--card); color: var(--ink); border-bottom: 1px solid var(--line); }
.preview-bar div { display: flex; gap: 8px; }
#preview-frame { flex: 1; width: 100%; border: 0; background: #fff; }

.foot { color: var(--muted); font-size: 13px; padding: 24px 16px 40px; text-align: center; }

@media (max-width: 640px) {
  .product { flex-direction: column; }
  .product img { width: 100%; height: 220px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .find button, .actions button { flex: 1; }
  .lines th:nth-child(5), .lines td:nth-child(5) { display: none; } /* 세액 열은 좁은 화면에서 숨긴다 */
}

/* 검색 결과 */
.card h3#results-title { font-size: 15px; font-weight: 600; color: var(--muted); margin: 0 0 12px; }
.results { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.result { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 6px; padding: 10px; text-align: left; font: inherit; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.result:hover, .result:focus-visible { border-color: var(--brand); }
.result img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 8px; }
.r-name { font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.r-meta { font-size: 12px; color: var(--muted); }
@media (max-width: 480px) { .results { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
