@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

/* ==========================================================================
   1. Design System & CSS Variables
   ========================================================================== */
:root {
  /* Color Space Interpolation Tokens */
  --in-oklab: ;
  --in-oklch: ;
  
  /* Fonts */
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  
  /* Modern Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Border Radius */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  
  /* Dark Mode Variables (Default) */
  --bg-app: oklch(10% 0.02 240);
  --bg-card: rgba(20, 24, 33, 0.65);
  --bg-card-hover: rgba(28, 33, 45, 0.75);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(255, 255, 255, 0.15);
  
  --text-primary: oklch(96% 0.01 240);
  --text-secondary: oklch(78% 0.02 240);
  --text-muted: oklch(58% 0.02 240);
  
  /* Brand/Accent Colors (OKLCH gradients) */
  --primary: oklch(62% 0.22 285);      /* Electric Violet */
  --primary-glow: oklch(62% 0.22 285 / 0.15);
  --secondary: oklch(68% 0.16 220);    /* Cyber Blue */
  --success: oklch(72% 0.18 150);      /* Emerald Teal */
  --success-glow: oklch(72% 0.18 150 / 0.15);
  --warning: oklch(76% 0.16 75);       /* Warm Orange/Amber */
  --danger: oklch(60% 0.2 25);         /* Rose Red */
  
  /* Glow overlays */
  --glow-1: radial-gradient(circle at 10% 20%, oklch(40% 0.2 280 / 0.15) 0%, transparent 40%);
  --glow-2: radial-gradient(circle at 90% 80%, oklch(50% 0.15 160 / 0.12) 0%, transparent 45%);
  
  /* Shadow Systems */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4), 0 0 80px rgba(99, 102, 241, 0.05);
  --shadow-inset: inset 0 2px 4px rgba(255, 255, 255, 0.03);
}

@supports (linear-gradient(in oklab, white, black)) {
  :root {
    --in-oklab: in oklab;
    --in-oklch: in oklch;
  }
}

/* Light Theme Variables */
.light-theme {
  --bg-app: oklch(98% 0.005 240);
  --bg-card: rgba(255, 255, 255, 0.7);
  --bg-card-hover: rgba(255, 255, 255, 0.85);
  --border-color: rgba(0, 0, 0, 0.06);
  --border-color-hover: rgba(0, 0, 0, 0.12);
  
  --text-primary: oklch(18% 0.02 240);
  --text-secondary: oklch(40% 0.02 240);
  --text-muted: oklch(55% 0.02 240);
  
  --primary: oklch(55% 0.21 285);
  --primary-glow: oklch(55% 0.21 285 / 0.08);
  --secondary: oklch(58% 0.16 220);
  --success: oklch(52% 0.17 150);
  --success-glow: oklch(52% 0.17 150 / 0.08);
  --warning: oklch(62% 0.16 75);
  --danger: oklch(55% 0.19 25);
  
  --glow-1: radial-gradient(circle at 10% 20%, oklch(85% 0.1 280 / 0.3) 0%, transparent 40%);
  --glow-2: radial-gradient(circle at 90% 80%, oklch(88% 0.08 160 / 0.25) 0%, transparent 45%);
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.08), 0 0 40px rgba(99, 102, 241, 0.02);
  --shadow-inset: inset 0 2px 4px rgba(0, 0, 0, 0.01);
}

/* ==========================================================================
   2. Reset & Global Styles
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  padding: 2rem 1rem;
}

/* Dynamic Radial Glow Overlays */
body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: var(--glow-1), var(--glow-2);
  pointer-events: none;
  z-index: -1;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h1 {
  font-size: 2.25rem;
  background: linear-gradient(135deg var(--in-oklch), var(--text-primary), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

h3 {
  font-size: 1.15rem;
}

p {
  color: var(--text-secondary);
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color-hover);
}

/* ==========================================================================
   3. Layout Elements & Cards
   ========================================================================== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg var(--in-oklch), var(--primary), var(--secondary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  color: white;
  font-weight: 800;
  font-size: 1.25rem;
}

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

/* Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
}

@media (min-width: 992px) {
  .dashboard-grid {
    grid-template-columns: 420px minmax(0, 1fr);
  }
}

/* Glass Card */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal), background var(--transition-normal);
  position: relative;
  overflow: hidden;
}

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

.glass-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: background var(--transition-normal);
}

.glass-card.accent-primary::before {
  background: linear-gradient(to right var(--in-oklch), var(--primary), var(--secondary));
}

.glass-card.accent-success::before {
  background: linear-gradient(to right var(--in-oklch), var(--success), var(--secondary));
}

/* ==========================================================================
   4. Form Elements & Custom Inputs
   ========================================================================== */
.form-group {
  margin-bottom: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
}

.input-suffix {
  position: absolute;
  right: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

input[type="number"], select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-inset);
}

.light-theme input[type="number"], .light-theme select {
  background: rgba(255, 255, 255, 0.8);
}

.input-wrapper.prefixed input {
  padding-left: 1.8rem;
}

.input-wrapper.suffixed input {
  padding-right: 2.2rem;
}

input[type="number"]:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-inset);
}

/* Button Group (Toggle Buttons) */
.btn-group {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.light-theme .btn-group {
  background: rgba(0, 0, 0, 0.05);
}

.btn-toggle {
  flex: 1;
  padding: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-toggle.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Interactive Timeline Slider */
.timeline-slider-container {
  margin: 2rem 0 1rem 0;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.light-theme .timeline-slider-container {
  background: rgba(0, 0, 0, 0.02);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border-color-hover);
  outline: none;
  margin: 1rem 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg var(--in-oklch), var(--primary), var(--secondary));
  cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow), 0 2px 6px rgba(0,0,0,0.3);
  transition: transform var(--transition-fast), background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.25);
  background: var(--primary);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg var(--in-oklch), var(--primary), var(--secondary));
  cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow), 0 2px 6px rgba(0,0,0,0.3);
  transition: transform var(--transition-fast);
}

input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb:active {
  transform: scale(1.25);
}

/* ==========================================================================
   5. Key Metrics Dashboard
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.metric-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: all var(--transition-normal);
}

.light-theme .metric-card {
  background: rgba(0, 0, 0, 0.01);
}

.metric-card:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-color-hover);
}

.metric-card.highlighted {
  background: linear-gradient(135deg var(--in-oklch), rgba(139, 92, 246, 0.08), rgba(99, 102, 241, 0.08));
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.05);
}

.metric-card.success-highlight {
  background: linear-gradient(135deg var(--in-oklch), rgba(16, 185, 129, 0.08), rgba(20, 184, 166, 0.08));
  border-color: rgba(16, 185, 129, 0.25);
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.05);
}

.metric-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.metric-value {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.metric-card.highlighted .metric-value {
  color: var(--primary);
  background: linear-gradient(135deg var(--in-oklch), var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.metric-card.success-highlight .metric-value {
  color: var(--success);
}

.metric-footer {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   6. Visualizations (Charts Section)
   ========================================================================== */
.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
  margin-bottom: 2rem;
}

@media (min-width: 768px) {
  .charts-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
}

.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 250px;
  max-height: 350px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
}

.chart-wrapper canvas {
  max-width: 100% !important;
}

.card-title-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ==========================================================================
   7. Interactive controls, switches, buttons
   ========================================================================== */
.theme-switch {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.theme-switch:hover {
  border-color: var(--border-color-hover);
  transform: rotate(15deg) scale(1.05);
}

.theme-switch svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Light/Dark Toggle Icon Visibility */
.theme-switch .sun-icon {
  display: none;
}
.light-theme .theme-switch .moon-icon {
  display: none;
}
.light-theme .theme-switch .sun-icon {
  display: block;
}

/* General Button style */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: linear-gradient(135deg var(--in-oklch), var(--primary), var(--secondary));
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 4px 15px var(--primary-glow);
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--primary-glow), 0 0 10px rgba(255,255,255,0.15);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-outline:hover {
  border-color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
}

.light-theme .btn-outline:hover {
  background: rgba(0, 0, 0, 0.02);
}

/* ==========================================================================
   8. Amortization Table Section
   ========================================================================== */
.table-header-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 576px) {
  .table-header-controls {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.search-wrapper {
  position: relative;
  max-width: 250px;
  width: 100%;
}

.search-wrapper input {
  padding-left: 2.2rem;
  font-size: 0.85rem;
}

.search-icon {
  position: absolute;
  left: 0.8rem;
  color: var(--text-muted);
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.1);
}

.light-theme .table-scroll {
  background: rgba(255, 255, 255, 0.2);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.8rem;
}

th, td {
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid var(--border-color);
}

th {
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.light-theme th {
  background: rgba(0, 0, 0, 0.02);
}

/* Responsive Table Column Hiding */
@media (max-width: 640px) {
  .hide-mobile {
    display: none !important;
  }
  th, td {
    padding: 0.5rem 0.25rem;
    font-size: 0.75rem;
  }
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.light-theme tbody tr:hover {
  background: rgba(0, 0, 0, 0.01);
}

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

.text-right {
  text-align: right;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
}

.pagination-buttons {
  display: flex;
  gap: 0.5rem;
}

.pagination-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Helper Utility Classes */
.hidden {
  display: none !important;
}

.text-success {
  color: var(--success) !important;
}

.text-danger {
  color: var(--danger) !important;
}

.text-warning {
  color: var(--warning) !important;
}

/* Validation Alert Banner */
.alert-banner {
  background: linear-gradient(135deg var(--in-oklch), rgba(244, 63, 94, 0.1), rgba(225, 29, 72, 0.1));
  border: 1px solid rgba(225, 29, 72, 0.25);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.alert-icon {
  color: var(--danger);
  flex-shrink: 0;
  margin-top: 0.15rem;
}

.alert-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.alert-message strong {
  color: var(--text-primary);
  display: block;
  margin-bottom: 0.15rem;
}

/* ==========================================================================
   9. Print Styles
   ========================================================================== */
@media print {
  body {
    background: white !important;
    color: black !important;
    padding: 0 !important;
  }
  
  body::before {
    display: none !important;
  }
  
  .glass-card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    margin-bottom: 2cm;
    page-break-inside: avoid;
  }
  
  .dashboard-grid {
    display: block !important;
  }
  
  .theme-switch, 
  .btn-group, 
  .timeline-slider-container, 
  .input-wrapper, 
  .table-header-controls, 
  .pagination,
  form {
    display: none !important;
  }
  
  header {
    border-bottom: 2px solid #ccc;
    padding-bottom: 1rem;
    margin-bottom: 2rem;
  }
  
  .metrics-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 1rem !important;
  }
  
  .metric-card {
    border: 1px solid #ccc !important;
    background: transparent !important;
  }
  
  table {
    border: 1px solid #ccc !important;
  }
  
  th {
    background: #f0f0f0 !important;
    color: black !important;
    border-bottom: 2px solid #ccc !important;
  }
  
  td {
    border-bottom: 1px solid #eee !important;
  }
  
  .charts-grid {
    page-break-before: always;
  }
}
