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

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

/* ─── DESIGN TOKENS ───────────────────────────────────────────────────────── */
:root {
  /* Category colors — vibrant flat palette */
  --color-trafico:      #E5473C;
  --color-obras:        #F09530;
  --color-metro:        #3A7CA5;
  --color-emt:          #1D8C8C;
  --color-aire:         #52A052;
  --color-agua:         #29B3C7;
  --color-electricidad: #D4AA00;
  --color-restriccion:  #B85CA8;
  --color-parques:      #3A8A52;
  --color-semaforo:     #8295A8;
  --color-cercanias:    #C4282E;
  --color-meteorologia: #7055B8;

  /* Editorial palette */
  --cream:        #F5F0E8;
  --ivory:        #FDFAF4;
  --paper:        #FFFFFF;
  --navy:         #1A2744;
  --navy-mid:     #2E4070;
  --coral:        #D94035;
  --teal:         #3A7CA5;
  --amber:        #E8922A;

  /* Surfaces */
  --bg:             var(--cream);
  --bg-2:           var(--ivory);
  --surface:        var(--paper);
  --surface-2:      #F0EBE0;
  --surface-hover:  #EAE3D7;
  --border:         rgba(26,39,68,0.09);
  --border-bright:  rgba(26,39,68,0.17);
  --text:           var(--navy);
  --text-muted:     #4E5E80;
  --text-dim:       #8898B8;
  --accent:         var(--coral);
  --accent-glow:    rgba(217,64,53,0.18);

  /* Severity */
  --sev-grave-bg:   rgba(217,64,53,0.10);
  --sev-grave-fg:   #B83028;
  --sev-mod-bg:     rgba(232,146,42,0.12);
  --sev-mod-fg:     #B86A10;
  --sev-leve-bg:    rgba(82,160,82,0.11);
  --sev-leve-fg:    #2E7A2E;

  /* Layout */
  --topbar-h:     62px;
  --stats-h:      46px;
  --filters-h:    46px;
  --panel-w:      320px;
  --header-total: calc(var(--topbar-h) + var(--stats-h) + var(--filters-h));

  /* Motion */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

/* ─── BASE ────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── TOPBAR ──────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 2px solid var(--coral);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 1px 8px rgba(26,39,68,0.08);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-notices {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-right: 1px solid var(--border-bright);
  padding-right: 20px;
}

.logo {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0.2px;
  color: var(--navy);
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--coral);
  background: rgba(217,64,53,0.09);
  border: 1px solid rgba(217,64,53,0.25);
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--coral);
  animation: pulse-dot 1.8s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.3; transform: scale(0.7); }
}

.update-time {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.disclaimer {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
}

/* ─── STATS BAR ───────────────────────────────────────────────────────────── */
.stats-bar {
  height: var(--stats-h);
  background: var(--navy);
  border-bottom: none;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 28px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
  position: relative;
}

.stat span {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #FFFFFF;
  transition: color 0.3s var(--ease-out);
}

.stat small {
  font-size: 9px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.stat-grave span   { color: #FF7A72; }
.stat-mod   span   { color: #FFCA7A; }
.stat-leve  span   { color: #7ED07E; }
.stat-aire  span   { color: #7EC8E3; font-size: 14px; }

#stat-aire-box {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 4px 10px;
  border-radius: 6px;
  transition: border-color 0.3s;
}

/* ─── FILTROS ─────────────────────────────────────────────────────────────── */
.filters {
  height: var(--filters-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-bright);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  flex-shrink: 0;
  padding: 5px 13px;
  border-radius: 4px;
  border: 1px solid var(--border-bright);
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s var(--ease-in-out);
  white-space: nowrap;
  letter-spacing: 0.1px;
  text-transform: uppercase;
}

.filter-btn:hover {
  border-color: var(--navy);
  color: var(--navy);
  background: var(--surface-hover);
}

.filter-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

/* Category-colored active states */
.filter-btn[data-cat="trafico"].active     { background: var(--color-trafico);      border-color: var(--color-trafico);      color: #fff; }
.filter-btn[data-cat="obras"].active       { background: var(--color-obras);        border-color: var(--color-obras);        color: #fff; }
.filter-btn[data-cat="metro"].active       { background: var(--color-metro);        border-color: var(--color-metro);        color: #fff; }
.filter-btn[data-cat="emt"].active         { background: var(--color-emt);          border-color: var(--color-emt);          color: #fff; }
.filter-btn[data-cat="aire"].active        { background: var(--color-aire);         border-color: var(--color-aire);         color: #fff; }
.filter-btn[data-cat="semaforo"].active    { background: var(--color-semaforo);     border-color: var(--color-semaforo);     color: #fff; }
.filter-btn[data-cat="restriccion"].active { background: var(--color-restriccion);  border-color: var(--color-restriccion);  color: #fff; }
.filter-btn[data-cat="parques"].active     { background: var(--color-parques);      border-color: var(--color-parques);      color: #fff; }
.filter-btn[data-cat="agua"].active        { background: var(--color-agua);         border-color: var(--color-agua);         color: #fff; }
.filter-btn[data-cat="electricidad"].active{ background: var(--color-electricidad); border-color: var(--color-electricidad); color: var(--navy); }
.filter-btn[data-cat="cercanias"].active   { background: var(--color-cercanias);    border-color: var(--color-cercanias);    color: #fff; }
.filter-btn[data-cat="meteorologia"].active{ background: var(--color-meteorologia); border-color: var(--color-meteorologia); color: #fff; }
.filter-btn[data-cat="incendio"].active    { background: #FF5500;                   border-color: #FF5500;                   color: #fff; }

/* ─── MAIN LAYOUT ─────────────────────────────────────────────────────────── */
.main {
  display: flex;
  height: calc(100vh - var(--header-total));
}

/* ─── MAPA ────────────────────────────────────────────────────────────────── */
#map {
  flex: 1;
  min-height: 300px;
}

/* Popups — light glass editorial style */
.leaflet-popup,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip-container,
.leaflet-popup-tip {
  pointer-events: none !important;
}

.leaflet-popup-content-wrapper {
  background: rgba(255,252,246,0.94) !important;
  color: var(--navy) !important;
  border: 1px solid var(--border-bright) !important;
  border-radius: 8px !important;
  box-shadow: 0 6px 24px rgba(26,39,68,0.18) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

.leaflet-popup-tip {
  background: rgba(255,252,246,0.94) !important;
}

.leaflet-popup-content {
  pointer-events: auto !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
}

/* Attribution */
.leaflet-control-attribution {
  background: rgba(255,252,246,0.88) !important;
  color: var(--text-dim) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

/* Zoom controls */
.leaflet-control-zoom a {
  background: var(--surface) !important;
  border-color: var(--border-bright) !important;
  color: var(--navy) !important;
  font-weight: 600 !important;
}

.leaflet-control-zoom a:hover {
  background: var(--surface-hover) !important;
}

/* ─── PANEL LATERAL ───────────────────────────────────────────────────────── */
.panel {
  width: var(--panel-w);
  min-width: 260px;
  background: var(--surface);
  border-left: 1px solid var(--border-bright);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 11px 16px;
  border-bottom: 2px solid var(--border-bright);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  flex-shrink: 0;
  background: var(--bg-2);
}

.panel-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-bright) transparent;
}

.panel-list::-webkit-scrollbar        { width: 3px; }
.panel-list::-webkit-scrollbar-track  { background: transparent; }
.panel-list::-webkit-scrollbar-thumb  { background: var(--border-bright); border-radius: 3px; }

.panel-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-2);
}

.panel-footer a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s;
}

.panel-footer a:hover { color: var(--teal); }

/* ─── TARJETAS INCIDENCIA ─────────────────────────────────────────────────── */
.inc-item {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s var(--ease-in-out);
  position: relative;
  background: var(--surface);
}

.inc-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: transparent;
  transition: background 0.15s;
}

.inc-item:hover {
  background: var(--surface-hover);
}

.inc-item.selected {
  background: rgba(58,124,165,0.06);
}

.inc-item.selected::before {
  background: var(--teal);
}

.inc-item:has(.sev-grave)::before  { background: rgba(217,64,53,0.3); }
.inc-item.selected:has(.sev-grave)::before { background: var(--color-trafico); }

.inc-icon {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 1px;
}

.inc-body  { flex: 1; min-width: 0; }

.inc-title {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  margin-bottom: 4px;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inc-meta {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
}

.inc-zona {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.inc-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

/* ─── SEVERITY BADGES ─────────────────────────────────────────────────────── */
.sev-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.sev-grave    { background: var(--sev-grave-bg); color: var(--sev-grave-fg); }
.sev-moderada { background: var(--sev-mod-bg);   color: var(--sev-mod-fg); }
.sev-leve     { background: var(--sev-leve-bg);  color: var(--sev-leve-fg); }

/* ─── ICONOS DE CATEGORÍA ─────────────────────────────────────────────────── */
.cat-trafico      { background: rgba(229, 71, 60, 0.12);  }
.cat-obras        { background: rgba(240,149, 48, 0.12);  }
.cat-metro        { background: rgba( 58,124,165, 0.12);  }
.cat-emt          { background: rgba( 29,140,140, 0.12);  }
.cat-aire         { background: rgba( 82,160, 82, 0.12);  }
.cat-agua         { background: rgba( 41,179,199, 0.12);  }
.cat-electricidad { background: rgba(212,170,  0, 0.12);  }
.cat-restriccion  { background: rgba(184, 92,168, 0.12);  }
.cat-parques      { background: rgba( 58,138, 82, 0.12);  }
.cat-semaforo     { background: rgba(130,149,168, 0.12);  }
.cat-cercanias    { background: rgba(196, 40, 46, 0.12);  }
.cat-meteorologia { background: rgba(112, 85,184, 0.12);  }
.cat-incendio     { background: rgba(255, 85,  0, 0.12);  }

/* ─── LOADING / EMPTY STATE ───────────────────────────────────────────────── */
.loading, .empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.loading::before {
  content: '';
  display: block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-bright);
  border-top-color: var(--coral);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

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

/* ─── ERROR BANNER ────────────────────────────────────────────────────────── */
.error-banner {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #8B1A1A;
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  border: 1px solid rgba(255,120,120,0.3);
  font-size: 12px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  white-space: nowrap;
}

/* ─── BUSCADOR FLOTANTE ───────────────────────────────────────────────────── */
.map-search-container {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  width: 300px;
  font-family: inherit;
}

.search-box {
  display: flex;
  align-items: center;
  background: rgba(255,252,246,0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  padding: 6px 12px;
  box-shadow: 0 2px 12px rgba(26,39,68,0.14);
  transition: all 0.22s var(--ease-out);
}

.search-box:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(58,124,165,0.12), 0 2px 12px rgba(26,39,68,0.14);
}

.search-icon {
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 8px;
  display: flex;
  align-items: center;
}

#search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--navy);
  font-family: inherit;
  font-size: 12px;
  height: 24px;
}

#search-input::placeholder {
  color: var(--text-dim);
}

#search-clear-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transition: all 0.15s;
}

#search-clear-btn:hover {
  color: var(--navy);
  background: var(--surface-hover);
}

.search-suggestions {
  margin-top: 5px;
  background: rgba(255,252,246,0.97);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 6px 20px rgba(26,39,68,0.14);
  scrollbar-width: thin;
}

.search-suggestions::-webkit-scrollbar { width: 3px; }
.search-suggestions::-webkit-scrollbar-track { background: transparent; }
.search-suggestions::-webkit-scrollbar-thumb { background: var(--border-bright); }

.search-suggestions li {
  padding: 9px 12px;
  font-size: 12px;
  color: var(--navy);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-suggestions li:last-child { border-bottom: none; }

.search-suggestions li:hover {
  background: var(--surface-hover);
  color: var(--navy);
}

.search-suggestions li.no-results {
  color: var(--text-muted);
  font-style: italic;
  cursor: default;
}

.search-suggestions li.no-results:hover { background: transparent; }

@keyframes search-pulse {
  0% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.4); opacity: 0.35; }
  100% { transform: scale(1); opacity: 0.8; }
}

.search-pulse-marker { animation: search-pulse 1.8s infinite ease-in-out; }

/* ─── BOTÓN CENTRAR MAPA ─────────────────────────────────────────────────── */
#btn-centrar-mapa {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 18px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 3px 14px rgba(26,39,68,0.35);
  transition: background 0.15s, transform 0.15s;
  white-space: nowrap;
}

#btn-centrar-mapa:hover {
  background: var(--teal);
}

#btn-centrar-mapa:active { transform: translateX(-50%) scale(0.97); }

/* ─── DISTRITO TOOLTIP ────────────────────────────────────────────────────── */
.distrito-tooltip {
  background: rgba(255,252,246,0.96) !important;
  border: 1px solid var(--border-bright) !important;
  color: var(--navy) !important;
  border-radius: 4px !important;
  padding: 4px 9px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  box-shadow: 0 3px 12px rgba(26,39,68,0.15) !important;
  font-family: inherit !important;
  letter-spacing: 0.2px !important;
}

/* ─── RESPONSIVE MÓVIL ────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  :root {
    --panel-w: 100%;
    --topbar-h: 50px;
    --stats-h: 40px;
  }

  .main {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - var(--header-total));
  }

  #map {
    height: 42vh;
    min-height: 220px;
  }

  .panel {
    width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--border-bright);
    height: 45vh;
    flex-shrink: 0;
  }

  .stats-bar {
    gap: 14px;
    padding: 0 14px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .stats-bar::-webkit-scrollbar { display: none; }

  .stat span  { font-size: 15px; }
  .stat small { font-size: 8px; }

  .logo { font-size: 16px; }

  .filters { padding: 0 10px; gap: 4px; }
  .filter-btn { font-size: 10px; padding: 4px 10px; }

  .map-search-container {
    width: calc(100% - 24px);
    left: 12px;
    right: 12px;
    top: 10px;
  }
}

@media (max-width: 360px) {
  #stat-aire-box { display: none; }
}

/* ─── REDUCED MOTION ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition-duration: 0.01ms !important; }
  .live-dot { animation: none !important; }
}
