* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #ffffff;
  color: #222;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chart-section {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.chart-header-text h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #111;
  margin-bottom: 3px;
}

.chart-header-text p {
  font-size: 0.8rem;
  color: #999;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.period-toggle {
  display: flex;
  border: 1px solid #ddd;
  border-radius: 7px;
  overflow: hidden;
}

.period-btn {
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 500;
  background: #fff;
  border: none;
  border-right: 1px solid #ddd;
  cursor: pointer;
  color: #555;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.period-btn:last-child { border-right: none; }

.period-btn:hover { background: #f0f0f0; }

.period-btn.active {
  background: #1a4f8a;
  color: #fff;
}

#dropdown-wrapper { position: relative; }

#dropdown-btn {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#dropdown-btn:hover { border-color: #999; }
#dropdown-btn::after { content: "▾"; font-size: 0.75rem; color: #666; }

#dropdown-list {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  padding: 8px 0;
  min-width: 210px;
  z-index: 200;
}

#dropdown-list.open { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
}

.dropdown-item:hover { background: #f5f5f5; }

.color-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dropdown-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: #1a4f8a;
}

.dropdown-item label {
  font-size: 0.85rem;
  color: #333;
  cursor: pointer;
  user-select: none;
}

#chart1 {
  width: 100%;
  height: 560px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 8px;
  overflow: hidden;
}

.total-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: #f5f5f5;
  border: 1px solid #dce8f7;
  border-radius: 8px;
  justify-content: center;
}

.total-label {
  font-size: 0.82rem;
  color: #666;
}

.total-count {
  font-size: 1.6rem;
  font-weight: 700;
  color: #181818;
  letter-spacing: -0.5px;
}

.total-unit {
  font-size: 0.82rem;
  color: #999;
}

.tooltip {
  position: fixed;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  font-size: 0.82rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tt-name { font-weight: 600; color: #111; margin-bottom: 2px; }
.tt-val  { font-size: 1rem; color: #1a4f8a; font-weight: 700; }
.tt-cat  { font-size: 0.75rem; color: #999; margin-top: 2px; }

/* =========================================
   Responsive Media Queries
   ========================================= */

/* Tablets and small desktops */
@media (max-width: 768px) {
  body {
    padding: 20px 15px;
  }

  .chart-header {
    flex-direction: column;
    align-items: stretch;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
  }

  .period-toggle {
    flex: 1;
  }

  .period-btn {
    flex: 1;
    text-align: center;
  }

  #dropdown-wrapper {
    flex: 1;
  }

  #dropdown-btn {
    width: 100%;
    justify-content: space-between;
  }

  #chart1 {
    height: 450px;
  }
}

/* Mobile phones */
@media (max-width: 480px) {
  body {
    padding: 15px 10px;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  #dropdown-list {
    width: 100%;
    min-width: auto;
    right: auto;
    left: 0;
  }

  #chart1 {
    height: 350px;
  }

  .total-bar {
    padding: 12px 15px;
    flex-direction: column;
    gap: 2px;
  }

  .total-count {
    font-size: 1.4rem;
  }
}