/* ==========================================================================
   屋算盤 WuSuanPan — Warm Architectural Editorial UI
   ========================================================================== */
:root {
  --bg: #f6f3ec;
  --bg-subtle: #eee9de;
  --surface: #ffffff;
  --surface-warm: #fbf9f4;
  --ink: #151c24;
  --ink-2: #424e5c;
  --ink-3: #6c7785;
  --border: #e3ddd0;
  --border-strong: #cfc6b4;

  --buy: #c64b30;       /* 台北紅磚陶土色 — 買房 */
  --buy-soft: #fdf1ed;
  --buy-border: #f2c4b8;

  --rent: #147467;      /* 台灣玉翠綠 — 租屋＋存股 */
  --rent-soft: #ecf7f5;
  --rent-border: #b6dfd8;

  --gold: #b87e1e;      /* 琥珀金 — Pro / 提醒 */
  --gold-soft: #fdf6e7;
  --gold-border: #edd7a6;

  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #157a4f;
  --ok-soft: #ecfdf3;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(21, 28, 36, 0.04);
  --shadow-md: 0 10px 30px rgba(21, 28, 36, 0.07);
  --shadow-lg: 0 18px 46px rgba(21, 28, 36, 0.12);

  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --font-num: "Inter", "Noto Sans TC", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.container {
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header & Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(246, 243, 236, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
  box-shadow: 0 4px 10px rgba(21, 28, 36, 0.16);
}

.brand-name {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.brand-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--buy-soft);
  color: var(--buy);
  border: 1px solid var(--buy-border);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease, border-color 0.14s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 4px 12px rgba(21, 28, 36, 0.18);
}

.btn-primary:hover {
  background: #24303e;
  box-shadow: 0 6px 18px rgba(21, 28, 36, 0.24);
}

.btn-accent {
  background: var(--buy);
  color: #fff;
  box-shadow: 0 4px 14px rgba(198, 75, 48, 0.28);
}

.btn-accent:hover {
  background: #b13f26;
}

.btn-rent {
  background: var(--rent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(20, 116, 103, 0.26);
}

.btn-rent:hover {
  background: #0f6055;
}

.btn-outline {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn-outline:hover {
  background: var(--surface-warm);
  border-color: var(--ink);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 8px;
}

/* Hero Section */
.hero {
  padding: 36px 0 24px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 14px;
}

.hero-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--buy);
  display: inline-block;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(26px, 3.8vw, 40px);
  line-height: 1.24;
  letter-spacing: -0.02em;
  font-weight: 900;
}

.hero h1 .hl-buy {
  color: var(--buy);
}

.hero h1 .hl-rent {
  color: var(--rent);
}

.hero-sub {
  margin: 0 0 20px;
  max-width: 760px;
  color: var(--ink-2);
  font-size: 15.5px;
}

/* Preset Pills */
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-3);
  margin-right: 4px;
}

.preset-btn {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.preset-btn.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* Main Workspace Grid */
.workspace {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 22px;
  align-items: start;
  padding-bottom: 48px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* Input Sidebar */
.controls-panel {
  padding: 20px;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.controls-panel::-webkit-scrollbar {
  width: 6px;
}

.controls-panel::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.section-heading h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.chip-buy { background: var(--buy-soft); color: var(--buy); }
.chip-rent { background: var(--rent-soft); color: var(--rent); }
.chip-gold { background: var(--gold-soft); color: var(--gold); }

.control-group {
  margin-bottom: 18px;
}

.field {
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
}

.field-val {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}

.field-hint {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 4px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
  cursor: pointer;
  height: 6px;
}

.range-buy { accent-color: var(--buy) !important; }
.range-rent { accent-color: var(--rent) !important; }

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.select-input, .num-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-warm);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
}

.select-input:focus, .num-input:focus {
  outline: none;
  border-color: var(--ink);
  background: #fff;
}

.toggle-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.toggle-title {
  font-size: 13.5px;
  font-weight: 800;
}

.toggle-desc {
  font-size: 11.5px;
  color: var(--ink-3);
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #cbd2d9;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider {
  background: var(--buy);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* Status banner inside Youth 3.0 block */
.youth-status {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  line-height: 1.5;
  margin-top: 8px;
  margin-bottom: 12px;
}

.youth-status.ok {
  background: var(--ok-soft);
  color: #105c3b;
  border: 1px solid #a6e3c5;
}

.youth-status.warn {
  background: var(--gold-soft);
  color: #7c510d;
  border: 1px solid var(--gold-border);
}

.youth-status.fail {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f7c1bc;
}

details.advanced-box {
  border-top: 1px dashed var(--border-strong);
  padding-top: 12px;
  margin-top: 10px;
}

details.advanced-box summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-2);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

details.advanced-box summary::-webkit-details-marker {
  display: none;
}

details.advanced-box[open] summary .chev {
  transform: rotate(180deg);
}

.chev {
  transition: transform 0.2s;
  font-size: 11px;
}

.advanced-body {
  padding-top: 12px;
}

/* Results Column */
.results-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Verdict Hero Card */
.verdict-card {
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.verdict-card.winner-buy {
  border-top: 5px solid var(--buy);
  background: linear-gradient(180deg, #fffaf8 0%, #ffffff 42%);
}

.verdict-card.winner-rent {
  border-top: 5px solid var(--rent);
  background: linear-gradient(180deg, #f3fbf9 0%, #ffffff 42%);
}

.verdict-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.verdict-eyebrow {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.winner-buy .verdict-eyebrow { color: var(--buy); }
.winner-rent .verdict-eyebrow { color: var(--rent); }

.verdict-headline {
  margin: 0;
  font-size: clamp(22px, 2.7vw, 30px);
  font-weight: 900;
  line-height: 1.25;
}

.verdict-sub {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--ink-2);
}

.verdict-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.kpi-box {
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
}

.kpi-box.buy-accent {
  background: var(--buy-soft);
  border-color: var(--buy-border);
}

.kpi-box.rent-accent {
  background: var(--rent-soft);
  border-color: var(--rent-border);
}

.kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 900;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--ink-2);
  margin-top: 4px;
}

/* Alerts Strip (Cliff + Appraisal Gap) */
.alerts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.alert-card {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

.alert-card.cliff {
  background: #fff9f2;
  border-color: #f0d0a8;
}

.alert-card.cash {
  background: #f8f9fc;
  border-color: #d6dde8;
}

.alert-title {
  font-size: 13.5px;
  font-weight: 800;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.alert-body {
  font-size: 13px;
  color: var(--ink-2);
  margin: 0;
  line-height: 1.55;
}

.badge-stress {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  margin-left: 4px;
}

.stress-ok { background: var(--ok-soft); color: var(--ok); }
.stress-warn { background: var(--gold-soft); color: var(--gold); }
.stress-high { background: var(--danger-soft); color: var(--danger); }

/* Chart Cards */
.chart-card {
  padding: 20px 22px;
}

.chart-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.chart-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-2);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 310px;
}

.chart-wrap.tall-sm {
  height: 230px;
}

.chart-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(21, 28, 36, 0.95);
  color: #fff;
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 15;
  min-width: 195px;
}

/* Breakdown Table */
.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th {
  text-align: right;
  padding: 10px 10px;
  border-bottom: 2px solid var(--border-strong);
  color: var(--ink-3);
  font-weight: 800;
  white-space: nowrap;
}

table.data-table th:first-child,
table.data-table td:first-child {
  text-align: left;
}

table.data-table td {
  text-align: right;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table tbody tr:hover {
  background: var(--surface-warm);
}

/* Pro Funnel Banner */
.pro-section {
  background: linear-gradient(135deg, #161f2a 0%, #233142 100%);
  color: #f8f6f1;
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 36px;
}

.pro-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 28px;
  align-items: center;
}

.pro-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(237, 215, 166, 0.16);
  color: #f3d287;
  border: 1px solid rgba(243, 210, 135, 0.35);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 12px;
}

.pro-section h2 {
  margin: 0 0 10px;
  font-size: clamp(22px, 2.8vw, 30px);
  line-height: 1.28;
}

.pro-lead {
  color: #cbd5e1;
  font-size: 14.5px;
  margin: 0 0 18px;
}

.pro-features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.pro-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: #edf1f7;
}

.pro-features .check {
  color: #5eead4;
  font-weight: 900;
  flex-shrink: 0;
}

.pro-price-card {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
}

.price-strike {
  color: #94a3b8;
  text-decoration: line-through;
  font-size: 15px;
}

.price-main {
  font-size: 42px;
  font-weight: 900;
  color: #f3d287;
  line-height: 1.1;
  margin: 4px 0;
}

.price-note {
  font-size: 12.5px;
  color: #cbd5e1;
  margin-bottom: 18px;
}

.btn-pro-cta {
  width: 100%;
  padding: 14px 20px;
  font-size: 16px;
  background: #e5a93c;
  color: #151c24;
  border-radius: 12px;
  font-weight: 900;
  box-shadow: 0 8px 24px rgba(229, 169, 60, 0.35);
}

.btn-pro-cta:hover {
  background: #f0b954;
}

.pro-guarantees {
  margin-top: 12px;
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.6;
}

/* Modal for Share Card Preview */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 21, 28, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 18px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  max-height: 92vh;
  overflow-y: auto;
}

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

.modal-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--ink-3);
  line-height: 1;
}

.share-preview-img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px 0 42px;
  font-size: 12.5px;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
}

/* Responsive */
@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .controls-panel {
    position: static;
    max-height: none;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .pro-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .alerts-grid {
    grid-template-columns: 1fr;
  }
  .topbar-inner {
    height: auto;
    padding: 10px 0;
  }
  .brand-tag {
    display: none;
  }
  .verdict-card, .chart-card, .pro-section {
    padding: 18px;
  }
  .kpi-value {
    font-size: 18px;
  }
}
