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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #333;
  display: flex;
  justify-content: center;
  padding: 40px 16px;
  min-height: 100vh;
}

.container {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  height: fit-content;
}

h1 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.8rem;
  color: #444;
}

#search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
}

#city-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

#city-input:focus {
  border-color: #667eea;
}

/* Autocomplete dropdown */
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}

.autocomplete-list.hidden {
  display: none;
}

.ac-item {
  padding: 10px 14px;
  font-size: 0.9rem;
  color: #444;
  cursor: pointer;
  transition: background 0.15s;
}

.ac-item:hover,
.ac-item.ac-active {
  background: #f0f4ff;
  color: #667eea;
}

.ac-item + .ac-item {
  border-top: 1px solid #f0f0f0;
}

#search-form button {
  padding: 10px 18px;
  background: #667eea;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

#search-form button:hover {
  background: #5a6fd6;
}

#location-btn {
  display: block;
  width: 100%;
  padding: 8px;
  background: none;
  border: 1px dashed #bbb;
  border-radius: 10px;
  color: #888;
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 20px;
  transition: all 0.2s;
}

#location-btn:hover {
  border-color: #667eea;
  color: #667eea;
}

/* Error */
.error {
  text-align: center;
  color: #e74c3c;
  background: #fdf0ef;
  padding: 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.error.hidden {
  display: none;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 0;
  color: #888;
  font-size: 0.9rem;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #eee;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Current weather */
.weather.hidden {
  display: none;
}

.weather-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.weather-header h2 {
  font-size: 1.4rem;
  color: #333;
}

.weather-header p {
  text-transform: capitalize;
  color: #888;
  font-size: 0.9rem;
}

#weather-icon {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.temp-main {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

#temp {
  font-size: 3rem;
  font-weight: 700;
  color: #333;
  line-height: 1;
}

#unit-toggle {
  padding: 4px 10px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}

#unit-toggle:hover {
  border-color: #667eea;
  color: #667eea;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.detail {
  background: #f8f8fa;
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}

.detail-label {
  display: block;
  font-size: 0.72rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: #444;
}

/* Time section */
.time-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.time-section.hidden {
  display: none;
}

.time-section h3 {
  font-size: 1rem;
  color: #666;
  margin-bottom: 12px;
}

.time-cards {
  display: flex;
  gap: 10px;
}

.time-card {
  flex: 1;
  background: #f8f8fa;
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
}

.time-label {
  display: block;
  font-size: 0.75rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.time-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: #333;
  font-variant-numeric: tabular-nums;
}

.time-date {
  display: block;
  font-size: 0.72rem;
  color: #aaa;
  margin-top: 4px;
}

.time-diff {
  text-align: center;
  margin-top: 10px;
  font-size: 0.82rem;
  color: #888;
}

/* Forecast */
.forecast.hidden {
  display: none;
}

.forecast h3 {
  font-size: 1rem;
  color: #666;
  margin: 24px 0 12px;
}

.forecast-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.forecast-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #f8f8fa;
  border-radius: 10px;
  animation: fadeIn 0.3s ease;
}

.fc-day {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  width: 90px;
  flex-shrink: 0;
}

.forecast-card img {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.fc-temps {
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
  white-space: nowrap;
  flex-shrink: 0;
}

.fc-desc {
  font-size: 0.78rem;
  color: #999;
  text-transform: capitalize;
  text-align: right;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* History comparison */
.history-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.history-section.hidden {
  display: none;
}

.history-section h3 {
  font-size: 1rem;
  color: #666;
  margin-bottom: 12px;
}

.compare-cards {
  display: flex;
  gap: 10px;
}

.compare-card {
  flex: 1;
  background: #f8f8fa;
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
}

.compare-label {
  display: block;
  font-size: 0.72rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.compare-temp {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  color: #333;
}

.compare-range {
  display: block;
  font-size: 0.78rem;
  color: #999;
  margin-top: 2px;
}

.compare-diff {
  text-align: center;
  margin-top: 10px;
  font-size: 0.85rem;
  color: #888;
  font-weight: 500;
}

.compare-diff.warmer {
  color: #e67e22;
}

.compare-diff.cooler {
  color: #3498db;
}

/* Trend chart */
.trend-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.trend-section.hidden {
  display: none;
}

.trend-section h3 {
  font-size: 1rem;
  color: #666;
  margin-bottom: 10px;
}

.trend-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.75rem;
  color: #999;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 2px;
}

.legend-this-year {
  background: #667eea;
}

.legend-last-year {
  background: #ccc;
  background-image: repeating-linear-gradient(
    90deg,
    #ccc 0px,
    #ccc 6px,
    transparent 6px,
    transparent 10px
  );
}

.legend-dot-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #667eea;
}

.chart-wrapper {
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
  background: #fafafa;
  padding: 4px 0;
  position: relative;
}

.chart-wrapper canvas {
  display: block;
  width: 100%;
  cursor: crosshair;
}

/* Chart tooltip */
.chart-tooltip {
  position: absolute;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  z-index: 10;
  min-width: 150px;
  font-size: 0.78rem;
}

.chart-tooltip.hidden {
  display: none;
}

.tt-date {
  font-weight: 700;
  color: #333;
  margin-bottom: 6px;
  font-size: 0.82rem;
}

.tt-section {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 6px;
}

.tt-section:last-child {
  margin-bottom: 0;
}

.tt-label {
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.tt-val {
  color: #555;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile responsive */
@media (max-width: 480px) {
  body {
    padding: 0;
    min-height: 100dvh;
  }

  .container {
    border-radius: 0;
    padding: 24px 16px;
    min-height: 100dvh;
  }

  h1 {
    font-size: 1.5rem;
  }

  #city-input {
    font-size: 16px;
  }

  #temp {
    font-size: 2.5rem;
  }

  .details-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .detail {
    padding: 10px 8px;
  }

  .detail-value {
    font-size: 0.85rem;
  }

  .fc-day {
    width: 70px;
    font-size: 0.78rem;
  }

  .fc-temps {
    font-size: 0.78rem;
  }

  .fc-desc {
    display: none;
  }

  .time-value {
    font-size: 1.1rem;
  }

  .time-card {
    padding: 10px 8px;
  }

  .time-date {
    font-size: 0.65rem;
  }

  .chart-tooltip {
    font-size: 0.7rem;
    min-width: 130px;
    padding: 8px 10px;
  }

  .compare-temp {
    font-size: 1.2rem;
  }

  .compare-card {
    padding: 10px 8px;
  }

  .trend-legend {
    gap: 10px;
    font-size: 0.7rem;
  }
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  padding: 20px;
  color: white;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}