﻿:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #fafbfc;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;
  --primary: #2563eb;
  --primary-weak: #eff6ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 2px 8px rgba(17, 24, 39, 0.10);
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --duration-fast: 120ms;
  --duration-base: 160ms;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-soft: #1d212a;
  --border: #2a2f3a;
  --border-strong: #3a4150;
  --text: #f3f4f6;
  --text-muted: #a1a1aa;
  --text-soft: #71717a;
  --primary: #60a5fa;
  --primary-weak: rgba(96, 165, 250, 0.12);
  --success: #4ade80;
  --warning: #f59e0b;
  --danger: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: var(--space-6);
  min-width: 320px;
  overflow-x: hidden;
}

.container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.header,
.summary-banner,
.panel,
.chart-container,
.kpi-card,
.leverage-card,
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
}

.header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.summary-banner {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.summary-banner span {
  color: var(--primary);
  font-size: 20px;
  font-weight: 700;
}

.panel {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
}

.input-group {
  margin-bottom: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.input-group-header {
  background: var(--surface-soft);
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.input-group-header:hover {
  background: var(--primary-weak);
}

.input-group-header span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.input-group-content {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.input-group.collapsed .input-group-content {
  display: none;
}

.form-control {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-control label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-control input,
.monthly-input-cell input,
.optional-role-input {
  width: 100%;
  height: 40px;
  padding: 0 44px 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  box-shadow: none;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background-color var(--duration-fast) ease;
}

.form-control input:focus,
.monthly-input-cell input:focus,
.optional-role-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-control input[readonly] {
  background: var(--surface-soft);
  color: var(--text-muted);
}

.input-suffix {
  position: absolute;
  right: 12px;
  font-size: 12px;
  color: var(--text-soft);
  pointer-events: none;
}

.form-control input[type="range"] {
  width: 100%;
  height: 6px;
  padding: 0;
  background: var(--border);
  border: 0;
  border-radius: 999px;
  appearance: none;
}

.form-control input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 0;
  box-shadow: none;
  cursor: pointer;
}

.range-value {
  font-weight: 700;
  color: var(--primary);
}

.info-icon {
  color: var(--primary);
  cursor: help;
  margin-left: var(--space-1);
  font-size: 12px;
}

.global-tooltip {
  position: fixed;
  background: #111827;
  color: #fff;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  z-index: 99999;
  pointer-events: none;
  max-width: 260px;
  line-height: 1.5;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity var(--duration-fast) ease;
}

.global-tooltip.visible {
  opacity: 1;
}

.btn {
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--duration-fast) ease, background-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.btn:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  box-shadow: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
}

.results-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.kpi-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.kpi-value.highlight-text { color: var(--warning); }
.kpi-value.success-text { color: var(--success); }

.kpi-subtext {
  font-size: 12px;
  color: var(--text-muted);
}

.chart-container {
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}

.chart-container.full-width {
  grid-column: 1 / -1;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.chart-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-body {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 240px;
  max-height: 420px;
}

.chart-body canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.sensitivity-table-container {
  width: 100%;
  overflow-x: hidden;
}

.sensitivity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  text-align: center;
  table-layout: fixed;
}

.sensitivity-table th,
.sensitivity-table td {
  padding: 6px 4px;
  border: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sensitivity-table th {
  background: var(--surface-soft);
  font-weight: 700;
  font-size: 11px;
}

.sensitivity-table td {
  font-weight: 600;
}

.sensitivity-table th:first-child,
.sensitivity-table td:first-child {
  width: 72px;
}

.leverage-comparison {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.leverage-card {
  flex: 1;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  text-align: center;
}

.leverage-card h4 {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.leverage-card .val {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.leverage-card.active {
  border-color: var(--primary);
  background: var(--primary-weak);
}

.monthly-multiplier-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.monthly-input-cell label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.monthly-flow-arrow {
  font-size: 14px;
  color: var(--text-muted);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(17, 24, 39, 0.48);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-base) ease, visibility var(--duration-base) ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 90%;
    max-width: 860px;
    max-height: 85vh;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    transform: translateY(8px);
    transition: transform var(--duration-base) ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
    color: var(--text);
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-close:hover {
    color: var(--danger);
}

.modal-body {
    padding: var(--space-5);
    overflow-y: auto;
}

.term-item {
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-5);
    border-bottom: 1px dashed var(--border);
}

.term-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.term-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-2);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.term-formula {
    background: var(--surface-soft);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: var(--primary);
    margin-bottom: var(--space-3);
    border-left: 3px solid var(--primary);
}

.term-desc {
    color: var(--text-muted);
    line-height: 1.6;
}

.term-example {
    margin-top: var(--space-3);
    padding: var(--space-3);
    background-color: rgba(22, 163, 74, 0.08);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
}

@media (max-width: 1024px) {
  .chart-container.full-width {
    grid-column: auto;
  }
  .leverage-comparison {
    flex-direction: column;
  }
  .monthly-multiplier-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .chart-body {
    aspect-ratio: 16 / 10;
  }
}

@media (max-width: 768px) {
  body {
    padding: var(--space-4);
  }
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
  }
  .header h1 {
    font-size: 20px;
  }
  .panel {
    padding: var(--space-4);
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .monthly-multiplier-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .monthly-multiplier-grid {
    grid-template-columns: 1fr;
  }
  .chart-body {
    aspect-ratio: 4 / 3;
    min-height: 220px;
  }
  .sensitivity-table {
    font-size: 10px;
  }
  .sensitivity-table th,
  .sensitivity-table td {
    padding: 5px 3px;
  }
  .sensitivity-table th:first-child,
  .sensitivity-table td:first-child {
    width: 64px;
  }
}
