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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

button,
select,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.container {
  max-width: 1600px;
  margin: 0 auto;
}

.header {
  text-align: center;
  color: white;
  padding: 15px 0 25px;
}

.header h1 {
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.header p {
  opacity: 0.9;
  font-size: 0.9rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card,
.card,
.controls-bar {
  background: white;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-card {
  padding: 16px;
  transition: transform 0.2s ease;
}

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

.stat-card .label {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 6px;
  text-align: center;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #333;
  text-align: center;
  line-height: 1.4;
}

.stat-card .value .join {
  color: #10b981;
}

.stat-card .value .leave {
  color: #ef4444;
}

.controls-bar {
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
  align-items: center;
}

.control-label {
  font-size: 0.9rem;
  color: #555;
}

.chart-toggle-buttons {
  display: inline-flex;
  gap: 2px;
  margin-right: 15px;
}

.chart-toggle-buttons input[type="radio"] {
  display: none;
}

.chart-toggle-btn,
.secondary-btn {
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.chart-toggle-btn {
  display: inline-block;
  padding: 6px 16px;
  background: #f0f0f0;
  color: #666;
  user-select: none;
}

.chart-toggle-btn:hover,
.secondary-btn:hover {
  border-color: #667eea;
}

.chart-toggle-btn:first-of-type {
  border-radius: 6px 0 0 6px;
}

.chart-toggle-btn:last-of-type {
  border-radius: 0 6px 6px 0;
}

.chart-toggle-buttons input[type="radio"]:checked + .chart-toggle-btn {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.secondary-btn {
  padding: 8px 14px;
  background: white;
  color: #555;
}

.file-hint {
  margin-left: auto;
  font-size: 0.8rem;
  color: #888;
}

.dept-selector {
  position: relative;
  display: inline-block;
  margin-right: 15px;
  vertical-align: middle;
}

.dept-button {
  min-width: 180px;
  padding: 6px 12px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #555;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s ease;
}

.dept-button:hover {
  border-color: #667eea;
}

.dept-button.active {
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.dept-arrow {
  font-size: 0.7rem;
  margin-left: 8px;
  transition: transform 0.2s ease;
}

.dept-button.active .dept-arrow {
  transform: rotate(180deg);
}

.dept-tree-popup {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 1000;
  min-width: 280px;
  max-width: 400px;
  max-height: 400px;
  overflow-y: auto;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 8px;
}

.dept-tree {
  font-size: 0.9rem;
}

.dept-tree-item {
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.dept-tree-item:hover {
  background-color: #f5f5f5;
}

.dept-tree-item.selected {
  background-color: #e8f0fe;
  color: #667eea;
}

.dept-tree-toggle {
  display: inline-block;
  width: 16px;
  height: 16px;
  text-align: center;
  line-height: 16px;
  font-size: 10px;
  color: #888;
  margin-right: 2px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.dept-tree-toggle.expanded {
  transform: rotate(90deg);
}

.hidden-toggle {
  visibility: hidden;
}

.dept-tree-title {
  flex: 1;
  cursor: pointer;
}

.dept-tree-children {
  display: none;
  margin-left: 18px;
  border-left: 1px solid #eee;
  padding-left: 4px;
}

.dept-tree-children.visible {
  display: block;
}

.dept-tree-item.all-option {
  font-weight: 600;
  border-bottom: 1px solid #eee;
  margin-bottom: 4px;
}

.card {
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
}

.chart-container {
  position: relative;
  height: 750px;
}

.chart {
  height: 100%;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  z-index: 10;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.loading-overlay p {
  margin-top: 12px;
  color: #666;
  font-size: 0.9rem;
}

.upload-section {
  text-align: center;
  padding: 60px 20px;
}

.upload-btn {
  padding: 12px 24px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.upload-btn:hover {
  background: #5a6fd6;
}

.upload-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.upload-loading {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  color: #666;
  font-size: 0.9rem;
}

.upload-loading .spinner {
  width: 22px;
  height: 22px;
}

.upload-hint {
  margin-top: 12px;
  font-size: 0.85rem;
  color: #888;
}

.legend-note {
  font-size: 0.8rem;
  color: #666;
  margin-top: 10px;
  text-align: center;
}

@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  .header h1 {
    font-size: 1.4rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-container {
    height: 600px;
  }

  .controls-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .file-hint {
    margin-left: 0;
  }
}

