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

:root {
  --color-none: #4caf50;
  --color-low: #8bc34a;
  --color-moderate: #ffc107;
  --color-high: #ff9800;
  --color-very-high: #f44336;
  --color-bg: #f5f7fa;
  --color-card: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #5a5a7a;
  --color-border: #e0e4ea;
  --color-primary: #3b82f6;
  --color-primary-dark: #2563eb;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--color-text-secondary);
  font-size: 1rem;
}

/* Search */
.search-section {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
}

.search-box {
  background: var(--color-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}

.search-box label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

#zip-input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  font-size: 1.1rem;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}

#zip-input:focus {
  border-color: var(--color-primary);
}

#search-btn {
  padding: 0.75rem 1.5rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
  flex-shrink: 0;
  white-space: nowrap;
}

#search-btn:hover {
  background: var(--color-primary-dark);
}

#search-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.location-info {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  min-height: 1.3em;
}

/* Error */
.error-message {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  margin-bottom: 1.5rem;
}

/* Loading */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}

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

/* Results */
.results-header {
  margin-bottom: 1.5rem;
}

.results-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.results-date {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

/* Source Section */
.source-section {
  background: var(--color-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.source-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.source-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.source-badge {
  background: #eef2ff;
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
}

/* Allergen Grid */
.allergen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.allergen-card {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1rem;
  transition: box-shadow 0.2s;
}

.allergen-card:hover {
  box-shadow: var(--shadow);
}

.allergen-card-hide-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  margin: -0.25rem -0.25rem -0.25rem 0;
}

.allergen-card:hover .allergen-card-hide-btn {
  opacity: 1;
}

.allergen-card-hide-btn:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* Hidden allergens section */
.hidden-allergens-section:empty {
  display: none;
}

.hidden-allergens-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.5rem 0;
  font-family: inherit;
}

.hidden-allergens-toggle:hover {
  color: var(--color-text);
}

.hidden-allergens-toggle .chevron {
  transition: transform 0.2s;
  font-size: 0.7rem;
}

.hidden-allergens-toggle.expanded .chevron {
  transform: rotate(90deg);
}

.hidden-allergens-list {
  display: none;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.hidden-allergens-list.visible {
  display: flex;
}

.hidden-allergen-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f1f5f9;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: 0.3rem 0.5rem 0.3rem 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.hidden-allergen-chip button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--color-primary);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
}

.hidden-allergen-chip button:hover {
  background: var(--color-primary);
  color: white;
}

.allergen-card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.allergen-card-header > div:first-child {
  flex: 1;
  min-width: 0;
}

.allergen-card-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.allergen-name {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.allergen-name-latin {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.severity-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  color: white;
  white-space: nowrap;
}

.severity-none { background: var(--color-none); }
.severity-low { background: var(--color-low); }
.severity-moderate { background: var(--color-moderate); color: #1a1a2e; }
.severity-high { background: var(--color-high); }
.severity-very-high { background: var(--color-very-high); }

.allergen-value {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

/* Severity bar */
.severity-bar-container {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
}

.severity-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.severity-bar.level-none { width: 0%; background: var(--color-none); }
.severity-bar.level-low { width: 25%; background: var(--color-low); }
.severity-bar.level-moderate { width: 50%; background: var(--color-moderate); }
.severity-bar.level-high { width: 75%; background: var(--color-high); }
.severity-bar.level-very-high { width: 100%; background: var(--color-very-high); }

/* Forecast row */
.forecast-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.forecast-day {
  flex: 1;
  text-align: center;
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.forecast-day-label {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 0.25rem;
}

.forecast-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.1);
}

/* Attribution */
.source-attribution {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  border-top: 1px solid var(--color-border);
  padding-top: 0.75rem;
}

.source-attribution a {
  color: var(--color-primary);
  text-decoration: none;
}

.source-attribution a:hover {
  text-decoration: underline;
}

.polleninfo-badge {
  background: #fef3c7;
  color: #92400e;
}

/* Polleninfo Allergy Risk */
.allergy-risk-summary {
  grid-column: 1 / -1;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.5rem;
}

.risk-header {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.risk-meter {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.risk-meter-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.risk-values {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.risk-day {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.risk-day strong {
  color: var(--color-text);
}

.risk-subheader {
  font-weight: 400;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

/* Hourly allergy-risk chart */
.hourly-chart {
  margin-bottom: 0.75rem;
}

.hourly-plot {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.hourly-yaxis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 1.25rem;
  height: 80px;
  font-size: 0.65rem;
  color: var(--color-text-secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hourly-yaxis span:nth-child(2) {
  transform: translateY(50%);
}

.hourly-yaxis span:last-child {
  transform: translateY(100%);
}

.hourly-bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 80px;
  padding: 0 2px;
  border-bottom: 1px solid var(--color-border);
  background-image:
    linear-gradient(to bottom, var(--color-border) 1px, transparent 1px),
    linear-gradient(to bottom, transparent calc(50% - 1px), var(--color-border) calc(50% - 1px), var(--color-border) 50%, transparent 50%);
  background-repeat: no-repeat;
  background-size: 100% 100%, 100% 100%;
}

.hourly-bar {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
  position: relative;
}

.hourly-bar-fill {
  width: 100%;
  min-height: 1px;
  border-radius: 2px 2px 0 0;
  transition: height 0.4s ease;
  position: relative;
  z-index: 1;
}

.hourly-bar.is-now {
  outline: 1px solid var(--color-text);
  outline-offset: 1px;
  border-radius: 2px;
}

.hourly-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--color-text-secondary);
  padding: 2px 0 0 calc(1.25rem + 4px + 2px);
  font-variant-numeric: tabular-nums;
}

.trmnl-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-decoration: none;
}

.trmnl-link[hidden] {
  display: none;
}

.trmnl-link:hover {
  text-decoration: underline;
  color: var(--color-text);
}

/* ORF Section */
.orf-badge {
  background: #f0fdf4;
  color: #16a34a;
}

.orf-state-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 0.75rem;
}

.orf-textbox {
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--color-text);
  margin-bottom: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.orf-textbox p {
  margin-bottom: 0.75rem;
}

.orf-textbox p:last-child {
  margin-bottom: 0;
}

.orf-textbox .orf-date {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  font-style: italic;
}

.orf-error {
  color: #991b1b;
  font-style: italic;
  font-size: 0.85rem;
}

/* No data message */
.no-data-message {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

/* Responsive */
@media (max-width: 500px) {
  .container {
    padding: 1rem 0.75rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .allergen-grid {
    grid-template-columns: 1fr;
  }

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

  .allergen-card-hide-btn {
    opacity: 0.4;
  }
}
