:root {
  --bg: #f3f5f7;
  --text: #172026;
  --hint: #5c6b73;
  --link: #1d6f8a;
  --button: #1f6f86;
  --button-text: #ffffff;
  --card: #ffffff;
  --section: #ffffff;
  --subtitle: #314047;
  --danger: #b42318;
  --accent: #1d6f8a;
  --line: rgba(23, 32, 38, 0.12);
  --ok: #1d7a45;
  --wait: #8a5a00;
  --shadow: 0 1px 2px rgba(23, 32, 38, 0.05);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #121416;
  --text: #f3f6f8;
  --hint: #a8b2b8;
  --link: #8ecae6;
  --button: #8ecae6;
  --button-text: #102026;
  --card: #1c2024;
  --section: #1c2024;
  --subtitle: #d5dee4;
  --danger: #ffb4ab;
  --accent: #8ecae6;
  --line: rgba(243, 246, 248, 0.14);
  --ok: #8ed7ad;
  --wait: #e6c36a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: manipulation;
}
#frame { min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--button); outline-offset: 2px; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.45rem; line-height: 1.2; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; }

header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--bg);
}
header h1 { font-size: 1.05rem; flex: 1; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
}
main { padding: 4px 16px calc(84px + env(safe-area-inset-bottom)); }
body.no-tabs main { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.resort { color: var(--subtitle); margin-top: 4px; }
.dates { color: var(--hint); margin-top: 2px; }
.departure {
  margin: 16px 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--hint);
  font-size: 0.82rem;
}
.pill.ok { color: var(--ok); }
.pill.wait { color: var(--wait); }
.pill.bad { color: var(--danger); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.stat {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
  min-height: 76px;
}
.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--hint); font-size: 0.78rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  margin: 10px 0;
  box-shadow: var(--shadow);
}
.card h2 { margin-bottom: 6px; }
.muted { color: var(--hint); }
.small { font-size: 0.84rem; }
.banner {
  border-radius: 14px;
  padding: 12px;
  margin: 12px 0;
  background: var(--card);
  border: 1px solid var(--line);
}
.banner strong { display: block; margin-bottom: 8px; }
.row-actions, .seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button, .chips button {
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 6px 12px;
  white-space: nowrap;
}
.seg button[aria-pressed="true"], .chips button[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
  border-color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 0;
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--link); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.55; }
.stack { display: grid; gap: 8px; margin: 12px 0; }

.item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 10px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.item:first-of-type { border-top: 0; }
.check {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  display: grid;
  place-items: center;
}
.check[aria-pressed="true"],
.check[aria-checked="true"] { background: var(--button); color: var(--button-text); border-color: transparent; }
.check[aria-checked="mixed"] {
  background: linear-gradient(90deg, var(--button) 50%, transparent 50%);
  border-color: var(--button);
}
.item.has-marks { align-items: start; }
.item.has-marks .check { margin-top: 4px; }
.item-body { grid-column: 2; min-width: 0; }
.mark-list { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; }
.mark-list li { font-size: 0.82rem; color: var(--hint); overflow-wrap: anywhere; }
.mark-list li.on { color: var(--text); }
.mark-list li.on::before { content: "✓ "; color: var(--ok); }
.item-main {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 4px 0;
  min-height: 44px;
}
.item-main.done { color: var(--hint); text-decoration: line-through; }
.remind-list { margin-top: 8px; }
.remind-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.remind-row strong { font-weight: 600; display: block; }
.saved-open {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  min-height: 0;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.item-tools { grid-column: 2; display: flex; gap: 8px; align-items: center; }
.item > .linkish { grid-column: 2; justify-self: start; }
select, input, textarea {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 10px 12px;
}
textarea { min-height: 88px; resize: vertical; }
label { display: grid; gap: 6px; font-size: 0.86rem; color: var(--hint); }
label.tick {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  color: var(--text);
  line-height: 1.35;
}
label.tick input {
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  margin: 1px 0 0;
  padding: 0;
  flex: none;
}
.option-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.linkish {
  border: 0;
  background: transparent;
  color: var(--danger);
  min-height: 36px;
  padding: 0;
}

.person, .feed-item, .poll-card {
  width: 100%;
  text-align: left;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  padding: 12px 0;
  display: block;
}
.person { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.feed-item.cancelled { opacity: 0.62; }
.feed-item .num.cancelled { text-decoration: line-through; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.mine-money { margin: 0 0 12px; font-weight: 700; }
.row-actions + .chips { margin-top: 14px; }
.chips button { flex: 0 0 auto; }

.money-block + .money-block { margin-top: 12px; }
.balance-line { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; }
.settle-line { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.plus { color: var(--ok); }
.minus { color: var(--danger); }

.empty { padding: 28px 8px; text-align: center; color: var(--hint); }
.empty p + p { margin-top: 6px; }

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar a, #tabbar button {
  min-height: 56px;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.01em;
  text-decoration: none;
  padding: 6px 2px;
  white-space: nowrap;
}
#tabbar [aria-current="page"] { color: var(--link); font-weight: 800; }
body.no-tabs #tabbar { display: none; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 6;
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
}
.sheet { position: fixed; inset: 0; z-index: 7; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); border: 0; width: 100%; }
.sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--section);
  color: var(--text);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet-card p { margin-bottom: 14px; }

.devbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 0 8px;
  color: var(--hint);
  font-size: 12px;
  align-items: center;
}
.devbar button {
  border: 1px dashed var(--line);
  background: transparent;
  border-radius: 999px;
  min-height: 32px;
  padding: 2px 8px;
  color: var(--hint);
}

.check-list .check svg { width: 18px; height: 18px; }

@media (min-width: 840px) {
  body { background: #d7dee6; }
  html[data-theme="dark"] body { background: #070809; }
  #frame {
    width: 440px;
    margin: 0 auto;
    min-height: 100vh;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
  }
  #tabbar, .sheet-card, .toast {
    width: 440px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

.weather-levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 8px; }
.weather-level { display: grid; gap: 2px; }
.weather-temp { font-size: 1.6rem; line-height: 1.1; }
.tiny { font-size: 0.72rem; margin-top: 4px; }
.snow { color: var(--link); font-weight: 600; }

/* Карта: экран без прокрутки, MapLibre занимает всё между шапкой и табами. */
body.map-screen main { display: none; }
body.map-screen #frame { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; }
#map-view { position: relative; flex: 1; min-height: 0; margin-bottom: calc(57px + env(safe-area-inset-bottom)); background: #eef1ec; }
#map-view[hidden] { display: none; }
#map-canvas { position: absolute; inset: 0; }
.map-note {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: calc(100% - 70px);
  z-index: 2;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.map-note p + p, .map-note p + .chips { margin-top: 6px; }
.map-people { padding-bottom: 0; }
.person-pin {
  width: 30px;
  height: 30px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.person-pin.me { outline: 3px solid #1d6f8a; }
.person-pin.stale { opacity: 0.55; filter: grayscale(0.6); }
.maplibregl-popup-content { color: #172026; font: 14px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; }

.map-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.map-note .small-btn { min-height: 34px; margin-top: 0; padding: 4px 12px; font-size: 0.85rem; }
.stat-day { margin: 12px 0 0; }
.stat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card .stats { margin: 8px 0 0; }
.card .stat { min-height: 0; box-shadow: none; }

.basemap-toggle { display: grid; place-items: center; color: #9aa3a9; }
.basemap-toggle[aria-pressed="true"] { color: #1d6f8a; }
