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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #273548;
  --border: #334155;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --error: #f87171;
  --success: #4ade80;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 24px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

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

.refresh-btn {
  background: var(--accent);
  color: #0f172a;
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.refresh-btn:hover {
  background: var(--accent-dark);
  color: #fff;
}

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

.refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Main */
main {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.last-updated {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-bottom: 20px;
  min-height: 1rem;
}

/* Error banner */
.error-banner {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.875rem;
}

.hidden {
  display: none !important;
}

/* City grid */
.city-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

/* City card */
.city-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.city-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.city-card.error {
  border-color: var(--error);
  opacity: 0.7;
}

.city-card.loading {
  opacity: 0.5;
  pointer-events: none;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.city-name {
  font-size: 1.25rem;
  font-weight: 700;
}

.city-state {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.weather-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
}

.temperature {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
}

.temperature span {
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.forecast-label {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}

.forecast-detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.card-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.meta-value {
  font-size: 0.875rem;
  font-weight: 600;
}

.period-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  width: fit-content;
}

.period-badge.night {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  height: 1em;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

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

/* Clickable card hint */
.city-card {
  cursor: pointer;
}

.city-card::after {
  content: 'Click for forecast';
  display: block;
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.city-card:hover::after {
  opacity: 1;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.modal-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 2px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--border);
}

/* Tabs */
.modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.tab-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f172a;
  font-weight: 600;
}

.tab-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent);
}

.tab-panel {
  position: relative;
  min-height: 280px;
}

.tab-panel canvas {
  width: 100% !important;
}

.modal-close {
  position: relative;
  z-index: 10;
}

.modal-loading {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 0;
  font-size: 0.9rem;
}

.modal-chart-error {
  color: var(--error);
  font-size: 0.875rem;
  padding: 16px 0;
}

/* Responsive */
@media (max-width: 600px) {
  header {
    padding: 16px;
  }

  main {
    padding: 16px;
  }

  header h1 {
    font-size: 1.4rem;
  }

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