:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --text: #16211c;
  --muted: #667572;
  --line: #dde3e1;
  --accent: #2f6f4e;
  --accent-soft: #e3f0e9;
  --danger: #b4402f;
  --radius: 14px;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111512;
    --surface: #1a201d;
    --surface-2: #232b27;
    --text: #e7eeea;
    --muted: #93a29d;
    --line: #2c3531;
    --accent: #6ec295;
    --accent-soft: #1f2f28;
    --danger: #e8806f;
  }
}

* { box-sizing: border-box; }

/* .dialog 의 display:grid 같은 규칙이 hidden 속성을 덮어쓰지 않도록 못박는다.
   이게 없으면 숨겨둔 다이얼로그가 화면 전체의 클릭을 가로챈다. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic",
               "Noto Sans KR", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ───────────────────────── 상단바 / 탭바 ───────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(env(safe-area-inset-top), 10px) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }

.icon-btn {
  background: none; border: none; color: var(--muted);
  font-size: 22px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px); }

.view { display: none; }
.view.active { display: block; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0; height: var(--tabbar-h);
  font-size: 11px; color: var(--muted); position: relative;
}
.tabbar button span { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 700; }

/* ───────────────────────────── 카드 ───────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 700; }

.feature { background: linear-gradient(140deg, var(--accent-soft), var(--surface)); }
.placeholder { margin: 0; color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
.hint { margin: 0 0 12px; font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 28px 0; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 10px; text-align: center;
}
.stat b { display: block; font-size: 20px; color: var(--accent); }
.stat span { font-size: 11.5px; color: var(--muted); }

/* ─────────────────────────── 세그먼트 ─────────────────────────── */

.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: 12px; margin-bottom: 14px;
}
.segmented button {
  flex: 1; border: none; background: none; cursor: pointer;
  padding: 9px 4px; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.segmented button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.badge {
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 3px 6px; border-radius: 99px; min-width: 17px; text-align: center;
}
.tabbar .badge { position: absolute; top: 4px; right: 50%; margin-right: -26px; font-style: normal; }

/* ─────────────────────────── 매물 카드 ─────────────────────────── */

.list { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; cursor: pointer;
  border-left: 3px solid transparent;
}
.item:active { background: var(--surface-2); }
.item.unread { border-left-color: var(--accent); }
.item h3 {
  margin: 0 0 6px; font-size: 14.5px; font-weight: 600;
  line-height: 1.45; letter-spacing: -.01em;
}
.item .meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.item .meta .src { color: var(--accent); font-weight: 600; }
.item .raw { margin: 5px 0 0; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.compact .item { padding: 10px 12px; }

/* ─────────────────────────── 필터 카드 ─────────────────────────── */

.filter-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.filter-card.off { opacity: .55; }
.filter-card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.filter-card h3 { margin: 0; font-size: 15px; }
.filter-card .tag {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.filter-card dl { margin: 10px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 12.5px; }
.filter-card dt { color: var(--muted); }
.filter-card dd { margin: 0; }
.filter-card .actions { display: flex; gap: 8px; margin-top: 12px; }
.filter-card .actions button { flex: 1; }

/* ─────────────────────────── 소스 목록 ─────────────────────────── */

.source-list { display: flex; flex-direction: column; gap: 10px; }
.source {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 12px; background: var(--surface-2); border-radius: 11px;
}
.source .info { min-width: 0; }
.source .name { font-size: 13.5px; font-weight: 600; }
.source .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.source .sub.err { color: var(--danger); }

/* ───────────────────────────── 버튼 ───────────────────────────── */

button.primary, button.secondary, button.ghost {
  border-radius: 10px; padding: 9px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; font-family: inherit;
}
button.primary { background: var(--accent); color: #fff; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.ghost { background: none; color: var(--danger); border-color: var(--line); }
button.block { width: 100%; margin-bottom: 14px; }
button:disabled { opacity: .5; cursor: default; }

/* ───────────────────────────── 시트 ───────────────────────────── */

.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(100%); } }

.sheet-body h2 { margin: 0 0 4px; font-size: 17px; line-height: 1.4; }
.sheet-body .sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }

.detail { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13.5px; margin-bottom: 16px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }

.body-text {
  background: var(--surface-2); border-radius: 10px; padding: 12px;
  font-size: 13px; line-height: 1.6; white-space: pre-wrap;
  max-height: 200px; overflow-y: auto; margin-bottom: 16px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  font-size: 11.5px; padding: 4px 9px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

.link-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link-row a {
  font-size: 12px; padding: 7px 11px; border-radius: 9px;
  background: var(--surface-2); color: var(--text); text-decoration: none; border: 1px solid var(--line);
}

a.source-link {
  display: block; text-align: center; background: var(--accent); color: #fff;
  padding: 12px; border-radius: 11px; text-decoration: none;
  font-weight: 700; font-size: 14px; margin-bottom: 16px;
}

/* ───────────────────────────── 폼 ───────────────────────────── */

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

input[type=text], input[type=number], select {
  width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
}
input.tiny { width: 62px; padding: 6px 8px; text-align: center; }
.pair { display: flex; align-items: center; gap: 8px; }
.pair input { flex: 1; }
.pair span { color: var(--muted); font-size: 13px; }

.choices { display: flex; flex-wrap: wrap; gap: 7px; }
.choices label {
  font-size: 12.5px; padding: 7px 12px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--line); cursor: pointer;
}
.choices input { display: none; }
.choices input:checked + span { color: var(--accent); font-weight: 700; }
.choices label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; font-size: 13.5px; }
.row + .row { border-top: 1px solid var(--line); }

.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions button { flex: 1; padding: 12px; }

/* ─────────────────────────── 다이얼로그 ─────────────────────────── */

.dialog { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(0,0,0,.45); padding: 24px; }
.dialog-box { background: var(--surface); border-radius: 16px; padding: 22px; max-width: 340px; width: 100%; }
.dialog-box p { margin: 0 0 20px; font-size: 14.5px; line-height: 1.6; }
.dialog-actions { display: flex; gap: 8px; }
.dialog-actions button { flex: 1; padding: 11px; }

.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 22px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 99px; font-size: 13px; z-index: 80;
  max-width: 88vw; text-align: center;
}

/* ── 금액 입력: 숫자만 치고 단위는 고정 표시 ── */
.unit-input { display: flex; align-items: center; gap: 8px; }
.unit-input input { flex: 1; min-width: 0; }
.unit-input .unit {
  flex: none;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
}
.unit-preview {
  margin: 5px 0 0;
  font-size: 12.5px;
  color: var(--accent);
  min-height: 16px;
}

/* 상단 필터 아이콘이 켜져 있을 때 */
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }

/* ── 실거래가 탭 ── */
.deal-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px 4px;
}
.deal-bar .hint { margin: 0; }
.item.deal h3 { margin-bottom: 2px; }
.spec {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px;
  margin: 10px 0 0; font-size: 13.5px;
}
.spec dt { color: var(--muted); white-space: nowrap; }
.spec dd { margin: 0; }

/* ── 알림 설정 안내 (아이폰 등) ── */
.guide {
  margin: 10px 0 4px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.6;
}
.guide strong { display: block; margin-bottom: 6px; }
.guide ol { margin: 0; padding-left: 20px; }
.guide li { margin: 3px 0; }
.guide .hint { margin: 8px 0 0; }
