:root {
  color-scheme: dark;
  --bg: #05070b;
  --surface: rgba(14, 18, 28, 0.92);
  --surface-strong: #0d1320;
  --line: rgba(122, 146, 199, 0.16);
  --ink: #f3f7ff;
  --muted: #8d9ab5;
  --accent: #2583ff;
  --accent-deep: #1567d6;
  --accent-soft: rgba(37, 131, 255, 0.18);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
  --button-active-bg: #f3f7ff;
  --button-active-ink: #0a0f18;
  --message-bg: #0b1018;
  --message-border: rgba(104, 131, 184, 0.14);
  --message-traffic-bg: #0d1727;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #000;

}

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

button {
  border: 0;
}

.app-shell {
  max-width: 880px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 10px 10px calc(18px + env(safe-area-inset-bottom));
  display: block;
  overflow: hidden;
}

.top-fixed-shell {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 20px);
  max-width: 880px;
  z-index: 20;
}

.topbar,
.message-card,
.map-card,
.settings-sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: 22px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1,
h2 {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: -0.03em;
}

h1 {
  font-size: 1.02rem;
  line-height: 1.1;
}

.topbar-copy {
  min-width: 0;
}

.topbar-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.avatar-button,
.icon-button,
.send-button,
.mode-button {
  border-radius: 999px;
  cursor: pointer;
  transition: 150ms ease;
}

.avatar-button,
.icon-button,
.mode-button {
  background: rgba(22, 28, 42, 0.86);
  border: 1px solid var(--line);
  padding: 10px 12px;
  color: var(--ink);
}

.avatar-button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.icon-button.is-active,
.mode-button.active {
  background: var(--button-active-bg);
  color: var(--button-active-ink);
}

.send-button {
  width: 46px;
  height: 46px;
  background: linear-gradient(180deg, #2d91ff 0%, #1567d6 100%);
  color: #fff;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-button:active {
  transform: scale(0.97);
}

.status-strip {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 0 4px;
  padding-top: 8px;
  padding-bottom: 8px;
  min-width: 0;
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
  padding: 0 4px;
}

.view-tab,
.filter-button,
.secondary-action {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15, 22, 34, 0.92);
  color: var(--muted);
  padding: 10px 12px;
  cursor: pointer;
}

.view-tab.is-active,
.filter-button.is-active {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}

.status-note,
.feed-summary,
.map-fallback p {
  color: var(--muted);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(20, 29, 44, 0.92);
  border: 1px solid var(--line);
  font-size: 0.78rem;
}

.status-link,
.status-chip {
  cursor: pointer;
}

.status-link {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--ink);
  font-weight: 700;
  flex-shrink: 0;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-note {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content-stack {
  margin-top: 180px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: calc(100dvh - 190px);
  overflow: hidden;
}

.desktop-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: calc(100dvh - 80px);
  overflow: hidden;
}

.view-panel {
  display: none;
}

.view-panel.is-active {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  overflow: hidden;
}

.map-view.is-active,
.flow-view.is-active {
  grid-template-rows: minmax(0, 1fr);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(10, 15, 24, 0.92);
  color: var(--ink);
  padding: 14px 16px;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  box-shadow: none;
  -webkit-appearance: none;
}

textarea::placeholder,
input::placeholder {
  color: #7080a0;
}

textarea {
  resize: none;
  min-height: 46px;
  max-height: 130px;
}

.feed-head,
.slider-head,
.map-head,
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.feed-head {
  margin: 0;
  padding: 0 6px 8px;
  flex-shrink: 0;
}

.feed {
  display: grid;
  gap: 10px;
  min-height: 0;
}

.message-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  padding: 6px 2px;
  background: transparent;
  border: 0;
  box-shadow: none;
  line-height: 1.42;
  min-width: 0;
}

.message-card.is-traffic .message-meta-line {
  color: #8bc0ff;
}

.message-card.is-event .message-avatar {
  background: #ff9e0b !important;
}

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 900;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.message-content {
  min-width: 0;
}

.message-line {
  display: inline;
}

.message-meta-line,
.status-note,
.feed-summary {
  font-size: 0.82rem;
}

.message-meta-line {
  color: var(--muted);
  white-space: normal;
}

.message-status:not(:empty)::after,
.message-location::after,
.message-distance::after {
  content: "·";
  margin-left: 6px;
  margin-right: 2px;
}

.message-author {
  color: var(--author-color, #58a6ff);
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
}

.message-author::after {
  content: ":";
  color: var(--muted);
  margin-right: 3px;
}

.message-body {
  font-size: 0.96rem;
  color: #edf3ff;
  overflow-wrap: anywhere;
}

.map-filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.map-pulse-marker {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(37, 131, 255, 0.55);
  animation: pulseMarker 1.6s infinite;
}

@keyframes pulseMarker {
  70% {
    box-shadow: 0 0 0 16px rgba(37, 131, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(37, 131, 255, 0);
  }
}

.flow-view {
  padding-bottom: 12px;
}

.flow-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 6px 10px;
}

.flow-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 6px 4px 118px;
}

.flow-card {
  border: 1px solid rgba(37, 131, 255, 0.28);
  border-radius: 16px;
  background: rgba(8, 14, 24, 0.94);
  padding: 12px;
  animation: flowIn 180ms ease-out;
}

.flow-card.is-event {
  border-color: rgba(255, 158, 11, 0.5);
}

.flow-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.flow-card p {
  margin: 8px 0;
}

.flow-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

@keyframes flowIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.map-view {
  padding-bottom: 0;
  min-height: 0;
  height: 100%;
}

.map-card {
  border-radius: 12px;
  padding: 8px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.yandex-map,
.map-fallback {
  border-radius: 10px;
  min-height: 0;
  height: 100%;
  margin-top: 8px;
}

.yandex-map {
  overflow: hidden;
  background: #0a101b;
}

.map-fallback {
  display: none;
  padding: 18px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.56);
}

.map-fallback.is-visible {
  display: block;
}

.empty-state {
  padding: 18px;
  border-radius: 20px;
  border: 1px dashed var(--line);
  color: var(--muted);
  background: rgba(15, 21, 34, 0.72);
}

.settings-panel {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.settings-panel.is-open {
  pointer-events: auto;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 12, 0.3);
  opacity: 0;
  transition: 180ms ease;
}

.settings-sheet {
  position: absolute;
  inset: auto 0 0 0;
  border-radius: 28px 28px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(102%);
  transition: 220ms ease;
}

.settings-panel.is-open .settings-backdrop {
  opacity: 1;
}

.settings-panel.is-open .settings-sheet {
  transform: translateY(0);
}

.settings-group {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.setting-block {
  display: none;
}

.setting-block.active {
  display: grid;
  gap: 10px;
}

.setting-block[data-setting="radius"] {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  font-size: 0.9rem;
  font-weight: 700;
}

.setting-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}


.chat-feed {
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 8px 4px calc(92px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
  align-content: start;
  overscroll-behavior: contain;
}

.composer-docked {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(9px + env(safe-area-inset-bottom));
  width: calc(100% - 0px);
  max-width: 860px;
  margin-top: 0;
  padding: 7px;
  border-radius: 6px;
  background: rgba(8, 12, 19, 0.98);
  box-shadow: 0 -16px 44px rgba(0, 0, 0, 0.34);
  z-index: 15;
}

.composer-docked textarea {
  border-radius: 14px;
  min-height: 40px;
  padding-top: 9px;
  padding-bottom: 9px;
  line-height: 1.25;
}

.composer-docked textarea::placeholder {
  line-height: 1.25;
}

.overlay-panel {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 50;
}

.overlay-panel.is-open {
  display: block;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 14, 10, 0.42);
}

.overlay-card {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% - 20px);
  max-width: 520px;
  border-radius: 26px;
  padding: 18px;
  background: #0b1220;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.overlay-card-wide {
  max-width: 620px;
  max-height: min(72vh, 680px);
  overflow: auto;
}

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.overlay-text {
  color: var(--muted);
  line-height: 1.5;
}

.map-event-button {
  width: auto;
  white-space: nowrap;
  color: var(--ink);
  padding: 8px 12px;
}

.overlay-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.primary-action {
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  padding: 14px 16px;
  font-weight: 800;
  cursor: pointer;
}

.secondary-action {
  width: 100%;
}

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

.toggle-row small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 2px;
}

.toggle-row input {
  width: 46px;
  height: 26px;
  accent-color: var(--accent);
}

.toggle-row input:disabled {
  opacity: 0.95;
}

.district-progress {
  display: grid;
  gap: 8px;
}

.district-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.district-progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.district-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.district-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.district-option {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(10, 15, 24, 0.92);
  color: var(--ink);
  cursor: pointer;
}

.district-option small {
  color: var(--muted);
}

.district-option.is-active {
  border-color: var(--accent);
}


.online-list,
.quick-radius-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.online-item,
.quick-radius-button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(17, 24, 38, 0.9);
  padding: 12px 14px;
}

.quick-radius-button {
  color: var(--ink);
}

.online-item strong,
.online-item span {
  display: block;
}

.online-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.quick-radius-button.is-active {
  background: var(--button-active-bg);
  color: var(--button-active-ink);
}

.event-type-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 900px) {
  .app-shell {
    padding: 24px;
    max-width: 1320px;
  }

  .top-fixed-shell {
    top: 24px;
    max-width: 1320px;
    width: calc(100% - 48px);
  }

  .desktop-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 16px;
    align-items: stretch;
  }

  .topbar {
    padding: 18px 20px;
  }

  .status-strip {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .content-stack {
    display: grid;
    grid-template-columns: minmax(0, 430px) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
    margin-top: 196px;
    height: calc(100dvh - 196px);
  }

  #chatView {
    position: relative;
  }

  #chatView,
  #mapView {
    display: grid;
  }

  .topbar-actions #mapToggleButton {
    display: none;
  }

  .settings-panel {
    position: static;
    pointer-events: auto;
    margin-top: 196px;
  }

  .settings-backdrop {
    display: none;
  }

  .settings-sheet {
    position: sticky;
    top: 24px;
    transform: none;
    border-radius: 24px;
    inset: auto;
  }

  .yandex-map,
  .map-fallback {
    min-height: 0;
    height: 100%;
  }

  .chat-feed {
    padding-bottom: 92px;
  }

  .composer-docked {
    position: absolute;
    left: 0;
    right: 0;
    transform: none;
    bottom: 0;
    width: 100%;
    max-width: none;
  }
}
