@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface2: #f3f6fa;
  --surface3: #e7edf4;
  --border: rgba(15,23,42,0.08);
  --border-hover: rgba(15,23,42,0.16);
  --text: #1e293b;
  --text2: #64748b;
  --text3: #94a3b8;
  --accent: #0284c7;
  --accent2: #0ea5e9;
  --accent-glow: rgba(2, 132, 199, 0.10);
  --good: #10b981;
  --moderate: #f59e0b;
  --sensitive: #f97316;
  --unhealthy: #ef4444;
  --very-unhealthy: #8b5cf6;
  --hazardous: #b91c1c;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,42,0.06), 0 6px 20px rgba(15,23,42,0.08);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Toast System ── */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 420px;
  width: calc(100% - 32px);
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 8px 32px rgba(0,0,0,0.4);
  backdrop-filter: blur(20px);
  font-size: 0.82rem;
  line-height: 1.5;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transform-origin: top right;
  overflow: hidden;
  position: relative;
}

.toast.exiting {
  animation: toastOut 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

.toast::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  animation: toastTimer var(--toast-duration, 6000ms) linear forwards;
}

.toast.warning { border-left: 3px solid var(--sensitive); }
.toast.warning::after { background: var(--sensitive); }
.toast.danger { border-left: 3px solid var(--unhealthy); }
.toast.danger::after { background: var(--unhealthy); }
.toast.success { border-left: 3px solid var(--good); }
.toast.success::after { background: var(--good); }
.toast.info { border-left: 3px solid var(--accent); }
.toast.info::after { background: var(--accent); }

.toast-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  margin-top: 1px;
}

.toast.warning .toast-icon { background: rgba(251,146,60,0.15); color: var(--sensitive); }
.toast.danger .toast-icon { background: rgba(248,113,113,0.15); color: var(--unhealthy); }
.toast.success .toast-icon { background: rgba(52,211,153,0.15); color: var(--good); }
.toast.info .toast-icon { background: rgba(56,189,248,0.15); color: var(--accent); }

.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; font-size: 0.82rem; margin-bottom: 2px; }
.toast-message { color: var(--text2); font-size: 0.78rem; }

.toast-close {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  line-height: 1;
  border-radius: 4px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text); background: var(--surface3); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); max-height: 200px; margin-bottom: 0; }
  to   { opacity: 0; transform: translateX(40px) scale(0.95); max-height: 0; margin-bottom: -8px; padding: 0; }
}
@keyframes toastTimer {
  from { width: 100%; }
  to   { width: 0%; }
}

/* ── Offline Banner ── */
.offline-banner {
  background: linear-gradient(90deg, var(--sensitive), #ea580c);
  color: #fff;
  text-align: center;
  padding: 10px;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  animation: slideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.hidden { display: none !important; }

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 1500;
}

.header-content {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #000;
}

.header-content h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.header-content h1 span { color: var(--accent); font-weight: 700; }

.subtitle {
  font-size: 0.75rem;
  color: var(--text3);
  margin-left: auto;
  display: none;
}

/* ── Centro de Notificaciones ── */
.notif-center { margin-left: auto; position: relative; }

.notify-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-hover);
  background: var(--surface);
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}
.notify-btn:hover { color: var(--accent); border-color: var(--accent); }
.notify-btn.has-unread .notify-icon { animation: bellRing 0.6s ease; }

.notify-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--unhealthy);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  box-shadow: 0 1px 4px rgba(239,68,68,0.4);
}

@keyframes bellRing {
  0%,100% { transform: rotate(0); }
  20% { transform: rotate(-14deg); }
  40% { transform: rotate(11deg); }
  60% { transform: rotate(-7deg); }
  80% { transform: rotate(4deg); }
}

.notif-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 12px 40px rgba(15,23,42,0.15);
  z-index: 200;
  overflow: hidden;
  animation: fadeScale 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.notif-panel-head h3 { font-size: 0.9rem; font-weight: 600; color: var(--text); }

.notif-clear {
  background: none;
  border: none;
  color: var(--text2);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--transition);
}
.notif-clear:hover { background: var(--surface3); color: var(--text); }

.notif-push-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.notif-push-text { display: flex; flex-direction: column; gap: 2px; }
.notif-push-text strong { font-size: 0.78rem; color: var(--text); }
.notif-push-text span { font-size: 0.68rem; color: var(--text2); }

.push-toggle {
  flex-shrink: 0;
  padding: 7px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.push-toggle:hover { background: var(--accent2); border-color: var(--accent2); }
.push-toggle.active {
  background: var(--accent-glow);
  color: var(--accent);
}
.push-toggle.blocked {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: var(--unhealthy);
  cursor: not-allowed;
}

.notif-list {
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}

.notif-item {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  animation: fadeScale 0.25s ease;
}
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--accent-glow); }

.notif-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.notif-item.warning .notif-item-dot { background: var(--sensitive); }
.notif-item.danger  .notif-item-dot { background: var(--unhealthy); }
.notif-item.success .notif-item-dot { background: var(--good); }
.notif-item.info    .notif-item-dot { background: var(--accent); }

.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-size: 0.78rem; font-weight: 600; color: var(--text); }
.notif-item-msg { font-size: 0.72rem; color: var(--text2); margin-top: 2px; line-height: 1.45; }
.notif-item-time { font-size: 0.64rem; color: var(--text3); margin-top: 4px; }

.notif-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text3);
  font-size: 0.76rem;
}

.badge {
  margin-left: 0;
  padding: 4px 12px;
  font-size: 0.65rem;
  background: var(--accent-glow);
  border: 1px solid rgba(2,132,199,0.2);
  border-radius: 20px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Main Layout ── */
main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  align-items: start;
}

/* ── Map ── */
.map-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

#map {
  height: 560px;
  z-index: 1;
  background: var(--surface);
}

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1200;
  display: flex;
  gap: 8px;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border: 1px solid rgba(15,23,42,0.14);
  background: #ffffff;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--transition);
  letter-spacing: 0.2px;
  box-shadow: 0 2px 6px rgba(15,23,42,0.18), 0 4px 16px rgba(15,23,42,0.12);
}

.ctrl-btn svg { color: var(--accent); transition: color var(--transition); }

.ctrl-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.ctrl-btn:hover svg { color: #fff; }
.ctrl-btn.active svg { color: #fff; }

.ctrl-btn:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

.ctrl-btn.secondary {
  border-color: transparent;
  background: rgba(255,255,255,0.04);
  color: var(--text3);
}
.ctrl-btn.secondary:hover { background: rgba(255,255,255,0.08); color: var(--text2); }

.ctrl-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

/* ── Route Panel ── */
.route-panel {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  width: 320px;
  font-size: 0.82rem;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  animation: fadeScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeScale {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ctrl-btn svg { flex-shrink: 0; }

.route-handle {
  display: none;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-hover);
  margin: 0 auto 12px;
}

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

.route-panel h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
.route-panel h3 svg { color: var(--accent); flex-shrink: 0; }

.route-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--surface2);
  color: var(--text2);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.route-close:hover { background: var(--surface3); color: var(--text); }

.route-instructions {
  color: var(--text2);
  margin-bottom: 12px;
  font-size: 0.78rem;
  line-height: 1.6;
}

.route-mode {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.route-mode label {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  color: var(--text2);
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  padding: 7px 4px;
  border-radius: 6px;
  transition: all var(--transition);
}
.route-mode label svg { flex-shrink: 0; }
.route-mode label:hover { color: var(--text); }

.route-mode label:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

.route-mode input { display: none; }

.route-point {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 0.78rem;
  color: var(--text2);
}

.route-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.route-dot.origin { background: var(--good); box-shadow: 0 0 8px rgba(52,211,153,0.4); }
.route-dot.dest   { background: var(--unhealthy); box-shadow: 0 0 8px rgba(248,113,113,0.4); }

.route-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.route-actions .ctrl-btn { flex: 1; text-align: center; }

#route-result {
  margin-top: 14px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  animation: fadeScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.route-stat {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.78rem;
}

.route-stat-label { color: var(--text3); }
.route-stat-value { font-weight: 600; color: var(--text); }

.route-recommendation {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.5;
}

.route-recommendation.good   { background: rgba(52,211,153,0.1); color: var(--good); border: 1px solid rgba(52,211,153,0.15); }
.route-recommendation.moderate { background: rgba(251,191,36,0.1); color: var(--moderate); border: 1px solid rgba(251,191,36,0.15); }
.route-recommendation.bad    { background: rgba(248,113,113,0.1); color: var(--unhealthy); border: 1px solid rgba(248,113,113,0.15); }

/* ── Sidebar ── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}

.panel:hover { border-color: var(--border-hover); }

.panel h2 {
  font-size: 0.72rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ── Station Cards ── */
.station-card {
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
}

.station-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  transition: background var(--transition);
  border-radius: 3px 0 0 3px;
}

.station-card:hover {
  background: var(--surface3);
  border-color: var(--border-hover);
  transform: translateX(2px);
}

.station-card.selected {
  border-color: rgba(56,189,248,0.2);
  background: rgba(56,189,248,0.04);
}

.station-card.selected::before { background: var(--accent); }

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

.station-info {}
.station-name { font-weight: 600; font-size: 0.82rem; }

.station-profile {
  font-size: 0.68rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 2px;
}

.aqi-chip {
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: -0.3px;
  transition: transform var(--transition);
}

.station-card:hover .aqi-chip { transform: scale(1.05); }

.station-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.metric {
  text-align: center;
  padding: 6px 4px;
  background: var(--surface);
  border-radius: 6px;
}

.metric-val {
  font-weight: 600;
  font-size: 0.82rem;
  display: block;
}

.metric-lbl {
  font-size: 0.62rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.station-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text3);
}

.trend-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.trend-badge.up   { background: rgba(248,113,113,0.1); color: var(--unhealthy); }
.trend-badge.down { background: rgba(52,211,153,0.1);  color: var(--good); }
.trend-badge.flat { background: rgba(122,138,158,0.1); color: var(--text2); }

/* ── Charts ── */
.chart-wrap { height: 160px; position: relative; }
canvas { width: 100% !important; height: 100% !important; }

/* ── Footer ── */
footer {
  text-align: center;
  padding: 20px;
  color: var(--text3);
  font-size: 0.7rem;
  border-top: 1px solid var(--border);
  margin-top: 32px;
  letter-spacing: 0.2px;
}

/* ── Leaflet overrides ── */
.leaflet-control-attribution { font-size: 9px !important; opacity: 0.5; }
.leaflet-popup-content-wrapper {
  background: #ffffff !important;
  color: var(--text) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-popup-tip { background: #ffffff !important; }
.leaflet-popup-content { font-family: 'Inter', sans-serif !important; font-size: 0.78rem !important; }

/* ── Animations ── */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.loading { animation: pulse 1.5s ease-in-out infinite; }

/* Valores numéricos se animan suavemente via CSS transition en el contenedor */
.metric-val, .aqi-chip, .pred-text, .trend-badge {
  transition: all 0.4s ease;
}

/* ── Responsive ── */
@media (min-width: 1100px) {
  .subtitle { display: block; }
}

@media (max-width: 900px) {
  .dashboard { grid-template-columns: 1fr; }
  #map { height: 420px; }

  /* Panel de ruta como bottom sheet: no tapa el mapa, se queda abajo y es desplazable */
  .route-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-height: 52vh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding: 12px 16px 20px;
    box-shadow: 0 -8px 32px rgba(15,23,42,0.18);
    animation: sheetUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-overflow-scrolling: touch;
  }
  .route-handle { display: block; }

  .header-content { flex-wrap: wrap; gap: 8px; }
  .badge { margin-left: 0; }
  .sidebar { max-height: none; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Centro de notificaciones: en móvil baja desde la campana, a todo el ancho
   de la pantalla (con márgenes) para que el contenido nunca se corte */
@media (max-width: 600px) {
  .notif-center { position: static; }
  .badge { display: none; }

  .notif-panel {
    position: fixed;
    top: 64px;
    left: 12px;
    right: 12px;
    bottom: auto;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
    box-shadow: 0 16px 50px rgba(15,23,42,0.30);
    animation: notifDrop 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 2000;
  }
  .notif-list { max-height: none; flex: 1; }
}

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

@media (max-width: 480px) {
  main { padding: 8px; }
  .dashboard { gap: 8px; }
  #map { height: 320px; }
  .map-controls { flex-direction: column; }
  .station-metrics { grid-template-columns: repeat(2, 1fr); }
}
