:root {
  --primary: #0076CE;
  --primary-dark: #00468B;
  --secondary: #6c757d;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --light: #f8f9fa;
  --dark: #343a40;
  --border: #dee2e6;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: var(--dark);
  line-height: 1.5;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 16px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.app-header h1 {
  font-size: 20px;
  color: var(--primary-dark);
}

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

.lang-switcher {
  display: flex;
  gap: 2px;
  background: var(--light);
  padding: 2px;
  border-radius: var(--radius);
}

.lang-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  background: transparent;
  color: var(--secondary);
  transition: all 0.2s;
}

.lang-btn.active {
  background: white;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.upload-mode {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.mode-switcher {
  display: flex;
  gap: 2px;
  background: var(--light);
  padding: 2px;
  border-radius: var(--radius);
}

.mode-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  background: transparent;
  color: var(--secondary);
  transition: all 0.2s;
}

.mode-btn.active {
  background: white;
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.file-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-status { color: var(--secondary); font-size: 14px; }
.row-count { color: var(--primary); font-weight: 600; }

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #5a6268; }

.btn-ghost { background: transparent; color: var(--secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--light); }

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

.filters-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  text-transform: uppercase;
}

.filter-group input, .filter-group select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}

.columns-pool {
  background: white;
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.columns-pool h3 {
  font-size: 14px;
  color: var(--secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.column-cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 50px;
}

.column-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  cursor: grab;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  user-select: none;
  position: relative;
}

.column-card:hover { transform: translateY(-2px); }

.column-card .col-key {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 2px;
}

.column-card.dragging { opacity: 0.5; cursor: grabbing; }

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.analysis-box {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 300px;
}

.box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.box-header h4 {
  font-size: 15px;
  color: var(--dark);
  flex-shrink: 0;
}

.box-header select {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

.analysis-type-display {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  min-height: 28px;
}

.analysis-type-display .type-badge {
  background: var(--primary);
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.analysis-type-display.unknown .type-badge {
  background: var(--warning);
  color: var(--dark);
}

.analysis-type-display .type-name {
  color: var(--dark);
  font-weight: 500;
}

.analysis-type-display.unknown .type-name {
  color: var(--secondary);
}

.type-selector {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.type-option {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.type-option:hover {
  border-color: var(--primary);
  background: rgba(0,118,206,0.05);
}

.type-option input[type="radio"] {
  margin: 0;
}

.type-option:has(input:checked) {
  border-color: var(--primary);
  background: rgba(0,118,206,0.08);
  color: var(--primary);
  font-weight: 500;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  transition: all 0.2s;
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(0,118,206,0.05);
}

.drop-hint {
  color: var(--secondary);
  font-size: 13px;
}

.drop-zone .column-card {
  cursor: default;
  font-size: 12px;
  padding: 6px 12px;
}

.drop-zone .column-card .remove-btn {
  margin-left: 6px;
  cursor: pointer;
  opacity: 0.7;
}

.drop-zone .column-card .remove-btn:hover { opacity: 1; }

.condition-area, .prop-options {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.condition-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 8px;
  font-family: monospace;
}

.prop-options {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.prop-options select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}

.prop-options label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.result-area {
  margin-top: 16px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--light);
  padding: 12px;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.stat-card:hover {
  background: #e9ecef;
  transform: translateY(-1px);
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 11px;
  color: var(--secondary);
  margin-top: 4px;
}

.stat-card .stat-hint {
  font-size: 10px;
  color: #888;
  margin-top: 4px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chart-container {
  position: relative;
  height: 200px;
  margin-bottom: 16px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.detail-table th, .detail-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.detail-table th {
  background: var(--light);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--secondary);
}

.detail-table tr:hover { background: rgba(0,118,206,0.03); cursor: pointer; }

.detail-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.detail-modal.active { display: flex; }

.modal-content {
  background: white;
  border-radius: var(--radius);
  width: 90%;
  max-width: 1000px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 16px 20px;
  overflow: auto;
}

.mismatch-summary {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

@media (max-width: 900px) {
  .analysis-grid { grid-template-columns: 1fr; }
  .app-header { flex-direction: column; gap: 10px; }
}
