:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-strong: #ffffff;
  --surface-soft: #f6f6f6;
  --text: var(--tg-theme-text-color, #171717);
  --muted: var(--tg-theme-hint-color, #737373);
  --border: #e5e5e5;
  --accent: var(--tg-theme-button-color, #171717);
  --accent-strong: #171717;
  --accent-text: var(--tg-theme-button-text-color, #fafafa);
  --green: #0f766e;
  --amber: #b7791f;
  --rose: #dc2626;
  --sky: #0369a1;
  --accent-soft: rgba(23, 23, 23, 0.06);
  --green-soft: rgba(15, 118, 110, 0.08);
  --coral-soft: rgba(220, 38, 38, 0.08);
  --sun-soft: rgba(183, 121, 31, 0.09);
  --sky-soft: rgba(3, 105, 161, 0.08);
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
  --soft-shadow: 0 6px 16px rgba(0, 0, 0, 0.04);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-width: 320px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

a {
  color: inherit;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon,
.nav-icon,
.response-icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.nav-icon {
  width: 20px;
  height: 20px;
}

.response-icon {
  width: 16px;
  height: 16px;
}

button .icon,
button .nav-icon {
  pointer-events: none;
}

.app-shell {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom));
}

.topbar,
.status-line,
.main-content,
.bottom-nav {
  width: min(100%, 860px);
  margin-right: auto;
  margin-left: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 900;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 1px 0 0;
  overflow: hidden;
  font-size: 19px;
  line-height: 1.14;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.send-button {
  display: grid;
  min-width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 900;
}

.top-actions .icon-button:first-child {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.status-line {
  min-height: 34px;
  margin-top: 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
  padding: 8px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.main-content {
  position: relative;
  padding: 0 16px;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

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

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

.quick-strip button,
.bottom-nav button,
.ghost-button,
.primary-button,
.place-actions a,
.place-actions button,
.segmented button,
.toggle-grid button,
.message-actions button,
.rating-row button {
  min-height: 42px;
  border-radius: 8px;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.quick-strip button {
  display: flex;
  min-width: max-content;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
  font-weight: 800;
}

.quick-strip button:nth-child(1) .icon {
  color: var(--green);
}

.quick-strip button:nth-child(2) .icon {
  color: var(--rose);
}

.quick-strip button:nth-child(3) .icon {
  color: var(--amber);
}

.quick-strip button:nth-child(4) .icon {
  color: var(--sky);
}

.chat-feed {
  display: flex;
  min-height: calc(100dvh - 244px);
  max-height: calc(100dvh - 244px);
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 2px 1px 12px;
  scroll-behavior: smooth;
}

.message {
  max-width: min(88%, 700px);
  padding: 12px 13px;
  border-radius: 8px;
  line-height: 1.46;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
}

.message.assistant,
.message.system {
  align-self: flex-start;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.message.assistant {
  max-width: min(94%, 720px);
  padding: 9px;
  white-space: normal;
}

.message.user,
.message.system,
.assistant-text {
  white-space: pre-wrap;
}

.message.system {
  max-width: 100%;
  color: var(--muted);
}

.assistant-stack {
  display: grid;
  gap: 8px;
}

.response-card {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}

.response-title {
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.28;
}

.response-index {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

.response-lines {
  display: grid;
  gap: 7px;
  margin-top: 9px;
}

.response-line {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.response-line-address .response-icon {
  color: var(--accent);
}

.response-line-rating .response-icon {
  color: var(--amber);
}

.response-line-time .response-icon,
.response-line-price .response-icon {
  color: var(--sky);
}

.response-line-tip .response-icon {
  color: var(--rose);
}

.response-line-warning .response-icon {
  color: var(--amber);
}

.message-actions,
.rating-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}

.message-actions button,
.rating-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.rating-row button.is-selected {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
}

.composer {
  position: sticky;
  bottom: calc(64px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 12px 0;
  background: var(--bg);
}

.composer textarea,
.feedback-form textarea,
.profile-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.composer textarea {
  min-height: 42px;
  max-height: 118px;
  resize: none;
  padding: 10px 12px;
}

.composer textarea:focus,
.feedback-form textarea:focus,
.profile-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-geo {
  color: var(--muted);
}

.send-button {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 18px;
}

.send-button:disabled,
.primary-button:disabled,
.place-actions button:disabled,
.quick-strip button:disabled {
  opacity: 0.6;
}

.map-band {
  position: relative;
  min-height: 280px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.map-empty {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.map-empty .icon {
  color: var(--muted);
}

.map-band.is-empty .map-empty {
  display: grid;
}

.map-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.45;
}

.pin {
  position: absolute;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 900;
  box-shadow: var(--soft-shadow);
  transform: translate(-50%, -50%);
}

.places-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.place-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.place-card h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.28;
}

.place-card p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.place-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.place-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 11px;
}

.place-actions a,
.place-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.profile-form,
.feedback-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

label,
.field-group {
  display: grid;
  gap: 8px;
}

label span,
.field-group > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.profile-form input,
.feedback-form textarea {
  min-height: 44px;
  padding: 10px 12px;
}

.feedback-form textarea {
  min-height: 174px;
  resize: vertical;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
  gap: 8px;
}

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

.segmented button,
.toggle-grid button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.segmented button.is-selected,
.toggle-grid button.is-selected {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: var(--accent-text);
}

.ghost-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.bottom-nav button {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.1;
}

.bottom-nav button.is-active {
  color: var(--accent);
}

.help-dialog {
  width: min(92vw, 560px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

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

.help-dialog pre {
  overflow: auto;
  margin: 14px 0 0;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 20;
  max-width: 520px;
  margin: 0 auto;
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (hover: hover) {
  button:hover,
  .place-actions a:hover {
    transform: translateY(-1px);
  }

  .quick-strip button:hover,
  .message-actions button:hover,
  .rating-row button:hover,
  .place-actions a:hover,
  .place-actions button:hover,
  .ghost-button:hover,
  .icon-button:hover {
    background: var(--surface-soft);
  }

  .send-button:hover,
  .primary-button:hover,
  .segmented button.is-selected:hover,
  .toggle-grid button.is-selected:hover {
    background: var(--accent);
  }
}

@media (min-width: 760px) {
  .chat-feed {
    min-height: calc(100dvh - 246px);
    max-height: calc(100dvh - 246px);
  }
}

@media (max-width: 430px) {
  .main-content,
  .topbar,
  .status-line {
    padding-right: 12px;
    padding-left: 12px;
  }

  .place-actions {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 18px;
  }

  .profile-form,
  .feedback-form {
    padding: 12px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #09090b);
    --surface: var(--tg-theme-secondary-bg-color, #09090b);
    --surface-strong: #18181b;
    --surface-soft: #18181b;
    --text: var(--tg-theme-text-color, #fafafa);
    --muted: var(--tg-theme-hint-color, #a1a1aa);
    --border: #27272a;
    --accent: var(--tg-theme-button-color, #fafafa);
    --accent-strong: #fafafa;
    --accent-text: var(--tg-theme-button-text-color, #18181b);
    --green: #5eead4;
    --amber: #facc15;
    --rose: #fb7185;
    --sky: #7dd3fc;
    --accent-soft: rgba(250, 250, 250, 0.1);
    --green-soft: rgba(94, 234, 212, 0.1);
    --coral-soft: rgba(251, 113, 133, 0.1);
    --sun-soft: rgba(250, 204, 21, 0.12);
    --sky-soft: rgba(125, 211, 252, 0.1);
    --shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
    --soft-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
  }

  .icon-button,
  .quick-strip button,
  .message.assistant,
  .message.system,
  .profile-form,
  .feedback-form,
  .place-card,
  .composer textarea,
  .feedback-form textarea,
  .profile-form input,
  .segmented button,
  .toggle-grid button,
  .ghost-button,
  .message-actions button,
  .rating-row button,
  .place-actions a,
  .place-actions button {
    background: var(--surface-strong);
  }

  .top-actions .icon-button:first-child {
    background: transparent;
  }

  .bottom-nav {
    background: var(--surface);
  }

  .composer {
    background: var(--bg);
  }

  .map-band {
    background: var(--surface-soft);
  }

  .map-grid {
    opacity: 0.55;
  }
}
