:root {
  color-scheme: light;
  --bg: #edf4f7;
  --surface: #ffffff;
  --surface-strong: #e6f0f6;
  --ink: #102033;
  --muted: #5d6d7d;
  --line: #cbddea;
  --primary: #075a9f;
  --primary-dark: #033f73;
  --accent: #27a444;
  --bot: #ffffff;
  --user: #075a9f;
  --shadow: 0 16px 36px rgba(7, 90, 159, .15);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(39, 164, 68, .35);
  outline-offset: 2px;
}

.chat-shell {
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #eaf2f6;
  box-shadow: var(--shadow);
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: var(--primary-dark);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.brand-mark {
  width: 104px;
  height: 40px;
  display: grid;
  place-items: center;
  overflow: visible;
  border-radius: 8px;
  background: transparent;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 2px;
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
}

h1 {
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  line-height: 1.1;
  color: #fff;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  align-self: start;
  min-height: 26px;
  padding: 5px 8px;
  border: 1px solid rgba(232, 255, 240, .36);
  border-radius: 999px;
  color: #e8fff0;
  font-size: 12px;
  font-weight: 700;
  background: rgba(39, 164, 68, .24);
}

.lead-panel {
  margin: 10px 12px 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfe;
}

.lead-panel.hidden {
  display: none;
}

.lead-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

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

.quick-actions button {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid #bdd6e9;
  border-radius: 8px;
  color: var(--primary-dark);
  background: #ffffff;
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
}

.quick-actions button:hover,
.quick-actions button:focus-visible {
  border-color: var(--primary);
}

.quick-actions button:active {
  color: #fff;
  background: var(--primary);
}

.quick-actions button:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.messages {
  min-height: 0;
  height: 100%;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px 14px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, .42) 0 1px, transparent 1px),
    #eaf2f6;
  background-size: 18px 18px;
}

.message {
  width: fit-content;
  max-width: min(88%, 390px);
  padding: 10px 11px 8px;
  border-radius: 8px;
  line-height: 1.45;
  box-shadow: 0 1px 2px rgba(16, 37, 26, .08);
  font-size: 15px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-link-button {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin: 6px 4px 0 0;
  padding: 0 10px;
  border: 1px solid #b8d4e7;
  border-radius: 8px;
  color: var(--primary-dark);
  background: #eef7fc;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: normal;
}

.message-link-button:focus-visible {
  outline: 3px solid rgba(39, 164, 68, .35);
  outline-offset: 2px;
}

.message time {
  display: inline-block;
  margin-top: 6px;
  color: rgba(16, 37, 26, .55);
  font-size: 11px;
}

.message.bot {
  align-self: flex-start;
  background: var(--bot);
  border: 0;
}

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

.message.user time {
  color: rgba(255, 255, 255, .72);
}

.message.system {
  align-self: center;
  width: auto;
  max-width: 92%;
  padding: 4px 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, .58);
  box-shadow: none;
  text-align: center;
  font-size: 13px;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  align-items: end;
  gap: 8px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: #f5f8fb;
  border-top: 1px solid var(--line);
}

.message-field {
  min-width: 0;
  min-height: 44px;
  display: grid;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.message-field span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

textarea {
  width: 100%;
  min-height: 24px;
  max-height: 112px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 16px;
  line-height: 1.5;
}

.send-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
}

.send-button {
  width: 72px;
  padding: 0 8px;
  font-weight: 700;
}

.send-button:disabled {
  opacity: .58;
  cursor: not-allowed;
}

@media (max-width: 360px) {
  .chat-header {
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 8px;
  }

  .brand-mark {
    width: 86px;
    height: 40px;
  }

  .status {
    display: none;
  }

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

  .composer {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 6px;
  }

  .send-button {
    width: 64px;
  }
}

@media (max-height: 620px) {
  .lead-panel {
    margin-top: 8px;
    padding: 9px;
  }

  .lead-panel p {
    margin-bottom: 8px;
  }

  .quick-actions button {
    min-height: 38px;
  }

  .messages {
    padding-top: 10px;
  }
}

@media (min-width: 720px) {
  body {
    display: grid;
    place-items: center;
    padding: 28px;
  }

  .chat-shell {
    width: 420px;
    height: min(820px, calc(100dvh - 56px));
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
  }
}
