/* Malaysian Mortgage Calculator - Banking Trust Theme */
/* Professional, trustworthy, clean design */

/* ===== CSS Variables ===== */
:root {
  /* Banking Trust Color Palette */
  --primary: #0F766E;
  --primary-dark: #0D5D57;
  --primary-light: #14B8A6;
  --secondary: #0369A1;
  --secondary-light: #0EA5E9;
  --accent: #D97706;
  --accent-light: #F59E0B;

  /* Backgrounds */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F0FDFA;
  --bg-tertiary: #CCFBF1;
  --bg-card: #FFFFFF;

  /* Text colors */
  --text-primary: #134E4A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --text-light: #94A3B8;

  /* Status colors */
  --success: #059669;
  --success-light: #D1FAE5;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --error: #DC2626;
  --error-light: #FEE2E2;

  /* Borders */
  --border-color: #E2E8F0;
  --border-light: #99F6E4;
  --border-focus: #14B8A6;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 118, 110, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 118, 110, 0.08), 0 2px 4px -1px rgba(15, 118, 110, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 118, 110, 0.08), 0 4px 6px -2px rgba(15, 118, 110, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(15, 118, 110, 0.1), 0 10px 10px -5px rgba(15, 118, 110, 0.04);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* Border radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;

  /* Typography */
  --font-heading: 'Poppins', system-ui, -apple-system, sans-serif;
  --font-body: 'Open Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
}

h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

/* ===== Layout ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--spacing-md);
}

/* ===== Header ===== */
.header {
  background: var(--bg-primary);
  padding: var(--spacing-xl) 0;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--spacing-xl);
  box-shadow: var(--shadow-sm);
}

.header h1 {
  color: var(--primary);
  margin-bottom: var(--spacing-xs);
}

.header p {
  color: var(--text-secondary);
  font-size: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: 9999px;
  font-size: 0.875rem;
  color: var(--primary);
  margin-top: var(--spacing-md);
  font-weight: 500;
}

.badge .flag {
  font-size: 1.25rem;
}

/* ===== Navigation ===== */
.nav {
  display: flex;
  gap: var(--spacing-xs);
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: var(--spacing-xl);
  padding: var(--spacing-sm);
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.nav-btn {
  padding: var(--spacing-sm) var(--spacing-lg);
  background: transparent;
  border: none;
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease-out;
  white-space: nowrap;
}

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

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

/* ===== Tab Content ===== */
.tab-content {
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Cards ===== */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease-out;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.card-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  color: var(--primary);
}

.card-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--spacing-lg);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input,
.form-select {
  padding: 0.75rem 1rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1rem;
  transition: all 0.2s ease-out;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.form-input::placeholder {
  color: var(--text-light);
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748B'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.25rem;
  padding-right: 2.5rem;
  appearance: none;
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Radio/Checkbox Group */
.toggle-group {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

.toggle-option {
  flex: 1;
  min-width: 140px;
}

.toggle-option input {
  display: none;
}

.toggle-option label {
  display: block;
  padding: var(--spacing-md);
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease-out;
  font-weight: 500;
  color: var(--text-secondary);
}

.toggle-option input:checked + label {
  background: var(--bg-tertiary);
  border-color: var(--primary);
  color: var(--primary);
}

.toggle-option label:hover {
  border-color: var(--primary-light);
}

/* Checkbox */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-group label {
  cursor: pointer;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: 0.875rem 1.5rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease-out;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--primary);
}

.btn-block {
  width: 100%;
}

/* ===== Results Grid ===== */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
}

.result-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.result-card.primary {
  background: var(--primary);
  border: none;
  color: white;
  grid-column: span 2;
}

@media (max-width: 600px) {
  .result-card.primary {
    grid-column: span 1;
  }
}

.result-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.result-card.primary .result-label {
  color: rgba(255, 255, 255, 0.8);
}

.result-value {
  font-size: 1.375rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.result-card.primary .result-value {
  font-size: 1.75rem;
  color: white;
}

/* ===== Comparison Grid ===== */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.comparison-column {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
}

.comparison-column.highlight {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.comparison-column h4 {
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-sm);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.stat {
  display: flex;
  justify-content: space-between;
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--border-color);
}

.stat:last-child {
  border-bottom: none;
}

.stat-label {
  color: var(--text-secondary);
}

.stat-value {
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* ===== Savings Summary ===== */
.savings-summary {
  background: var(--success-light);
  border: 1px solid var(--success);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
}

.savings-summary h4 {
  color: var(--success);
  margin-bottom: var(--spacing-md);
}

.savings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--spacing-md);
  text-align: center;
}

.saving-item {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.saving-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.saving-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }

/* ===== Recommendation Badge ===== */
.recommendation {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-lg);
  border-radius: var(--radius-lg);
  margin-bottom: var(--spacing-lg);
}

.recommendation.positive {
  background: var(--success-light);
  border: 1px solid var(--success);
}

.recommendation.negative {
  background: var(--error-light);
  border: 1px solid var(--error);
}

.recommendation-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: bold;
}

.recommendation.positive .recommendation-icon {
  background: var(--success);
  color: white;
}

.recommendation.negative .recommendation-icon {
  background: var(--error);
  color: white;
}

.recommendation-text {
  font-weight: 500;
  color: var(--text-primary);
}

/* ===== Tables ===== */
.table-controls {
  display: flex;
  gap: var(--spacing-md);
  flex-wrap: wrap;
  margin-bottom: var(--spacing-lg);
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.amortization-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.amortization-table th,
.amortization-table td {
  padding: var(--spacing-md);
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.amortization-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-family: var(--font-body);
}

.amortization-table th:first-child,
.amortization-table td:first-child {
  text-align: left;
}

.amortization-table tbody tr:hover {
  background: var(--bg-secondary);
}

/* ===== Cost Breakdown ===== */
.cost-summary {
  text-align: center;
  margin-bottom: var(--spacing-xl);
}

.cost-total {
  display: inline-flex;
  flex-direction: column;
  background: var(--primary);
  color: white;
  padding: var(--spacing-xl) var(--spacing-2xl);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.cost-label {
  font-size: 0.875rem;
  opacity: 0.9;
}

.cost-value {
  font-size: 2.25rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.cost-breakdown {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
}

.cost-item {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
}

.cost-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cost-name {
  font-weight: 500;
  color: var(--text-primary);
}

.cost-amount {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

.cost-detail {
  margin-top: var(--spacing-sm);
  padding-top: var(--spacing-sm);
  border-top: 1px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.summary-table {
  margin-top: var(--spacing-xl);
}

.summary-table h4 {
  margin-bottom: var(--spacing-md);
}

.summary-table table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.summary-table td {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.summary-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 500;
}

.summary-table .total-row {
  background: var(--bg-tertiary);
}

.summary-table .total-row td {
  border-bottom: none;
  color: var(--primary);
}

/* ===== DSR Breakdown Bar ===== */
.breakdown-section {
  margin-top: var(--spacing-xl);
}

.breakdown-bar {
  display: flex;
  height: 40px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: var(--spacing-md) 0;
  box-shadow: var(--shadow-sm);
}

.bar-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  transition: all 0.3s ease-out;
}

.bar-segment.existing { background: var(--error); color: white; }
.bar-segment.available { background: var(--success); color: white; }
.bar-segment.unused { background: var(--text-light); color: white; }

.bar-label {
  font-size: 0.75rem;
  font-weight: 600;
}

.breakdown-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-lg);
  font-size: 0.875rem;
}

.breakdown-legend span {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dot.existing { background: var(--error); }
.dot.available { background: var(--success); }
.dot.unused { background: var(--text-light); }

/* ===== Islamic Note ===== */
.islamic-note {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.islamic-note strong {
  color: var(--primary);
}

.islamic-note p {
  margin-top: var(--spacing-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ===== Chart Section ===== */
.chart-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-lg);
  padding: var(--spacing-xl);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  margin-top: var(--spacing-lg);
  border: 1px solid var(--border-color);
}

.chart-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.chart-container canvas {
  width: 180px !important;
  height: 180px !important;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--spacing-xl);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.legend-color.principal {
  background: var(--primary);
}

.legend-color.interest {
  background: var(--warning);
}

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

/* ===== Toast Notifications ===== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease-out;
  z-index: 1000;
}

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

.toast.error {
  border-color: var(--error);
  background: var(--error-light);
  color: var(--error);
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: var(--spacing-xl);
  border-top: 1px solid var(--border-color);
  margin-top: var(--spacing-2xl);
  color: var(--text-muted);
  font-size: 0.875rem;
  background: var(--bg-primary);
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.footer a:hover {
  text-decoration: underline;
}

/* ===== Print Styles ===== */
@media print {
  body {
    background: white;
  }

  .nav, .btn, .toggle-group {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .amortization-table {
    font-size: 10px;
  }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
  html {
    font-size: 15px;
  }

  .container {
    padding: var(--spacing-sm);
  }

  .header {
    padding: var(--spacing-lg) var(--spacing-sm);
  }

  .header h1 {
    font-size: 1.5rem;
  }

  .card {
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
  }

  .card-header {
    flex-direction: column;
    text-align: center;
  }

  .nav {
    padding: var(--spacing-xs);
    gap: var(--spacing-xs);
    border-radius: var(--radius-lg);
  }

  .nav-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.75rem;
    flex: 1 1 auto;
  }

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

  .toggle-group {
    flex-direction: column;
  }

  .toggle-option {
    min-width: 100%;
  }

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

  .result-card.primary {
    grid-column: span 1;
  }

  .result-value {
    font-size: 1.125rem;
  }

  .result-card.primary .result-value {
    font-size: 1.5rem;
  }

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

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

  .chart-container canvas {
    width: 150px !important;
    height: 150px !important;
  }

  .chart-legend {
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
  }

  .cost-value {
    font-size: 1.75rem;
  }

  .table-controls {
    flex-direction: column;
  }

  .table-controls select,
  .table-controls button {
    width: 100%;
  }

  .amortization-table {
    font-size: 0.75rem;
  }

  .amortization-table th,
  .amortization-table td {
    padding: var(--spacing-sm);
  }

  .stat {
    flex-direction: column;
    gap: var(--spacing-xs);
    align-items: flex-start;
  }

  .breakdown-legend {
    flex-direction: column;
    gap: var(--spacing-sm);
  }
}

@media (max-width: 480px) {
  .nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .nav-btn {
    text-align: center;
    font-size: 0.7rem;
    padding: var(--spacing-sm);
  }

  .card-icon {
    width: 40px;
    height: 40px;
  }

  .result-card.primary .result-value {
    font-size: 1.25rem;
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .form-input,
  .form-select {
    padding: 0.625rem 0.875rem;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Focus Visible ===== */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-light);
}
