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

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --principal-color: #1a73e8;
  --interest-color: #ea4335;
  --total-color: #34a853;
  --bg: #f8f9fa;
  --card-bg: #ffffff;
  --text: #202124;
  --text-light: #5f6368;
  --border: #e0e0e0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

/* === Header === */
.header {
  background: var(--primary);
  color: white;
  padding: 20px 0 16px;
  text-align: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo-link {
  text-decoration: none;
  color: inherit;
}

.tagline {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-top: 4px;
}

/* === Calculator Card Grid (Homepage) === */
.calc-cards-section {
  background: white;
  padding: 16px 0 8px;
  border-bottom: 1px solid var(--border);
}

.calc-cards {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.calc-cards::-webkit-scrollbar { display: none; }

.card-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.card-group-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  padding-left: 4px;
}

.card-group-items {
  display: flex;
  gap: 8px;
}

.calc-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 2px solid transparent;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  gap: 4px;
}

.calc-card:hover, .calc-card:focus {
  border-color: var(--primary);
  background: var(--primary-light);
}

.calc-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.calc-card-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.calc-card-name {
  font-size: 0.65rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.1;
}

@media (max-width: 480px) {
  .calc-card {
    width: 60px;
    height: 60px;
  }
  .calc-card-icon { font-size: 1.3rem; }
}

/* === Calculator Navigation === */
.calc-nav {
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.calc-nav .container {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 0;
}

.calc-nav .container::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  flex: 0 0 auto;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.nav-btn:hover {
  color: var(--primary);
}

/* Links inside calc-nav (used on sub-pages) */
.calc-nav a {
  flex: 0 0 auto;
  padding: 12px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.calc-nav a.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.calc-nav a:hover {
  color: var(--primary);
}

/* === Calculator Sections === */
.calc-section {
  display: none;
  padding: 20px 0;
}

.calc-section.active {
  display: block;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.section-desc {
  color: var(--text-light);
  font-size: 0.875rem;
  margin-bottom: 20px;
}

/* === Loan Type Tabs === */
.loan-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.loan-tab {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.loan-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.loan-tab:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.loan-tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* === Calculator Grid (Input + Results) === */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 768px) {
  .calc-grid {
    grid-template-columns: 1fr 1fr;
    gap: 32px;
  }
}

/* === Input Groups === */
.calc-inputs {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.input-group {
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.input-header label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.input-value-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.currency {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.unit {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-light);
}

.input-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  border: none;
  text-align: right;
  width: 140px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--primary-light);
  outline: none;
  transition: box-shadow 0.2s;
}

.input-value:focus {
  box-shadow: 0 0 0 2px var(--primary);
}

.input-small {
  width: 70px;
}

/* === Tenure Toggle === */
.tenure-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-left: 8px;
}

.tenure-btn {
  padding: 4px 12px;
  border: none;
  background: white;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tenure-btn:hover {
  color: var(--primary);
}

.tenure-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.tenure-btn.active {
  background: var(--primary);
  color: white;
}

/* === Range Slider === */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  margin: 4px 0;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(26, 115, 232, 0.4);
  border: 3px solid white;
  transition: transform 0.15s;
}

.slider::-webkit-slider-thumb:active {
  transform: scale(1.2);
}

.slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(26, 115, 232, 0.4);
  border: 3px solid white;
}

.slider-range {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 2px;
}

/* Slider track fill */
.slider {
  background: linear-gradient(to right, var(--primary) 0%, var(--primary) 50%, var(--border) 50%, var(--border) 100%);
}

/* === Results Panel === */
.calc-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.emi-result {
  background: var(--primary);
  color: white;
  padding: 20px;
  border-radius: var(--radius);
  text-align: center;
}

.emi-label {
  display: block;
  font-size: 0.85rem;
  opacity: 0.9;
  margin-bottom: 4px;
}

.emi-amount {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -1px;
}

/* === Result Breakdown === */
.result-breakdown {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.result-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bg);
}

.result-row:last-child {
  border-bottom: none;
}

.total-row {
  background: var(--bg);
  font-weight: 600;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
}

.dot-principal { background: var(--principal-color); }
.dot-interest { background: var(--interest-color); }
.dot-total { background: var(--total-color); }

.result-label {
  flex: 1;
  font-size: 0.875rem;
}

.result-value {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

/* === Pie Chart === */
.chart-container {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

#pieChart, #affPieChart {
  max-width: 220px;
  max-height: 220px;
}

/* === Amortization Schedule === */
.schedule-section {
  margin-top: 32px;
}

.schedule-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.schedule-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.schedule-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.schedule-btn {
  padding: 6px 16px;
  border: none;
  background: white;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.schedule-btn:hover {
  color: var(--primary);
}

.schedule-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.schedule-btn.active {
  background: var(--primary);
  color: white;
}

/* === Bar Chart === */
.bar-chart-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#barChart {
  width: 100%;
  min-width: 500px;
  height: 250px;
}

/* === Schedule Table === */
.schedule-table-wrap {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 500px;
}

.schedule-table th {
  background: var(--primary);
  color: white;
  padding: 12px 14px;
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.schedule-table th:first-child {
  text-align: center;
}

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

.schedule-table td:first-child {
  text-align: center;
  font-weight: 600;
  color: var(--primary);
}

.schedule-table tbody tr:hover {
  background: var(--primary-light);
}

.schedule-table tbody tr:last-child td {
  border-bottom: none;
}

/* === Prepayment Comparison === */
.pp-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pp-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.pp-box h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}

.pp-box-highlight {
  border: 2px solid var(--total-color);
}

.pp-box-highlight h3 {
  color: var(--total-color);
}

.pp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--bg);
}

.pp-row:last-child {
  border-bottom: none;
}

.pp-row span:first-child {
  color: var(--text-light);
}

.pp-row span:last-child {
  font-weight: 600;
}

.pp-savings {
  background: var(--total-color);
  color: white;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.savings-label {
  display: block;
  font-size: 0.85rem;
  opacity: 0.9;
}

.savings-amount {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  margin: 4px 0;
}

.savings-sub {
  display: block;
  font-size: 0.85rem;
  opacity: 0.9;
}

/* === Skip Link (Accessibility) === */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 8px 16px;
  z-index: 200;
  font-size: 0.875rem;
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
  top: 0;
}

/* === Visually Hidden (for screen readers, SEO) === */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* === Info Section === */
.info-section {
  padding: 32px 0;
  background: white;
  margin-top: 20px;
}

.info-section h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
}

.info-intro {
  font-size: 0.95rem;
  color: var(--text-light);
  line-height: 1.7;
  max-width: 720px;
  margin: 0 auto 24px;
  text-align: center;
}

.formula-box {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  text-align: center;
}

.formula {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 12px;
}

.formula-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-light);
}

.info-subhead {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 24px 0 12px;
}

.info-text {
  font-size: 0.9rem;
  color: var(--text-light);
  line-height: 1.6;
  margin-bottom: 12px;
}

.info-list {
  font-size: 0.9rem;
  color: var(--text-light);
  line-height: 1.7;
  padding-left: 20px;
  margin-bottom: 16px;
}

.info-list li {
  margin-bottom: 4px;
}

.info-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 24px;
}

@media (min-width: 600px) {
  .info-cards {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.info-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  border-left: 4px solid var(--primary);
}

.info-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.info-card p {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* === Factors Grid === */
.factors-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

@media (min-width: 600px) {
  .factors-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.factor-item {
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius);
}

.factor-item h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--primary);
}

.factor-item p {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* === FAQ Section === */
.faq-section {
  padding: 32px 0;
  background: var(--bg);
}

.faq-section h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
}

.faq-list {
  max-width: 720px;
  margin: 0 auto;
}

.faq-item {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}

.faq-item summary {
  padding: 16px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::after {
  content: '+';
  font-size: 1.25rem;
  font-weight: 300;
  color: var(--primary);
  flex-shrink: 0;
  margin-left: 12px;
  transition: transform 0.2s;
}

.faq-item[open] summary::after {
  content: '−';
}

.faq-answer {
  padding: 0 20px 16px;
  font-size: 0.875rem;
  color: var(--text-light);
  line-height: 1.7;
}

.faq-answer p {
  margin-bottom: 10px;
}

.faq-answer p:last-child {
  margin-bottom: 0;
}

.faq-answer ul, .faq-answer ol {
  padding-left: 20px;
  margin-bottom: 10px;
}

.faq-answer li {
  margin-bottom: 4px;
}

/* === Footer === */
.footer {
  background: #2d2d2d;
  color: #ccc;
  padding: 24px 0;
  text-align: center;
  font-size: 0.85rem;
}

.footer-links {
  margin: 10px 0;
}

.footer-links a {
  color: #90caf9;
  text-decoration: none;
  font-size: 0.8rem;
}

.footer-links a:hover,
.footer-links a:focus-visible {
  text-decoration: underline;
}

.footer-note {
  font-size: 0.75rem;
  margin-top: 8px;
  opacity: 0.7;
}

/* === Mobile Specific === */
@media (max-width: 480px) {
  .header {
    padding: 16px 0 12px;
  }

  .logo {
    font-size: 1.25rem;
  }

  .emi-amount {
    font-size: 1.6rem;
  }

  .pp-comparison {
    grid-template-columns: 1fr;
  }

  .input-value {
    width: 120px;
    font-size: 1rem;
  }

  .input-small {
    width: 60px;
  }

  .loan-tab {
    padding: 8px 8px;
    font-size: 0.8rem;
  }
}

/* === Print === */
@media print {
  .calc-nav, .header, .footer, .slider, .slider-range, .tenure-toggle, .loan-tabs, .schedule-toggle, .nav-btn {
    display: none !important;
  }

  .calc-section {
    display: block !important;
  }

  .calc-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* === Accessibility === */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Selection color */
::selection {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* === Bottom Navigation Bar === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  z-index: 100;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom, 0px));
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.65rem;
  font-weight: 500;
  padding: 6px 4px 4px;
  flex: 1;
  text-align: center;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav a.active {
  color: var(--primary);
}

.bottom-nav a:hover {
  color: var(--primary);
}

.bottom-nav svg {
  flex-shrink: 0;
}

/* Add padding to body when bottom-nav is present */
body:has(.bottom-nav) {
  padding-bottom: 64px;
}

body:has(.bottom-nav) .footer {
  padding-bottom: 72px;
}

@media (min-width: 769px) {
  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}

@media print {
  .bottom-nav {
    display: none !important;
  }
}
