/* Telegram supplies --tg-theme-*; the fallbacks only show before it loads. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fff));
  --text: var(--tg-theme-text-color, #101114);
  --accent: var(--tg-theme-button-color, #2481cc);
  --on-accent: var(--tg-theme-button-text-color, #fff);
  --link: var(--tg-theme-link-color, var(--accent));
  --bar: var(--tg-theme-bottom-bar-bg-color, var(--surface));

  /* Theme hint colours are often below 3:1, too faint for "не указано". */
  --muted: #666d78;
  --line: rgba(60, 60, 67, .13);
  --fill: rgba(118, 118, 128, .11);
  --yes: #137a3b;
  --yes-bg: rgba(28, 166, 82, .13);
  --no: #c22f2f;
  --no-bg: rgba(224, 60, 60, .12);
  --maybe: #8f5a00;
  --maybe-bg: rgba(240, 160, 20, .17);
  --shadow: 0 3px 14px rgba(0, 0, 0, .16);

  --safe-top: calc(max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: calc(max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));

  color-scheme: light;
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}

:root[data-scheme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #101114);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1d21));
  --text: var(--tg-theme-text-color, #f4f4f6);
  --muted: #9ea5af;
  --line: rgba(255, 255, 255, .1);
  --fill: rgba(140, 145, 155, .16);
  --yes: #5cd88c;
  --yes-bg: rgba(52, 199, 110, .17);
  --no: #ff8078;
  --no-bg: rgba(255, 90, 80, .17);
  --maybe: #f2bb5c;
  --maybe-bg: rgba(242, 170, 50, .17);
  --shadow: 0 3px 14px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
}

body { -webkit-tap-highlight-color: transparent; }

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

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

button:focus-visible,
[tabindex="0"]:focus-visible,
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

[tabindex="-1"]:focus { outline: none; }

h1, h2, h3, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }

.icon {
  flex: none;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.solid { fill: currentColor; stroke: none; }
.muted { color: var(--muted); }

/* Frame */

#app,
#overlays > * {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--tg-viewport-stable-height, 100%);
}

#app {
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

#views { position: relative; flex: 1; min-height: 0; }

/* visibility, not display: each tab keeps its scroll position. */
.view { position: absolute; inset: 0; visibility: hidden; }
.view.active { visibility: visible; }

.scroll {
  height: 100%;
  overflow: hidden auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#tabs {
  display: flex;
  flex: none;
  padding-bottom: var(--safe-bottom);
  background: var(--bar);
  border-top: 1px solid var(--line);
}

#tabs button {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: 7px 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

#tabs button { position: relative; }
#tabs .icon { width: 24px; height: 24px; }

.tab-count {
  position: absolute;
  top: 3px;
  left: calc(50% + 6px);
  min-width: 18px;
  padding: 1px 5px;
  border-radius: 9px;
  background: #f0435c;
  color: #fff;
  font-size: 11px;
  text-align: center;
}
#tabs [aria-current] { color: var(--accent); }

/* Headers and controls */

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 14px) 16px 8px;
}

.view-header h1 { font-size: 27px; font-weight: 750; letter-spacing: -.4px; line-height: 1.15; }
.status { margin-top: 3px; color: var(--muted); font-size: 13px; }
.status.stale { color: var(--maybe); }

.status-warning {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--maybe-bg);
  color: var(--maybe);
  font-size: 12px;
  font-weight: 600;
}

.heading { min-width: 0; }

.toolbar {
  position: sticky;
  top: var(--safe-top);
  z-index: 5;
  padding: 6px 0 8px;
  background: var(--bg);
}

/* Content scrolls under the system bars, so paint the strip behind them. */
.view:not(.map-view)::before {
  content: "";
  position: absolute;
  z-index: 7;
  top: 0;
  left: 0;
  right: 0;
  height: var(--safe-top);
  background: var(--bg);
  pointer-events: none;
}
.toolbar-row { display: flex; gap: 8px; padding: 0 12px; }

.pill {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.pill .icon { width: 18px; height: 18px; color: var(--accent); }

.pill-count {
  min-width: 19px;
  padding: 1px 5px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px;
  text-align: center;
}

.pill.sort { position: relative; flex: 1; min-width: 0; }

.pill.sort select {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
}

.pill.sort option { background: var(--surface); color: var(--text); }

.quick {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px 0;
  scrollbar-width: none;
}

.quick::-webkit-scrollbar { display: none; }

.choice {
  flex: none;
  max-width: 100%;
  min-height: 34px;
  padding: 6px 13px;
  border-radius: 17px;
  background: var(--fill);
  font-size: 14px;
  white-space: nowrap;
}

.choice[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.choice.budget { color: var(--link); font-weight: 600; }

.icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--muted);
}

.icon-button:active { opacity: .6; }
.icon-button.tinted { background: var(--fill); color: var(--text); }
.like.on { color: #f0435c; }
.like.on .icon { fill: currentColor; }
.like.pop .icon { animation: pop .42s cubic-bezier(.2, .8, .3, 1.3); }
.dislike.on { color: var(--no); }

.floating {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 650;
}

.button:active,
.button:disabled { opacity: .75; }
.button.primary { background: var(--accent); color: var(--on-accent); }
.button.secondary { background: var(--fill); color: var(--text); }
.button .icon { width: 18px; height: 18px; }

.more {
  min-height: 36px;
  color: var(--link);
  font-size: 15px;
  font-weight: 600;
}

/* States */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 56px 32px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--fill);
  color: var(--muted);
}

.empty-icon .icon { width: 32px; height: 32px; }
.empty h2 { font-size: 19px; }
.empty p { color: var(--muted); font-size: 15px; }
.empty .button { margin-top: 12px; }
.fatal { display: flex; height: 100%; align-items: center; justify-content: center; }

.bone {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: var(--fill);
}

.bone::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--fill), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.3s infinite;
}

.spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

#toast {
  position: fixed;
  z-index: 100;
  left: calc(var(--safe-left) + 12px);
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 70px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 6px 16px;
  border-radius: 14px;
  background: #2b2d32;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 15px;
  visibility: hidden;
  opacity: 0;
  transition: opacity .18s, visibility .18s;
}

#toast.show { visibility: visible; opacity: 1; }
#toast > span { min-width: 0; overflow-wrap: anywhere; }
.toast-action {
  flex: none;
  min-height: 40px;
  padding: 0 4px;
  color: #78b7ff;
  font-weight: 650;
  white-space: nowrap;
}

/* Above the compare bar, which has to stay tappable. */
body:has(.view.active.comparing) #toast { bottom: calc(var(--safe-bottom) + 132px); }

/* Overlays */

#overlays > * { z-index: 20; }

.detail {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: slide-in .2s ease-out;
}

.detail.leaving { animation: slide-out .18s ease-in forwards; }

.sheet-layer { display: flex; flex-direction: column; justify-content: flex-end; }

.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  animation: fade-in .2s;
}

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - var(--safe-top) - 24px);
  overflow: hidden;
  border-radius: 20px 20px 0 0;
  background: var(--bg);
  animation: sheet-in .22s ease-out;
}

.leaving .sheet { animation: sheet-out .18s ease-in forwards; }
.leaving .backdrop { animation: fade-out .18s forwards; }
.gallery.leaving,
.full-map.leaving { animation: fade-out .15s forwards; }

@keyframes pop { 35% { transform: scale(1.45); } 70% { transform: scale(.9); } }

@keyframes burst {
  0% { transform: scale(.3); opacity: 0; }
  25% { transform: scale(1.15); opacity: 1; }
  45% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.1); opacity: 0; }
}

@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes spin { to { transform: rotate(1turn); } }
@keyframes slide-in { from { transform: translateX(30%); opacity: .2; } }
@keyframes slide-out { to { transform: translateX(30%); opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

@media (min-width: 640px) {
  #app,
  #overlays > .detail,
  .sheet { width: 100%; max-width: 560px; margin: 0 auto; }
}
