/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0D9488;
  --primary-light: #14B8A6;
  --primary-dark: #0F766E;
  --primary-bg: #F0FDFA;
  --accent: #2DD4BF;
  --danger: #EF4444;
  --warning: #F59E0B;
  --success: #10B981;
  --neutral-50: #F8FAFC;
  --neutral-100: #F1F5F9;
  --neutral-200: #E2E8F0;
  --neutral-300: #CBD5E1;
  --neutral-400: #94A3B8;
  --neutral-500: #64748B;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1E293B;
  --neutral-900: #0F172A;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 4px 10px -5px rgba(0,0,0,0.03);
  --font: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: linear-gradient(135deg, #F0FDFA 0%, #F0F9FF 50%, #F5F3FF 100%);
  color: var(--neutral-800);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Header ===== */
.app-header {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--neutral-200);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo svg { width: 40px; height: 40px; }
.logo-img { width: 44px; height: 44px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 1.15rem; font-weight: 700; color: var(--primary-dark); letter-spacing: -0.02em; }
.brand-sub { font-size: 0.8rem; color: var(--neutral-500); font-weight: 400; }
.header-badge {
  font-size: 0.75rem;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 5px 14px;
  border-radius: 20px;
  font-weight: 500;
  border: 1px solid rgba(13,148,136,0.15);
}

/* ===== Step Nav ===== */
.step-nav {
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--neutral-200);
}
.step-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}
.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.25s;
  white-space: nowrap;
  flex-shrink: 0;
}
.step-item:hover:not(.disabled) { background: var(--neutral-100); }
.step-item.active { background: var(--primary-bg); }
.step-item.disabled { opacity: 0.45; cursor: default; }
.step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--neutral-200);
  color: var(--neutral-600);
  transition: all 0.25s;
}
.step-item.active .step-number { background: var(--primary); color: #fff; }
.step-item.completed .step-number { background: var(--success); color: #fff; }
.step-label { font-size: 0.85rem; color: var(--neutral-600); font-weight: 500; }
.step-item.active .step-label { color: var(--primary-dark); font-weight: 600; }

/* ===== Main Content ===== */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
.step-panel {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--neutral-100);
}
.panel-header { margin-bottom: 24px; }
.panel-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--neutral-900); margin-bottom: 6px; }
.panel-desc { color: var(--neutral-500); font-size: 0.9rem; }

/* ===== Buttons ===== */
.btn {
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(13,148,136,0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13,148,136,0.35); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-outline {
  background: #fff;
  color: var(--neutral-700);
  border: 1.5px solid var(--neutral-300);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-sm { padding: 7px 16px; font-size: 0.82rem; }

/* ===== Upload Area ===== */
.upload-area {
  border: 2px dashed var(--neutral-300);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  transition: all 0.25s;
  background: var(--neutral-50);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.upload-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-area p { color: var(--neutral-500); margin-bottom: 12px; }
.upload-hint { font-size: 0.8rem; color: var(--neutral-400); margin-top: 10px !important; }
.upload-btn { cursor: pointer; }

.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
  color: var(--neutral-400);
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--neutral-200);
}
.divider span { padding: 0 16px; font-size: 0.85rem; }

.sample-btn-area { text-align: center; margin-bottom: 8px; }
.sample-hint { font-size: 0.8rem; color: var(--neutral-400); margin-top: 8px; }

/* ===== Data Preview ===== */
.data-preview { margin-top: 28px; }
.preview-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.preview-header h3 { font-size: 1.1rem; font-weight: 600; }
.preview-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-badge {
  font-size: 0.78rem;
  padding: 4px 12px;
  background: var(--neutral-100);
  border-radius: 20px;
  color: var(--neutral-600);
  font-weight: 500;
}
.stat-warn { background: #FEF3C7; color: #92400E; }

/* ===== Tables ===== */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--neutral-200); }
.data-table, .result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.data-table th, .result-table th {
  background: var(--neutral-100);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--neutral-700);
  border-bottom: 2px solid var(--neutral-200);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table td, .result-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--neutral-100);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--neutral-50); }
.row-num { color: var(--neutral-400); font-weight: 500; }
.missing-cell { color: var(--danger); font-style: italic; }
.more-rows { text-align: center; color: var(--neutral-400); padding: 12px !important; }

.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--primary); }
.sort-icon { font-size: 0.7rem; }

.highlight-row { background: rgba(16,185,129,0.05) !important; }
.high-value { color: var(--primary-dark); font-weight: 600; }

/* ===== Variable Selection ===== */
.var-selection { margin-top: 28px; }
.var-selection h3 { font-size: 1.1rem; margin-bottom: 8px; }
.selection-desc { color: var(--neutral-500); font-size: 0.85rem; margin-bottom: 16px; }
.var-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.var-col h4 { font-size: 0.9rem; margin-bottom: 10px; color: var(--neutral-700); }
.var-count { font-weight: 400; color: var(--neutral-400); }
.var-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
  padding: 8px;
}
.var-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.85rem;
}
.var-item:hover:not(.disabled) { background: var(--neutral-50); }
.var-item.selected { background: var(--primary-bg); color: var(--primary-dark); }
.var-item.disabled { opacity: 0.4; cursor: not-allowed; }
.var-item input { display: none; }
.var-check, .var-radio {
  width: 18px;
  height: 18px;
  border: 2px solid var(--neutral-300);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.var-radio { border-radius: 50%; }
.var-item.selected .var-check {
  background: var(--primary);
  border-color: var(--primary);
}
.var-item.selected .var-check::after {
  content: '✓';
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}
.var-item.selected .var-radio {
  border-color: var(--primary);
}
.var-item.selected .var-radio::after {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
}
.selection-summary {
  margin-top: 16px;
  padding: 12px 18px;
  background: var(--primary-bg);
  border: 1px solid rgba(13,148,136,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--primary-dark);
  font-weight: 500;
}

/* ===== Calibration ===== */
.calibration-info { margin-bottom: 24px; }
.info-box {
  background: var(--primary-bg);
  border: 1px solid rgba(13,148,136,0.15);
  border-radius: var(--radius);
  padding: 18px 22px;
}
.info-box strong { color: var(--primary-dark); display: block; margin-bottom: 6px; }
.info-box p { color: var(--neutral-600); font-size: 0.85rem; margin-bottom: 8px; }
.info-box ul { padding-left: 20px; color: var(--neutral-600); font-size: 0.85rem; }
.info-box ul li { margin-bottom: 4px; }

.calibration-cards { display: flex; flex-direction: column; gap: 20px; }
.cal-card {
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  padding: 22px;
  transition: box-shadow 0.2s;
}
.cal-card:hover { box-shadow: var(--shadow); }
.cal-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.cal-card-header h4 { font-size: 1rem; font-weight: 600; }
.cal-type-badge {
  font-size: 0.72rem;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 500;
}
.cal-type-badge.cond { background: #DBEAFE; color: #1E40AF; }
.cal-type-badge.outcome { background: #FCE7F3; color: #9D174D; }

.cal-inputs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.cal-input-group label { display: block; font-size: 0.8rem; color: var(--neutral-600); margin-bottom: 4px; font-weight: 500; }
.cal-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--neutral-200);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: 'SF Mono', 'Consolas', monospace;
  transition: border-color 0.2s;
}
.cal-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,148,136,0.1); }
.cal-input.fi { border-left: 3px solid var(--success); }
.cal-input.cp { border-left: 3px solid var(--warning); }
.cal-input.fo { border-left: 3px solid var(--danger); }
.cal-hint { font-size: 0.72rem; color: var(--neutral-400); margin-top: 4px; display: block; }

.cal-validation {
  margin-top: 10px;
  padding: 8px 14px;
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #92400E;
}

.cal-chart { margin-top: 16px; height: 200px; }

.cal-manual-adjust {
  margin-top: 14px;
}
.cal-manual-adjust summary {
  font-size: 0.85rem;
  color: var(--neutral-500);
  cursor: pointer;
  padding: 6px 0;
}
.manual-adjust-table { max-height: 300px; overflow-y: auto; margin-top: 8px; }
.manual-adjust-table table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.manual-adjust-table th, .manual-adjust-table td { padding: 5px 10px; border-bottom: 1px solid var(--neutral-100); text-align: left; }
.manual-adjust-table th { background: var(--neutral-50); font-weight: 600; position: sticky; top: 0; }
.manual-input {
  width: 80px;
  padding: 4px 8px;
  border: 1px solid var(--neutral-200);
  border-radius: 4px;
  font-size: 0.8rem;
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: #D1FAE5; color: #065F46; }
.badge-neutral { background: var(--neutral-100); color: var(--neutral-500); }
.badge-danger { background: #FEE2E2; color: #991B1B; }

/* ===== Necessity ===== */
.chart-container { margin-top: 20px; height: 350px; border-radius: var(--radius-sm); }

/* ===== Truth Table ===== */
.tt-params { display: flex; gap: 24px; margin-bottom: 20px; flex-wrap: wrap; }
.param-group { display: flex; flex-direction: column; gap: 4px; }
.param-group label { font-size: 0.85rem; font-weight: 500; color: var(--neutral-700); }
.param-input {
  padding: 8px 14px;
  border: 1.5px solid var(--neutral-200);
  border-radius: 6px;
  font-size: 0.9rem;
  width: 140px;
}
.param-input:focus { outline: none; border-color: var(--primary); }
.param-hint { font-size: 0.75rem; color: var(--neutral-400); }

.tt-table-wrapper { max-height: 500px; overflow-y: auto; }
.bit-cell { text-align: center; }
.bit-value { font-weight: 600; font-size: 0.85rem; }
.bit-in { color: var(--primary-dark); }
.bit-out { color: var(--neutral-400); }
.tt-include { background: rgba(16,185,129,0.04); }
.outcome-cell { font-weight: 700; text-align: center; }

.tt-summary {
  display: flex;
  gap: 20px;
  margin-top: 16px;
  padding: 14px 20px;
  background: var(--neutral-50);
  border-radius: var(--radius-sm);
}
.summary-item { display: flex; flex-direction: column; }
.summary-item span { font-size: 0.78rem; color: var(--neutral-500); }
.summary-item strong { font-size: 1.1rem; color: var(--neutral-800); }

/* ===== QMC / Configuration ===== */
.direction-settings { margin-bottom: 16px; }
.direction-settings h3 { font-size: 1.05rem; margin-bottom: 6px; }
.direction-desc { font-size: 0.85rem; color: var(--neutral-500); margin-bottom: 14px; }
.direction-list { display: flex; flex-direction: column; gap: 8px; }
.direction-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-sm);
}
.dir-var-name { font-weight: 500; font-size: 0.9rem; }
.dir-options { display: flex; gap: 8px; }
.dir-option {
  padding: 6px 16px;
  border: 1.5px solid var(--neutral-200);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.15s;
}
.dir-option input { display: none; }
.dir-option.active { border-color: var(--primary); background: var(--primary-bg); color: var(--primary-dark); font-weight: 600; }

.solution-block {
  margin-top: 24px;
  padding: 22px;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
}
.solution-block h3 { font-size: 1.05rem; margin-bottom: 4px; }
.solution-desc { font-size: 0.82rem; color: var(--neutral-500); margin-bottom: 14px; }

.config-table-wrapper { overflow-x: auto; }
.config-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.config-table th, .config-table td {
  padding: 8px 12px;
  border: 1px solid var(--neutral-200);
  text-align: center;
}
.config-table th { background: var(--neutral-100); font-weight: 600; }
.symbol-cell { font-size: 1.1rem; font-weight: 700; }
.sym-present { color: var(--neutral-800); }
.sym-absent { color: var(--neutral-500); }
.sym-doncare { color: var(--neutral-300); }

.solution-summary {
  margin-top: 14px;
  padding: 10px 16px;
  background: var(--primary-bg);
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--neutral-700);
}

.no-solution { text-align: center; padding: 20px; color: var(--neutral-400); }

/* ===== Export ===== */
.export-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.export-card {
  border: 1.5px solid var(--neutral-200);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
}
.export-card:hover { border-color: var(--primary); background: var(--primary-bg); transform: translateY(-2px); box-shadow: var(--shadow); }
.export-icon { font-size: 2rem; margin-bottom: 10px; }
.export-card h4 { font-size: 0.95rem; margin-bottom: 6px; }
.export-card p { font-size: 0.8rem; color: var(--neutral-500); margin-bottom: 12px; }
.full-width { grid-column: 1 / -1; }

/* ===== Step Actions ===== */
.step-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--neutral-200);
}

/* ===== Footer ===== */
.app-footer {
  margin-top: 40px;
  background: var(--neutral-900);
  color: var(--neutral-300);
  padding: 28px 24px;
}
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}
.footer-brand { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 8px; }
.footer-logo { font-size: 1.4rem; }
.footer-logo-img { width: 28px; height: 28px; object-fit: contain; }
.footer-brand span { font-size: 1rem; font-weight: 600; color: #fff; }
.footer-slogan { font-size: 0.9rem; color: var(--accent); margin-bottom: 6px; font-weight: 500; }
.footer-links { font-size: 0.78rem; color: var(--neutral-500); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  html { font-size: 14px; }
  .main-content { padding: 12px; }
  .step-panel { padding: 18px; }
  .step-nav-inner { padding: 10px 12px; gap: 2px; }
  .step-item { padding: 6px 10px; }
  .step-label { display: none; }
  .header-badge { display: none; }
  .var-columns { grid-template-columns: 1fr; }
  .cal-inputs { grid-template-columns: 1fr; }
  .tt-params { flex-direction: column; }
  .export-grid { grid-template-columns: 1fr; }
  .direction-item { flex-direction: column; align-items: flex-start; gap: 8px; }
  .tt-summary { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .preview-stats { flex-direction: column; }
  .step-actions { flex-direction: column; gap: 10px; }
  .step-actions .btn { width: 100%; justify-content: center; }
}
