:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --text: var(--tg-theme-text-color, #17212b);
  --hint: var(--tg-theme-hint-color, #6d7f8f);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 28%, transparent);
  --urgent: #d9480f;
  --tabs-h: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #8b9aa8);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --accent: var(--tg-theme-button-color, #5288c1);
    --urgent: #ff8a50;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

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

button { cursor: pointer; }

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--hint);
}

main {
  padding: 8px 8px calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.hint { color: var(--hint); font-size: 13px; }

.filters {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.filters summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.filters summary::-webkit-details-marker { display: none; }

.filters summary .hint {
  font-weight: 400;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 2px 16px 14px;
  max-width: 720px;
  margin: 0 auto;
}

.filter-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--hint);
  min-width: 0;
}

.filter-grid label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

select, input[type="search"], input[type="time"] {
  width: 100%;
  min-height: 38px;
  padding: 6px 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

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

.card {
  background: var(--bg);
  border-radius: 12px;
  overflow: hidden;
}

.card.is-seen { opacity: .62; }

.card img.photo {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  background: var(--bg2);
}

.card-body { padding: 11px 13px 12px; }

.card h2 { margin: 0; font-size: 17px; line-height: 1.25; }

.latin { font-style: italic; color: var(--hint); font-size: 13px; overflow-wrap: anywhere; }

.badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 7px 0; }

.badge {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg2);
  color: var(--hint);
  font-size: 12px;
}

.badge.urgent { color: var(--urgent); font-weight: 600; }

.meta { margin: 0; display: grid; gap: 2px; font-size: 14px; }

.meta div { overflow-wrap: anywhere; }

.meta span { color: var(--hint); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.actions button, .ghost {
  min-height: 36px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--link);
  font-size: 13px;
}

.actions button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.wide { width: 100%; margin-top: 8px; background: var(--bg); }

.empty { padding: 32px 16px; text-align: center; color: var(--hint); }

#map {
  height: calc(100vh - var(--tabs-h) - 92px - env(safe-area-inset-bottom));
  min-height: 300px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

.map-note { margin: 6px 4px 0; }

.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.35; }

.leaflet-popup-content b { font-size: 14px; }

.popup-link {
  display: inline-block;
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: #2481cc;
}

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

.panel { background: var(--bg); border-radius: 12px; padding: 13px; }

.panel h2 { margin: 0 0 3px; font-size: 16px; }

.panel > p { margin: 0 0 10px; }

.times { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

.time-row { display: flex; gap: 4px; align-items: center; }

.time-row input { width: 136px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  min-height: 32px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: transparent;
  font-size: 13px;
  text-align: left;
  overflow-wrap: anywhere;
}

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.chip .remove { color: var(--hint); font-size: 16px; line-height: 1; }

.group-title { margin: 11px 0 5px; font-size: 13px; color: var(--hint); }

.search { margin-bottom: 8px; }

.results { display: flex; flex-direction: column; margin-bottom: 8px; }

.results button {
  display: block;
  width: 100%;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
}

.count { color: var(--hint); font-weight: 400; font-size: 13px; }

.tabs {
  position: fixed;
  z-index: 1001;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.tabs button {
  border: 0;
  background: none;
  color: var(--hint);
  font-size: 14px;
  font-weight: 500;
}

.tabs button.active { color: var(--link); font-weight: 700; }

.toast {
  position: fixed;
  z-index: 1002;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 10px;
  background: #1f2933;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 25%);
}

.toast button {
  flex: none;
  border: 0;
  background: none;
  color: #7cc4ff;
  font-weight: 600;
}

button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

@media (max-width: 360px) {
  .filter-grid { grid-template-columns: minmax(0, 1fr); }
}
