/* ═══════════════════════════════════════════════════════════════════════════
   RetroCast – Main Stylesheet
   Glassmorphism · Animated gauges · Dark-mode · 3 breakpoints
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  /* palette */
  --c-bg:        #eef1f6;
  --c-surface:   rgba(255,255,255,.72);
  --c-surface-solid: #ffffff;
  --c-text:      #1e293b;
  --c-text-dim:  #64748b;
  --c-border:    rgba(148,163,184,.25);
  --c-accent:    #6366f1;
  --c-accent-soft: rgba(99,102,241,.12);

  /* semantic */
  --c-excellent: #10b981;
  --c-good:      #22d3ee;
  --c-fair:      #f59e0b;
  --c-poor:      #ef4444;

  /* shadows & radii */
  --shadow-sm:   0 1px 3px rgba(0,0,0,.06);
  --shadow-md:   0 4px 14px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 30px rgba(0,0,0,.12);
  --r-sm:  8px;
  --r-md: 14px;
  --r-lg: 20px;

  /* layout */
  --max-w: 1140px;
  --gap:   20px;
}

/* ── Dark Mode ─────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:        #0f172a;
    --c-surface:   rgba(30,41,59,.72);
    --c-surface-solid: #1e293b;
    --c-text:      #e2e8f0;
    --c-text-dim:  #94a3b8;
    --c-border:    rgba(148,163,184,.15);
    --c-accent:    #818cf8;
    --c-accent-soft: rgba(129,140,248,.15);
    --shadow-sm:   0 1px 3px rgba(0,0,0,.2);
    --shadow-md:   0 4px 14px rgba(0,0,0,.3);
    --shadow-lg:   0 8px 30px rgba(0,0,0,.4);
  }
}

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.6;
  min-height: 100dvh;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; cursor: pointer; border: none; background: none; }

img, svg { display: block; max-width: 100%; }

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.main {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--gap) var(--gap);
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--c-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}

.header__inner {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px var(--gap);
  flex-wrap: wrap;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--c-text);
  flex-shrink: 0;
}
.brand-icon { width: 28px; height: 28px; color: var(--c-accent); }
.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header__search { flex: 1; min-width: 220px; max-width: 440px; }

/* ── Search box ────────────────────────────────────────────────────────────── */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--c-surface-solid);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: visible;
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-soft);
}
.search-box__input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  padding: 10px 4px;
  font-size: .95rem;
  color: var(--c-text);
  min-width: 0;
}
.search-box__input::placeholder { color: var(--c-text-dim); }

/* Button base */
.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  color: var(--c-text-dim);
  transition: color .2s, background .2s;
  flex-shrink: 0;
}
.btn--icon:hover { color: var(--c-accent); background: var(--c-accent-soft); }
.btn--icon svg { width: 18px; height: 18px; }

/* Detect button pulse while locating */
.btn--icon.detecting { animation: pulse 1s ease infinite; }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%     { opacity: .4; }
}

/* Autocomplete dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--c-surface-solid);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  max-height: 280px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}
.search-dropdown.open { display: block; }

.search-dropdown__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  color: var(--c-text);
  transition: background .15s;
  border-bottom: 1px solid var(--c-border);
}
.search-dropdown__item:last-child { border-bottom: none; }
.search-dropdown__item:hover { background: var(--c-accent-soft); }
.search-dropdown__item svg { width: 16px; height: 16px; color: var(--c-text-dim); flex-shrink: 0; }
.search-dropdown__item small {
  margin-left: auto;
  font-size: .78rem;
  color: var(--c-text-dim);
  white-space: nowrap;
}
.search-dropdown__empty {
  padding: 14px;
  text-align: center;
  color: var(--c-text-dim);
  font-size: .9rem;
}

/* ── Favorites slot ────────────────────────────────────────────────────────── */
.favorites-slot {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--gap);
}

.favorites-bar {
  display: flex;
  gap: 8px;
  padding: 10px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.fav-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  backdrop-filter: blur(8px);
  transition: all .2s;
}
.fav-chip svg { width: 14px; height: 14px; }
.fav-chip:hover { border-color: var(--c-accent); color: var(--c-accent); }
.fav-chip--active {
  background: var(--c-accent);
  color: #fff;
  border-color: var(--c-accent);
}
.fav-chip--active:hover { opacity: .9; color: #fff; }

/* ── Banner ────────────────────────────────────────────────────────────────── */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: var(--gap);
  background: var(--c-accent-soft);
  border: 1px solid var(--c-accent);
  border-radius: var(--r-md);
  color: var(--c-text);
  font-size: .9rem;
  line-height: 1.5;
}
.banner[hidden] { display: none; }
.banner__icon { flex-shrink: 0; width: 20px; height: 20px; color: var(--c-accent); margin-top: 2px; }
.banner__text { flex: 1; }
.banner__text em { font-style: italic; font-weight: 600; }
.banner__close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--c-text-dim);
  transition: color .2s, background .2s;
}
.banner__close:hover { color: var(--c-accent); background: var(--c-accent-soft); }
.banner__close svg { width: 16px; height: 16px; }

/* ── Location bar ──────────────────────────────────────────────────────────── */
.location-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  margin-bottom: 4px;
}
.location-bar__icon { width: 20px; height: 20px; color: var(--c-accent); }
.location-bar__name { font-size: 1.15rem; font-weight: 600; }
.btn--fav { color: var(--c-text-dim); }
.btn--fav:hover, .btn--fav.is-fav { color: #f59e0b; }
.btn--fav.is-fav svg { fill: #f59e0b; }

/* ── Summary bar ───────────────────────────────────────────────────────────── */
.summary-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  margin-bottom: var(--gap);
  background: var(--c-surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}
.summary-bar__label { font-size: .88rem; font-weight: 500; color: var(--c-text-dim); white-space: nowrap; }
.summary-bar__track {
  flex: 1;
  height: 8px;
  background: var(--c-border);
  border-radius: 999px;
  overflow: hidden;
}
.summary-bar__fill {
  height: 100%;
  border-radius: 999px;
  width: var(--pct);
  transition: width .8s cubic-bezier(.4,0,.2,1);
}
.summary-bar--excellent { background: var(--c-excellent); }
.summary-bar--good      { background: var(--c-good); }
.summary-bar--fair       { background: var(--c-fair); }
.summary-bar--poor       { background: var(--c-poor); }
.summary-bar__value { font-size: 1.1rem; font-weight: 700; min-width: 42px; text-align: right; }

/* ── Days grid ─────────────────────────────────────────────────────────────── */
.days-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}

/* Placeholder (before a city is chosen) */
.placeholder {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--c-text-dim);
}
.placeholder__icon { width: 56px; height: 56px; margin: 0 auto 12px; opacity: .4; }

/* ── Day card ──────────────────────────────────────────────────────────────── */
.day-card {
  background: var(--c-surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp .5s cubic-bezier(.4,0,.2,1) both;
  transition: transform .25s, box-shadow .25s;
}
.day-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Card header */
.day-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px 10px;
}
.day-card__label { font-weight: 600; font-size: .95rem; }
.day-card__date  { font-size: .8rem; color: var(--c-text-dim); }

/* Card body – 3-col: forecast | gauge | actual */
.day-card__body {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  padding: 0 14px 12px;
  align-items: start;
}

.day-card__col {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}
.day-card__col-title {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-text-dim);
  margin-bottom: 2px;
}
.day-card__col-title svg { width: 13px; height: 13px; }

.day-card__col--forecast { color: var(--c-text); }
.day-card__col--actual   { color: var(--c-text); }

.day-card__icon svg { width: 32px; height: 32px; }
.day-card__condition { font-size: .78rem; color: var(--c-text-dim); min-height: 2.4em; }

.day-card__temps {
  display: flex;
  gap: 10px;
  font-size: .82rem;
  font-weight: 500;
}
.day-card__temps svg { width: 14px; height: 14px; }
.temp-hi { color: #ef4444; display: inline-flex; align-items: center; gap: 2px; }
.temp-lo { color: #3b82f6; display: inline-flex; align-items: center; gap: 2px; }

.day-card__precip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  color: var(--c-text-dim);
}
.day-card__precip svg { width: 14px; height: 14px; color: #60a5fa; }

/* Gauge in the centre */
.day-card__gauge {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}

/* ── SVG Gauge ─────────────────────────────────────────────────────────────── */
.gauge { position: relative; width: 90px; height: 90px; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge circle {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
}
.gauge-bg { stroke: var(--c-border); }
.gauge-fill {
  transition: stroke-dashoffset 1.2s cubic-bezier(.4,0,.2,1);
}
.gauge-excellent { stroke: var(--c-excellent); }
.gauge-good      { stroke: var(--c-good); }
.gauge-fair      { stroke: var(--c-fair); }
.gauge-poor      { stroke: var(--c-poor); }

.gauge-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.gauge-grade { font-size: 1.3rem; font-weight: 700; line-height: 1; }
.gauge-pct   { font-size: .7rem; color: var(--c-text-dim); }

/* ── Card footer – stats ───────────────────────────────────────────────────── */
.day-card__footer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--c-border);
  border-top: 1px solid var(--c-border);
}
.day-card__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  background: var(--c-surface-solid);
  font-size: .78rem;
}
.stat-label {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--c-text-dim);
  font-weight: 500;
}
.stat-label svg { width: 13px; height: 13px; }
.stat-value { font-weight: 600; display: flex; align-items: center; gap: 3px; }
.stat-value svg { width: 13px; height: 13px; }

/* Accuracy colour tokens */
.acc-excellent { color: var(--c-excellent); }
.acc-good      { color: var(--c-good); }
.acc-fair      { color: var(--c-fair); }
.acc-poor      { color: var(--c-poor); }

/* ── Error / empty card ────────────────────────────────────────────────────── */
.day-card--error { opacity: .6; }
.day-card__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 18px;
  text-align: center;
  color: var(--c-text-dim);
}
.empty-icon { width: 36px; height: 36px; opacity: .5; }

/* ── Skeleton cards ────────────────────────────────────────────────────────── */
.day-card--skeleton { pointer-events: none; }

.skel {
  background: linear-gradient(90deg, var(--c-border) 25%, transparent 50%, var(--c-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-sm);
}
.skel-text   { height: 14px; width: 60%; margin: 8px auto; }
.skel-circle { width: 40px; height: 40px; border-radius: 50%; margin: 12px auto; }
.skel-gauge  { width: 70px; height: 70px; border-radius: 50%; margin: 12px auto; }
.skel-bar    { height: 12px; width: 80%; margin: 14px auto; }

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

/* ── Global error (when all data fails) ────────────────────────────────────── */
.global-error {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 50px 20px;
  text-align: center;
  color: var(--c-text-dim);
}
.global-error svg { width: 40px; height: 40px; color: var(--c-poor); }

.btn--primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  background: var(--c-accent);
  color: #fff;
  border-radius: var(--r-md);
  font-weight: 600;
  transition: opacity .2s;
}
.btn--primary:hover { opacity: .85; }
.btn--primary svg { width: 16px; height: 16px; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  padding: 12px 22px;
  border-radius: var(--r-md);
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { background: var(--c-poor); color: #fff; box-shadow: var(--shadow-lg); }
.toast--error svg { width: 18px; height: 18px; }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 20px var(--gap);
  font-size: .8rem;
  color: var(--c-text-dim);
  border-top: 1px solid var(--c-border);
  margin-top: auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════════════ */

/* Tablet */
@media (max-width: 1024px) {
  .days-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
}

/* Small tablet / large phone */
@media (max-width: 768px) {
  .days-grid { grid-template-columns: 1fr; max-width: 480px; margin-left: auto; margin-right: auto; }

  .header__inner { flex-wrap: wrap; }
  .header__search { min-width: 100%; order: 1; }

  .summary-bar { flex-wrap: wrap; }
  .summary-bar__label { flex-basis: 100%; }
}

/* Phone */
@media (max-width: 480px) {
  html { font-size: 14px; }
  :root { --gap: 14px; }

  .gauge { width: 72px; height: 72px; }
  .gauge-grade { font-size: 1.1rem; }

  .brand-name { font-size: 1.1rem; }
}
