:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #162033;
  background: #e8edf5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat {
  width: min(860px, 100%);
  height: min(860px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto auto auto auto 1fr auto auto;
  border: 1px solid #cfd8e6;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 20px 70px rgba(36, 50, 82, 0.18);
  overflow: hidden;
}

.chat__header,
.case-form__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat__header {
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}

.eyebrow {
  margin: 0 0 4px;
  color: #66758d;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: #111827;
}

h1 {
  font-size: 22px;
  line-height: 1.25;
}

h2 {
  font-size: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  padding: 6px 11px;
  color: #526078;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status.online {
  border-color: #9bd6b5;
  color: #087443;
  background: #effbf4;
}

.status.subtle {
  background: #f8fafc;
}

.meta-bar {
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  padding: 8px 20px;
  font-size: 12px;
  line-height: 1.45;
}

.pull-refresh {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  background: #f6f8fb;
  font-size: 12px;
  transition: height 0.18s ease;
}

.pull-refresh.visible {
  height: 34px;
  border-bottom: 1px solid #e2e8f0;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 20px;
  overflow: auto;
  background: #f6f8fb;
  overscroll-behavior-y: contain;
}

.message {
  max-width: 82%;
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  background: #245bd6;
  color: #fff;
}

.message.assistant,
.message.human {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e0e7f0;
}

.message.human {
  border-color: #bbd6ff;
  background: #eef6ff;
}

.message.system {
  align-self: center;
  max-width: 100%;
  color: #64748b;
  font-size: 13px;
  text-align: center;
}

.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.message-images img {
  width: 120px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #64748b;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #7a8aa2;
  animation: pulse 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

.typing em {
  margin-left: 6px;
  font-style: normal;
  font-size: 13px;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.composer,
.case-form,
.password-form {
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.case-form {
  display: grid;
  gap: 12px;
}

.password-form {
  border-top: 0;
  border-bottom: 1px solid #e2e8f0;
}

.password-form label,
.case-form label span {
  display: block;
  margin-bottom: 8px;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

textarea,
input {
  width: 100%;
  resize: none;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 12px;
  color: #162033;
  font: inherit;
  outline: none;
}

#input {
  min-height: 34px;
  max-height: 110px;
}

textarea:focus,
input:focus {
  border-color: #245bd6;
  box-shadow: 0 0 0 3px rgba(36, 91, 214, 0.14);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 4px 8px;
}

.attachment {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  padding: 6px 9px;
  font-size: 12px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.composer-pill {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px 42px;
  align-items: end;
  gap: 6px;
  padding: 8px;
  border: 1px solid #d8dee9;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 10px 32px rgba(36, 50, 82, 0.14);
}

.composer-pill:focus-within {
  border-color: #9eb7f0;
  box-shadow: 0 12px 34px rgba(36, 91, 214, 0.18);
}

.composer-pill #input {
  min-width: 0;
  border: 0;
  border-radius: 14px;
  padding: 7px 4px;
  line-height: 1.45;
  background: transparent;
}

.composer-pill #input:focus {
  box-shadow: none;
}

button,
.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: #245bd6;
  color: #fff;
  padding: 9px 14px;
  font-weight: 800;
  cursor: pointer;
}

.upload-button,
.icon-button,
.send-button {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 999px;
}

.upload-button svg,
.icon-button svg,
.send-button svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.ghost {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
}

.upload-button,
.icon-button {
  border: 0;
  background: transparent;
  color: #334155;
}

.upload-button:active,
.icon-button:active {
  background: #eef2f7;
}

.send-button {
  background: #245bd6;
  color: #fff;
}

.send-button.busy {
  background: #475569;
}

.upload-button input {
  display: none;
}

.hidden {
  display: none;
}

@media (max-width: 640px) {
  .shell {
    padding: 0;
  }

  .chat {
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .chat__header {
    padding: 12px 16px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 11px;
  }

  h1 {
    font-size: 19px;
  }

  .meta-bar {
    padding: 7px 16px;
  }

  .messages {
    padding: 14px 16px;
  }

  .message {
    max-width: 86%;
    font-size: 15px;
  }

  .message.system {
    max-width: 92%;
  }

  .composer,
  .case-form,
  .password-form {
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  }

  button,
  .upload-button {
    min-height: 40px;
  }

  .composer {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), #fff 26%);
  }

  .composer-pill {
    grid-template-columns: 40px minmax(0, 1fr) 40px 42px;
    border-radius: 24px;
    padding: 7px;
  }

  .upload-button,
  .icon-button,
  .send-button {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }
}
