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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #eef1f5;
  color: #1a1a2e;
  min-height: 100vh;
}

.page-wrapper {
  max-width: 1680px;
  margin: 0 auto;
}

header {
  padding: 1.2rem 2rem 0.6rem;
  background: linear-gradient(135deg, #0d47a1, #1565c0);
  border-bottom: 1px solid #0a3880;
}
header h1 {
  font-size: 1.6rem;
  color: #ffffff;
  letter-spacing: 1px;
}
.subtitle {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.72);
  margin-top: 2px;
}

/* Controls */
.controls {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
  background: #dde3ee;
  border-bottom: 1px solid #c0cad8;
}
.search-box {
  position: relative;
  flex: 1 1 120px;
  min-width: 80px;
}
.search-box input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid #9aaabf;
  border-radius: 6px;
  background: #ffffff;
  color: #1a1a2e;
  font-size: 0.85rem;
  outline: none;
}
.search-box input:focus { border-color: #1565c0; }

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid #9aaabf;
  border-radius: 0 0 6px 6px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
}
.search-results.hidden { display: none; }
.search-result-item {
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid #e0e6ef;
}
.search-result-item:hover { background: #dde3ee; }
.search-result-item .country {
  color: #556;
  font-size: 0.75rem;
}

/* Preset dropdown */
#preset-select {
  padding: 0.4rem 0.5rem;
  border: 1px solid #9aaabf;
  border-radius: 6px;
  background: #ffffff;
  color: #1a1a2e;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  min-width: 0;
  max-width: 140px;
  text-overflow: ellipsis;
}
#preset-select:focus { border-color: #1565c0; }

/* Legend toggle */
.legend-toggle {
  padding: 0.4rem 0.6rem;
  border: 1px solid #9aaabf;
  border-radius: 6px;
  background: #ffffff;
  color: #445;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.legend-toggle:hover { border-color: #1565c0; color: #1a1a2e; }
.legend-toggle.active { border-color: #1565c0; color: #1565c0; }

/* Charts container */
#charts-container {
  padding: 0.5rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.location-card {
  background: #ffffff;
  border: 1px solid #c0cad8;
  border-radius: 8px;
  overflow: hidden;
}
.location-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.75rem;
  background: #dde3ee;
  border-bottom: 1px solid #c0cad8;
}
.location-header h2 {
  font-size: 0.95rem;
  color: #0d47a1;
}
.remove-btn {
  background: none;
  border: 1px solid #9aaabf;
  color: #556;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  font-size: 0.7rem;
}
.remove-btn:hover { border-color: #e74c3c; color: #e74c3c; }

.chart-scroll-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.4rem;
}
.chart-scroll-wrapper::-webkit-scrollbar { height: 6px; }
.chart-scroll-wrapper::-webkit-scrollbar-track { background: #dde3ee; border-radius: 4px; }
.chart-scroll-wrapper::-webkit-scrollbar-thumb { background: #9aaabf; border-radius: 4px; }
.chart-scroll-wrapper::-webkit-scrollbar-thumb:hover { background: #6b7a90; }

.chart-inner {
  position: relative;
}

.chart-section-label {
  font-size: 0.75rem;
  color: #0d47a1;
  padding: 0.3rem 0.75rem 0.1rem;
  font-weight: 600;
}

.loading {
  text-align: center;
  padding: 2rem;
  color: #778;
  font-size: 0.85rem;
}

/* Legend */
.chart-legend {
  display: none;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.2rem 0.75rem 0.3rem;
  font-size: 0.7rem;
  color: #334;
}
.legends-visible .chart-legend {
  display: flex;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.legend-line {
  width: 14px;
  height: 2px;
  border-radius: 2px;
}

/* Pull-to-refresh indicator — only active when installed as a web app */
.ptr-indicator {
  display: none;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: #1565c0;
  color: #fff;
  border-radius: 0 0 20px 20px;
  padding: 0.3rem 1.2rem 0.5rem;
  font-size: 0.85rem;
  z-index: 200;
  transition: transform 0.15s ease;
  pointer-events: none;
  white-space: nowrap;
}

body.ptr-standalone .ptr-indicator { display: block; }

footer {
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  opacity: 0.5;
}

footer a {
  color: inherit;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}
