:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e4ded4;
  --accent: #7a2e2e;      /* granito y teja compostelana */
  --accent-ink: #ffffff;
  --today: #fbeee0;
  --radius: 12px;
  --hour: 64px;           /* alto de una hora en la vista de día */
  --c-musica: #2f6fdb;
  --c-teatro: #c2410c;
  --c-expo: #7c3aed;
  --c-cine: #0f766e;
  --c-infantil: #db2777;
  --c-confe: #4d7c0f;
  --c-fiestas: #b45309;
  --c-visitas: #475569;
  --c-otros: #8a8f98;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1e2125; --ink: #e8e6e3; --muted: #9aa0a6;
    --line: #2e3238; --accent: #e08a7a; --accent-ink: #1a1a1a; --today: #2b2420;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; overflow-x: hidden; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, select { font: inherit; color: var(--ink); }

.top {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 20px 6px; max-width: 1400px; margin: 0 auto;
}
.brand { display: flex; gap: 10px; align-items: center; }
.logo { width: 40px; height: 40px; border-radius: 10px; flex: none; }
h1 { font-size: 21px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; font-size: 14px; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); }

.filters {
  max-width: 1400px; margin: 0 auto; padding: 4px 20px 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
#search, #place {
  width: 100%; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
}
#search { flex: 1 1 200px; max-width: 280px; }
.placebox { flex: 1 1 260px; max-width: 360px; }
.active { display: flex; flex-wrap: wrap; gap: 6px; }
.active:empty { display: none; }
.tag-on {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px;
  padding: 5px 10px; font-size: 13px; background: var(--accent); color: var(--accent-ink);
}
.cats { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.cat {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 10px 4px 8px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.cat .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.cat[aria-pressed="false"] { opacity: .45; }

main { max-width: 1400px; margin: 0 auto; padding: 0 20px 20px; }
.view { display: none; }
.view.on { display: block; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 2px 0 12px; }
.bar h2 { font-size: 19px; margin: 0 4px; }
.round, .pill {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; height: 36px;
}
.round { width: 36px; font-size: 20px; line-height: 1; }
.pill { padding: 0 14px; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); margin-left: auto; }
.seg button { border: 0; background: none; padding: 7px 12px; font-size: 13px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- Mes ---------- */
.hint { color: var(--muted); font-size: 12px; margin: 8px 2px 0; }
.calendar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays span {
  padding: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); border-bottom: 1px solid var(--line); text-align: center;
}
.cell {
  min-height: 116px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 6px; text-align: left; background: none;
  display: flex; flex-direction: column; gap: 3px; overflow: hidden;
}
.cell:nth-child(7n) { border-right: 0; }
.cell.out { background: color-mix(in srgb, var(--bg) 60%, transparent); color: var(--muted); }
.cell.today { background: var(--today); }
.cell.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.num { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 2px; }
.cell.today .num b { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; }
.badge { font-size: 11px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.chip {
  font-size: 12px; line-height: 1.3; padding: 2px 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--c) 14%, transparent); border-left: 3px solid var(--c);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip time { font-variant-numeric: tabular-nums; opacity: .75; margin-right: 3px; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.dots { display: none; gap: 3px; flex-wrap: wrap; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }

h4.sec { margin: 14px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ev {
  display: grid; grid-template-columns: 50px minmax(0, 1fr); gap: 10px; width: 100%;
  text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 9px 0;
}
.ev .t { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--c); font-size: 14px; }
.ev .ttl { font-weight: 600; display: block; }
.ev .meta { color: var(--muted); font-size: 13px; display: block; }
.ev .tag { display: inline-block; font-size: 11px; color: var(--c); margin-top: 2px; }
.fest { display: inline-block; font-size: 11px; margin: 2px 0 0 6px; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; }

/* ---------- Día (estilo Google Calendar) ---------- */
.allday { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.allday details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.allday summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; }
.allday .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.allday .chip { cursor: pointer; border: 0; text-align: left; max-width: 100%; font-size: 13px; padding: 4px 8px; }
.timeline {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: auto; max-height: calc(100vh - 220px); -webkit-overflow-scrolling: touch;
}
.tl { display: grid; grid-template-columns: 52px var(--cols, minmax(0, 1fr)); min-width: 100%; }
.tl-head {
  position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; padding: 8px 6px; text-align: center; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; border-left: 1px solid var(--line);
}
.tl-head.corner { position: sticky; left: 0; z-index: 4; border-left: 0; }
.tl-hours { position: sticky; left: 0; z-index: 2; background: var(--surface); }
.tl-hours div {
  height: var(--hour); font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px;
  transform: translateY(-7px); font-variant-numeric: tabular-nums;
}
.tl-col {
  position: relative; border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--hour));
}
.blk {
  position: absolute; border: 0; text-align: left; border-radius: 6px; padding: 3px 6px; overflow: hidden;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); border-left: 3px solid var(--c);
  font-size: 12px; line-height: 1.25; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.blk b { display: block; font-size: 12.5px; }
.blk small { color: var(--muted); display: block; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: #e53935; z-index: 1; }
.now-line::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: #e53935; }

/* ---------- Mapa ---------- */
.maplayout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
.map { height: calc(100vh - 230px); min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.maplist {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; max-height: calc(100vh - 230px); overflow: auto;
}
.maplist h3 { margin: 4px 0; font-size: 15px; }
.radius { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
#view-map .radius:first-of-type { margin-left: auto; }
.radius select { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 4px; }
.pin {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--c); color: #fff; font: 600 12px/1 system-ui, sans-serif;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.leaflet-popup-content { margin: 10px 12px; font: 13px/1.4 system-ui, sans-serif; }
.pop h4 { margin: 0 0 4px; font-size: 14px; }
.pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 3px 0; color: inherit; }
.pop button b { font-variant-numeric: tabular-nums; margin-right: 4px; }

.status { max-width: 1400px; margin: 0 auto; padding: 0 20px 24px; color: var(--muted); font-size: 12px; }

/* ---------- Detalle ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog article { position: relative; }
dialog .close {
  position: absolute; right: 10px; top: 10px; z-index: 1000; border: 0; width: 34px; height: 34px;
  border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 20px;
}
.d-img { width: 100%; max-height: 240px; object-fit: cover; display: block; }
.d-body { padding: 16px 20px 20px; }
.d-body h3 { margin: 0 0 6px; font-size: 20px; padding-right: 30px; }
.d-cat { color: var(--c); font-size: 13px; font-weight: 600; }
.d-fest { display: inline-block; margin: 6px 0 0; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.d-meta { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 4px; font-size: 14px; }
.d-desc { font-size: 14px; }
.d-map { height: 180px; border-radius: 10px; margin: 10px 0; border: 1px solid var(--line); }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.d-actions a, .d-actions button {
  text-decoration: none; padding: 8px 14px; border-radius: 999px; font-size: 14px;
  border: 1px solid var(--line); color: var(--ink); background: none;
}
.d-actions .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.d-prog h4 { margin: 14px 0 2px; font-size: 13px; color: var(--muted); }
.d-src { color: var(--muted); font-size: 12px; margin-top: 12px; }

.bottom { display: none; }

@media (max-width: 960px) {
  .maplayout { grid-template-columns: minmax(0, 1fr); }
  .maplist { max-height: none; }
  .map { height: 58vh; }
}
@media (max-width: 640px) {
  .top, .filters, main, .status { padding-left: 16px; padding-right: 16px; }
  .top { padding-top: 10px; }
  .tabs { display: none; }
  #search, .placebox { max-width: none; flex-basis: 100%; }
  .cats { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; width: calc(100% + 32px); scrollbar-width: none; }
  .cat { flex: none; }
  .cell { min-height: 58px; padding: 4px; }
  .chip, .more, .badge .wide { display: none; }
  .cell .chip { display: none; }
  .dots { display: flex; }
  .weekdays span { padding: 6px 0; font-size: 11px; }
  .num { flex-wrap: wrap; }
  .seg { margin-left: 0; }
  .radius { margin-left: 0; }
  .timeline { max-height: calc(100vh - 250px); }
  .status { padding-bottom: calc(80px + var(--safe-b)); }
  .bottom {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b));
  }
  .bottom button { flex: 1; border: 0; background: none; font-size: 11px; display: grid; justify-items: center; gap: 1px; color: var(--muted); padding: 4px 0; }
  .bottom button span { font-size: 20px; line-height: 1.1; }
  .bottom button.on { color: var(--accent); font-weight: 600; }
  dialog { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  dialog .d-body { padding-bottom: calc(20px + var(--safe-b)); }
}
