/* frontend/css/app.css */

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

:root {
  --clr-bg:        #0f1117;
  --clr-surface:   #1a1d27;
  --clr-surface2:  #22263a;
  --clr-border:    #2e3347;
  --clr-text:      #e8ecf4;
  --clr-muted:     #7a8099;
  --clr-accent:    #4f9dff;

  /* Condition colours */
  --clr-excellent: #22c55e;   /* green  */
  --clr-good:      #84cc16;   /* lime   */
  --clr-fair:      #f59e0b;   /* amber  */
  --clr-bad:       #ef4444;   /* red    */

  --radius:   10px;
  --shadow:   0 4px 24px rgba(0,0,0,.45);
  --header-h: 56px;
  --sidebar-w: 340px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1000;
}
.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 1.4rem; }
.logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -.3px; }
.header-meta { display: flex; align-items: center; gap: 12px; }

.season-badge {
  font-size: .75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.season-badge.winter { color: #7dd3fc; border-color: #7dd3fc44; }
.season-badge.summer { color: #86efac; border-color: #86efac44; }

.update-time { font-size: .72rem; color: var(--clr-muted); }

/* ── Main layout ───────────────────────────────────────────────── */
.app-main {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
}

/* ── Map ───────────────────────────────────────────────────────── */
.map-panel {
  flex: 1;
  position: relative;
}
#map {
  width: 100%;
  height: 100%;
  background: #0d1117;
}

/* Leaflet dark tile filter */
.leaflet-tile { filter: brightness(.85) saturate(.7) hue-rotate(180deg) invert(1); }

/* Custom marker pulse */
.marker-pulse {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3);
  position: relative;
  cursor: pointer;
  transition: transform .15s;
}
.marker-pulse:hover { transform: scale(1.3); }
.marker-pulse::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  opacity: 0;
  animation: pulse 2s ease-out infinite;
}
.marker-excellent { background: var(--clr-excellent); }
.marker-excellent::after { border: 2px solid var(--clr-excellent); }
.marker-good { background: var(--clr-good); }
.marker-good::after { border: 2px solid var(--clr-good); }
.marker-fair { background: var(--clr-fair); }
.marker-fair::after { border: 2px solid var(--clr-fair); }
.marker-bad { background: var(--clr-bad); }
.marker-bad::after { border: 2px solid var(--clr-bad); }

@keyframes pulse {
  0%   { transform: scale(1);   opacity: .6; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--clr-text);
  padding: 0;
}
.leaflet-popup-content { margin: 0; }
.leaflet-popup-tip { background: var(--clr-surface); }
.popup-inner { padding: 12px 16px; }
.popup-name { font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.popup-label { font-size: .8rem; color: var(--clr-muted); }
.popup-score { font-size: 1.5rem; font-weight: 800; }
.popup-detail-btn {
  display: block;
  text-align: center;
  margin-top: 8px;
  padding: 5px;
  background: var(--clr-surface2);
  border-radius: 6px;
  font-size: .78rem;
  color: var(--clr-accent);
  cursor: pointer;
  border: none;
  width: 100%;
  transition: background .15s;
}
.popup-detail-btn:hover { background: var(--clr-border); }

/* Map legend */
.map-legend {
  position: absolute;
  bottom: 30px;
  left: 12px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 500;
  font-size: .78rem;
}
.legend-title { font-weight: 600; margin-bottom: 6px; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .5px; font-size: .68rem; }
.legend-item { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-excellent { background: var(--clr-excellent); }
.dot-good      { background: var(--clr-good); }
.dot-fair      { background: var(--clr-fair); }
.dot-bad       { background: var(--clr-bad); }

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--clr-surface);
  border-left: 1px solid var(--clr-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--clr-border);
}
.tab-btn {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--clr-muted);
  font-size: .83rem;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-bottom .15s;
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--clr-accent);
  border-bottom-color: var(--clr-accent);
}
.tab-content { display: none; flex-direction: column; overflow-y: auto; flex: 1; }
.tab-content.active { display: flex; }

/* Top lists */
.top-list-section { padding: 16px; }
.list-heading { font-size: .85rem; font-weight: 700; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.top-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.top-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--clr-surface2);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
}
.top-list-item:hover { background: var(--clr-border); border-color: var(--clr-border); }
.rank { font-size: .7rem; font-weight: 700; color: var(--clr-muted); width: 16px; }
.rank-1 { color: #fbbf24; }
.rank-2 { color: #94a3b8; }
.rank-3 { color: #cd7c2f; }
.item-name { flex: 1; font-size: .86rem; font-weight: 600; }
.item-score { font-size: .86rem; font-weight: 700; }
.item-label { font-size: .72rem; color: var(--clr-muted); }

/* All locations */
.location-search {
  margin: 12px;
  padding: 9px 14px;
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  border-radius: 8px;
  color: var(--clr-text);
  font-size: .85rem;
  outline: none;
}
.location-search:focus { border-color: var(--clr-accent); }
.location-list { list-style: none; overflow-y: auto; flex: 1; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.location-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s;
}
.location-list-item:hover { background: var(--clr-surface2); }
.loc-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.loc-name { flex: 1; font-size: .84rem; }
.loc-score { font-size: .82rem; font-weight: 700; }
.loc-country { font-size: .7rem; color: var(--clr-muted); }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
  box-shadow: var(--shadow);
  animation: slide-up .2s ease;
}
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } }

.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--clr-surface2);
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  color: var(--clr-muted);
  font-size: .9rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--clr-border); color: var(--clr-text); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.modal-title { font-size: 1.35rem; font-weight: 800; margin-bottom: 4px; }
.modal-meta { font-size: .78rem; color: var(--clr-muted); }

.modal-score-badge {
  text-align: center;
  background: var(--clr-surface2);
  border-radius: var(--radius);
  padding: 10px 18px;
  border: 2px solid var(--clr-border);
  min-width: 90px;
  flex-shrink: 0;
}
.modal-score-badge.excellent { border-color: var(--clr-excellent); }
.modal-score-badge.good      { border-color: var(--clr-good); }
.modal-score-badge.fair      { border-color: var(--clr-fair); }
.modal-score-badge.bad       { border-color: var(--clr-bad); }

.score-value { font-size: 2rem; font-weight: 900; line-height: 1; }
.score-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--clr-muted); margin-top: 2px; }

/* Conditions grid */
.conditions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.cond-card {
  background: var(--clr-surface2);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}
.cond-icon { font-size: 1.3rem; }
.cond-value { font-size: 1rem; font-weight: 700; margin: 2px 0; }
.cond-name { font-size: .68rem; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .4px; }

.modal-summary {
  font-size: .84rem;
  color: var(--clr-muted);
  line-height: 1.6;
  margin-bottom: 18px;
  padding: 10px 14px;
  background: var(--clr-surface2);
  border-radius: 8px;
  border-left: 3px solid var(--clr-accent);
}

/* Score breakdown bars */
.score-breakdown { margin-bottom: 20px; }
.score-breakdown h4 { font-size: .78rem; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.breakdown-row { display: flex; align-items: center; gap: 10px; margin: 5px 0; font-size: .82rem; }
.breakdown-label { width: 90px; color: var(--clr-muted); flex-shrink: 0; }
.breakdown-bar-wrap { flex: 1; background: var(--clr-surface2); border-radius: 99px; height: 6px; }
.breakdown-bar { height: 6px; border-radius: 99px; transition: width .4s; }
.breakdown-val { width: 28px; text-align: right; font-weight: 600; font-size: .78rem; }

/* Recent observations */
.recent-obs { margin-bottom: 20px; }
.recent-obs h4 { font-size: .78rem; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.obs-list { display: flex; flex-direction: column; gap: 6px; }
.obs-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: var(--clr-surface2);
  border-radius: 8px;
  font-size: .8rem;
}
.obs-time { color: var(--clr-muted); width: 50px; flex-shrink: 0; }
.obs-icon { font-size: 1rem; }
.obs-temp { font-weight: 700; width: 44px; }
.obs-desc { flex: 1; color: var(--clr-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.obs-snow { color: #7dd3fc; }
.obs-rain { color: #93c5fd; }

/* Chart */
.chart-section h4 { font-size: .78rem; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }

/* ── Loading overlay ───────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--clr-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: 16px;
  font-size: .9rem;
  color: var(--clr-muted);
  transition: opacity .4s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--clr-border);
  border-top-color: var(--clr-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-main { flex-direction: column; }
  .map-panel { height: 55vh; }
  .sidebar { width: 100%; height: 45vh; border-left: none; border-top: 1px solid var(--clr-border); }
  :root { --sidebar-w: 100%; }
  .conditions-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Score colour helpers */
.score-excellent { color: var(--clr-excellent); }
.score-good      { color: var(--clr-good); }
.score-fair      { color: var(--clr-fair); }
.score-bad       { color: var(--clr-bad); }
