/* ============================================================
   CalcNest — Design System (V1.4)
   V1.4: fixed Credit Card Payoff neverPaidOff guard (天文数字 BUG)
   Principles: 一色(blue single-hue) / 一景(tool is the hero) / 一呼吸(subtle interaction)
   Mobile-first. Trust-focused (financial tools).
   ============================================================ */

:root {
  /* Brand — single blue hue */
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-deep: #1e3a8a;
  --brand-soft: #eff6ff;
  --brand-softer: #f8fbff;

  /* Neutrals */
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Feedback */
  --success: #059669;
  --success-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #b45309;
  --warn-bg: #fffbeb;

  /* Shape */
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------- Header ---------- */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}
.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo .logo-mark {
  width: 28px; height: 28px;
  background: var(--brand);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}
.logo:hover { text-decoration: none; }

.site-nav ul {
  display: flex;
  gap: 4px;
  list-style: none;
}
.site-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 500;
}
.site-nav a:hover {
  color: var(--text);
  background: var(--bg-soft);
  text-decoration: none;
}
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  margin-top: 64px;
  padding: 40px 0 32px;
  font-size: 14px;
  color: var(--text-muted);
}
.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 32px;
}
.footer-grid h4 {
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
}
.footer-grid ul { list-style: none; }
.footer-grid ul li { margin-bottom: 8px; }
.footer-bottom {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- Hero (home) ---------- */
.hero {
  background: linear-gradient(180deg, var(--brand-soft) 0%, var(--bg) 100%);
  padding: 56px 0 40px;
  text-align: center;
}
.hero h1 {
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.2;
  font-weight: 800;
  margin-bottom: 12px;
}
.hero p {
  font-size: 18px;
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Section ---------- */
.section { padding: 40px 0; }
.section-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}
.section-sub {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 16px;
}

/* ---------- Tool cards grid (home) ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.tool-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg);
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.tool-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--brand);
  text-decoration: none;
  transform: translateY(-2px);
}
.tool-card .tool-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}
.tool-card h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.tool-card p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------- Calculator page layout ---------- */
.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  padding: 16px 0 0;
}
.breadcrumb a { color: var(--text-muted); }
.page-title {
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 800;
  margin: 8px 0 8px;
  line-height: 1.25;
}
.page-lead {
  color: var(--text-muted);
  font-size: 16px;
  max-width: 760px;
  margin-bottom: 28px;
}

.calc-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 32px;
  align-items: start;
}
@media (max-width: 900px) {
  .calc-layout { grid-template-columns: 1fr; }
  .calc-sidebar { order: -1; }
}

.calc-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Form ---------- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group .hint {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 400;
}
.input-wrap { position: relative; }
.input-wrap .prefix,
.input-wrap .suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}
.input-wrap .prefix { left: 14px; }
.input-wrap .suffix { right: 14px; }
.input-wrap input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input-wrap.prefixed input { padding-left: 34px; }
.input-wrap.suffixed input { padding-right: 40px; }
.input-wrap input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input[type="range"] {
  width: 100%;
  accent-color: var(--brand);
  margin-top: 8px;
}
.range-value {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 13px 24px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  font-family: inherit;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.35); outline-offset: 2px; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--brand-soft); color: var(--brand); }
.btn-sm { padding: 8px 14px; font-size: 14px; }

/* ---------- Results ---------- */
.result-card {
  margin-top: 20px;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-soft);
  padding: 20px;
  display: none;
}
.result-card.show { display: block; animation: fadeUp 0.35s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.result-big {
  font-size: 32px;
  font-weight: 800;
  color: var(--brand-dark);
  margin: 4px 0 8px;
}
.result-big .currency { font-size: 20px; margin-right: 4px; }
.result-list { list-style: none; margin-top: 12px; }
.result-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14.5px;
}
.result-list li:last-child { border-bottom: none; }
.result-list .k { color: var(--text-muted); }
.result-list .v { font-weight: 600; color: var(--text); }
.result-note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---------- Insight (AI-differentiation: explain the result) ---------- */
.insight-box {
  margin-top: 16px;
  border-left: 4px solid var(--success);
  background: var(--success-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 16px;
  font-size: 14.5px;
}
.insight-box h4 {
  color: var(--success);
  font-size: 14px;
  margin-bottom: 6px;
  font-weight: 700;
}

/* ---------- Typographic content blocks ---------- */
.prose { max-width: 760px; }
.prose h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 32px 0 12px;
  padding-top: 8px;
}
.prose h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 24px 0 8px;
}
.prose p { margin-bottom: 16px; color: #334155; }
.prose ul, .prose ol { margin: 0 0 16px 22px; color: #334155; }
.prose li { margin-bottom: 6px; }
.prose code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 13.5px;
}
.prose .formula {
  background: var(--brand-softer);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 15px;
  overflow-x: auto;
  margin: 12px 0 20px;
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 20px;
  font-size: 14.5px;
}
.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.prose th { background: var(--bg-soft); font-weight: 600; }

/* ---------- Sidebar ---------- */
.side-widget {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  background: var(--bg);
}
.side-widget h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.side-widget ul { list-style: none; }
.side-widget li { margin-bottom: 8px; font-size: 14px; }
.side-widget li a { color: var(--text); }
.side-widget li a:hover { color: var(--brand); }

/* ---------- FAQ (accordion) ---------- */
.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.faq-q {
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: none;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: inherit;
}
.faq-q:hover { background: var(--bg-soft); }
.faq-q .faq-arrow { transition: transform 0.2s ease; color: var(--text-muted); }
.faq-item.open .faq-arrow { transform: rotate(180deg); }
.faq-a {
  display: none;
  padding: 0 16px 14px;
  font-size: 14.5px;
  color: #334155;
  line-height: 1.65;
}
.faq-item.open .faq-a { display: block; }

/* ---------- Compliance pages ---------- */
.prose.page { max-width: 800px; }
.contact-list { list-style: none; margin: 12px 0; }
.contact-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.contact-list .tag {
  display: inline-block;
  min-width: 92px;
  font-weight: 700;
  color: var(--brand);
  font-size: 14px;
}

/* ---------- Cookie banner ---------- */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--text);
  color: #f1f5f9;
  padding: 14px 20px;
  z-index: 100;
  display: none;
  font-size: 14px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
}
.cookie-banner.show { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.cookie-banner a { color: #93c5fd; }
.cookie-banner .btn { background: #fff; color: var(--text); }
.cookie-banner .btn:hover { background: #e2e8f0; }

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* ---------- Chart ---------- */
.chart-box { margin-top: 20px; }
.chart-box canvas { width: 100%; height: auto; }

/* ---------- Responsive nav ---------- */
@media (max-width: 720px) {
  .nav-toggle { display: block; }
  .site-nav {
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: none;
    box-shadow: var(--shadow-md);
  }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; padding: 8px; }
  .site-nav a { padding: 12px 16px; }
  .footer-grid { grid-template-columns: 1fr; gap: 20px; }
}

/* ---------- Print (nice for PDF-exported results) ---------- */
@media print {
  .site-header, .site-footer, .cookie-banner, .calc-sidebar, .no-print { display: none !important; }
  body { font-size: 13px; }
  .result-card { display: block; border: 1px solid var(--border); }
}

/* ---------- Ad slot placeholder (MVP: just a container) ---------- */
.ad-slot {
  margin: 24px 0;
  min-height: 90px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
  background: var(--bg-soft);
}
