:root {
  --primary: #c9a227;
  --primary-light: #f5e6a8;
  --primary-bg: #fdf8e7;
  --bg: #f7f8fa;
  --card-bg: #ffffff;
  --text: #2c2e31;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --border-light: #f0f2f5;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #fffdf4 0%, #fff 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  margin-bottom: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--primary-bg);
  border-radius: 12px;
}

.title-block h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.5px;
}

.title-block .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.formula-display {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--primary-bg);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--primary);
}

.formula-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.formula {
  font-family: 'Cambria Math', 'Times New Roman', serif;
  font-size: 15px;
  color: #8b7014;
  font-weight: 600;
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.mode-tab {
  flex: 1;
  padding: 12px 20px;
  background: none;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.25s ease;
}

.mode-tab:hover {
  color: var(--text);
  background: var(--border-light);
}

.mode-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(201, 162, 39, 0.35);
}

.tab-icon {
  font-weight: 600;
  font-size: 16px;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.card-indicator {
  width: 4px;
  height: 18px;
  background: var(--primary);
  border-radius: 2px;
}

.card-indicator.highlight {
  background: linear-gradient(to bottom, var(--primary), #e55);
}

/* Sample Params */
.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.param-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.param-item label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  transition: border-color 0.2s ease;
}

.input-with-unit:focus-within {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.15);
}

.input-with-unit input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: var(--text);
  font-family: 'Consolas', 'Monaco', monospace;
}

.input-with-unit .unit {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.input-with-unit .unit-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-with-unit .unit-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.2);
}

.input-with-unit .unit-select:hover {
  border-color: var(--primary);
}

.param-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 12px;
  background: var(--primary-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed #d1d5db;
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  color: var(--text-secondary);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--text);
}

.upload-icon {
  margin-bottom: 12px;
  color: #9ca3af;
  transition: color 0.25s ease;
}

.upload-zone:hover .upload-icon {
  color: var(--primary);
}

.upload-text {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-link {
  color: var(--primary);
  text-decoration: underline;
}

.upload-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.file-info {
  margin-top: 16px;
  padding: 12px 16px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #166534;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sample-data-hint {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
}

/* Data Section */
.data-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.temp-unit-select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.temp-unit-select select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.temp-unit-select select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.15);
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: #b8910f;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(201, 162, 39, 0.3);
}

.btn-secondary {
  background: #f3f4f6;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #e5e7eb;
}

.btn-danger {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}

/* Data Preview */
.data-preview {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #fafbfc;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  font-family: 'Consolas', 'Monaco', monospace;
}

.data-table tbody tr:hover {
  background: var(--primary-bg);
}

/* Chart Container */
.chart-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 20px;
}

.csv-export-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  padding: 4px 10px;
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.csv-export-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.fit-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 16px;
  background: #fafbfc;
  border-radius: var(--radius-sm);
  align-items: start;
}

.fit-range {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fit-range > label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.fit-mode-tabs {
  display: flex;
  gap: 4px;
  background: #fff;
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--border);
}

.fit-mode-tab {
  flex: 1;
  padding: 7px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.fit-mode-tab:hover {
  color: var(--text);
  background: var(--border-light);
}

.fit-mode-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(201, 162, 39, 0.3);
}

.fit-mode-panel {
  padding: 12px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.auto-detect-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auto-detect-info .info-item {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.info-value-small {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  font-family: 'Consolas', 'Monaco', monospace;
}

.sensitivity-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.sensitivity-slider input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 5px;
  background: #e5e7eb;
  border-radius: 3px;
  outline: none;
}

.sensitivity-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.sensitivity-slider span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  font-family: 'Consolas', 'Monaco', monospace;
  min-width: 40px;
  text-align: right;
}

.manual-range-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.range-segment {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}

.range-segment.hot {
  border-color: #fecaca;
  background: linear-gradient(135deg, #fff5f5 0%, #fff 100%);
}

.range-segment.cold {
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #f5f9ff 0%, #fff 100%);
}

.range-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.range-segment.hot .range-label {
  color: #dc2626;
}

.range-segment.cold .range-label {
  color: #2563eb;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-inputs input {
  flex: 1;
  min-width: 0;
}

.range-sep {
  color: var(--text-secondary);
  font-weight: 500;
}

.fit-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
}

.range-slider {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-slider input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  outline: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.range-slider span {
  font-size: 13px;
  font-family: 'Consolas', 'Monaco', monospace;
  color: var(--text);
  min-width: 60px;
  text-align: center;
}

.fit-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.fit-info-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.segment-title {
  font-size: 13px;
  font-weight: 600;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 2px;
}

.segment-title.hot {
  color: #dc2626;
}

.segment-title.cold {
  color: #2563eb;
}

.hot-color {
  color: #dc2626 !important;
}

.cold-color {
  color: #2563eb !important;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.info-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-family: 'Consolas', 'Monaco', monospace;
}

/* Result Section */
.result-display.single {
  margin-bottom: 16px;
}

.result-value-box.hot-box,
.result-value-box.cold-box {
  padding: 20px;
  border-radius: var(--radius-sm);
  text-align: center;
  border: 1px solid;
}

.result-value-box.hot-box {
  background: linear-gradient(135deg, #fef2f2 0%, #fff 100%);
  border-color: #fecaca;
}

.result-value-box.hot-box.primary {
  padding: 32px 24px;
  border-width: 2px;
  max-width: 420px;
  margin: 0 auto;
}

.result-value-box.hot-box .result-number {
  color: #dc2626;
}

.result-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'Consolas', 'Monaco', monospace;
}

.formula-box.center {
  text-align: center;
  margin-bottom: 16px;
}

.formula-box {
  padding: 20px;
  background: var(--primary-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary-light);
}

.formula-line {
  font-family: 'Cambria Math', 'Times New Roman', serif;
  color: #8b7014;
}

.formula-line:first-child {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
}

.formula-line.sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.center-narrow {
  text-align: center;
  margin: 8px 0;
  font-size: 15px !important;
}

.ea-explanation {
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.ea-explanation-title {
  font-weight: 600;
  color: #1e40af;
  margin-bottom: 10px;
  font-size: 14px;
}

.ea-explanation-content {
  font-size: 13px;
  line-height: 1.7;
  color: #374151;
}

.ea-explanation-content p {
  margin: 0 0 8px 0;
}

.ea-explanation-content ul {
  margin: 8px 0;
  padding-left: 22px;
}

.ea-explanation-content li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.ea-formula-note {
  margin-top: 10px !important;
  padding-top: 10px;
  border-top: 1px dashed #bfdbfe;
  font-size: 12px !important;
  color: #1e40af !important;
  font-style: italic;
}

.result-value-box {
  padding: 24px;
  background: linear-gradient(135deg, #fffdf4 0%, #fff 100%);
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary-light);
  text-align: center;
}

.result-number {
  font-size: 36px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.unit-ea {
  font-size: 18px;
  color: var(--text-secondary);
  font-weight: 500;
}

.result-label {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.result-detail {
  margin-bottom: 16px;
}

.result-detail .data-table {
  max-height: 240px;
  overflow: auto;
  display: block;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* I-V Curve Canvas Wrapper */
.iv-canvas-wrap {
  height: 280px;
  position: relative;
  margin: 16px 0;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .formula-display {
    width: 100%;
  }

  .mode-tab {
    padding: 10px 12px;
    font-size: 13px;
  }

  .card {
    padding: 18px;
  }

  .fit-controls {
    grid-template-columns: 1fr;
  }

  .result-display {
    grid-template-columns: 1fr;
  }

  .chart-container {
    aspect-ratio: 4 / 3;
  }

  .params-grid {
    grid-template-columns: 1fr;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}
