/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --red: #e53e3e;
  --red-light: #fef2f2;
  --green: #059669;
  --green-light: #ecfdf5;
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* === Navigation === */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
}

.nav-brand { font-size: 14px; font-weight: 600; color: var(--text); }

.nav-links { display: flex; gap: 20px; align-items: center; }
.nav-links a { font-size: 13px; color: var(--text-secondary); text-decoration: none; }
.nav-links a:hover { color: var(--blue); }

/* === Tools Dropdown === */
.tools-dropdown { position: relative; display: inline-flex; }

.tools-trigger {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  font-family: inherit;
}

.tools-trigger:hover { color: var(--blue); }

.tools-trigger::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

.tools-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  min-width: 200px;
  z-index: 20;
  padding: 4px 0;
}

.tools-dropdown:hover .tools-menu { display: block; }

.tools-menu a {
  display: block;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.tools-menu a:hover { background: var(--blue-light); color: var(--blue); }
.tools-menu a.active { background: var(--blue-light); color: var(--blue); font-weight: 500; }

/* === Language Toggle === */
.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.lang-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn.active { background: var(--blue); color: #fff; }

/* === Layout === */
.container { max-width: 720px; margin: 0 auto; padding: 24px 20px 48px; }
.intro { padding: 32px 0 8px; }
h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

/* === Cards & Forms === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.input-row:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-prefix, .input-suffix {
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-secondary);
  background: #f9fafb;
  white-space: nowrap;
}
.input-prefix { border-right: 1px solid var(--border); }
.input-suffix { border-left: 1px solid var(--border); }

input {
  flex: 1;
  border: none;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  min-width: 0;
}

/* Custom select (used by index & prepay) */
select {
  flex: 1;
  border: none;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236B7280' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* === Rate Cards === */
.rate-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.rate-card .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.rate-card .value { font-size: 28px; font-weight: 700; }
.rate-card .delta { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* Reusable card color themes */
.rate-card.invested { background: var(--blue-light); border-color: #bfdbfe; }
.rate-card.invested .value { color: var(--blue); }
.rate-card.gain { background: var(--green-light); border-color: #a7f3d0; }
.rate-card.gain .value { color: var(--green); }

/* === Chart Bars === */
.chart-bar-group {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.chart-label {
  width: 80px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.chart-bar-wrap {
  flex: 1;
  height: 32px;
  background: #f3f4f6;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.chart-bar {
  height: 100%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding-left: 12px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  transition: width 0.4s ease;
  white-space: nowrap;
}

.chart-bar.invested { background: var(--blue); }
.chart-bar.positive { background: var(--green); }

/* === Comparison Layouts === */
.result-summary { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.comp-row { display: flex; gap: 12px; margin-bottom: 12px; }
.comp-row .rate-card { flex: 1; }
.savings-badge {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
}

/* === Tables === */
.table-scroll { max-height: 360px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  font-size: 12px;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }

/* === Insight Box === */
.insight-box {
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 20px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.6;
}

.insight-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }

/* === FAQ === */
.faq { margin-top: 8px; }
.faq h2 { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.faq-item { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }

.faq-q {
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}

.faq-q:hover { background: #eef0f3; }

.faq-q::after {
  content: "+";
  font-size: 18px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

.faq-item.open .faq-q::after { content: "\2212"; }

.faq-a {
  padding: 0 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.faq-item.open .faq-a { max-height: 400px; padding: 8px 16px 16px; }

/* === Disclaimer & Footer === */
.disclaimer {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 24px 0;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}

footer a { color: var(--blue); text-decoration: none; }
footer a:hover { text-decoration: underline; }

.footer-links { display: flex; justify-content: center; gap: 16px; margin-bottom: 8px; }

/* === Cookie Consent Banner === */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  font-size: 13px;
  color: var(--text-secondary);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.cookie-banner a { color: var(--blue); }

.cookie-btn {
  padding: 6px 18px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.cookie-btn:hover { opacity: 0.9; }

/* ================================================================
   Responsive: max-width 480px
   ================================================================ */
@media (max-width: 480px) {
  .container     { padding: 16px 12px 32px; }
  .card          { padding: 16px; }
  .intro         { padding: 20px 0 8px; }

  h1             { font-size: 18px; }
  .subtitle      { font-size: 13px; }

  /* Rate cards */
  .rate-card .value { font-size: 22px; }

  /* Navigation */
  .nav-brand     { font-size: 12px; }
  .nav-links     { gap: 8px; }
  .nav-links a,
  .tools-trigger { font-size: 11px; }
  .tools-menu    { left: auto; right: 0; min-width: 160px; }
  .lang-btn      { padding: 3px 8px; font-size: 10px; }
  .nav           { padding: 0 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav-inner     { min-width: 380px; gap: 4px; }

  /* Touch-friendly targets */
  a, button, .preset-btn, .lang-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Input */
  input          { font-size: 16px; }
  select         { font-size: 16px; }
  .input-prefix,
  .input-suffix  { padding: 10px 8px; font-size: 12px; }

  /* Result grids */
  .result-summary     { grid-template-columns: 1fr; }
  .comp-row           { flex-direction: column; }
  .breakdown-grid     { grid-template-columns: 1fr; }

  /* Tables */
  .table-scroll  { max-height: 280px; overflow-x: auto; }
  table          { font-size: 11px; min-width: 500px; }
  thead th,
  tbody td       { padding: 6px 8px; }

  /* Charts */
  .chart-label   { width: 60px; font-size: 11px; }
  .chart-bar     { font-size: 11px; padding-left: 8px; }
  .chart-bar-group { gap: 8px; }

  /* FAQ */
  .faq-q         { font-size: 13px; padding: 12px 14px; }
  .faq-a         { font-size: 12px; }

  /* Footer */
  .footer-links  { gap: 10px; flex-wrap: wrap; }
  .footer-links a { font-size: 11px; }
  footer         { padding: 16px 0; margin-top: 24px; }

  /* Misc */
  .insight-box   { font-size: 12px; padding: 12px 14px; }
  .disclaimer    { font-size: 11px; padding: 10px 12px; }
  .savings-badge { font-size: 12px; padding: 8px 12px; }
  .verdict       { font-size: 14px; padding: 12px 14px; }

  /* Cookie banner */
  .cookie-banner { flex-direction: column; gap: 10px; text-align: center; }
}
