:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #e2e5ea;
  --text: #1b1e24;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --pos: #16a34a;
  --neg: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.topnav { display: flex; gap: 4px; }

.topnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
}

.topnav a:hover { background: var(--bg); }
.topnav a.active { color: var(--primary); background: #eef2ff; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: 1.4rem;
  margin: 0;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); margin-top: 8px; }
.btn-danger:hover { background: #fef2f2; }
.btn-block { width: 100%; }

.empty-state {
  background: var(--card-bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.compare-table th, .compare-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
/* 숫자 칸은 한 줄, 주소(매물명)와 헤더는 줄바꿈 허용 → 가로 스크롤 없이 한 화면에 */
.compare-table td:not(:nth-child(3)) { white-space: nowrap; }
.compare-table td:nth-child(3) { min-width: 150px; line-height: 1.3; }
.compare-table th { white-space: normal; line-height: 1.25; }

.compare-table th {
  background: #fafbfc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.compare-table tr:last-child td { border-bottom: none; }
.compare-table a { color: var(--primary); text-decoration: none; font-weight: 600; }

.row-actions { display: flex; gap: 12px; align-items: center; }
.row-actions form { display: inline; margin: 0; }
.link-danger {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 0.9rem; padding: 0; text-decoration: underline;
}

.thumb-cell { width: 56px; padding-left: 12px !important; }

.row-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  background: var(--bg);
}

.row-thumb-empty {
  border: 1px dashed var(--border);
}

.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }

.calc-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

.col-inputs { display: flex; flex-direction: column; gap: 16px; }
.col-summary { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 16px;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
}

.field input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.input-suffix {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.input-suffix input {
  border: none !important;
  border-radius: 0 !important;
  flex: 1;
}

.input-suffix .suffix {
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  background: #fafbfc;
}

.input-suffix.prefix .suffix { order: -1; border-right: 1px solid var(--border); }
.input-suffix:not(.prefix) .suffix { border-left: 1px solid var(--border); }

.out-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.9rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
}

.out-row b { color: var(--text); font-weight: 600; }
.out-row.total { font-weight: 700; }
.out-row.total b { color: var(--primary); }

.summary-card .metric {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.summary-card .metric:first-of-type { border-top: none; padding-top: 0; }
.summary-card .metric span { color: var(--muted); font-size: 0.88rem; }
.summary-card .metric b { font-size: 1.15rem; }

.actions { display: flex; flex-direction: column; gap: 0; }
.actions form { margin: 0; }

@media (max-width: 860px) {
  .calc-grid { grid-template-columns: 1fr; }
  .col-summary { position: static; }
}

.lead {
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 760px;
  margin: -8px 0 20px;
  line-height: 1.5;
}

.lev-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

.lev-controls .field input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.lev-controls .field label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.lev-controls .field label b { color: var(--text); font-size: 0.95rem; }

.leverage-note {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

.leverage-note.pos { color: var(--pos); }
.leverage-note.neg { color: var(--neg); }

.lev-chart-card { display: flex; align-items: center; justify-content: center; }

#chart { width: 100%; height: auto; }
#chart .grid-line { stroke: var(--border); stroke-width: 1; }
#chart .grid-line-v { stroke: var(--border); stroke-width: 1; opacity: 0.5; }
#chart .zero-line { stroke: #9ca3af; stroke-width: 1; }
#chart .ref-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
#chart .ref-label { fill: var(--muted); font-size: 10px; }
#chart .axis-label { fill: var(--muted); font-size: 11px; }
#chart .axis-title { fill: var(--text); font-size: 12px; font-weight: 600; }
#chart .coc-line { fill: none; stroke: var(--primary); stroke-width: 2.5; }

@media (max-width: 760px) {
  .lev-grid { grid-template-columns: 1fr; }
}

.listing-photo {
  margin-bottom: 14px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.listing-photo img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.listing-links {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.listing-links a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.listing-links a:hover { text-decoration: underline; }

.row-actions button.link-danger, .row-actions button.link { background: none; border: none; cursor: pointer; font: inherit; padding: 0; }
.row-actions button.link { color: var(--primary); font-weight: 600; }
.toolbar { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.storage-note { color: var(--muted); font-size: 0.85rem; margin-top: 12px; }

.gate { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.gate-card { width: min(360px, 90vw); display: flex; flex-direction: column; gap: 12px; }
.gate-card input { padding: 9px 10px; border: 1px solid var(--border, #d1d5db); border-radius: 6px; font: inherit; }
.gate-msg { margin: 0; color: var(--muted); font-size: 0.9rem; }

[hidden] { display: none !important; }

/* 주소 조회로 자동 입력된 칸: 직접 고치면 해제된다 */
.field input.auto-filled { background: #fef08a; }

/* 목록 표 다듬기: 삭제 칸을 표 셀로 유지(경계선 정렬), 한글 단어 중간에서 끊지 않기 */
.compare-table td.row-actions { display: table-cell; }
.compare-table th { word-break: keep-all; }
.compare-table th:nth-child(n+4):nth-child(-n+11) { min-width: 66px; }

/* 즐겨찾기 */
.fav-cell { width: 28px; padding-right: 0 !important; }
.fav-btn { background: none; border: none; cursor: pointer; font-size: 1.35rem; line-height: 1; color: var(--muted); padding: 2px 4px; }
.fav-btn:hover { color: #e11d48; }
.fav-btn.on { color: #e11d48; }
.compare-table tr.fav td { background: #fff7f8; }

/* 주소는 "거리주소 / 도시, 주 우편번호" 두 줄. 각 줄 안에서는 줄바꿈하지 않는다 */
.compare-table td:nth-child(3) a { white-space: nowrap; }

/* 월 순현금흐름 헤더: "MONTHLY NET / CASH FLOW / (월 순현금흐름)" 줄 고정 */
.compare-table th:nth-child(8) { white-space: nowrap; }

/* 총 투자현금 헤더: "TOTAL CASH / INVESTED / (총 투자현금)" 줄 고정 */
.compare-table th:nth-child(7) { white-space: nowrap; }

/* 예상 렌트비 헤더가 어색하게 끊기지 않도록 */
.compare-table th:nth-child(5) { white-space: nowrap; }

/* 좁은 화면에서도 목록 표가 가로 스크롤 없이 한 폭에 들어오도록: 여백·글자 축소, 줄바꿈 허용 */
@media (max-width: 1000px) {
  .container { padding: 16px 10px; }
  .compare-table { font-size: 0.8rem; }
  .compare-table th, .compare-table td { padding: 8px 4px; }
  .compare-table th { font-size: 0.66rem; }
  .compare-table td:nth-child(3) { min-width: 0; }
  .compare-table td:nth-child(3) a { white-space: normal; }
  .compare-table th:nth-child(n+4):nth-child(-n+11) { min-width: 0; }
  .row-thumb { width: 36px; height: 36px; }
  .thumb-cell { width: 40px; padding-left: 4px !important; }
  .fav-cell { width: 22px; }
  .fav-btn { font-size: 1.15rem; padding: 2px 2px; }
}

/* 삭제: 쓰레기통 아이콘 */
.row-actions button.link-danger { display: inline-flex; align-items: center; padding: 4px; border-radius: 6px; text-decoration: none; }
.row-actions button.link-danger:hover { background: #fef2f2; }

/* 쓰레기통은 빨강이 아닌 일반(회색) 색, 마우스를 올리면 진하게 */
.row-actions button.link-danger { color: var(--muted); }
.row-actions button.link-danger:hover { color: var(--text); background: var(--bg); }

/* 초기수리비 헤더: "INITIAL / FIX-UP COST / (초기수리비)" 줄 고정 (좁은 화면 규칙이 뒤에서 풀어 준다) */
@media (min-width: 1001px) { .compare-table th:nth-child(6) { white-space: nowrap; } }

/* 헤더는 항상 정해 둔 줄(최대 3줄)로만 표시하고 줄 안에서는 줄바꿈하지 않는다. 폭이 좁으면 글자만 줄인다. */
.compare-table th { white-space: nowrap !important; }
@media (max-width: 1100px) {
  .compare-table th { font-size: 0.6rem; letter-spacing: 0; }
  .compare-table td { font-size: 0.76rem; }
  .compare-table th, .compare-table td { padding: 8px 3px; }
}

/* 언어 전환 (국기) */
.lang-switch { display: inline-flex; gap: 2px; margin-right: 10px; vertical-align: middle; }
.lang-btn { background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; font-size: 1.15rem; line-height: 1; padding: 4px 6px; opacity: 0.45; }
.lang-btn:hover { opacity: 0.8; }
.lang-btn.active { opacity: 1; border-color: var(--border); background: #fff; }

/* 목록 화면은 열이 많아 컨테이너를 조금 더 넓게 */
body.page-list .container { max-width: 1240px; }

/* MC 공식 안내 */
.mc-help { margin-top: 12px; font-size: 0.85rem; }
.mc-help summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.mc-help p { margin: 8px 0; color: var(--muted); line-height: 1.5; }
.mc-help .mc-sub { margin-bottom: 2px; color: var(--text); font-weight: 600; }
.mc-help pre.formula { margin: 6px 0; padding: 8px 10px; background: var(--bg); border-radius: 6px; overflow-x: auto; font-size: 0.8rem; line-height: 1.5; white-space: pre; color: var(--text); }

/* MC 공식 안내는 그래프 아래 전체 폭 카드 */
details.card.mc-help { margin-top: 16px; }

/* 수식 (MathML) */
.mc-help math { font-size: 1.25rem; margin: 10px 0; color: var(--text); }
.mc-help .mc-sub-note { margin-top: 0; }

/* 한글이 단어 중간에서 끊기지 않게 (라벨·결과 행·지표) */
label, .out-row span, .out-row b, .metric span, .card h2 { word-break: keep-all; }

/* 슬라이더 + 직접 입력 */
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type="range"] { flex: 1; min-width: 0; }
.num-pct { width: 104px; flex: none; }
.lev-controls .num-pct input { padding: 6px 8px; font-size: 0.95rem; }
.slider-note { margin: 0 0 8px; }

/* 레버리지 화면: 슬라이더 카드는 스크롤해도 화면에 붙어 있고, 계산식은 그래프 아래(오른쪽 열) */
.lev-right { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.lev-right details.card.mc-help { margin-top: 0; }
@media (min-width: 761px) {
  .lev-controls { position: sticky; top: 12px; align-self: start; max-height: calc(100vh - 24px); overflow-y: auto; }
}

/* 총수익 곡선 + 범례 */
#chart .total-line { fill: none; stroke: #d97706; stroke-width: 2.5; }
#chart .legend-label { text-anchor: start; font-size: 11px; fill: var(--text); }
.chart-note { margin: 0; }

/* 숫자 입력: 기본 화살표를 숨기고 직접 만든 ▲▼ (누르고 있으면 연속 증감) */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper { display: flex; flex-direction: column; align-self: stretch; width: 20px; border-left: 1px solid var(--border); }
.stepper button { flex: 1; min-height: 0; padding: 0; border: none; background: #fafbfc; color: var(--muted); font-size: 8px; line-height: 1; cursor: pointer; user-select: none; touch-action: none; }
.stepper button:first-child { border-bottom: 1px solid var(--border); }
.stepper button:hover { background: var(--bg); color: var(--text); }
.stepper button:active { background: #e5e7eb; }
