/* ========================================
   Compound Calculator View
   ========================================= */

/* === View Container === */

.view--compound {
  display: none;
  flex-direction: column;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.view--compound.view--active {
  display: flex;
}

.view--compound.view--hidden {
  display: none !important;
}

/* === Header === */

.compound-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.compound-header__left {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.compound-header__icon {
  display: none;
}

.compound-header__title {
  color: var(--text-primary);
  font-weight: var(--font-bold);
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  margin: 0;
}

.compound-header__subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* === 2-Column Layout === */

.compound-layout {
  display: flex;
  gap: var(--space-6);
  flex: 1;
  min-height: 0;
}

/* === Sidebar === */

.compound-sidebar {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Sidebar cards */
.compound-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 2px 8px rgba(20, 20, 20, 0.05);
}

.compound-card .card__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.compound-card .card__icon {
  display: none;
}

.compound-card .card__title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.compound-card .label-optional {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: var(--font-normal);
  margin-left: auto;
}

.compound-card .card__body {
  padding: var(--space-4);
}

.compound-card .input-group {
  margin-bottom: var(--space-3);
}

.compound-card .input-group:last-child {
  margin-bottom: 0;
}

.compound-card .preset-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.compound-card .preset-btn {
  padding: var(--space-2);
  font-size: var(--text-xs);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.compound-card .preset-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.compound-card .preset-btn.active {
  background: var(--primary-muted);
  border-color: var(--primary);
  color: var(--primary);
}

/* === Info Card === */

.compound-info {
  padding: var(--space-3);
  border-radius: var(--border-radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.compound-info__text {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

.compound-info__text strong {
  color: var(--text-secondary);
}

/* === Contributions Section === */

.contribution-mode-toggle {
  margin-bottom: var(--space-3);
}

.contribution-mode-toggle .preset-btn {
  font-family: var(--font-sans);
}

.contribution-fields-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.contribution-fields {
  flex: 1;
}

.input-label--sm {
  font-size: var(--text-xs);
  margin-bottom: var(--space-2);
  display: block;
  color: var(--text-muted);
}

.contribution-input-row {
  display: flex;
  gap: var(--space-2);
}

.contribution-input-row .input-wrapper {
  flex: 1;
}

.contribution-input-row .input--select {
  width: 100px;
  flex-shrink: 0;
}

/* Select inputs */
.input--select {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
}

.input--select:focus {
  outline: none;
  border-color: var(--primary);
}

/* === Main Content === */

.compound-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

/* === Table Container === */

.compound-table-container {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  overflow-x: auto;
  overflow-y: visible;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* Subtle scroll cue */
.compound-table-container::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, var(--bg-base));
  pointer-events: none;
  opacity: 0.75;
  transition: opacity 0.2s ease;
}

.compound-table-container.scrolled-end::after {
  opacity: 0;
}

/* === Table === */

.compound-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
}

.compound-th,
.compound-cell {
  padding: var(--space-3) var(--space-4);
  text-align: right;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.compound-th {
  font-family: var(--font-mono);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: var(--text-xs);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 1;
}

.compound-th--year {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--bg-elevated);
  z-index: 2;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
}

.compound-cell {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.compound-cell--year {
  text-align: left;
  color: var(--text-primary);
  font-weight: var(--font-medium);
  position: sticky;
  left: 0;
  background: var(--bg-surface);
  z-index: 1;
}

.compound-row {
  transition: background-color var(--transition-fast);
}

.compound-row:hover {
  background: var(--bg-hover);
}

.compound-row:hover .compound-cell--year {
  background: var(--bg-hover);
}

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

/* === Value Emphasis === */

.compound-cell--growth {
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.compound-cell--contribution {
  color: var(--warning);
  font-weight: var(--font-medium);
}

.compound-cell--withdrawal {
  color: var(--danger);
  font-weight: var(--font-medium);
}

.compound-cell--balance {
  color: var(--text-primary);
  font-weight: var(--font-semibold);
}

/* Column header states */
.compound-th--selected {
  background: rgba(158, 123, 59, 0.12) !important;
  box-shadow: inset 0 -2px 0 var(--primary);
  cursor: pointer;
}

.compound-th[data-rate] {
  cursor: pointer;
  transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.compound-th[data-rate]:hover {
  background: rgba(158, 123, 59, 0.08);
}

/* === Summary Stats === */

.compound-summary {
  margin-top: 0;
}

/* === Insights Row === */

.compound-insights {
  margin-top: var(--space-4);
  margin-bottom: var(--space-4);
}

.stats-grid--insights {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

/* === Insight Cards === */

.insight-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  box-shadow: 0 2px 8px rgba(20, 20, 20, 0.05);
}

.insight-card__text {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--text-secondary);
}

.insight-card__text strong {
  color: var(--text-primary);
  font-weight: var(--font-semibold);
}

.insight-highlight {
  font-family: var(--font-mono);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.insight-highlight--success {
  color: var(--text-primary);
}

.insight-highlight--warning {
  color: var(--warning);
}

/* === Entrance Animations === */

.view--compound.view--active .compound-header,
.view--compound.view--active .compound-sidebar,
.view--compound.view--active .compound-table-container,
.view--compound.view--active .compound-summary,
.view--compound.view--active .compound-insights {
  animation: fadeIn 0.24s ease-out;
}

/* === Mobile / Responsive === */

@media (max-width: 1024px) {
  .compound-layout {
    flex-direction: column;
  }

  .compound-sidebar {
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .compound-sidebar .compound-card {
    flex: 1;
    min-width: 250px;
  }

  .stats-grid--insights {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .view--compound {
    padding: var(--space-4);
  }

  .compound-sidebar {
    flex-direction: column;
  }

  .compound-sidebar .compound-card {
    min-width: 100%;
  }

  .compound-th,
  .compound-cell {
    padding: var(--space-2);
    font-size: var(--text-xs);
  }

  .view--compound.view--active .compound-header,
  .view--compound.view--active .compound-sidebar,
  .view--compound.view--active .compound-table-container,
  .view--compound.view--active .compound-summary,
  .view--compound.view--active .compound-insights {
    animation: fadeIn 0.2s ease-out;
  }

  .compound-insights {
    margin-top: var(--space-3);
  }

  .stats-grid--insights {
    gap: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .view--compound.view--active .compound-header,
  .view--compound.view--active .compound-sidebar,
  .view--compound.view--active .compound-table-container,
  .view--compound.view--active .compound-summary,
  .view--compound.view--active .compound-insights,
  .compound-row,
  .compound-th[data-rate] {
    animation: none !important;
    transition: none !important;
  }
}