:root {
  --main: #ff5a36;
  --main-d: #e8461f;
  --main-soft: #fff1ec;
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #191b1f;
  --muted: #6b7280;
  --line: #e4e6ea;
  --bubble: #fef01b;
  --ok: #12a150;
  --warn: #b45309;
  --nav-h: 64px;
  --bar-h: 76px;
  --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1114; --card: #1a1d22; --text: #eceef1; --muted: #9aa0a8; --line: #2b2f36; --main-soft: #3a2119; --bubble: #3b3a1a; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 17px; line-height: 1.5; }
body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); min-height: 100vh; }
body.has-bar { padding-bottom: calc(var(--nav-h) + var(--bar-h) + env(safe-area-inset-bottom) + 12px); }
svg { width: 24px; height: 24px; fill: currentColor; }
h2 { font-size: 22px; margin: 4px 0; }
h3 { font-size: 17px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.pad { padding: 0 4px; }

/* 상단 */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--main); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: #fff; color: var(--main); font-weight: 900; font-size: 15px; }
.logo.big { width: 72px; height: 72px; border-radius: 20px; font-size: 34px; background: var(--main); color: #fff; margin: 0 auto 12px; }
.pill { font-size: 12px; background: rgba(255,255,255,.22); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

.screen { padding: 14px 14px 0; max-width: 560px; margin: 0 auto; }

/* 공통 컴포넌트 */
.card { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
input, textarea { width: 100%; font: inherit; font-size: 16px; color: inherit; background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--main); }
textarea { resize: vertical; line-height: 1.55; }
label, .lbl { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.btn { appearance: none; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600;
  border-radius: 12px; padding: 12px 16px; min-height: 48px; cursor: pointer; white-space: nowrap; }
body { word-break: keep-all; }
.btn.primary { background: var(--main); border-color: var(--main); color: #fff; }
.btn.primary:active { background: var(--main-d); }
.btn.sm { min-height: 42px; padding: 8px 16px; font-size: 15px; }
.btn.xl { width: 100%; min-height: 56px; font-size: 18px; border-radius: 14px; }
.btn:disabled { opacity: .5; }
button:active { transform: scale(.98); }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row .btn { flex: 1; }
.link-btn { border: 0; background: none; color: var(--main); font: inherit; font-weight: 600; padding: 6px; }
.msg { font-size: 15px; margin-top: 10px; min-height: 1.2em; }
.msg.err { color: #dc2626; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 15px; }

/* 로그인 */
.login { display: grid; place-items: center; min-height: 75vh; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-box h1 { margin: 0 0 6px; font-size: 24px; }
.login-box input { margin: 18px 0 12px; text-align: center; font-size: 18px; }

/* 변환 화면 */
.hero { width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #ff6a3d, #ff3d5a); color: #fff; border-radius: 20px; padding: 22px 18px; font: inherit;
  box-shadow: 0 8px 20px rgba(255, 80, 60, .28); margin-bottom: 12px; }
.hero-ic { flex: none; width: 52px; height: 52px; border-radius: 14px; background: rgba(255,255,255,.2); display: grid; place-items: center; }
.hero-ic svg { width: 30px; height: 30px; }
.hero-t b { display: block; font-size: 21px; }
.hero-t small { opacity: .9; font-size: 14px; }
.hero:disabled { opacity: .7; }

.fold { padding: 0; }
.fold summary { padding: 14px 16px; font-weight: 600; color: var(--muted); list-style: none; cursor: pointer; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: "▾"; float: right; }
.fold[open] summary::after { content: "▴"; }
.fold textarea { margin: 0 16px; width: calc(100% - 32px); }
.fold .btn { margin: 10px 16px 16px; width: calc(100% - 32px); }

.notes { background: #fff7e6; color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: 15px; margin-bottom: 12px; }
@media (prefers-color-scheme: dark) { .notes { background: #3a2a0f; color: #fbbf24; } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 18px; color: var(--muted); }
.spin { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--main); animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.result-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.ok-badge { background: #e7f8ee; color: var(--ok); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; }
@media (prefers-color-scheme: dark) { .ok-badge { background: #12321f; } }
.bubble { background: var(--bubble); color: #191919; border-radius: 4px 16px 16px 16px; padding: 14px 15px; white-space: pre-wrap;
  word-break: keep-all; overflow-wrap: anywhere; font-size: 15.5px; line-height: 1.55; }
@media (prefers-color-scheme: dark) { .bubble { color: #f5f5f5; } }
.bubble a { color: #1d4ed8; }
.edit { margin-top: 6px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1.5px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px;
  padding: 8px 14px; font: inherit; font-size: 14px; white-space: nowrap; }
.chips button.on { border-color: var(--main); background: var(--main-soft); color: var(--main); font-weight: 700; }

.recent h3 { margin: 18px 4px 8px; font-size: 15px; color: var(--muted); }
.recent-item { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.recent-item .t { flex: 1; min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item .d { font-size: 12px; color: var(--muted); }
.recent-item button { flex: none; }

/* 상품 목록 */
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.sec-head p { margin: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.prod { position: relative; background: var(--card); border-radius: 14px; overflow: hidden; border: 2.5px solid transparent; cursor: pointer; }
.prod.sel { border-color: var(--main); }
.prod img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #eee; }
.prod .info { padding: 8px 10px 10px; }
.prod .t { font-size: 13.5px; line-height: 1.35; height: 2.7em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.prod .p { font-weight: 800; font-size: 16px; margin-top: 4px; }
.prod .rk { font-size: 11px; color: #2563eb; font-weight: 700; }
.prod .check { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,.35);
  border: 2px solid #fff; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 15px; }
.prod.sel .check { background: var(--main); }
.search { display: flex; gap: 8px; margin-bottom: 6px; }
.search input { flex: 1; }

/* 실적 */
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin: 10px 0; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; font: inherit; font-size: 15px; padding: 10px 0; border-radius: 9px; color: var(--muted); }
.seg button.on { background: var(--main); color: #fff; font-weight: 700; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: 14px; padding: 14px; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi b { display: block; font-size: 22px; margin-top: 2px; }
.tbl { background: var(--card); border-radius: 14px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }

/* 하단 */
.action-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 9;
  padding: 10px 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.action-bar .btn { max-width: 532px; margin: 0 auto; display: block; box-shadow: 0 6px 16px rgba(255, 80, 60, .3); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.tabs button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; }
.tabs button svg { width: 25px; height: 25px; }
.tabs button.on { color: var(--main); font-weight: 700; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--bar-h) + env(safe-area-inset-bottom) + 6px); transform: translate(-50%, 10px);
  background: rgba(20,20,20,.9); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 15px; opacity: 0; transition: .2s;
  pointer-events: none; z-index: 30; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 카테고리 칩 / 순위 배지 */
.chips.cats { margin: 4px 0 6px; }
.prod .rank { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; font-weight: 800;
  padding: 3px 8px; border-radius: 999px; }
.prod .rank.top { background: var(--main); }
.info-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 10px; padding: 0 4px; }
