/* Mortgage Calculator */
.mortgage-container {
  max-width: 85%;
  margin: 2rem auto;
  padding: 2rem;
  background: var(--card); 
  border-radius: 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  color: var(--text); 
}

.mortgage-container h1 {
  font-size: 2rem;
  font-weight: 800;
  margin: .4rem 0 0.5rem;
  text-align: center;
  color: var(--text);
}

.mortgage-container p {
  font-size: 1rem;
  text-align: center;
  color: var(--soft);
  margin-bottom: 2rem;
}

  .mortgage-container:hover {
    transform: translateY(-1px);
    opacity: 1;
  }

.mortgage-result {
  margin-top:1rem;
  padding: .8rem;
  background:var(--muted);
  border-radius:8px;
  font-size:1rem;
  text-align:center;
}

.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.form-card {
  background: var(--muted);
  padding: 1rem 1.2rem;
  border-radius: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.form-card h3 {
  margin-bottom: 0.6rem;
  font-size: 1.1rem;
  color: var(--primary);
}

  .form-card:hover {
    transform: translateY(-1px);
    opacity: 1;
  }

/* Inputs */
.mortgage-form input {
  width: 100%;
  margin-bottom: 0.8rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  font-size: 1rem;
}

.mortgage-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--ring);
}

/* Calculate Button */
.calc-btn {
  font-size: 1.2rem;
  padding: 0.9rem 2rem;
  border-radius: 0.8rem;
  margin-top: 1rem;
}

@media (min-width: 768px) {
  .calc-btn {
    font-size: 1rem;
    padding: 1rem 2.5rem;
  }
}

/* Results Section */
.mortgage-result {
  margin-top:1rem;
  padding: .8rem;
  background:var(--muted);
  border-radius:8px;
  font-size:1rem;
  text-align:center;
}

/* Breakdown Title */
.breakdown-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.8rem;
  text-align: center;
}

/* Breakdown Boxes */
.breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
  margin: 1rem 0;
}

.breakdown .box {
  flex: 1 1 150px;
  min-width: 140px;
  padding: 0.8rem;
  border-radius: 0.8rem;
  color: #fff;
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: default;
}

.breakdown .box:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.box span {
  display: block;
  font-size: 0.85rem;
  opacity: 0.9;
}
.box strong {
  font-size: 1.2rem;
}

  /* Current Rates Widget */
  
#currentRatesWidget {
  background: var(--card);
  color: var(--text);
  border-radius: 1rem;
  padding: 1rem 1rem;
  margin: 2rem auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  max-width: 1200px;
  text-align: center;
  transition: all 0.3s ease;
}

#currentRatesWidget:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

#currentRatesWidget h3 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 1.2rem;
  letter-spacing: -0.01em;
}

/* Current rates container */
#currentRates {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--muted);
  border-radius: 0.75rem;
  padding: 0rem 1.2rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

/* Rates grid */
#currentRates .rates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  justify-content: center;
  align-items: center;
}

#currentRates .rate-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: all 0.25s ease-in-out;
}

#currentRates .rate-box:hover {
  background: var(--primary-soft);
  transform: scale(1.03);
}

#currentRates .rate-box span {
  display: block;
  font-size: 0.9rem;
  color: var(--soft);
  margin-bottom: 0.4rem;
}

#currentRates .rate-box strong {
  font-size: 1.45rem;
  color: var(--primary);
  font-weight: 900;
  letter-spacing: -0.02em;
}

/* Timestamp and error states */
#currentRates .timestamp {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--soft);
}

#currentRates .error {
  color: var(--danger, #e63946);
  font-weight: 700;
  background: rgba(230, 57, 70, 0.05);
  padding: 1rem;
  border-radius: 0.5rem;
}

/* Loading state */
#currentRates .loading {
  font-size: 1rem;
  color: var(--soft);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

/* Color assignments */
.box.principal { background: #2563eb; }
.box.tax { background: #f59e0b; }
.box.insurance { background: #3b82f6; }
.box.hoa { background: #8b5cf6; }
.box.pmi { background: #ef4444; }
.box.total { background: #10b981; }

/* Charts */
#mortgageChart,
#stackedChart {
  width: 100%;
  max-height: 350px;
  height: 45vh;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.8rem;
}
.table th, table td {
  padding: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: right;
}
.table th {
  background: var(--muted);
  font-weight: 600;
  text-align: center;
}

#schedule {
  margin-top:1.25rem;
  overflow-x:auto;
}

#schedule table {
  width:100%;
  border-collapse:collapse;
}

#schedule th,
#schedule td {
  padding:.5rem;
  border:1px solid var(--border);
  text-align:right;
  font-size:.9rem;
}

#schedule th {
  background:var(--primary);
  color:#fff;
  text-align:center;
}

/* Controls row */
.controls-row {
  display:flex;
  gap:.6rem;
  align-items:right;
  margin-top:.8rem;
  flex-wrap:wrap;
}

.controls-row button {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
}

.toggle-btn {
  background: var(--primary);
  color: #fff;
}

.download-btn {
  padding:.6rem .9rem;
  border-radius:8px;
  border:none;
  cursor:pointer;
  font-weight:700;
  background: #374151;
  color: #fff;
}

.play-btn {
  background: var(--primary);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
}
#resultsSection {
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
}
#resultsSection.show {
  opacity: 1;
}

.form-group {
  position: relative;
  margin-bottom: 1.25rem; 
}

input.error {
  border: 1px solid #e53e3e;
  box-shadow: 0 0 0 1px #e53e3e;
}

.error-msg {
  color: #e53e3e;
  font-size: 0.875rem; 
  left: 0;
}

.required-asterisk {
  color: #e53e3e;
  font-weight: bold;
  margin-left: 2px;
}

/* Amortization table */
.amort-table { width:100%; border-collapse:collapse; margin-top:1rem; font-size:.95rem; }
.amort-table th, .amort-table td { padding:.6rem .6rem; border-bottom:1px solid var(--border); text-align:right; }
.amort-table th { text-align:left; color:var(--soft); font-weight:700 }
.amort-wrap { max-height:280px; overflow:auto; margin-top:.8rem; border-radius:8px; border:1px solid var(--border); background:var(--card); padding:.5rem; }

/* =======================
   Mortgage Chart Styling
======================= */

.rates-chart-card {
  background: #ffffff;
  border-radius: 14px;
  padding: 18px 20px 12px;
  margin: 1rem auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  max-width: 1200px;
  max-height: 420px;
  margin: 30px auto;
  overflow: auto;
}

.rates-chart-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

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

.chart-header h3 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 1.2rem;
  letter-spacing: -0.01em;
}

/* ===== Mortgage Trend Chart ===== */

.chart-controls {
  display: flex;
  gap: 6px;
}

.chart-controls button {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}

.chart-controls button.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.chart-wrapper {
  position: relative;
  height: 140px;
}

.chart-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    #eee 25%,
    #f5f5f5 37%,
    #eee 63%
  );
  background-size: 400% 100%;
  animation: skeleton 1.4s ease infinite;
  border-radius: 8px;
}

@keyframes skeleton {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

.trend-badge {
  margin-left: 10px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  vertical-align: middle;
}

.trend-up {
  background: #dcfce7;
  color: #166534;
}

.trend-down {
  background: #fee2e2;
  color: #991b1b;
}

.rate-sparkline {
  width: 100%;
  max-height: 400px;
  margin-top: 6px;
  opacity: 0.85;
}
.rates-chart-body {
  position: relative;
  height: 260px;
  width: 100%;
}

.rate-sparkline {
  width: 100%;
  height: 26px;
  margin-top: 6px;
  opacity: 0.85;
}

.trend-badge {
  margin-left: 10px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
}

.trend-up {
  background: #dcfce7;
  color: #166534;
}

.trend-down {
  background: #fee2e2;
  color: #991b1b;
}

/* =========================
   MOBILE ENHANCEMENTS 
   ========================= */
@media (max-width: 520px) {

  .mortgage-container {
    max-width: none !important; 
    width: 100% !important;
    padding: 1.4rem !important;
    margin: -1rem auto 1rem !important;
    border-radius: 12px !important;
    background: var(--card);
    box-shadow: 0 3px 10px rgba(0,0,0,0.15) !important;
  }

  /* Headings & Text */
  .mortgage-container h1 {
    font-size: 1.55rem !important;
    line-height: 1.3 !important;
    text-align: center !important;
  }

    /* Headings & Text */
  .mortgage-container h3 {
    font-size: 1rem !important;
    text-align: center !important;
  }

  .mortgage-container p,
  .mortgage-sub {
    font-size: 0.92rem !important;
    line-height: 1.55 !important;
    text-align: center !important;
    margin-bottom: 1rem !important;
  }

  /* Form Grid */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .form-card {
    padding: 1rem !important;
  }

  /* Inputs & Labels */
  .mortgage-form input {
    padding: 0.75rem 0.85rem !important;
    font-size: 0.96rem !important;
    border-radius: 8px !important;
    min-height: 46px !important;
    appearance: none;
  }
  .mortgage-form label {
    font-size: 0.88rem !important;
    font-weight: 600;
  }

  /* Buttons */
  .calc-btn,
  .download-btn,
  .toggle-btn,
  .play-btn {
    width: 60% !important;
    font-size: 1rem !important;
    padding: 1rem 1.2rem !important;
    border-radius: 10px !important;
    margin-top: 0.8rem !important;
    box-shadow: 0 3px 8px rgba(37,99,235,0.25) !important;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .calc-btn:active,
  .play-btn:active,
  .download-btn:active,
  .toggle-btn:active {
    transform: scale(0.99) !important;
    opacity: 0.92;
  }

  /* Chart scroll container */
  #chartContainer {
    width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    position: relative;
    margin-top: 1rem;
  }

  #currentRatesWidget {
    padding: 1rem 1rem;
    margin: 1rem auto;
    border-radius: 0.9rem;
  }

  #currentRatesWidget h3 {
    font-size: 1rem;
  }

  #currentRates .rate-box strong {
    font-size: 1.2rem;
  }

  #currentRates .rates-grid {
    grid-template-columns: 1fr;
  }

  #mortgageChart {
    min-width: 500px !important;
    max-height: 260px !important;
  }

  #chartContainer::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 40px;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(to left, var(--bg), transparent);
  }

  /* Amortization Table scroll */
  #schedule {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    position: relative;
    margin-bottom: 1rem;
  }

  #schedule table {
    min-width: 500px;
    font-size: 0.86rem !important;
  }

  #schedule::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 40px;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(to left, var(--bg), transparent);
  }

  /* Cards and text readability */
  .card {
    padding: 1rem !important;
    margin-bottom: 1rem !important;
  }

  .card h2 {
    font-size: 1.15rem !important;
    text-align: center !important;
    margin-bottom: 0.5rem !important;
  }

  .card p,
  .card li {
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
  }

  #currentRatesWidget {
    padding: 1.2rem 1.4rem;
    margin: 1rem auto;
    border-radius: 0.9rem;
  }

  #currentRatesWidget h3 {
    font-size: 1.3rem;
  }

  #currentRates .rate-box strong {
    font-size: 1.2rem;
  }

  #currentRates .rates-grid {
    grid-template-columns: 1fr;
  }

  /* Fade-in animations for results */
  #resultsSection {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
  }

  #resultsSection.show {
    opacity: 1;
    transform: translateY(0);
  }

  /* Accessibility focus highlight */
  input:focus, button:focus {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
  }
}
