:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-strong: #edf6f2;
  --panel-soft: #f8fbf9;
  --text: #14201b;
  --muted: #66736d;
  --line: #dbe3df;
  --brand: #0f766e;
  --brand-strong: #0b5e58;
  --accent: #c7562f;
  --shadow: 0 18px 60px rgba(25, 45, 38, 0.14);
  --shell-width: 840px;
  --touch: 44px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.10), transparent 36%),
    linear-gradient(315deg, rgba(199, 86, 47, 0.08), transparent 32%),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.chat-panel,
.chat-panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(219, 227, 223, 0.92);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(16px, env(safe-area-inset-left)) 14px max(16px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1.08rem;
}

.notice {
  margin: 12px 14px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: #fff7f2;
  color: #693a24;
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 16px 14px 18px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.message {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  font-size: 0.68rem;
  font-weight: 800;
}

.message.user .avatar {
  background: var(--accent);
}

.bubble {
  max-width: calc(100vw - 76px);
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--panel-strong);
  line-height: 1.48;
  overflow-wrap: anywhere;
  font-size: 0.96rem;
}

.message.user .bubble {
  background: var(--brand);
  color: white;
}

.bubble img {
  display: block;
  max-width: min(320px, 100%);
  margin-top: 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.bubble p {
  margin: 0 0 12px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble strong {
  font-weight: 800;
}

.bubble em {
  font-style: italic;
}

.bubble .md-heading {
  display: block;
  margin-top: 4px;
  color: var(--brand-strong);
  font-size: 1.02rem;
}

.bubble hr {
  height: 1px;
  margin: 14px 0;
  border: 0;
  background: rgba(15, 118, 110, 0.22);
}

.bubble .citation {
  color: var(--muted);
  font-size: 0.78em;
  font-weight: 700;
  white-space: nowrap;
}

.composer {
  padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px);
}

.input-row {
  display: grid;
  grid-template-columns: var(--touch) 1fr var(--touch);
  gap: 8px;
  align-items: end;
}

.attach-button,
.icon-button,
.send-button {
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  cursor: pointer;
}

.attach-button input {
  display: none;
}

.send-button {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.send-button:disabled {
  opacity: 0.58;
  cursor: wait;
}

.attach-button[aria-disabled="true"] {
  opacity: 0.58;
  pointer-events: none;
}

.icon-button.small {
  width: 34px;
  height: 34px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: var(--touch);
  max-height: 150px;
  resize: none;
  padding: 12px 13px;
  line-height: 1.35;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.preview {
  position: relative;
  width: fit-content;
  margin: 0 0 10px 52px;
}

.preview img {
  display: block;
  width: 120px;
  height: 90px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preview .small {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.92);
}

.hidden {
  display: none;
}

.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;
}

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

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

  .app-shell {
    display: grid;
    place-items: center;
    width: min(var(--shell-width), 100%);
    min-height: calc(100vh - 48px);
    min-height: calc(100dvh - 48px);
  }

  .chat-panel {
    width: 100%;
    min-height: min(820px, calc(100vh - 48px));
    min-height: min(820px, calc(100dvh - 48px));
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .topbar {
    padding: 18px 20px;
  }

  h1 {
    font-size: 1.58rem;
  }

  .notice {
    margin: 14px 20px 0;
    padding: 11px 14px;
    font-size: 0.92rem;
  }

  .messages {
    padding: 20px;
    gap: 16px;
  }

  .message {
    gap: 10px;
  }

  .avatar {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
    font-size: 0.72rem;
  }

  .bubble {
    max-width: min(680px, calc(var(--shell-width) - 112px));
    padding: 12px 14px;
    font-size: 1rem;
  }

  .composer {
    padding: 14px;
  }

  .input-row {
    gap: 10px;
  }

}

@media (min-width: 1120px) {
  :root {
    --shell-width: 880px;
  }

}
