/* DCA Calculator - Compact Design */
.dca-calculator-container, .dca-calculator-container *, .dca-calculator-container *::before, .dca-calculator-container *::after { box-sizing: border-box; }

.dca-calculator-container {
  --bg: #f5f5f0; --bg2: #fff; --border: #333; --text: #222; --text2: #555; --text3: #888;
  --blue: #3498db; --green: #27ae60; --purple: #9b59b6; --orange: #f39c12; --red: #e74c3c; --teal: #1abc9c;
  --shadow: 3px 3px 0 rgba(0,0,0,0.12);
  position: relative; max-width: 900px; width: 100%; margin: 8px auto; padding: 12px;
  background: var(--bg); border: 2px solid var(--border); border-radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
  color: var(--text); box-shadow: 6px 6px 0 rgba(0,0,0,0.12); line-height: 1.4;
  font-size: 16px; overflow-x: auto; box-sizing: border-box;
}

.dca-calculator-container.dark {
  --bg: #1a1a1a; --bg2: #2d2d2d; --border: #555; --text: #e8e8e8; --text2: #b0b0b0; --text3: #888;
  --blue: #5dade2; --green: #52c77a; --purple: #af7ac5; --orange: #f5b041; --red: #ec7063; --teal: #48d1cc;
}

@media (prefers-color-scheme: dark) {
  .dca-calculator-container:not(.dark):not(.light) {
    --bg: #1a1a1a; --bg2: #2d2d2d; --border: #555; --text: #e8e8e8; --text2: #b0b0b0; --text3: #888;
    --blue: #5dade2; --green: #52c77a; --purple: #af7ac5; --orange: #f5b041; --red: #ec7063; --teal: #48d1cc;
  }
}

/* Dark Toggle */
.dark-mode-toggle {
  position: absolute; top: 8px; right: 8px; padding: 4px 10px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 4px; cursor: pointer; font-size: 18px; z-index: 10;
}
.dark-mode-toggle:hover { transform: translate(1px,1px); }

/* Header */
.calculator-header {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding-bottom: 8px; margin-bottom: 10px; border-bottom: 2px solid var(--border);
}
.header-icon { font-size: 28px; }
.calculator-header h2 { margin: 0; font-size: 24px; font-weight: 700; }

/* Main Grid */
.main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }

/* Sections */
.input-section, .result-section {
  background: var(--bg2); padding: 10px; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--shadow);
}

/* Section Header with inline total */
.section-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
  font-size: 17px; font-weight: 600;
}
.badge {
  padding: 2px 8px; font-size: 11px; font-weight: 700; border-radius: 10px; color: #fff;
}
.badge.blue { background: var(--blue); }
.badge.green { background: var(--green); }
.badge.purple { background: var(--purple); }

.total-inline {
  margin-left: auto; font-size: 16px; font-weight: 700; font-family: 'Courier New', monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px;
}
.total-inline.blue { color: var(--blue); }
.total-inline.green { color: var(--green); }

/* Input Row - 2 columns */
.input-row { display: flex; gap: 8px; margin-bottom: 8px; }
.input-group { flex: 1; }
.input-group label { display: block; font-size: 14px; font-weight: 600; color: var(--text2); margin-bottom: 3px; }

.input-wrapper { position: relative; display: flex; align-items: center; }
.input-wrapper input {
  width: 100%; padding: 8px 30px 8px 10px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg2); color: var(--text); font-size: 17px; font-family: 'Courier New', monospace; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis;
}
.input-wrapper input:focus { outline: none; border-color: var(--blue); background: #fffacd; }
.dca-calculator-container.dark .input-wrapper input:focus { background: #3a3a3a; }
.input-wrapper .unit { position: absolute; right: 8px; font-size: 14px; color: var(--text3); }

/* Quick Row - inline */
.quick-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.quick-label { font-size: 13px; font-weight: 600; color: var(--text3); white-space: nowrap; }
.quick-grid { display: flex; gap: 4px; flex: 1; }
.quick-btn {
  flex: 1; padding: 6px 2px; background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  font-size: 13px; font-weight: 700; color: var(--red); cursor: pointer;
}
.quick-btn:hover { background: var(--red); color: #fff; }

/* Fee Row - single line */
.fee-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; color: var(--text2); cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--blue); }
.fee-inputs { display: none; gap: 6px; align-items: center; }
.fee-inputs.active { display: flex; }
.fee-item { display: flex; align-items: center; gap: 3px; font-size: 13px; color: var(--text2); }
.fee-item input { width: 50px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 3px; font-size: 13px; text-align: center; background: var(--bg2); color: var(--text); }

/* Action Row */
.action-row { display: flex; gap: 6px; }
.calculate-btn {
  flex: 2; padding: 10px; background: linear-gradient(135deg, var(--blue), #2980b9); color: #fff;
  border: 1.5px solid var(--border); border-radius: 5px; font-size: 18px; font-weight: 700;
  cursor: pointer; box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}
.calculate-btn:hover { transform: translate(1px,1px); box-shadow: 2px 2px 0 rgba(0,0,0,0.15); }
.sub-btn {
  flex: 1; padding: 10px 6px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.sub-btn.sample { background: var(--green); color: #fff; }
.sub-btn.reset { background: var(--orange); color: #fff; }
.sub-btn:hover { filter: brightness(1.1); }

/* Result Section */
.result-comparison { display: flex; align-items: stretch; gap: 6px; margin-bottom: 8px; }
.compare-card {
  flex: 1; padding: 10px 8px; border-radius: 5px; text-align: center; position: relative;
}
.compare-card.before { background: linear-gradient(135deg, rgba(52,152,219,0.1), rgba(52,152,219,0.02)); border: 1.5px solid var(--blue); }
.compare-card.after { background: linear-gradient(135deg, rgba(39,174,96,0.12), rgba(39,174,96,0.02)); border: 1.5px solid var(--green); }
.compare-badge {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  padding: 2px 10px; font-size: 11px; font-weight: 700; border-radius: 8px; color: #fff;
}
.compare-card.before .compare-badge { background: var(--blue); }
.compare-card.after .compare-badge { background: var(--green); }
.compare-main { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.compare-price { font-size: 22px; font-weight: 700; font-family: 'Courier New', monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-sub { font-size: 12px; color: var(--text3); }
.compare-arrow { display: flex; align-items: center; font-size: 22px; font-weight: 700; color: var(--purple); }

/* Stats Row - 3 columns */
.stats-row { display: flex; gap: 6px; margin-bottom: 4px; }
.stat-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
}
.stat-item.highlight { border-color: var(--green); background: linear-gradient(135deg, rgba(39,174,96,0.08), transparent); }
.stat-item.breakeven { border-color: var(--teal); background: linear-gradient(135deg, rgba(26,188,156,0.08), transparent); }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text3); }
.stat-value { font-size: 18px; font-weight: 700; font-family: 'Courier New', monospace; color: var(--green); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.stat-item.breakeven .stat-value { color: var(--teal); }
.breakeven-info { font-size: 12px; color: var(--text2); text-align: center; margin-bottom: 8px; }

/* Scenario Section */
.scenario-section { margin-bottom: 8px; }
.scenario-header { font-size: 14px; font-weight: 700; color: var(--text2); margin-bottom: 6px; }
.scenario-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.scenario-card {
  display: flex; flex-direction: column; align-items: center; padding: 6px 2px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px; text-align: center;
}
.scenario-card.loss { border-color: var(--red); background: linear-gradient(135deg, rgba(231,76,60,0.08), transparent); }
.scenario-label { font-size: 12px; font-weight: 700; color: var(--text3); }
.scenario-profit { font-size: 13px; font-weight: 700; font-family: 'Courier New', monospace; color: var(--green); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scenario-card.loss .scenario-profit { color: var(--red); }

/* Result Actions */
.result-actions { display: flex; gap: 6px; }
.action-btn {
  flex: 1; padding: 7px; background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  font-size: 14px; font-weight: 600; color: var(--text2); cursor: pointer;
}
.action-btn:hover { background: var(--bg); }

/* Simulation Section - Compact Single Row */
.simulation-section {
  background: var(--bg2); padding: 10px; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--shadow); margin-bottom: 8px;
}
.sim-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; font-weight: 700; margin-bottom: 8px;
}
.slider-value { font-size: 20px; font-weight: 700; color: var(--purple); font-family: 'Courier New', monospace; }

.sim-content { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.slider-wrap { flex: 1; }
.price-slider {
  width: 100%; height: 10px; border-radius: 5px;
  background: linear-gradient(to right, var(--red), var(--orange), var(--green));
  -webkit-appearance: none; cursor: pointer;
}
.price-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--purple); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.3); cursor: pointer;
}
.price-slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--purple); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.3); cursor: pointer;
}
.slider-range { display: flex; justify-content: space-between; font-size: 11px; color: var(--text3); margin-top: 4px; }

.sim-stats { display: flex; gap: 8px; }
.sim-stat { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.sim-label { font-size: 11px; font-weight: 600; color: var(--text3); }
.sim-value { font-size: 16px; font-weight: 700; font-family: 'Courier New', monospace; color: var(--text); }
.sim-value.primary { color: var(--purple); font-size: 18px; }
.sim-value.accent { color: var(--red); }

.efficiency-row { display: flex; align-items: center; gap: 10px; }
.eff-label { font-size: 13px; font-weight: 700; color: var(--text2); }
.eff-bar { flex: 1; height: 12px; background: var(--bg); border-radius: 6px; border: 1px solid var(--border); overflow: hidden; }
.eff-fill { height: 100%; transition: width 0.3s, background 0.3s; border-radius: 6px; }
.eff-text { font-size: 14px; font-weight: 700; min-width: 80px; text-align: right; }

/* Footer */
.footer-note { font-size: 12px; color: var(--text3); text-align: center; padding: 6px; }
.watermark { position: absolute; bottom: 8px; right: 10px; font-size: 11px; color: var(--text3); opacity: 0.4; }

/* ===== VISUAL ANALYSIS CHARTS SECTION ===== */
.charts-section {
  background: var(--bg2); padding: 12px; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--shadow); margin-bottom: 8px;
}
.charts-header {
  font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 10px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.charts-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
}
.chart-card {
  background: var(--bg); padding: 10px; border: 1px solid var(--border); border-radius: 6px;
}
.chart-card.wide { grid-column: span 2; }
.chart-title {
  font-size: 13px; font-weight: 700; color: var(--text2); margin-bottom: 8px;
  text-align: center;
}

/* Donut Chart */
.donut-chart {
  position: relative; width: 100px; height: 100px; margin: 0 auto 8px;
}
.donut-chart svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-bg { fill: none; stroke: var(--bg2); stroke-width: 8; }
.donut-segment { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dasharray 0.5s; }
.donut-segment.current { stroke: var(--blue); }
.donut-segment.add { stroke: var(--green); }
.donut-center {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center;
}
.donut-total { display: block; font-size: 13px; font-weight: 700; font-family: 'Courier New', monospace; }
.donut-label { display: block; font-size: 10px; color: var(--text3); }

.chart-legend {
  display: flex; justify-content: center; gap: 12px; font-size: 11px;
}
.legend-item { display: flex; align-items: center; gap: 4px; color: var(--text2); }
.legend-color {
  width: 10px; height: 10px; border-radius: 2px;
}
.legend-color.current { background: var(--blue); }
.legend-color.add { background: var(--green); }

/* Bar Chart */
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-item { display: flex; align-items: center; gap: 6px; }
.bar-label { font-size: 11px; color: var(--text3); min-width: 50px; }
.bar-track {
  flex: 1; height: 14px; background: var(--bg2); border-radius: 3px;
  border: 1px solid var(--border); overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 2px; transition: width 0.5s;
}
.bar-fill.blue { background: linear-gradient(90deg, var(--blue), #5dade2); }
.bar-fill.green { background: linear-gradient(90deg, var(--green), #52c77a); }
.bar-fill.purple { background: linear-gradient(90deg, var(--purple), #af7ac5); }
.bar-fill.teal { background: linear-gradient(90deg, var(--teal), #48d1cc); }
.bar-value {
  font-size: 11px; font-weight: 700; font-family: 'Courier New', monospace;
  min-width: 55px; text-align: right; color: var(--text);
}

/* Quantity Chart */
.qty-chart {
  display: flex; justify-content: center; gap: 16px; height: 90px; align-items: flex-end;
}
.qty-bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.qty-bar {
  width: 36px; height: 70px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 4px; position: relative; overflow: hidden;
  display: flex; align-items: flex-end;
}
.qty-fill {
  width: 100%; transition: height 0.5s; display: flex; align-items: center; justify-content: center;
  border-radius: 3px;
}
.qty-fill.current { background: linear-gradient(180deg, var(--blue), #2980b9); }
.qty-fill.add { background: linear-gradient(180deg, var(--green), #1e8449); }
.qty-fill.total { background: linear-gradient(180deg, var(--purple), #7d3c98); }
.qty-num {
  font-size: 10px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.qty-label { font-size: 11px; color: var(--text3); font-weight: 600; }
.qty-bar-wrap.total .qty-label { color: var(--purple); font-weight: 700; }

/* Range Chart */
.range-chart { padding: 5px 0; }
.range-scale {
  display: flex; justify-content: space-between; margin-bottom: 4px;
}
.range-marker { font-size: 10px; font-weight: 600; }
.range-marker.loss { color: var(--red); }
.range-marker.zero { color: var(--text3); }
.range-marker.profit { color: var(--green); }

.range-bar {
  height: 20px; background: linear-gradient(90deg, var(--red) 0%, var(--red) 16.67%, var(--orange) 16.67%, var(--orange) 33.33%, #f1c40f 33.33%, #f1c40f 50%, var(--green) 50%, var(--green) 100%);
  border-radius: 4px; position: relative; border: 1px solid var(--border);
}
.range-pointer {
  position: absolute; top: -6px; left: 16.67%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  transition: left 0.5s;
}
.range-pointer::after {
  content: '▼'; font-size: 12px; color: var(--text); line-height: 1;
}
.pointer-label {
  font-size: 9px; font-weight: 700; background: var(--bg2); padding: 1px 4px;
  border-radius: 3px; border: 1px solid var(--border); white-space: nowrap; margin-top: -2px;
}
.range-values {
  display: flex; justify-content: space-between; margin-top: 4px;
}
.range-val {
  font-size: 11px; font-weight: 700; font-family: 'Courier New', monospace;
}
.range-val.loss { color: var(--red); }
.range-val.zero { color: var(--text3); }
.range-val.profit { color: var(--green); }

/* Toast */
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--bg2); border: 2px solid var(--green);
  border-radius: 6px; padding: 10px 16px; display: flex; gap: 8px; align-items: center;
  opacity: 0; transform: translateY(20px); transition: all 0.3s; z-index: 1000;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-title { font-size: 15px; font-weight: 700; color: var(--text); }
.toast-value { font-size: 13px; color: var(--text2); font-family: 'Courier New', monospace; }

/* Capturing */
.dca-calculator-container.capturing .dark-mode-toggle,
.dca-calculator-container.capturing .action-btn { display: none; }

/* Responsive - Tablet */
@media (max-width: 768px) {
  .dca-calculator-container { margin: 6px; padding: 8px; max-width: calc(100% - 12px); }
  .main-grid { grid-template-columns: 1fr; gap: 8px; }
  .calculator-header h2 { font-size: 20px; }
  .sim-content { flex-direction: column; gap: 8px; }
  .sim-stats { width: 100%; justify-content: space-between; }
  .scenario-grid { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-card.wide { grid-column: span 2; }
}

/* Responsive - Mobile */
@media (max-width: 480px) {
  .dca-calculator-container { max-width: calc(100% - 12px); }
  .calculator-header h2 { font-size: 18px; }
  .header-icon { font-size: 22px; }
  .input-row { flex-direction: column; gap: 6px; }
  .quick-row { flex-wrap: wrap; }
  .quick-grid { flex-wrap: wrap; }
  .quick-btn { min-width: 40px; }
  .fee-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .fee-inputs.active { flex-wrap: wrap; }
  .result-comparison { flex-direction: column; gap: 8px; }
  .compare-arrow { transform: rotate(90deg); align-self: center; }
  .stats-row { flex-wrap: wrap; }
  .stat-item { min-width: calc(50% - 3px); }
  .scenario-grid { grid-template-columns: repeat(3, 1fr); }
  .sim-stats { flex-wrap: wrap; justify-content: center; }
  .sim-stat { min-width: 60px; }
  .charts-grid { grid-template-columns: 1fr 1fr; }
  .chart-card.wide { grid-column: span 2; }
  .donut-chart { width: 80px; height: 80px; }
  .qty-chart { gap: 10px; height: 80px; }
  .qty-bar { width: 30px; height: 60px; }
  .compare-price { font-size: 18px; }
  .stat-value { font-size: 15px; }
  .total-inline { max-width: 120px; font-size: 14px; }
}