/* ============================================================
   NPV CALCULATOR STYLES (Net Present Value)
   Tradesala ToolSpot | Emerald Green & Financial Decisions
   ============================================================ */

.container {
  --tool-fire: #10b981; /* Emerald Green standard */
  --tool-fire-soft: rgba(16, 185, 129, 0.12);
  --tool-danger: #ef4444; /* Crimson Red for negative NPV */
  --tool-danger-soft: rgba(239, 68, 68, 0.12);
  --tool-red: #10b981; /* Map slider theme variables to emerald green */
  --tool-red-soft: rgba(16, 185, 129, 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(16, 185, 129, 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(16, 185, 129, 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;
}

/* ── Dynamic KPI Colors based on NPV ── */
.kpi-card.hero.emerald.unviable {
  box-shadow: 0 8px 32px rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0.05) 100%);
}

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

.kpi-card.hero.emerald.unviable .kpi-label {
  color: #fca5a5;
}

/* ── Scrollable Cash Flows Grid Container ── */
.cash-flows-container-scroll {
  max-height: 380px;
  overflow-y: auto; /* Changed to auto for better dynamic scrolling calculations */
  padding-right: 6px;
  margin-top: 12px;
  -webkit-overflow-scrolling: touch; /* Smooth momentum scrolling for iOS Safari scroll containers */
}

/* Custom Scrollbar - Forced Permanent Styling */
.cash-flows-container-scroll::-webkit-scrollbar {
  width: 6px;
}

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

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

.cash-flows-container-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(16, 185, 129, 0.4);
}

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

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

body.light .cash-flows-container-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(16, 185, 129, 0.5);
}


/* ── Amortization Table Styles ── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.01);
  margin-top: 16px;
  -webkit-overflow-scrolling: touch; /* Smooth momentum scrolling for horizontal tables on iOS Safari */
}

body.light .table-wrap {
  background: rgba(0, 0, 0, 0.01);
  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: 12px 16px;
  font-weight: 600;
  color: var(--text-2);
  border-bottom: 1px solid var(--glass-border);
  white-space: nowrap;
}

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

.projection-table td {
  padding: 12px 16px;
  color: var(--text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  white-space: nowrap;
}

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

.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;
}

.projection-table tr:hover td {
  background: rgba(255, 255, 255, 0.015);
}

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

/* ── Chart Toggle Buttons ── */
.chart-toggle {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 4px;
}

body.light .chart-toggle {
  background: rgba(0, 0, 0, 0.02);
}

.chart-toggle-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-toggle-btn:hover {
  color: var(--text);
}

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

body.light .chart-toggle-btn.active {
  background: rgba(16, 185, 129, 0.15);
}

/* ── 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;
  }
}

@media (max-width: 480px) {
  .qf-action-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .qf-action-row .qf-input-group {
    width: 100%;
    flex: none !important;
  }
  .qf-action-row .quick-fill-btn {
    width: 100%;
  }
}

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

.status-banner {
  padding: 14px 18px;
  border-radius: 14px;
  margin-bottom: 20px;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
}

.status-banner.achieved {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.25);
  color: #10b981;
}

.status-banner.warning {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: rgba(239, 68, 68, 0.25) !important;
  color: #ef4444 !important;
}

body.light .status-banner.achieved {
  background: rgba(16, 185, 129, 0.06);
  color: #059669;
  border-color: rgba(5, 150, 105, 0.2);
}

body.light .status-banner.warning {
  background: rgba(239, 68, 68, 0.06) !important;
  color: #c2410c !important;
  border-color: rgba(239, 68, 68, 0.2) !important;
}

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

.kpi-card.hero.emerald .kpi-val {
  color: var(--tool-fire) !important;
  text-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

.kpi-card.hero.emerald .kpi-label {
  color: rgba(16, 185, 129, 0.8) !important;
}

body.light .kpi-card.hero.emerald {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(16, 185, 129, 0.02) 100%);
  border-color: rgba(16, 185, 129, 0.2);
}

body.light .kpi-card.hero.emerald .kpi-val {
  color: #047857 !important;
}

body.light .kpi-card.hero.emerald .kpi-label {
  color: #065f46 !important;
}

/* Unviable overrides */
body.light .kpi-card.hero.emerald.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.emerald.unviable .kpi-val {
  color: #b91c1c !important;
}

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

/* 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;
}

@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;
  }
}

