/* mobile-first; pensado para iPhone (safe-areas) y desktop */
:root {
  --bg: #f6f7fb;
  --fg: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --card: #ffffff;
  --primary: #1e3a8a;
  --open: #16a34a;
  --soon: #ea580c;
  --closed: #6b7280;
  --info: #2563eb;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --fg: #e5e7eb;
    --muted: #94a3b8;
    --line: #1f2937;
    --card: #111827;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}

.topbar {
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 14px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.topbar .sub { margin: 4px 0 0; font-size: 13px; opacity: .85; }

.tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 8px;
  position: sticky;
  top: calc(env(safe-area-inset-top) + 56px);
  z-index: 4;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  padding: 8px 14px;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

main { padding: 16px; max-width: 980px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

h2 {
  font-size: 17px;
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
h2 .dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--primary));
  display: inline-block;
}

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
}
.badge.open { background: #dcfce7; color: #166534; }
.badge.soon { background: #ffedd5; color: #9a3412; }
.badge.closed { background: #e5e7eb; color: #374151; }
@media (prefers-color-scheme: dark) {
  .badge.open { background: #064e3b; color: #bbf7d0; }
  .badge.soon { background: #7c2d12; color: #fed7aa; }
  .badge.closed { background: #1f2937; color: #cbd5e1; }
}

.empty { color: var(--muted); font-style: italic; }

/* Hero cards: "Esta semana" / "Próximos 30 días" */
.hero-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--primary);
}
.hero-week { border-left-color: #ea580c; }
.hero-urgent { border-left-color: #1e3a8a; }
.hero-card header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.hero-card h2 { margin: 0; font-size: 16px; }
.hero-icon { font-size: 22px; line-height: 1; }
.hero-list { list-style: none; margin: 0; padding: 0; }
.hero-list li {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center;
  font-size: 14px;
}
.hero-list li:first-child { border-top: 0; }
.hero-d {
  display: inline-block;
  min-width: 36px;
  padding: 2px 6px;
  border-radius: 6px;
  background: #fee2e2; color: #991b1b;
  font-weight: 700;
  text-align: center;
  font-size: 12px;
}
.hero-t { flex: 1 1 60%; }
.hero-f { color: var(--muted); font-size: 12px; }
@media (prefers-color-scheme: dark) {
  .hero-d { background: #7f1d1d; color: #fecaca; }
}

/* Centros grid */
.centros-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 600px) { .centros-grid { grid-template-columns: repeat(2,1fr); } }
@media (min-width: 1000px) { .centros-grid { grid-template-columns: repeat(3,1fr); } }
.centro-item { padding: 10px 12px; font-size: 14px; }
.centro-item.preferido { border-left: 4px solid #fbbf24; background: color-mix(in srgb, #fbbf24 8%, var(--card)); }
.centro-item header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.centro-item .dir, .centro-item .tel { margin: 2px 0; color: var(--muted); font-size: 13px; }
.star {
  background: transparent; border: 0; cursor: pointer;
  font-size: 22px; color: #cbd5e1; padding: 0; line-height: 1;
}
.star.on { color: #fbbf24; }
.star:disabled { opacity: .5; cursor: wait; }
.star:hover { color: #fbbf24; }

/* Print */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .tabs, footer, .layer-toggles { display: none; }
  .panel { display: block !important; page-break-inside: avoid; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  a { color: #000; }
}

.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--c, var(--primary));
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.card h3 { margin: 4px 0 4px; font-size: 16px; }
.card .organismo { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.card p { margin: 6px 0; font-size: 14px; }
.card ul.meta, .card ul.links, .card details ul {
  margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px;
}
.card ul.meta li { color: var(--muted); }
.card ul.links li { margin: 4px 0; }
.card a { color: var(--info); text-decoration: none; word-break: break-word; }
.card a:hover { text-decoration: underline; }
.card details { margin: 8px 0 0; font-size: 13px; }
.card details summary { cursor: pointer; color: var(--muted); }
.card .nota { font-size: 12px; color: var(--muted); margin-top: 8px; }

.estado {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.estado-abierto { background: #dcfce7; color: #166534; }
.estado-proximo { background: #ffedd5; color: #9a3412; }
.estado-cerrado { background: #e5e7eb; color: #374151; }
.estado-info { background: #dbeafe; color: #1e40af; }
@media (prefers-color-scheme: dark) {
  .estado-abierto { background: #064e3b; color: #bbf7d0; }
  .estado-proximo { background: #7c2d12; color: #fed7aa; }
  .estado-cerrado { background: #1f2937; color: #cbd5e1; }
  .estado-info { background: #1e3a8a; color: #bfdbfe; }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: var(--c);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); display: inline-block; }
.chip input { display: none; }
.chip:has(input:not(:checked)) { opacity: .35; }

.layer-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

#calendar { background: var(--card); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); }
.fc { font-size: 14px; }
.fc .fc-toolbar-title { font-size: 16px !important; }
.fc .fc-button { font-size: 13px !important; padding: 4px 10px !important; }
@media (max-width: 720px) {
  .fc .fc-toolbar.fc-header-toolbar { flex-wrap: wrap; gap: 6px; }
}

footer {
  text-align: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--muted);
}
footer a { color: var(--info); margin-left: 6px; }

/* Modal */
#modal { position: fixed; inset: 0; display: none; z-index: 50; }
#modal.open { display: block; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal-box {
  position: absolute;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  max-height: 80vh;
  overflow: auto;
}
@media (min-width: 720px) {
  .modal-box { bottom: auto; top: 10vh; border-radius: var(--radius); }
}
.modal-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: 0; font-size: 26px; color: var(--muted); cursor: pointer;
}
.modal-body h3 { margin: 8px 0; }
.modal-body .organismo { color: var(--muted); margin: 0 0 8px; }
.modal-body .links a { margin-right: 8px; }

/* Countdown badge en cards */
.card-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.countdown-badge {
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
}
.countdown-badge.hoy    { background: #fef08a; color: #713f12; }
.countdown-badge.critico{ background: #fee2e2; color: #991b1b; }
.countdown-badge.urgente{ background: #ffedd5; color: #9a3412; }
.countdown-badge.prox   { background: #dbeafe; color: #1e40af; }
@media (prefers-color-scheme: dark) {
  .countdown-badge.hoy    { background: #713f12; color: #fef08a; }
  .countdown-badge.critico{ background: #7f1d1d; color: #fecaca; }
  .countdown-badge.urgente{ background: #7c2d12; color: #fed7aa; }
  .countdown-badge.prox   { background: #1e3a8a; color: #bfdbfe; }
}

/* Badge fecha tentativa */
.badge-tentativo {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: #fef9c3; color: #854d0e; white-space: nowrap;
}
@media (prefers-color-scheme: dark) {
  .badge-tentativo { background: #713f12; color: #fef08a; }
}

/* iCal link en header */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.topbar-left { flex: 1; }
.ical-btn {
  flex: 0 0 auto; align-self: center;
  background: rgba(255,255,255,.15); color: #fff;
  padding: 5px 11px; border-radius: 999px;
  font-size: 13px; text-decoration: none; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.3);
}
.ical-btn:hover { background: rgba(255,255,255,.25); }

/* Botón watcher en footer */
#btn-watcher {
  background: none; border: 1px solid var(--line);
  color: var(--muted); padding: 4px 12px; border-radius: 999px;
  font: inherit; font-size: 12px; cursor: pointer;
  transition: background .15s, color .15s;
}
#btn-watcher:hover  { background: var(--primary); color: #fff; border-color: var(--primary); }
#btn-watcher:disabled { opacity: .6; cursor: wait; }

/* Grid centro preferido (centro + AMPA lado a lado) */
.centro-preferido-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (min-width: 600px) {
  .centro-preferido-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Guía / Manual de usuario ─────────────────────────────────────────────── */
.guia { max-width: 860px; }

.guia-hero {
  background: linear-gradient(135deg, var(--primary) 0%, #3949ab 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-bottom: 24px;
}
.guia-hero h2 { margin: 0 0 8px; font-size: 22px; }
.guia-hero p  { margin: 0; opacity: .9; font-size: 15px; }

.guia-h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 28px 0 12px;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
}
.guia-h3::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.guia-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 600px) { .guia-grid { grid-template-columns: 1fr; } }

.guia-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.guia-card-full { grid-column: 1 / -1; }
.guia-icon { font-size: 28px; margin-bottom: 8px; line-height: 1; }
.guia-card h4 { margin: 0 0 6px; font-size: 15px; }
.guia-card p  { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.guia-tip {
  font-size: 13px !important;
  color: var(--info) !important;
  margin-top: 8px !important;
}

.guia-comandos {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.guia-cmd {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.guia-cmd:last-child { border-bottom: 0; }
.guia-cmd code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.guia-cmd span { color: var(--muted); flex: 1; }
.guia-cmd em { color: var(--fg); font-style: normal; font-weight: 600; }
.guia-note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.guia-fuentes {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  font-size: 14px;
}
@media (max-width: 600px) { .guia-fuentes { grid-template-columns: 1fr; } }
.guia-fuentes li { color: var(--muted); }
.guia-fuentes strong { color: var(--fg); }

.guia-steps {
  margin: 8px 0;
  padding-left: 20px;
  font-size: 14px;
  color: var(--muted);
}
.guia-steps li { padding: 3px 0; }
.guia-steps strong { color: var(--fg); }
.guia-steps code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
  background: var(--line);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

.guia-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  font-size: 14px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.guia-badges > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Botón Telegram en header */
.tg-btn {
  flex: 0 0 auto; align-self: center;
  background: #229ED9; color: #fff;
  padding: 5px 11px; border-radius: 999px;
  font-size: 13px; text-decoration: none; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.3);
}
.tg-btn:hover { background: #1a8bbf; }

/* Botón grande de enlace al bot en la guía */
.guia-bot-link { margin: 12px 0 4px; }
.btn-telegram {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #229ED9;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(34,158,217,.4);
}
.btn-telegram:hover { background: #1a8bbf; }

/* Icono admin en el header */
.admin-btn {
  flex: 0 0 auto; align-self: center;
  font-size: 18px; line-height: 1;
  opacity: .35; text-decoration: none;
  transition: opacity .2s;
  padding: 4px;
}
.admin-btn:hover { opacity: .9; }
