:root {
  color-scheme: light;
  --paper: #fff;
  --ink: #161616;
  --subtle: #666;
  --line: #dedede;
  --soft: #f5f5f5;
  --focus: #777;
  font-family: system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 0; min-height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
body { min-height: 600px; }
button, textarea { font: inherit; }

.chat-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 85vh;
  min-height: 600px;
  background: var(--paper);
}

html.in-iframe, html.in-iframe body {
  width: 100%;
  height: 100%;
  min-height: 600px;
}
html.in-iframe .chat-shell { height: 100%; min-height: 600px; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding: 30px clamp(18px, 5vw, 48px);
  scroll-behavior: smooth;
}

.message {
  max-width: min(78%, 680px);
  padding: 13px 17px;
  border: 1px solid var(--line);
  border-radius: 19px 19px 19px 5px;
  background: var(--soft);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.user {
  align-self: flex-end;
  border-color: var(--ink);
  border-radius: 19px 19px 5px 19px;
  background: var(--ink);
  color: var(--paper);
}

.booking-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 17px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.booking-link:hover, .booking-link:focus-visible { color: var(--paper); background: var(--ink); }

.composer {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 0 clamp(12px, 3vw, 28px) max(16px, env(safe-area-inset-bottom));
  padding: 8px;
  border: 1px solid #bdbdbd;
  border-radius: 25px;
  background: var(--paper);
  box-shadow: 0 2px 12px rgb(0 0 0 / 5%);
}
.composer:focus-within { border-color: var(--focus); }
#message-input {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  max-height: 224px;
  min-height: 52px;
  padding: 13px 13px 11px;
  resize: none;
  overflow-y: hidden;
  border: 0;
  outline: 0;
  border-radius: 17px;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}
#message-input::placeholder { color: var(--subtle); opacity: 1; }
#send-button {
  flex: 0 0 auto;
  min-width: 76px;
  min-height: 44px;
  margin-bottom: 3px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#send-button:hover { background: #444; }
#send-button:focus-visible, .booking-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
#send-button[aria-disabled="true"] { opacity: .55; cursor: wait; }
.connection-status {
  position: absolute;
  left: 18px;
  bottom: calc(100% + 5px);
  margin: 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
}
.connection-status button {
  margin-left: 7px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

@media (max-width: 767px) {
  html, body { height: 100%; min-height: 0; }
  body { height: 100dvh; min-height: 0; overflow: hidden; }
  .chat-shell { height: 100%; height: 100dvh; min-height: 0; }
  html.in-iframe, html.in-iframe body { min-height: 0; }
  html.in-iframe .chat-shell { height: 100%; min-height: 0; }
  .messages { padding: 20px 16px; }
  .message { max-width: 88%; }
  .composer { margin: 0 10px max(10px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .messages { scroll-behavior: auto; }
}
