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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
  font-size: 15px;
}

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  background: #f5f7fa;
  color: #2c3e50;
  line-height: 1.6;
}

/* ===== Header ===== */
.site-header {
  background: linear-gradient(135deg, #1a3a4a 0%, #2c5f6e 100%);
  color: #fff;
  text-align: center;
  padding: 2rem 1rem;
}

.site-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-header .subtitle {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 0.3rem;
  font-weight: 400;
}

/* ===== Layout ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ===== Card ===== */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  padding: 1.5rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e8ecf1;
  color: #1a3a4a;
}

.card-hint {
  font-size: 0.8rem;
  color: #7f8c8d;
  text-align: center;
  margin-bottom: 0.75rem;
}

/* ===== Search Card ===== */
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: #f8fafb;
  border-radius: 8px;
}

.year-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.year-range label,
.month-selector label {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.year-range select {
  padding: 0.4rem 0.6rem;
  border: 1px solid #ccd5db;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  cursor: pointer;
}

.range-sep {
  color: #95a5a6;
}

.month-selector {
  flex: 1;
  min-width: 280px;
}

.month-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.month-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 32px;
  border: 1px solid #ccd5db;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  background: #fff;
  transition: all 0.15s ease;
  user-select: none;
}

.month-chip.active {
  background: #2c5f6e;
  color: #fff;
  border-color: #2c5f6e;
}

.btn-text {
  background: none;
  border: none;
  color: #7f8c8d;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 0.3rem;
}

.keyword-group {
  text-align: center;
}

.hint {
  font-size: 0.78rem;
  color: #95a5a6;
  margin-bottom: 0.5rem;
}

.keyword-group input[type="text"] {
  width: 100%;
  max-width: 600px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid #dce3e8;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}

.keyword-group input[type="text"]:focus {
  border-color: #2c5f6e;
}

.search-buttons {
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

/* ===== Buttons ===== */
.btn {
  padding: 0.6rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: #2c5f6e;
  color: #fff;
}

.btn-primary:hover {
  background: #1a3a4a;
}

.btn-secondary {
  background: #e8ecf1;
  color: #2c3e50;
}

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

.btn-accent {
  background: #27ae60;
  color: #fff;
  font-size: 0.85rem;
  padding: 0.5rem 1.2rem;
}

.btn-accent:hover {
  background: #219a52;
}

/* ===== Status Message ===== */
.status-msg {
  text-align: center;
  font-weight: 600;
  color: #7f8c8d;
  margin-top: 0.75rem;
  min-height: 1.4em;
}

.status-msg.error {
  color: #c0392b;
}

/* ===== Checkbox Containers ===== */
.checkbox-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.75rem;
  max-height: 260px;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  background: #fafbfc;
}

.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background 0.15s;
  white-space: nowrap;
}

.checkbox-item:hover {
  background: #eef2f5;
}

.checkbox-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: #2c5f6e;
  cursor: pointer;
}

/* ===== Results ===== */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.results-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a3a4a;
}

/* ===== Map ===== */
#map {
  width: 100%;
  height: 420px;
  border-radius: 8px;
  overflow: hidden;
}

/* ===== Charts ===== */
.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 300px;
}

.chart-month {
  min-height: 60px;
  max-height: 60px;
}

/* ===== Table ===== */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.table-toolbar label {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.table-toolbar input {
  flex: 1;
  max-width: 400px;
  padding: 0.4rem 0.75rem;
  border: 1px solid #ccd5db;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
}

.table-toolbar input:focus {
  border-color: #2c5f6e;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

thead th {
  background: #1a3a4a;
  color: #fff;
  padding: 0.6rem 0.5rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  position: sticky;
  top: 0;
}

thead th:hover {
  background: #2c5f6e;
}

.sort.asc::after {
  content: " ▲";
  font-size: 0.65rem;
}

.sort.desc::after {
  content: " ▼";
  font-size: 0.65rem;
}

tbody tr {
  border-bottom: 1px solid #eef2f5;
  transition: background 0.1s;
}

tbody tr:hover {
  background: #fdf8e8;
}

tbody tr:target {
  background: #fff3cd;
  outline: 2px solid #f0c040;
}

tbody td {
  padding: 0.45rem 0.5rem;
  vertical-align: top;
}

tr#noresults td {
  text-align: center;
  font-size: 1rem;
  color: #c0392b;
  background: #fef9e7;
  padding: 1rem;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e8ecf1;
  border-top-color: #2c5f6e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  margin-top: 0.75rem;
  font-weight: 600;
  color: #2c5f6e;
}

/* ===== Back to Top ===== */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1a3a4a;
  color: #fff;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.8rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 100;
}

.back-to-top.visible {
  opacity: 0.8;
  pointer-events: auto;
}

.back-to-top:hover {
  opacity: 1;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  html { font-size: 14px; }

  .site-header h1 { font-size: 1.3rem; }

  .filter-group { flex-direction: column; }

  .search-buttons { flex-direction: column; align-items: stretch; }

  .results-header { flex-direction: column; align-items: flex-start; }

  .checkbox-item { flex-basis: calc(50% - 0.75rem); }

  #map { height: 280px; }
}
