:root {
  color-scheme: light;
  --ink: #17312f;
  --muted: #6b7f7c;
  --line: #dce7e4;
  --panel: #ffffff;
  --wash: #edf4f1;
  --wash-strong: #e2eeea;
  --brand: #0b5d56;
  --brand-strong: #084a45;
  --brand-soft: #d8eee7;
  --user-bubble: #d9f7e9;
  --danger: #a84343;
  --shadow: 0 22px 70px rgba(17, 52, 48, 0.17);
  --radius-large: 24px;
  --radius-bubble: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  min-width: 280px;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(210, 238, 228, 0.9), transparent 32rem),
    radial-gradient(circle at 92% 90%, rgba(196, 221, 217, 0.78), transparent 34rem),
    #dfeae6;
  -webkit-font-smoothing: antialiased;
}

button,
textarea,
input {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

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

.chat-shell {
  width: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--panel);
}

.chat-header {
  position: relative;
  z-index: 5;
  min-height: 72px;
  padding: calc(10px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  background: linear-gradient(122deg, var(--brand-strong), var(--brand));
  box-shadow: 0 2px 14px rgba(8, 52, 48, 0.18);
}

.quartio-mark,
.empty-mark,
.typing-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-weight: 760;
  letter-spacing: -0.04em;
  border-radius: 50%;
}

.quartio-mark {
  width: 44px;
  height: 44px;
  color: var(--brand-strong);
  background: #f2fffa;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45), 0 5px 18px rgba(3, 34, 31, 0.24);
}

.chat-identity {
  min-width: 0;
  flex: 1;
}

.chat-identity h1 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
  font-weight: 710;
  letter-spacing: -0.015em;
}

.connection-label {
  margin: 3px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.75);
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffcf72;
  box-shadow: 0 0 0 3px rgba(255, 207, 114, 0.12);
}

.connection-dot[data-state="online"] {
  background: #72e1b3;
  box-shadow: 0 0 0 3px rgba(114, 225, 179, 0.14);
}

.connection-dot[data-state="offline"] {
  background: #e8a2a2;
  box-shadow: 0 0 0 3px rgba(232, 162, 162, 0.14);
}

.stop-button {
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.stop-button:hover {
  background: rgba(255, 255, 255, 0.19);
}

.stop-button:active {
  transform: scale(0.97);
}

.stop-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.stop-icon {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
}

.conversation {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 14px 14px, rgba(11, 93, 86, 0.035) 1px, transparent 1.5px) 0 0 / 28px 28px,
    linear-gradient(180deg, #f5f8f6 0%, var(--wash) 100%);
}

#messages {
  height: 100%;
  margin: 0;
  padding: 26px max(16px, env(safe-area-inset-left)) 82px max(16px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  list-style: none;
}

#messages:empty {
  pointer-events: none;
}

#messages::-webkit-scrollbar {
  width: 10px;
}

#messages::-webkit-scrollbar-thumb {
  background: rgba(73, 101, 96, 0.2);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.empty-state {
  position: absolute;
  z-index: 1;
  inset: 50% auto auto 50%;
  width: min(88%, 380px);
  padding: 26px 24px;
  text-align: center;
  transform: translate(-50%, -52%);
  color: var(--muted);
  border: 1px solid rgba(11, 93, 86, 0.08);
  border-radius: var(--radius-large);
  background: rgba(255, 255, 255, 0.66);
  box-shadow: 0 16px 44px rgba(27, 68, 63, 0.08);
  backdrop-filter: blur(12px);
}

.empty-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 15px;
  color: #fff;
  background: linear-gradient(145deg, var(--brand), #168579);
  box-shadow: 0 10px 25px rgba(11, 93, 86, 0.22);
}

.empty-state h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.empty-state p {
  margin: 8px auto 0;
  max-width: 31ch;
  font-size: 0.88rem;
  line-height: 1.55;
}

.message-row {
  width: 100%;
  display: flex;
  animation: message-in 160ms ease-out both;
}

.message-row--user {
  justify-content: flex-end;
}

.message-row--assistant {
  justify-content: flex-start;
}

.message-row--system {
  justify-content: center;
}

.message-bubble {
  position: relative;
  min-width: 72px;
  max-width: min(76%, 650px);
  padding: 10px 12px 7px;
  border: 1px solid rgba(26, 61, 57, 0.07);
  border-radius: var(--radius-bubble);
  background: #fff;
  box-shadow: 0 3px 13px rgba(33, 71, 66, 0.09);
}

.message-row--user .message-bubble {
  background: var(--user-bubble);
  border-color: rgba(20, 117, 91, 0.1);
  border-bottom-right-radius: 5px;
}

.message-row--assistant .message-bubble {
  border-bottom-left-radius: 5px;
}

.message-row--system .message-bubble {
  max-width: min(82%, 520px);
  padding: 6px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 0.78rem;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: none;
}

.message-bubble--progress {
  color: #3e5e59;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: none;
}

.message-bubble--error,
.message-bubble--warning {
  color: #713939;
  background: #fff3f0;
  border-color: #efd3cc;
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 0.94rem;
  line-height: 1.45;
}

.message-attachments {
  margin: 2px 0 4px;
  padding: 0;
  display: grid;
  gap: 6px;
  list-style: none;
}

.message-text + .message-attachments {
  margin-top: 9px;
}

.message-attachment {
  min-width: 0;
  padding: 8px 9px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: #34544f;
  border: 1px solid rgba(25, 95, 83, 0.1);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.58);
}

.attachment-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 800;
  border-radius: 9px;
  background: var(--brand-soft);
}

.attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 650;
}

.attachment-size {
  color: var(--muted);
  font-size: 0.68rem;
}

.message-meta {
  min-height: 14px;
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 7px;
  color: #738783;
  font-size: 0.64rem;
  line-height: 1;
}

.delivery--failed {
  color: var(--danger);
}

.retry-button {
  padding: 1px 0;
  color: var(--danger);
  font-size: inherit;
  font-weight: 750;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.safe-link-card {
  width: min(84%, 430px);
  padding: 15px;
  color: var(--ink);
  border: 1px solid rgba(11, 93, 86, 0.16);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(31, 74, 68, 0.1);
}

.safe-link-eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.safe-link-description {
  margin: 0 0 12px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.safe-link-action {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 720;
  text-decoration: none;
  border-radius: 10px;
  background: var(--brand);
}

#typing-indicator {
  position: absolute;
  z-index: 3;
  left: max(16px, env(safe-area-inset-left));
  bottom: 14px;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  pointer-events: none;
}

.typing-avatar {
  width: 26px;
  height: 26px;
  color: #fff;
  font-size: 0.68rem;
  background: var(--brand);
}

.typing-bubble {
  height: 31px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(26, 61, 57, 0.08);
  border-radius: 14px 14px 14px 4px;
  background: #fff;
  box-shadow: 0 3px 13px rgba(33, 71, 66, 0.09);
}

[data-typing-dot] {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #78908c;
  animation: typing-dot 1.15s ease-in-out infinite;
}

[data-typing-dot]:nth-child(2) {
  animation-delay: 140ms;
}

[data-typing-dot]:nth-child(3) {
  animation-delay: 280ms;
}

.new-messages-button {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 15px;
  min-height: 34px;
  padding: 0 12px;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 730;
  border: 1px solid rgba(11, 93, 86, 0.15);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(26, 65, 60, 0.16);
  transform: translateX(-50%);
  cursor: pointer;
}

.composer-wrap {
  position: relative;
  z-index: 6;
  padding: 9px max(12px, env(safe-area-inset-right)) calc(9px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(252, 254, 253, 0.96);
  box-shadow: 0 -7px 22px rgba(26, 65, 60, 0.06);
  backdrop-filter: blur(18px);
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

#attachment-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.attach-button,
.send-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 130ms ease, background 130ms ease;
}

.attach-button {
  color: #54706c;
  font-size: 1.65rem;
  line-height: 1;
  background: var(--wash);
}

.attach-button:hover {
  color: var(--brand);
  background: var(--brand-soft);
}

.send-button {
  color: #fff;
  font-size: 1.35rem;
  font-weight: 760;
  background: var(--brand);
  box-shadow: 0 5px 14px rgba(11, 93, 86, 0.24);
}

.send-button:hover {
  background: var(--brand-strong);
}

.attach-button:active,
.send-button:active {
  transform: scale(0.94);
}

#message-input {
  width: 100%;
  min-height: 42px;
  max-height: 144px;
  padding: 10px 13px;
  resize: none;
  overflow-y: auto;
  color: var(--ink);
  line-height: 1.35;
  border: 1px solid var(--line);
  border-radius: 18px;
  outline: none;
  background: #fff;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

#message-input::placeholder {
  color: #8a9b98;
}

#message-input:focus {
  border-color: rgba(11, 93, 86, 0.52);
  box-shadow: 0 0 0 3px rgba(11, 93, 86, 0.09);
}

.file-chips {
  max-height: 96px;
  margin: 0 0 8px 50px;
  padding: 1px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.file-chip {
  min-width: 0;
  max-width: 240px;
  height: 34px;
  padding: 0 5px 0 10px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(11, 93, 86, 0.12);
  border-radius: 10px;
  background: var(--brand-soft);
}

.file-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.74rem;
  font-weight: 670;
}

.file-chip__size {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.62rem;
}

.file-chip__remove {
  width: 24px;
  height: 24px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #4b6762;
  font-size: 1rem;
  line-height: 1;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.file-chip__remove:hover {
  color: var(--danger);
  background: rgba(255, 255, 255, 0.58);
}

.composer-status {
  min-height: 14px;
  margin: 4px 50px -3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button:focus-visible,
label:focus-within,
a:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(25, 145, 129, 0.38);
  outline-offset: 2px;
}

noscript {
  position: fixed;
  z-index: 20;
  inset: 20px;
  padding: 20px;
  color: var(--danger);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

@keyframes typing-dot {
  0%,
  60%,
  100% {
    opacity: 0.42;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 760px) and (min-height: 640px) {
  body {
    padding: 18px;
  }

  .chat-shell {
    max-width: 980px;
    height: calc(100dvh - 36px);
    border: 1px solid rgba(33, 73, 67, 0.12);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow);
  }

  .chat-header {
    padding-top: 10px;
  }

  #messages {
    padding-inline: 28px;
  }

  .composer-wrap {
    padding-inline: 20px;
  }
}

@media (max-width: 520px) {
  .chat-header {
    min-height: 66px;
  }

  .quartio-mark {
    width: 40px;
    height: 40px;
  }

  .stop-button {
    padding-inline: 10px;
    font-size: 0.78rem;
  }

  #messages {
    padding-top: 18px;
    gap: 7px;
  }

  .message-bubble {
    max-width: 86%;
  }

  .message-row--system .message-bubble,
  .safe-link-card {
    max-width: 92%;
    width: auto;
  }

  .empty-state {
    padding: 22px 18px;
    background: rgba(255, 255, 255, 0.55);
  }

  .composer-status {
    margin-inline: 4px;
  }

  .file-chips {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
