:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --text: #1d1c19;
  --muted: #6b6860;
  --line: #e4e1d8;
  --accent: #e8a317;
  --accent-ink: #7a4f00;
  --accent-soft: #fdf2d6;
  --good: #1f8a5b;
  --good-soft: #e3f4ec;
  --caution: #b26b00;
  --caution-soft: #fff1d9;
  --bad: #c2372b;
  --bad-soft: #fde7e4;
  --warn: #7b4fc9;
  --warn-soft: #efe8fb;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412; --surface: #1e1d1a; --surface-2: #272521; --text: #f0ede6; --muted: #a29e94;
    --line: #34322d; --accent: #f0b43a; --accent-ink: #f6cd74; --accent-soft: #3a2f17;
    --good: #4cc08a; --good-soft: #17322521; --caution: #f0a83a; --caution-soft: #3a2c15;
    --bad: #f07466; --bad-soft: #3b1d19; --warn: #b394f0; --warn-soft: #2b2340;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #151412; --surface: #1e1d1a; --surface-2: #272521; --text: #f0ede6; --muted: #a29e94;
  --line: #34322d; --accent: #f0b43a; --accent-ink: #f6cd74; --accent-soft: #3a2f17;
  --good: #4cc08a; --good-soft: #173225; --caution: #f0a83a; --caution-soft: #3a2c15;
  --bad: #f07466; --bad-soft: #3b1d19; --warn: #b394f0; --warn-soft: #2b2340; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 "Noto Sans KR", system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 19px; text-decoration: none; display: flex; align-items: center; gap: 6px; }
.logo { color: var(--accent); font-size: 22px; }
#nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
#nav a.active, #nav a:hover { background: var(--accent-soft); color: var(--accent-ink); }
#auth { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.demo-banner { background: var(--accent-soft); color: var(--accent-ink); font-size: 12px; text-align: center; padding: 4px 16px; }

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) {
  .grid-2, .grid-3, .grid-side { grid-template-columns: minmax(0, 1fr); }
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  #nav { order: 3; flex-basis: 100%; }
  main { padding: 20px 16px 60px; }
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.tight { padding: 14px 16px; }
.card + .card { margin-top: 16px; }
.section { margin-top: 32px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.hero { padding: 8px 0 20px; }
.hero h1 { font-size: 32px; }
.hero p { color: var(--muted); max-width: 720px; font-size: 16px; }
.pillars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0 8px; }
.pillar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.pillar b { display: block; margin-bottom: 2px; }
@media (max-width: 860px) { .pillars { grid-template-columns: minmax(0, 1fr); } }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 72px; resize: vertical; }
.field { margin-bottom: 12px; min-width: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1d1300; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.caution { background: var(--caution-soft); color: var(--caution); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.grade { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; font-weight: 800; font-size: 16px; background: var(--accent-soft); color: var(--accent-ink); flex: none; }
.grade.S { background: var(--accent); color: #1d1300; }
.grade.D { background: var(--surface-2); color: var(--muted); }

.stat { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat-label { font-size: 12px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }

/* 가격 밴드 */
.band { position: relative; height: 54px; margin: 18px 4px 6px; }
.band .track { position: absolute; left: 0; right: 0; top: 22px; height: 8px; border-radius: 4px; background: var(--surface-2); }
.band .range { position: absolute; top: 22px; height: 8px; border-radius: 4px; background: var(--good); opacity: .35; }
.band .mark { position: absolute; top: 14px; width: 2px; height: 24px; background: var(--text); transform: translateX(-1px); }
.band .mark span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; white-space: nowrap; color: var(--muted); }
.band .dot { position: absolute; top: 19px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--surface); transform: translateX(-7px); background: var(--accent); }
.band .dot.good { background: var(--good); } .band .dot.caution { background: var(--caution); }
.band .dot.bad { background: var(--bad); } .band .dot.warn { background: var(--warn); }
.band .lbl { position: absolute; top: 38px; font-size: 11px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; }

/* 점수 막대 */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 84px minmax(0, 1fr) 40px; gap: 10px; align-items: center; font-size: 13px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }

.cand { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cand:last-child { border-bottom: 0; }
.cand .name { font-weight: 700; }
.cand .meta { font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.price { font-weight: 800; font-size: 16px; text-align: right; white-space: nowrap; }
.match { font-size: 12px; color: var(--muted); text-align: right; }
@media (max-width: 560px) { .cand { grid-template-columns: auto minmax(0, 1fr); } .cand > :last-child { grid-column: 2; text-align: left; } .price, .match { text-align: left; } }

.bundle { cursor: default; }
.bundle.rec { border: 2px solid var(--accent); }
.bundle ol { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.bundle li { margin: 2px 0; }

.stage-builder { display: grid; gap: 10px; }
.stage-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.cat-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-picker button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font: inherit; font-size: 13px; cursor: pointer; color: var(--text); }
.cat-picker button.on { background: var(--accent); border-color: var(--accent); color: #1d1300; font-weight: 700; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.chain .arrow { color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-color: var(--accent); font-weight: 700; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 14px; padding: 24px; width: min(460px, 100%); max-height: 90vh; overflow: auto; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.formula { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; overflow-x: auto; white-space: pre; }
.hist { display: flex; align-items: flex-end; gap: 4px; height: 60px; }
.hist div { flex: 1; background: var(--accent); opacity: .7; border-radius: 3px 3px 0 0; min-height: 2px; }
.hist-labels { display: flex; gap: 4px; font-size: 10px; color: var(--muted); }
.hist-labels span { flex: 1; text-align: center; }
.stars { color: var(--accent); letter-spacing: 1px; }

/* 알림 */
.bell { position: relative; font-size: 16px; padding: 4px 8px; }
.bell-count { position: absolute; top: -2px; right: -2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; }
.noti { display: block; text-decoration: none; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 8px; }
.noti.unread { background: var(--accent-soft); border-color: transparent; }
.noti:hover { border-color: var(--accent); }
.modal-card { width: min(640px, 100%); }

/* ───── 확인·입력 다이얼로그 (native confirm/prompt 대체) ───── */
.modal.dialog { z-index: 55; }
.modal.dialog .modal-card { width: min(420px, 100%); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-actions .btn { min-width: 84px; justify-content: center; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ───── 내비 아이콘: 데스크톱에서는 숨김 ───── */
#nav .ico { display: none; }

/* ───── 휴대폰 폭 ───── */
@media (max-width: 560px) {
  /* 하단 탭 바 */
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; order: 0; flex-basis: auto;
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0;
    background: var(--surface); border-top: 1px solid var(--line); overflow: visible;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  #nav a { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; font-size: 11px; border-radius: 8px; }
  #nav a.active { background: none; color: var(--accent-ink); font-weight: 700; }
  #nav .ico { display: block; font-size: 18px; line-height: 1.2; }
  main { padding-bottom: 96px; }
  .toast { bottom: 84px; }
  .modal-card { padding: 18px; max-height: 86vh; }

  /* 표 → 카드형 행 (오른쪽 버튼이 잘리지 않게) */
  .table-wrap { overflow-x: visible; }
  .table-wrap table thead { display: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table-wrap td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0; border: 0; text-align: right; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  .table-wrap td:first-child { display: block; text-align: left; padding-bottom: 6px; }
  .table-wrap td:first-child::before, .table-wrap td[data-label=""]::before, .table-wrap td[colspan]::before { content: none; }
  .table-wrap td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; padding-top: 8px; }
  .table-wrap td[data-label=""] .btn { min-height: 40px; padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 560px) {
  .card[style*="padding:0"] .table-wrap tr { padding-left: 14px; padding-right: 14px; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: nowrap; justify-content: space-between; }
  #auth > span.muted { display: none; }
}

/* ───── 상단 로딩 바 ───── */
#loadbar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 100; opacity: 0; transition: width .4s ease, opacity .2s; pointer-events: none; }
#loadbar.on { width: 70%; opacity: 1; transition: width 8s cubic-bezier(.1,.6,.2,1), opacity .2s; }

/* ───── 앱(WebView) 안에서: 브라우저 전용 요소 정리, 터치 반응 ───── */
html.in-app { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
html.in-app .demo-banner { font-size: 11px; padding: 2px 12px; }
html.in-app .btn:active { transform: scale(.98); }
html.in-app #nav a:active { background: var(--accent-soft); }
