* { 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: 2rem;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem;
  text-align: center;
}

.header h1 { font-size: 1.8rem; margin-bottom: 0.4rem; font-weight: 700; }
.header p  { font-size: 0.95rem; opacity: 0.9; }

.content { padding: 2rem; }

.panel {
  margin-bottom: 1.8rem;
  padding-bottom: 1.6rem;
  border-bottom: 1px solid #eee;
}
.panel:last-of-type { border-bottom: none; }

.panel h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #667eea;
  display: inline-block;
}

.hint { font-size: 0.85rem; color: #666; margin-bottom: 0.6rem; }

input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 0.6rem;
}
input[type="text"]:focus { outline: none; border-color: #667eea; }

.region-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

.region-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.2rem;
  border-radius: 4px;
}
.region-row:hover { background: #f5f5fb; }
.region-row label { flex: 1; font-size: 0.9rem; cursor: pointer; }

.badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: white;
  text-transform: uppercase;
}
.badge.fylke { background: #667eea; }
.badge.kommune { background: #43c97b; }
.badge.land { background: #f0a500; }

.group-builder {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.6rem;
}
.group-builder input[type="text"] { flex: 1; min-width: 220px; margin-bottom: 0; }

button {
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
button:hover { opacity: 0.9; }
button:active { transform: scale(0.98); }
button.primary { background: #667eea; color: white; }
button.secondary { background: #eee; color: #333; }
button.large { font-size: 1rem; padding: 0.8rem 1.6rem; }
.actions { text-align: center; border-bottom: none; }
.axis-range-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 1rem;
  font-size: 0.9rem;
}
.axis-range-input {
  width: 6.5rem;
  margin-bottom: 0;
}

.chip-list { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-bottom: 0.8rem; }

.chip-wrapper { display: flex; flex-direction: column; gap: 0.25rem; max-width: 320px; }

.chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f0f0fb;
  border: 1px solid #d8d8f0;
  border-radius: 20px;
  padding: 0.4rem 0.5rem 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.chip-members {
  font-size: 0.75rem;
  color: #777;
  padding: 0 0.9rem;
  margin: 0;
}
.chip .chip-name { font-weight: 600; color: #333; }
.chip .chip-count { color: #666; }
.chip button.remove-chip {
  background: #d8d8f0;
  color: #333;
  border-radius: 50%;
  width: 1.4rem;
  height: 1.4rem;
  padding: 0;
  line-height: 1;
  font-size: 0.8rem;
}

.alt-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
}
.alt-row { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }

.age-group-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.4rem; }
.age-group-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.age-group-row label { min-width: 160px; }
.age-input {
  width: 4.5rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 0;
}
.age-input:focus { outline: none; border-color: #667eea; }

.chart-section { margin-top: 1rem; }

.chart-caption { font-size: 0.85rem; color: #555; margin-bottom: 0.6rem; white-space: pre-line; }

#chart { min-height: 100px; }

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: #666;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #eee;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

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

.error {
  background: #fff0f0;
  color: #c33;
  padding: 1.2rem;
  border-radius: 6px;
  border-left: 4px solid #c33;
}

.footnote {
  font-size: 0.82rem;
  color: #666;
  padding: 1rem 1.2rem;
  background: #f5f5f5;
  border-left: 3px solid #aaa;
  border-radius: 4px;
  margin-top: 1rem;
}
.footnote a { color: #667eea; }

@media (max-width: 680px) {
  body     { padding: 1rem; }
  .content { padding: 1rem; }
  .header h1 { font-size: 1.3rem; }
  .group-builder { flex-direction: column; align-items: stretch; }
}
