/* 공용 스타일. 모바일(390px) 우선, 데스크톱은 가운데 정렬.
 *
 * 규칙
 *  - 색·간격·반경은 아래 커스텀 프로퍼티만 쓴다. 값을 직접 박지 않는다.
 *  - 클래스는 `블록-요소` 케밥 표기(`row-price`), 상태는 `is-*`(`is-active`,
 *    `is-up`)로만 붙인다. 상세·관리 화면도 같은 규칙을 따른다.
 *  - 상승은 --up(붉은색), 하락은 --dn(푸른색). 한국 시세 관행이다.
 */

:root {
  --fg: #16181d;
  --fg-strong: #000;
  --muted: #6b7280;
  --bg: #fff;
  --bg-elev: #f6f7f9;
  --line: #e5e7eb;
  --accent: #2f7fd1;
  --accent-weak: #eaf2fb;
  --up: #c9453f;
  --dn: #2f6fd0;
  --warn: #b45309;
  --warn-weak: #fdf3e3;

  --radius: 10px;
  --radius-pill: 999px;
  --page-max: 480px;
  --gap: 8px;
  --font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --font-mono: ui-monospace, "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e6e8eb;
    --fg-strong: #fff;
    --muted: #9aa1ab;
    --bg: #14161a;
    --bg-elev: #1c1f25;
    --line: #2a2f37;
    --accent: #5aa2e8;
    --accent-weak: #1b2a3a;
    --up: #e8615a;
    --dn: #6ea2e8;
    --warn: #e0a458;
    --warn-weak: #2c2417;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--font);
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }

/* --- 골격 ---------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  gap: var(--gap);
  padding: 12px 14px calc(12px - 1px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar-title { font-size: 17px; font-weight: 700; text-decoration: none; }
.topbar-sub { font-size: 12px; color: var(--muted); }

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 10px 12px calc(40px + env(safe-area-inset-bottom));
}

/* 데스크톱 기준 화면(관리 화면 등)은 base.html 의 body_class 블록에 `wide` 를
   넣어 폭 제한을 푼다. */
body.wide .page { max-width: none; padding: 14px 18px 60px; }

/* --- 거래유형 세그먼트 ---------------------------------------------------- */

.segment {
  display: flex;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.segment-item {
  flex: 1;
  padding: 9px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  text-decoration: none;
}

.segment-item[aria-current="true"] {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* --- 권역 칩 -------------------------------------------------------------- */

.chiprow {
  display: flex;
  gap: 6px;
  margin: 0 -12px 8px;
  padding: 0 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chiprow::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  text-decoration: none;
}

.chip[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 600;
}

/* --- 컨트롤 -------------------------------------------------------------- */

.controls { display: flex; gap: 6px; margin-bottom: 6px; }

.control { flex: 1; display: flex; align-items: center; gap: 5px; }

.control-label { font-size: 11px; color: var(--muted); }

.control select {
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--fg);
  font-size: 12px;
}

.control-apply {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-elev);
  color: var(--fg);
  font-size: 12px;
}

.listinfo { margin: 0 0 2px; font-size: 11px; color: var(--muted); }

/* --- 목록 행 -------------------------------------------------------------- */

.list { display: block; }

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}

.row:active { background: var(--bg-elev); }

.row-rank {
  width: 16px;
  flex: none;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.row-main { flex: 1; min-width: 0; }

.row-name {
  display: block;
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }

.row-stale { display: block; margin-top: 2px; font-size: 10px; color: var(--warn); }

.row-figure { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }

/* 전용 평당가가 주(主), 공급 평당가는 옆에 흐리게 병기한다. */
.row-pyeong b { font-weight: 600; font-variant-numeric: tabular-nums; }
.row-supply { margin-left: 5px; opacity: 0.72; }

.row-spark {
  flex: none;
  width: 46px;
  height: 20px;
  color: var(--muted);
}

.row-figures { flex: none; text-align: right; }

.row-price {
  display: block;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row-change.is-up { color: var(--up); }
.row-change.is-down { color: var(--dn); }
.row-change.is-flat { color: var(--muted); }

/* 정렬 기준이 된 지표를 강조한다. 모바일에서 컬럼을 다 못 넣기 때문이다. */
.is-active { color: var(--fg-strong); font-weight: 650; }
.row-price.is-active { text-decoration: underline; text-underline-offset: 3px; }

.row-go { flex: none; color: var(--muted); font-size: 15px; }

.badge {
  margin-left: 4px;
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 500;
  vertical-align: 1px;
  white-space: nowrap;
}

.badge-stale { background: var(--warn-weak); color: var(--warn); }

.empty { padding: 30px 0; color: var(--muted); font-size: 13px; text-align: center; }

.more {
  display: block;
  margin-top: 12px;
  padding: 11px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}

.is-busy { opacity: 0.55; }

/* --- 검색 ---------------------------------------------------------------- */

.topsearch {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  min-width: 0;
}

.topsearch-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  color: var(--muted);
  border-radius: 50%;
  text-decoration: none;
}

.topsearch-toggle:hover { color: var(--fg-strong); background: var(--bg-elev); }

/* 접힌 상태는 폭 0. 펼치면 남은 자리를 채운다. 폭만 애니메이션하므로
   레이아웃이 튀지 않는다. */
.topsearch-form {
  width: 0;
  overflow: hidden;
  transition: width 0.16s ease;
}

.topsearch.is-open .topsearch-form { width: min(58vw, 240px); }

.topsearch-form input {
  width: 100%;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}

.topsearch-form input::placeholder { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .topsearch-form { transition: none; }
}

.topsearch button {
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.search-head { margin: 2px 0 10px; font-size: 12px; color: var(--muted); }
.search-head b { color: var(--fg-strong); }
.search-head .muted { color: var(--muted); }

.hits { margin: 0; padding: 0; list-style: none; }

.hit-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.hit-main { flex: 1 1 auto; min-width: 0; }

.hit-name {
  display: block;
  font-size: 14px;
  font-weight: 650;
  color: var(--fg-strong);
}

.hit-meta {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

.hit-figures { text-align: right; flex: 0 0 auto; }
.hit-price {
  display: block;
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.hit-sub { display: block; font-size: 10px; color: var(--muted); }

.badge-flagship {
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-weak);
  border-radius: var(--radius-pill);
}

/* 데이터 기준일. 화면 맨 아래에 작게 — 늘 보이되 읽기를 방해하지 않는다. */
.datastamp {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom));
  font-size: 10px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
  cursor: help;
}

body.wide .datastamp { max-width: none; }

/* --- 즐겨찾기 하트 -------------------------------------------------------- */

.topfav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  color: var(--muted);
  border-radius: 50%;
  text-decoration: none;
}

.topfav:hover { color: var(--accent); background: var(--bg-elev); }

/* 행 전체가 하나의 <a> 라서 하트를 그 안에 넣을 수 없다. 나란히 세운다. */
.row-wrap {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.row-wrap .row { flex: 1 1 auto; min-width: 0; border-bottom: none; }

.heart-form { display: flex; align-items: center; flex: 0 0 auto; }

.heart {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.heart:hover { color: var(--accent); background: var(--bg-elev); }
.heart.is-on { color: var(--up); }

.linkish { color: var(--accent); }

.comparelink {
  display: block;
  margin: 6px 0 2px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-weak);
  border-radius: var(--radius);
  text-align: center;
  text-decoration: none;
}


/* 손가락으로 누르는 버튼이다. 44px 은 애플·구글이 함께 권하는 최소 터치
   영역이고, 그보다 작으면 폰에서 정확히 못 누른다. */
.topbar-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin: -6px 2px -6px -8px;
  color: var(--fg-strong);
  font-size: 30px;
  line-height: 1;
  text-decoration: none;
  border-radius: 50%;
}

.topbar-back:hover,
.topbar-back:active { background: var(--bg-elev); }

/* --- 로그인 --------------------------------------------------------------- */

.loginnote { margin: 4px 0 14px; font-size: 12px; line-height: 1.6; color: var(--muted); }
.loginnote b { color: var(--fg-strong); }

.loginbuttons { display: flex; flex-direction: column; gap: 8px; }

.loginbtn {
  display: block;
  padding: 13px 12px;
  font-size: 14px;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  border-radius: var(--radius);
}

/* 카카오·네이버가 정한 브랜드 색이다. 다크 모드에서도 바꾸지 않는다 —
   사용자가 눈으로 알아보는 표식이기 때문이다. */
.login-kakao { background: #fee500; color: #191600; }
.login-naver { background: #03c75a; color: #ffffff; }

.logout {
  padding: 9px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.setuplist { margin: 8px 0 0; padding-left: 18px; font-size: 11.5px; line-height: 1.9; color: var(--muted); }
.setuplist code { font-size: 11px; }

/* 제목을 누르면 첫 화면으로. 링크지만 링크처럼 파랗게 물들이지 않는다 —
   제목은 제목으로 읽혀야 한다. */
a.topbar-title { color: inherit; text-decoration: none; }
a.topbar-title:active { opacity: 0.6; }
