.map-frame {
  --map-gutter: clamp(12px, 3vw, 48px);
  --toolbar-bottom: max(18px, var(--content-safe-bottom));
  display: grid;
  grid-template: ". ." minmax(0, 1fr) "chat chat" auto "legend zoom" auto / minmax(0, 1fr) auto;
  gap: 6px 4px;
  padding-inline: max(var(--map-gutter), env(safe-area-inset-left)) max(var(--map-gutter), env(safe-area-inset-right));
  padding-bottom: var(--toolbar-bottom);
}
.map-frame > #globe { position: absolute; inset: 0; }
.map-legend, .controls { position: static; z-index: 2; align-self: center; }
.map-legend { grid-area: legend; justify-self: start; min-width: 0; border-radius: var(--pill); }
.controls { grid-area: zoom; justify-self: end; }
.station-sheet[open] { z-index: 8; }

.guest-chat {
  grid-area: chat;
  z-index: 3;
  justify-self: start;
  width: clamp(316px, 32vw, 400px);
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}
.chat-launcher, .chat-panel { pointer-events: auto; }
.chat-launcher, .chat-collapse, .chat-send {
  display: inline-flex;
  flex: none;
  justify-content: center;
  align-items: center;
  padding: 0;
  color: var(--ink);
  border: 0;
  border-radius: var(--pill);
}
.chat-launcher {
  min-height: 42px;
  gap: 9px;
  padding: 6px 17px;
  border: 1px solid var(--line);
  background: #ececef;
  box-shadow: 0 3px 14px rgb(0 0 0 / 6%);
  font-size: 14px;
  font-weight: 620;
}
.chat-launcher svg, .chat-collapse svg {
  display: block;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chat-launcher:hover, .chat-collapse:hover { background: var(--line); }
.guest-chat[data-expanded="true"] .chat-launcher,
.guest-chat[data-expanded="false"] .chat-panel { display: none; }
.chat-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(465px, 58dvh, max(110px, calc(100dvh - 205px)));
  min-height: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: white;
  box-shadow: 0 6px 24px rgb(0 0 0 / 9%);
}
.chat-heading {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  padding: 0 0 7px 5px;
  border-bottom: 1px solid var(--line);
}
.chat-heading h2 { min-width: 0; margin: 0; font-size: clamp(14px, 4vw, 16px); font-weight: 650; line-height: 1.25; }
.chat-contacts { display: flex; flex: none; gap: 2px; }
.chat-contacts a {
  display: grid;
  place-items: center;
  width: 32px;
  height: 36px;
  color: var(--ink);
  border-radius: var(--pill);
}
.chat-contacts a:is(:hover, :active, :focus-visible) { background: var(--soft); }
.chat-contacts svg { display: block; width: 19px; height: 19px; }
.chat-collapse { margin-inline-start: auto; width: 36px; height: 36px; background: var(--soft); }
#guest-chat-help-back {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--ink);
  background: var(--soft);
  font: 600 14px/1.35 var(--ui-font);
}
#guest-chat-help-back::before {
  content: "";
  width: 7px;
  height: 7px;
  border: solid currentColor;
  border-width: 0 0 2px 2px;
  transform: rotate(45deg);
}
#guest-chat-help-back[hidden], .guest-chat.is-reading-help :is(.chat-heading h2, .chat-contacts, .chat-log, .chat-status, .chat-form) { display: none; }
#guest-chat-help-frame { flex: 1; display: block; min-height: 0; width: 100%; border: 0; border-radius: 0 0 14px 14px; background: white; }
.chat-log {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 3px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}
.chat-message {
  max-width: min(86%, 64ch);
  min-width: 0;
  flex: none;
  margin: 0;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-message.is-assistant {
  align-self: flex-start;
  border-radius: 0 12px 12px 12px;
  color: var(--ink);
  background: #ececef;
}
.chat-message.is-user {
  align-self: flex-end;
  border-radius: 12px 0 12px 12px;
  color: white;
  background: var(--ink);
}
.chat-message .chat-source { display: block; margin-bottom: 4px; font-size: 12px; line-height: 1.35; }
.chat-message .chat-source + br { display: none; }
.chat-source, .chat-source a, .chat-status a { color: inherit; text-underline-offset: 2px; }
.chat-status {
  flex: none;
  padding: 4px 0 6px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.chat-status:empty { display: none; }
.chat-status button {
  padding: 3px 8px;
  background: var(--soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--pill);
}
.chat-form {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 3px 3px 3px 15px;
  border: 1px solid #a7a7ae;
  border-radius: var(--pill);
  background: white;
}
.chat-form:focus-within { border-color: var(--ink); }
.chat-form input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  outline: none;
  color: var(--ink);
  background: transparent;
  font: 16px/1.35 var(--ui-font);
}
.chat-form input::placeholder { color: var(--muted); opacity: 1; }
.chat-send { width: 40px; height: 40px; background: var(--ink); color: white; }
.chat-send svg { width: 20px; height: 20px; display: block; fill: currentColor; }
.chat-send:hover:not(:disabled) { background: var(--ink-hover); }
.chat-send:disabled { background: #c8c8ce; color: #fff; cursor: default; }
.guest-chat :is(button, a):focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

@media (max-width: 1024px), (max-width: 1400px) and (any-pointer: coarse) {
  .site-layout {
    --chat-bottom-reserve: max(var(--nav-reserve), var(--chat-keyboard-inset, 0px));
    padding-bottom: var(--chat-bottom-reserve);
  }
  .map-frame {
    --map-gutter: 8px;
    --toolbar-bottom: 8px;
  }
  .guest-chat { justify-self: stretch; width: auto; }
  .guest-chat .chat-launcher { display: none; }
  .chat-panel {
    height: clamp(120px, calc((100dvh - var(--chat-bottom-reserve)) * .42), 320px);
    padding: 7px;
    box-shadow: none;
  }
  .guest-chat[data-expanded="false"] .chat-panel {
    display: flex;
    height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    pointer-events: none;
  }
  .chat-form { pointer-events: auto; }
  .guest-chat[data-expanded="false"] :is(.chat-heading, .chat-log, .chat-status) { display: none; }
  .chat-collapse { width: 38px; height: 38px; }
  .guest-chat.is-reading-help .chat-panel { height: max(160px, min(72dvh, calc(100dvh - var(--chat-bottom-reserve) - 110px))); }
}
@media (max-height: 430px) and (max-width: 1024px), (max-height: 430px) and (max-width: 1400px) and (any-pointer: coarse) {
  .guest-chat[data-expanded="true"] .chat-panel {
    height: clamp(116px, calc((100dvh - var(--chat-bottom-reserve)) * .55), 180px);
    padding: 5px;
  }
  .chat-heading { padding: 0 0 3px 5px; }
  .chat-collapse, .chat-contacts a { height: 32px; }
  .chat-collapse { width: 32px; }
  .chat-log { padding-block: 4px; }
}
