:root {
  --primary: #0066cc;
  --primary-dark: #004d99;
  --accent: #ff6b35;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #e0e4e8;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, "Microsoft JhengHei", "PingFang HK", "Noto Sans HK", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── HEADER ── */
.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 1.5rem 1rem 1rem;
  text-align: center;
}
.header h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.header .tagline { font-size: 0.85rem; opacity: 0.85; }

/* ── NAV ── */
.nav {
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.nav-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
  overflow-x: auto;
}
.nav-tab {
  flex: 1;
  min-width: max-content;
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.nav-tab:hover { background: var(--bg); color: var(--primary); }
.nav-tab.active { background: var(--primary); color: white; }

/* ── CONTAINER ── */
.container { max-width: 1000px; margin: 0 auto; padding: 1rem; }
.panel { display: none; }
.panel.active { display: block; }

/* ── CARD ── */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--bg);
  color: var(--primary-dark);
}

/* ── INPUTS ── */
.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .input-grid { grid-template-columns: 1fr; } }
.input-group { display: flex; flex-direction: column; gap: 0.35rem; }
.input-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.input-hint { font-size: 0.75rem; color: var(--text-muted); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .prefix { position: absolute; left: 0.75rem; color: var(--text-muted); font-size: 0.9rem; pointer-events: none; }
.input-wrap .suffix { position: absolute; right: 0.75rem; color: var(--text-muted); font-size: 0.9rem; pointer-events: none; }
input[type="number"], select, input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
  background: white;
}
.input-wrap input { padding-left: 2.5rem; }
input:focus, select:focus { outline: none; border-color: var(--primary); }
textarea {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}
textarea:focus { outline: none; border-color: var(--primary); }

/* ── BUTTONS ── */
.btn {
  display: inline-block;
  padding: 0.7rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}
.btn:hover { background: var(--primary-dark); }
.btn-block { display: block; width: 100%; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #e55a2b; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.82rem; }

/* ── RATE TABS ── */
.rate-tabs { display: flex; gap: 0.5rem; margin-top: 0.35rem; }
.rate-tab {
  flex: 1; padding: 0.4rem 0.5rem; text-align: center;
  background: var(--bg); border: 2px solid var(--border); border-radius: 6px;
  font-size: 0.8rem; cursor: pointer; transition: all 0.2s; user-select: none;
}
.rate-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── RESULTS ── */
.result-hero { text-align: center; padding: 1rem 0; }
.result-hero .amount { font-size: 2rem; font-weight: 800; color: var(--primary); }
.result-hero .label { font-size: 0.85rem; color: var(--text-muted); }
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem; margin-top: 1rem;
}
.result-item { background: var(--bg); border-radius: 8px; padding: 0.8rem; text-align: center; }
.result-item .value { font-size: 1.15rem; font-weight: 700; }
.result-item .label { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }
.stress-pass { color: var(--success); }
.stress-fail { color: var(--danger); }

/* ── TABLES ── */
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.6rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; }
.data-table td.value { text-align: right; font-weight: 600; font-family: "SF Mono","Menlo",monospace; }
.data-table .total td { font-weight: 800; font-size: 1rem; border-top: 2px solid var(--primary); border-bottom: none; color: var(--primary-dark); }

/* ── CARDS GRID (recommendations) ── */
.rec-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.rec-card {
  background: white; border-radius: 12px; padding: 1.2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-left: 5px solid var(--primary);
}
.rec-card .rank { font-size: 0.75rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.rec-card .name { font-size: 1.2rem; font-weight: 800; margin: 0.2rem 0 0.5rem; }
.rec-card .score-badge {
  display: inline-block; background: var(--success); color: white; font-weight: 700;
  padding: 0.2rem 0.6rem; border-radius: 20px; font-size: 0.8rem;
}
.rec-card .meta { display: flex; flex-wrap: wrap; gap: 1rem; margin: 0.75rem 0; font-size: 0.88rem; }
.rec-card .meta-item { color: var(--text-muted); }
.rec-card .meta-item strong { color: var(--text); font-size: 1rem; }
.rec-reasons { margin-top: 0.5rem; padding-left: 1.2rem; }
.rec-reasons li { font-size: 0.85rem; color: var(--success); margin-bottom: 0.2rem; }
.rec-reasons li.bad { color: var(--danger); }

/* ── BADGES / TAGS ── */
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px;
  font-size: 0.75rem; font-weight: 600;
}
.badge-success { background: #d4edda; color: #155724; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-info { background: #d1ecf1; color: #0c5460; }

/* ── GLOSSARY ── */
.glossary-item {
  padding: 0.75rem; border-bottom: 1px solid var(--border);
}
.glossary-item .term { font-weight: 700; color: var(--primary-dark); }
.glossary-item .en { font-size: 0.8rem; color: var(--text-muted); }
.glossary-item .zh { font-size: 0.88rem; margin-top: 0.25rem; }

/* ── ALERTS ── */
.disclaimer {
  font-size: 0.78rem; color: var(--text-muted);
  padding: 0.75rem; background: #fff9e6; border-radius: 8px;
  border-left: 4px solid var(--warning); line-height: 1.5;
}
.info-note {
  font-size: 0.85rem; padding: 0.75rem; background: #e7f1ff;
  border-radius: 8px; border-left: 4px solid var(--primary); color: var(--primary-dark);
}
.success-note {
  font-size: 0.85rem; padding: 0.75rem; background: #d4edda;
  border-radius: 8px; border-left: 4px solid var(--success);
}

/* ── TIMELINE ── */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before { content: ''; position: absolute; left: 0.5rem; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 1.5rem; }
.timeline-item::before {
  content: ''; position: absolute; left: -1.75rem; top: 0.25rem;
  width: 1rem; height: 1rem; border-radius: 50%; background: var(--border);
  border: 2px solid white;
}
.timeline-item.done::before { background: var(--success); }
.timeline-item.current::before { background: var(--primary); box-shadow: 0 0 0 4px rgba(0,102,204,0.2); }

/* ── CHAT ── */
.chat-box {
  background: var(--bg); border-radius: 12px; padding: 1rem;
  min-height: 100px; max-height: 400px; overflow-y: auto;
}
.chat-msg { margin-bottom: 0.75rem; padding: 0.6rem 0.8rem; border-radius: 8px; font-size: 0.9rem; }
.chat-msg.user { background: var(--primary); color: white; margin-left: 2rem; }
.chat-msg.ai { background: white; border: 1px solid var(--border); margin-right: 2rem; }
.chat-empty { color: var(--text-muted); text-align: center; padding: 1rem; font-size: 0.85rem; }

/* ── AMORT ── */
.amort-toggle {
  width: 100%; padding: 0.6rem; background: var(--bg);
  border: 2px solid var(--border); border-radius: 8px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  text-align: center; color: var(--primary-dark);
}
.amort-table-wrap { max-height: 320px; overflow-y: auto; margin-top: 0.75rem; border-radius: 8px; display: none; }
.amort-table-wrap.show { display: block; }
.amort-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.amort-table thead th { background: var(--primary-dark); color: white; padding: 0.5rem; text-align: right; position: sticky; top: 0; }
.amort-table thead th:first-child { text-align: left; }
.amort-table td { padding: 0.4rem 0.5rem; text-align: right; border-bottom: 1px solid var(--border); font-family: "SF Mono","Menlo",monospace; }
.amort-table td:first-child { text-align: left; font-family: inherit; }
.amort-table tr:nth-child(even) { background: var(--bg); }

.mip-note { font-size: 0.8rem; color: var(--accent); padding: 0.5rem 0.75rem; background: #fff5f0; border-radius: 6px; margin-top: 0.5rem; display: none; }
.mip-note.show { display: block; }