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

:root {
  --bg:        #f3f4f6;
  --superficie:#ffffff;
  --borde:     #d1d5db;
  --texto:     #111827;
  --suave:     #374151;
  --acento:    #1d4ed8;
  --radio:     8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100dvh;
}

/* ---- Accessibility ---- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---- Header ---- */
.cabecera {
  background: var(--superficie);
  border-bottom: 1px solid var(--borde);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.cabecera-titulo {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.cabecera-sub {
  font-size: 0.85rem;
  color: var(--suave);
}

.btn-vista {
  background: var(--bg);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-vista:hover { background: var(--borde); }

/* ---- Filters ---- */
.filtros {
  background: var(--superficie);
  border-bottom: 1px solid var(--borde);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filtros-cats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.chip {
  padding: 6px 14px;
  border: 1.5px solid var(--borde);
  border-radius: 999px;
  background: transparent;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  color: var(--texto);
  font-weight: 500;
}
.chip:hover { background: #e5e7eb; }
.chip.activo {
  background: var(--acento);
  border-color: var(--acento);
  color: #fff;
}

.ciudad-select {
  padding: 5px 10px;
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  background: var(--superficie);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--texto);
}

/* ---- Main content area ---- */
.contenido {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

/* ---- Month navigation ---- */
.mes-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.mes-nav h2 {
  font-size: 1.3rem;
  font-weight: 700;
  min-width: 180px;
  text-align: center;
}

.btn-mes {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.15s;
}
.btn-mes:hover { background: var(--borde); }

/* ---- Calendar grid ---- */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--borde);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  overflow: hidden;
}

.cal-hdr {
  background: #e5e7eb;
  text-align: center;
  padding: 10px 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #1f2937;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  /* prevent header from expanding column beyond its 1fr share */
  min-width: 0;
  overflow: hidden;
}

.cal-dia {
  background: var(--superficie);
  min-height: 160px;
  padding: 8px 6px 5px;
  position: relative;
  /* critical: allow grid cell to shrink below pill content width */
  min-width: 0;
  overflow: hidden;
}
.cal-dia--vacio { background: #f9fafb; }
.cal-dia--hoy { background: #eff6ff; border: 2px solid #93c5fd; }

.cal-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 4px;
}
.cal-dia--hoy .cal-num {
  background: var(--acento);
  color: #fff;
  border-radius: 50%;
}

.cal-pills { display: flex; flex-direction: column; gap: 3px; }

.cal-pill {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.72rem;
  padding: 3px 6px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.45;
  font-weight: 600;
  transition: opacity 0.1s;
  text-shadow: 0 1px 1px rgba(0,0,0,0.25);
}
.cal-pill:hover { opacity: 0.88; }

.cal-mas {
  font-size: 0.72rem;
  color: var(--acento);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 3px;
  text-align: left;
  font-weight: 600;
  text-decoration: underline;
}
.cal-mas:hover { opacity: 0.75; }

/* ---- List view ---- */
.lista { display: flex; flex-direction: column; gap: 0; }

.lista-encabezado {
  margin: 32px 0 16px;
  padding-top: 24px;
  border-top: 1px solid var(--borde);
  font-size: 1.25rem;
  color: var(--texto);
}
[data-theme="dark"] .lista-encabezado { color: #f9fafb; border-top-color: #374151; }
.lista-grupo { scroll-margin-top: 16px; }

/* ---- Holidays ---- */
.cal-dia--feriado:not(.cal-dia--hoy) { background: #fef2f2; }
.cal-feriado {
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.25;
  color: #b91c1c;
  margin-bottom: 4px;
  cursor: help;
}
.cal-feriado--laborable { color: #6b7280; font-weight: 500; font-style: italic; }

.feriados-mes {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid #b91c1c;
  border-radius: var(--radio);
  padding: 12px 16px;
  margin-bottom: 20px;
}
.feriados-mes h3 { font-size: 0.95rem; color: #991b1b; margin-bottom: 6px; }
.feriados-mes ul { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.feriados-mes li { font-size: 0.88rem; color: var(--texto); line-height: 1.4; }
.feriados-mes li.feriado-laborable { color: var(--suave); }

[data-theme="dark"] .cal-dia--feriado:not(.cal-dia--hoy) { background: #2a1416; }
[data-theme="dark"] .cal-feriado             { color: #fca5a5; }
[data-theme="dark"] .cal-feriado--laborable  { color: #9ca3af; }
[data-theme="dark"] .feriados-mes            { background: #2a1416; border-color: #7f1d1d; border-left-color: #f87171; }
[data-theme="dark"] .feriados-mes h3         { color: #fca5a5; }
[data-theme="dark"] .feriados-mes li         { color: #e5e7eb; }
[data-theme="dark"] .feriados-mes li.feriado-laborable { color: #9ca3af; }

.lista-grupo { margin-bottom: 24px; }

.lista-fecha-sep {
  font-size: 0.875rem;
  font-weight: 700;
  color: #1f2937;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 0 10px;
  border-bottom: 2px solid var(--borde);
  margin-bottom: 12px;
}

.lista-card {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.lista-card:hover {
  border-color: #c7d2fe;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.lista-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.lista-fecha-str {
  font-size: 0.78rem;
  color: var(--suave);
}

.lista-titulo {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.35;
  color: #111827;
}

.lista-lugar {
  font-size: 0.875rem;
  color: var(--suave);
  margin-bottom: 8px;
}

.lista-desc {
  font-size: 0.9rem;
  color: #1f2937;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
  line-height: 1.55;
}

.lista-pie {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---- Shared: badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

/* ---- Shared: source link ---- */
.fuente-link {
  font-size: 0.78rem;
  color: var(--acento);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.fuente-link:hover { text-decoration: underline; }

/* ---- Btn secondary ---- */
.btn-detalle {
  font-size: 0.78rem;
  color: var(--suave);
  background: none;
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-detalle:hover { background: var(--bg); }

/* ---- Empty state ---- */
.sin-eventos {
  color: var(--suave);
  text-align: center;
  padding: 48px 20px;
  font-size: 0.9rem;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal.oculto { display: none; }

.modal-fondo {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.modal-panel {
  position: relative;
  background: var(--superficie);
  border-radius: 16px 16px 0 0;
  padding: 28px 24px 32px;
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  z-index: 1;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
  }
  .modal-panel {
    border-radius: 16px;
    max-width: 580px;
    max-height: 80dvh;
  }
}

.modal-cerrar {
  position: absolute;
  top: 14px;
  right: 16px;
  background: var(--bg);
  border: 1px solid var(--borde);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.modal-cerrar:hover { background: var(--borde); }

.modal-cabecera {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.modal-ciudad {
  font-size: 0.78rem;
  color: var(--suave);
}

.modal-titulo {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 8px;
  padding-right: 32px;
  color: #111827;
}

.modal-fecha {
  font-size: 0.9rem;
  color: var(--suave);
  margin-bottom: 4px;
  font-weight: 500;
}

.modal-lugar {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: #111827;
}

.modal-desc {
  font-size: 0.95rem;
  color: #1f2937;
  line-height: 1.7;
  margin-bottom: 20px;
}

.modal-fuentes {
  margin-bottom: 16px;
  font-size: 0.82rem;
}

.modal-fuentes strong {
  display: block;
  margin-bottom: 6px;
  color: var(--suave);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
}

.fuentes-lista {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-acciones {
  display: flex;
  gap: 8px;
}

.btn-copiar {
  padding: 8px 16px;
  background: var(--bg);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
  font-weight: 500;
}
.btn-copiar:hover { background: var(--borde); }

.cabecera-controles { display: flex; gap: 8px; }

/* ---- Dark mode ---- */
[data-theme="dark"] {
  --bg:        #111827;
  --superficie:#1f2937;
  --borde:     #374151;
  --texto:     #f3f4f6;
  --suave:     #9ca3af;
  --acento:    #60a5fa;
}

body,
.cabecera, .filtros,
.cal-dia, .cal-hdr,
.lista-card, .modal-panel,
.chip, .btn-vista, .btn-mes, .ciudad-select {
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

[data-theme="dark"] .btn-vista           { background: #374151; color: #f9fafb; border-color: #6b7280; }
[data-theme="dark"] .btn-vista:hover     { background: #4b5563; }
[data-theme="dark"] .btn-mes            { background: #374151; border-color: #6b7280; }
[data-theme="dark"] .btn-mes:hover      { background: #4b5563; }
[data-theme="dark"] .chip:hover          { background: #374151; }
[data-theme="dark"] .cal-hdr            { background: #374151; color: #e5e7eb; }
[data-theme="dark"] .cal-dia--vacio     { background: #0d1117; }
[data-theme="dark"] .cal-dia--hoy       { background: #1e3a5f; border-color: #3b82f6; }
[data-theme="dark"] .cal-num            { color: #e5e7eb; }
[data-theme="dark"] .lista-fecha-sep    { color: #e5e7eb; border-bottom-color: #374151; }
[data-theme="dark"] .lista-card:hover   { border-color: #4b5563; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
[data-theme="dark"] .lista-titulo       { color: #f9fafb; }
[data-theme="dark"] .lista-lugar        { color: #9ca3af; }
[data-theme="dark"] .lista-desc         { color: #d1d5db; }
[data-theme="dark"] .modal-fondo        { background: rgba(0,0,0,0.65); }
[data-theme="dark"] .modal-titulo       { color: #f9fafb; }
[data-theme="dark"] .modal-lugar        { color: #f9fafb; }
[data-theme="dark"] .modal-desc         { color: #d1d5db; }
[data-theme="dark"] .modal-cerrar:hover { background: #374151; }
[data-theme="dark"] .btn-detalle:hover  { background: #374151; }
[data-theme="dark"] .btn-copiar         { background: #1f2937; }
[data-theme="dark"] .btn-copiar:hover   { background: #374151; }
[data-theme="dark"] .sin-eventos        { color: #9ca3af; }

.fer-corto { display: none; }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .contenido { padding: 12px; }
  .cabecera { padding: 12px 16px; }

  /* Stack chips then city selector, each full-width row */
  .filtros {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .filtros-cats { flex: unset; }
  .filtros-ciudad { align-self: flex-start; }
  .ciudad-select { font-size: 1rem; }

  /* Compact calendar cells — keep readable */
  .cal-dia { min-height: 108px; padding: 5px 4px 3px; }
  .cal-hdr {
    font-size: 0.68rem;
    padding: 7px 2px;
    letter-spacing: 0;
  }
  .cal-num { width: 22px; height: 22px; font-size: 0.78rem; }
  .cal-pill { font-size: 0.62rem; padding: 2px 4px; }

  /* Holiday labels: short form in narrow cells; full names are in "Feriados del mes" */
  .cal-feriado { font-size: 0.6rem; }
  .fer-largo { display: none; }
  .fer-corto { display: inline; }
}
