:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --text: #2b2420;
  --muted: #7a6f66;
  --line: #e8e1d8;
  --accent: #7a2e2e;
  --accent-soft: #f4e8e4;
  --gold: #b8892e;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --panel: #252120;
    --text: #efe9e3;
    --muted: #a59c93;
    --line: #3a3431;
    --accent: #d9897a;
    --accent-soft: #3b2925;
    --gold: #d8ad55;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100dvh;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto; /* na nízkych obrazovkách sa posúva celý panel */
}

#map { height: 100%; }

.brand { padding: 14px 16px 0; }
.brand h1 { margin: 0; font-size: 20px; color: var(--accent); }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline > span { text-transform: none; letter-spacing: 0; font-size: 13px; }

select, input[type="time"], input[type="search"] {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.time-range { display: flex; align-items: center; gap: 8px; }
.time-range input { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 13px;
  cursor: pointer;
}
.chips button:hover, .chips button.active { background: var(--accent-soft); border-color: var(--accent); }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; background: var(--bg); }
.segmented button {
  flex: 1;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .segmented button[aria-pressed="true"] { color: #1c1917; } }

.liturgy { margin: -4px 0 0; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.liturgy span:first-child { color: var(--text); }
.liturgy .fallback-note { flex-basis: 100%; font-size: 12px; color: var(--accent); }
.tag.feast { background: var(--gold); color: #fff; }
.tag.rite { text-transform: none; letter-spacing: 0; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pair select { min-width: 0; width: 100%; }
select:disabled { opacity: .5; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }

button.primary {
  padding: 7px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.primary:disabled { opacity: .6; cursor: wait; }
@media (prefers-color-scheme: dark) { button.primary { color: #1c1917; } }

.summary-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px 4px; }
.summary { margin: 0; font-size: 13px; color: var(--muted); }
.summary-row select { padding: 3px 6px; font-size: 13px; }

.search-row { display: flex; gap: 8px; }
.search-box { position: relative; flex: 1; min-width: 0; }
.search-box input { width: 100%; }
.suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1100;
  margin: 0; padding: 4px; list-style: none; max-height: 340px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.suggest li { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: var(--accent-soft); }
.suggest .icon { flex: none; width: 1.3em; text-align: center; }
.suggest small { display: block; color: var(--muted); font-size: 12px; }
.search-row button { padding: 0 12px; font-size: 18px; }

.day-row { display: flex; flex-direction: column; gap: 8px; }

details.more > summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--accent); }
details.more > summary span { font-weight: 400; }
.more-body { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }

.results {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  flex: 1 0 auto;
  min-height: 260px; /* zoznam má vždy aspoň takéto miesto, inak sa posúva panel */
  height: 0;
}

.results li {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 4px 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  border-radius: 8px;
}
.results li:hover, .results li.active { background: var(--accent-soft); }
.results .time { font-weight: 700; font-size: 17px; color: var(--accent); font-variant-numeric: tabular-nums; }
.results .name { font-weight: 600; }
.results .time small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.results .name small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.results .dist { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.results .meta { grid-column: 2 / 4; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.results .empty { display: block; color: var(--muted); cursor: default; text-align: center; padding: 24px 8px; }
.results .empty:hover { background: none; }

.tag {
  display: inline-block;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}
.tag.extra { background: var(--gold); color: #fff; }
.tag.changed { background: #e3f0ff; color: #1d4f91; }
@media (prefers-color-scheme: dark) { .tag.changed { background: #1d2c40; color: #9cc3ff; } }
a.tag { text-decoration: none; }
a.tag:hover { text-decoration: underline; }
.tag.place { background: #e7f5ea; color: #1e6b33; font-weight: 600; }
@media (prefers-color-scheme: dark) { .tag.place { background: #1f3326; color: #8fd6a2; } }
.tag.time-unsure { background: #eef2f6; color: #3b4a5a; }
@media (prefers-color-scheme: dark) { .tag.time-unsure { background: #2a323b; color: #c6d2de; } }
.tag.open-end { background: #fff4e0; color: #7a4b00; }
@media (prefers-color-scheme: dark) { .tag.open-end { background: #3a2c14; color: #f2c879; } }
.popup .alt-group { margin: 0 0 8px; padding: 6px 8px; border-left: 3px dashed var(--gold); background: var(--accent-soft); font-size: 13px; }
.tag.unsure { background: #fff3cd; color: #7a5200; border: 1px dashed #b8892e; }
@media (prefers-color-scheme: dark) { .tag.unsure { background: #3d3216; color: #f0c86a; } }

.source { padding: 10px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.source a { color: var(--accent); }

/* Značky na mape */
.pin {
  display: inline-block;
  transform: translate(-50%, -100%);
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
  position: relative;
  font-variant-numeric: tabular-nums;
}
.pin::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -5px;
  margin-left: -5px;
  border: 5px solid transparent;
  border-bottom: 0;
  border-top-color: var(--accent);
}
.pin.unsure { background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 6px, #b06a5e 6px, #b06a5e 12px); }
.pin.dim { background: #9a918a; }
.pin.approx { outline: 2px dashed var(--accent); outline-offset: 2px; }
.approx-note { margin: 6px 0; padding: 6px 8px; border-radius: 6px; background: #fff4e0; color: #7a4b00; font-size: .85em; }
@media (prefers-color-scheme: dark) { .approx-note { background: #3a2c14; color: #f2c879; } }
.manual-note { margin: 4px 0; font-size: .8em; color: var(--muted, #777); }
.pin.dim::after { border-top-color: #9a918a; }
.pin.active { background: var(--gold); z-index: 1000; }
.pin.active::after { border-top-color: var(--gold); }
@media (prefers-color-scheme: dark) { .pin { color: #1c1917; } }

.cluster {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent);
}
@media (prefers-color-scheme: dark) { .cluster { color: #1c1917; } }

.me-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #2a7de1;
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(42,125,225,.25);
}

/* Režim Online: bez mapy, zoznam na celú šírku */
.mode-online .app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.mode-online #map, .mode-online #locate, .mode-online #sort, .mode-online #show-all-wrap { display: none !important; }
.mode-online .panel { border-right: 0; }
.mode-online .panel > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; }
.mode-online .results { min-height: 0; }
.results li[data-online] { grid-template-columns: 56px 1fr auto; }
a.watch {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: #c4302b; color: #fff; font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
a.watch:hover { filter: brightness(1.1); }
.results li.online-detail { display: block; cursor: default; padding: 4px 8px 12px 66px; }
.results li.online-detail:hover { background: none; }
@media (max-width: 760px) {
  .mode-online .app { grid-template-rows: 1fr; }
  .results li.online-detail { padding-left: 8px; }
}

/* Detail kostola (Leaflet popup) podľa témy */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-popup-content a { color: var(--accent); }

.leaflet-popup-content { margin: 12px 14px; font-size: 14px; }
.popup h3 { margin: 0 0 2px; font-size: 15px; }
.popup .addr { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.popup .kind { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.popup ul { margin: 0 0 8px; padding: 0; list-style: none; }
.popup li { padding: 2px 0; }
.popup li.out { color: var(--muted); opacity: .75; }
.popup li b { font-variant-numeric: tabular-nums; }
.popup details { margin: 0 0 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.popup summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.popup details p { margin: 6px 0 0; max-height: 180px; overflow-y: auto; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.popup .none { color: var(--muted); opacity: .85; margin: 0 0 8px; }
.popup .week > .sched-body { max-height: min(240px, 32dvh); overflow-y: auto; }
.popup .sched-tabs { display: flex; gap: 4px; margin: 6px 0 2px; }
.popup .sched-tabs button {
  flex: 1 1 auto; white-space: nowrap; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); font-size: 12px; cursor: pointer;
}
.popup .sched-tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .popup .sched-tabs button[aria-pressed="true"] { color: #1c1917; } }
.popup .week h4 { margin: 10px 0 0; font-size: 13px; }
.popup .week .none { margin: 6px 0 0; font-size: 12px; }
.popup .week table { margin-top: 6px; border-collapse: collapse; font-size: 13px; width: 100%; }
.popup .week th { text-align: left; font-weight: 600; padding: 3px 10px 3px 0; vertical-align: top; white-space: nowrap; }
.popup .week td { padding: 3px 0; border-bottom: 1px solid var(--line); }
.popup .week th { border-bottom: 1px solid var(--line); }
.popup .church-note {
  margin: 0 0 8px; padding: 6px 8px; border-left: 3px solid var(--gold); background: var(--accent-soft);
  font-size: 13px; line-height: 1.4; overflow-wrap: anywhere;
}
.popup li.excluded, .popup .week s { color: var(--muted); }
.popup .excluded-why { font-size: 12px; color: var(--muted); font-style: italic; }
.popup .parish dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 6px 0 0; font-size: 13px; }
.popup .parish dt { color: var(--muted); }
.popup .parish dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.popup .links { display: flex; gap: 12px; }
.popup .links a { color: var(--accent); }

/* Mobil: mapa hore, zoznam dole */

/* odkaz na prenos v poznámke omše */
a.stream {
  display: inline-block; padding: 0 7px; border-radius: 999px;
  background: #c4302b; color: #fff !important; font-size: 12px; text-decoration: none; white-space: nowrap;
}
a.stream:hover { filter: brightness(1.1); }

.nearest-btn {
  padding: 8px 12px; border: 1px solid var(--accent); border-radius: 8px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; cursor: pointer;
}
.nearest-btn:disabled { opacity: .6; cursor: wait; }
.mode-online .nearest-btn, .mode-online .nearest-box { display: none !important; }
.nearest-box { margin: 8px 16px 0; padding: 8px; border: 1px solid var(--accent); border-radius: 10px; background: var(--panel); }
.nearest-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 4px; font-size: 14px; }
.nearest-head .close { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; }
.nearest-row {
  display: grid; grid-template-columns: 56px 1fr; gap: 10px; width: 100%; text-align: left;
  padding: 6px 4px; border: 0; border-top: 1px solid var(--line); background: none; cursor: pointer;
}
.nearest-row:hover { background: var(--accent-soft); }
.nearest-row .time { font-weight: 700; font-size: 16px; color: var(--accent); }
.nearest-row .name { font-weight: 600; }
.nearest-row small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.nearest-box .hint { margin: 6px 4px 0; font-size: 12px; color: var(--muted); }

.feast-alert {
  margin: 8px 16px 0; padding: 8px 10px; border-radius: 8px; font-size: 13px;
  background: var(--accent-soft); border-left: 3px solid var(--gold); color: var(--text);
}
button.link { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; text-align: left; }
.feasts ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.feasts li small { display: block; color: var(--muted); }
.feasts .workday { color: var(--accent); font-weight: 600; }
.feasts li button.link { text-decoration: none; color: var(--text); }
.feasts li button.link:hover b { text-decoration: underline; }

.stale {
  margin: 8px 16px 0; padding: 8px 10px; border-radius: 8px;
  background: var(--accent-soft); color: var(--text); border-left: 3px solid var(--gold); font-size: 13px;
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 45dvh 1fr; }
  #map { grid-row: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); overflow-y: auto; }
  .results { overflow: visible; height: auto; min-height: 0; }
  .leaflet-popup-content { max-height: calc(45dvh - 70px); overflow-y: auto; }
  .popup .week > .sched-body { max-height: none; }
  .brand { padding-top: 12px; }
}
