/* ============================================================
   IRR CALCULATOR STYLES (Internal Rate of Return)
   Tradesala ToolSpot | Indigo Theme & Financial Decisions
   ============================================================ */

.container {
  --tool-fire: #6366f1; /* Indigo / Violet standard */
  --tool-fire-soft: rgba(99, 102, 241, 0.12);
  --tool-danger: #ef4444; /* Crimson Red for negative or unviable IRR */
  --tool-danger-soft: rgba(239, 68, 68, 0.12);
  --tool-red: #6366f1; /* Map slider theme variables to Indigo */
  --tool-red-soft: rgba(99, 102, 241, 0.12);
}

/* ── Dynamic Cash Flow Inputs Grid ── */
.cash-flow-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
  transition: all 0.2s ease;
}

.cash-flow-row:hover {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(99, 102, 241, 0.2);
}

.cash-flow-row .year-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.cash-flow-row .slider-wrap {
  display: flex;
  align-items: center;
}

.cash-flow-row .slider-wrap input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  outline: none;
}

.cash-flow-row .cf-input-wrap {
  position: relative;
  width: 120px; /* Explicit width prevents input from stretching and overflowing on mobile Safari */
  flex-shrink: 0; /* Forced to prevent Safari flexbox item collapse/shrinkage */
}

.cash-flow-row .cf-input-wrap span {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 12px;
  pointer-events: none;
}

.cash-flow-row .cf-input-wrap input[type="number"] {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 6px 10px 6px 20px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  box-sizing: border-box;
  text-align: right;
  -webkit-appearance: none;
  margin: 0;
}

.cash-flow-row .cf-input-wrap input[type="number"]::-webkit-inner-spin-button,
.cash-flow-row .cf-input-wrap input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cash-flow-row .cf-input-wrap input[type="number"]:focus {
  border-color: var(--tool-fire);
  background: rgba(255, 255, 255, 0.05);
}

body.light .cash-flow-row .cf-input-wrap input[type="number"] {
  background: rgba(0, 0, 0, 0.02);
}

body.light .cash-flow-row .cf-input-wrap input[type="number"]:focus {
  border-color: var(--tool-fire);
}

/* ── Quick Fill Controls ── */
.quick-fill-panel {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}

.quick-fill-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  margin-bottom: 12px;
}

.quick-fill-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.qf-stacked-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.qf-stacked-row label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-2);
}

.qf-action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

/* ── Prefix & Suffix Inputs ── */
.qf-input-group {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0; /* Allows inputs to shrink correctly under flex box containers on iOS Safari */
}

.qf-input-group span {
  position: absolute;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}

.qf-input-group span.prefix {
  left: 8px;
}

.qf-input-group span.suffix {
  right: 8px;
}

.qf-input-group input {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
  text-align: right;
  transition: all 0.2s;
  -webkit-appearance: none;
  margin: 0;
}

.qf-input-group input::-webkit-inner-spin-button,
.qf-input-group input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

body.light .qf-input-group input {
  background: rgba(0, 0, 0, 0.02);
}

.qf-input-group input:focus {
  border-color: var(--tool-fire);
}

.qf-input-group.has-prefix input {
  padding-left: 20px;
}

.qf-input-group.has-suffix input {
  padding-right: 20px;
}

.quick-fill-btn {
  background: var(--tool-fire-soft);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--tool-fire);
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.quick-fill-btn:hover {
  background: var(--tool-fire);
  color: #ffffff;
}

.quick-fill-btn.reset-btn {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
  color: #f87171;
  width: 100%;
  padding: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.quick-fill-btn.reset-btn:hover {
  background: #ef4444;
  color: #ffffff;
}

/* ── KPI Grid & Status Banner Styles ── */
.fire-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 640px) {
  .fire-kpi-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-span-full {
  grid-column: 1 / -1;
}

/* ── KPI Card Color Theme Overrides (Indigo) ── */
.kpi-card.hero.indigo {
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.3);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(99, 102, 241, 0.02) 100%);
  transition: all 0.3s ease;
}

.kpi-card.hero.indigo .kpi-val {
  color: var(--tool-fire) !important;
  text-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

.kpi-card.hero.indigo .kpi-label {
  color: rgba(165, 180, 252, 0.8) !important;
}

body.light .kpi-card.hero.indigo {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(99, 102, 241, 0.02) 100%);
  border-color: rgba(99, 102, 241, 0.2);
}

body.light .kpi-card.hero.indigo .kpi-val {
  color: #4338ca !important;
}

body.light .kpi-card.hero.indigo .kpi-label {
  color: #3730a3 !important;
}

/* Unviable overrides */
.kpi-card.hero.indigo.unviable {
  box-shadow: 0 8px 32px rgba(239, 68, 68, 0.2);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0.05) 100%);
  border-color: rgba(239, 68, 68, 0.3);
}

.kpi-card.hero.indigo.unviable .kpi-val {
  color: #f87171 !important;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.kpi-card.hero.indigo.unviable .kpi-sub {
  color: rgba(248, 113, 113, 0.7);
}

body.light .kpi-card.hero.indigo.unviable {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.08) 0%, rgba(239, 68, 68, 0.02) 100%);
  border-color: rgba(239, 68, 68, 0.2);
}

body.light .kpi-card.hero.indigo.unviable .kpi-val {
  color: #b91c1c !important;
}

body.light .kpi-card.hero.indigo.unviable .kpi-label {
  color: #991b1b !important;
}

/* ── Status Banner Viability Modes ── */
.status-banner {
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  border: 1px solid transparent;
}

.status-banner.achieved {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
}

.status-banner.warning {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

body.light .status-banner.achieved {
  background: rgba(99, 102, 241, 0.06);
  border-color: rgba(99, 102, 241, 0.2);
  color: #312e81;
}

body.light .status-banner.warning {
  background: rgba(239, 68, 68, 0.04);
  border-color: rgba(239, 68, 68, 0.15);
  color: #7f1d1d;
}

/* ── Cash Flows Scrollable Container ── */
.cash-flows-container-scroll {
  max-height: 380px;
  overflow-y: auto;
  padding-right: 6px;
  margin-top: 12px;
  -webkit-overflow-scrolling: touch;
}

/* Scrollbar styling */
.cash-flows-container-scroll::-webkit-scrollbar {
  width: 5px;
}

.cash-flows-container-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
}

.cash-flows-container-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.cash-flows-container-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

body.light .cash-flows-container-scroll::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.02);
}

body.light .cash-flows-container-scroll::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
}

/* ── Chart Section Toggle Styling ── */
.chart-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 16px;
}

.chart-toggle-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-toggle-btn.active {
  background: var(--tool-fire-soft);
  border-color: var(--tool-fire);
  color: var(--tool-fire);
}

.chart-toggle-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
}

body.light .chart-toggle-btn:hover:not(.active) {
  background: rgba(0, 0, 0, 0.04);
}

.chart-wrap {
  position: relative;
  height: 320px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* Prevent Chart.js canvas from expanding beyond parent container */
.chart-wrap canvas {
  width: 100% !important;
  max-width: 100% !important;
}

/* Layout stabilization to prevent grid item content from causing horizontal overflow */
.main-grid {
  width: 100%;
  max-width: 100%;
}

.left-col,
.right-col {
  min-width: 0;
}

/* ── Amortization Table Styles ── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.015);
  margin-top: 16px;
  -webkit-overflow-scrolling: touch;
}

body.light .table-wrap {
  background: rgba(0, 0, 0, 0.005);
  border-color: rgba(0, 0, 0, 0.08);
}

.projection-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: right;
}

.projection-table th {
  background: rgba(255, 255, 255, 0.03);
  padding: 10px 8px;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 2px solid rgba(99, 102, 241, 0.15);
  /* Allowed wrapping on headers to shrink column width */
}

body.light .projection-table th {
  background: rgba(0, 0, 0, 0.02);
  color: #444;
  border-bottom-color: rgba(99, 102, 241, 0.12);
}

.projection-table td {
  padding: 10px 8px;
  color: var(--text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  white-space: nowrap;
  font-variant-numeric: tabular-nums; /* Perfect numerical vertical alignment */
}

body.light .projection-table td {
  color: #333;
  border-bottom-color: rgba(0, 0, 0, 0.035);
}

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

.projection-table th:first-child,
.projection-table td:first-child {
  text-align: left;
  font-weight: 600;
}

/* Zebra striping for improved legibility */
.projection-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.008);
}

body.light .projection-table tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.01);
}

/* Premium Indigo hover effect */
.projection-table tr:hover td {
  background: rgba(99, 102, 241, 0.07) !important;
}

body.light .projection-table tr:hover td {
  background: rgba(99, 102, 241, 0.04) !important;
}

.text-success {
  color: #10b981 !important;
}

body.light .text-success {
  color: #059669 !important;
}

.text-danger {
  color: #f87171 !important;
}

body.light .text-danger {
  color: #dc2626 !important;
}

/* ── Mobile Layout Adjustments (Width <= 768px) ── */
@media (max-width: 768px) {
  /* Reduce global page padding on small viewports */
  .container {
    padding: 0 12px 60px !important;
  }

  /* Reduce panel inner padding to fit labels and sliders */
  .panel {
    padding: 16px 12px !important;
    border-radius: 16px !important;
  }

  /* Shrink slider value badges and header fonts slightly to fit */
  .input-header label {
    font-size: 13px !important;
  }
  
  .value-badge {
    font-size: 11px !important;
    padding: 3px 8px !important;
  }

  /* Force cash flows elements to stay inside bounds */
  .cash-flows-container-scroll {
    overflow-x: hidden !important;
    padding-right: 2px !important;
  }

  .cash-flow-row {
    padding: 10px 8px !important;
    gap: 8px !important;
  }

  .cash-flow-row-top {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .cash-flow-row .cf-input-wrap {
    width: 100px !important;
  }

  /* Wrap Quick Fill growth compound input fields gracefully */
  .qf-action-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .qf-action-row .qf-input-group {
    width: 100% !important;
    flex: none !important;
  }

  .qf-action-row .quick-fill-btn {
    width: 100% !important;
  }

  /* Table adjustments to avoid horizontal scrolls on mobile */
  .projection-table th, 
  .projection-table td {
    padding: 8px 6px !important;
    font-size: 11.5px !important;
  }
}
