:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --green: #0b7a5a;
  --green-dark: #075f46;
  --green-soft: #dcf8c6;
  --ink: #17212b;
  --muted: #667781;
  --line: #d8e0e4;
  --page: #efeae2;
  --white: #ffffff;
  --danger: #b42318;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: #d9dedb; color: var(--ink); overflow: hidden; }
button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app {
  width: min(100%, 760px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  background: var(--page);
  box-shadow: 0 0 35px rgba(0,0,0,.16);
  position: relative;
  overflow: hidden;
}

.topbar {
  min-height: 64px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--green);
  color: white;
  z-index: 10;
}

.avatar, .welcome-avatar {
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: linear-gradient(145deg, #5ad2aa, #075f46);
  font-weight: 800;
}
.avatar { width: 42px; height: 42px; flex: none; font-size: 20px; }
.identity { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.identity strong { font-size: 17px; line-height: 1.25; }
.identity span { font-size: 12px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-button {
  width: 40px; height: 40px; border: 0; border-radius: 50%; color: white;
  background: transparent; font-size: 27px; cursor: pointer;
}
.icon-button:hover, .icon-button:focus-visible { background: rgba(255,255,255,.14); }

.menu {
  position: absolute; top: calc(58px + env(safe-area-inset-top)); right: 10px; z-index: 30;
  padding: 6px; border-radius: 12px; background: white; box-shadow: 0 8px 28px rgba(0,0,0,.2);
}
.menu button { border: 0; background: transparent; padding: 11px 18px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: #f3f5f6; }

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px 12px 28px;
  scroll-behavior: smooth;
  background-color: var(--page);
  background-image: radial-gradient(rgba(11,122,90,.055) 1px, transparent 1px);
  background-size: 18px 18px;
}

.welcome { text-align: center; padding: 12vh 26px 30px; color: var(--muted); }
.welcome-avatar { width: 70px; height: 70px; margin: 0 auto 16px; font-size: 32px; }
.welcome h1 { color: var(--ink); margin: 0 0 8px; font-size: 23px; }
.welcome p { margin: 0; line-height: 1.45; }

.message-row { display: flex; margin: 5px 0; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }
.bubble {
  max-width: min(84%, 580px);
  padding: 9px 11px 7px;
  border-radius: 12px;
  box-shadow: 0 1px 1px rgba(0,0,0,.09);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
  font-size: 15.5px;
}
.user .bubble { background: var(--green-soft); border-top-right-radius: 4px; }
.assistant .bubble { background: white; border-top-left-radius: 4px; }
.bubble.error { border-left: 3px solid var(--danger); }
.bubble a { color: var(--green-dark); }
.bubble pre { overflow-x: auto; margin: 8px 0; padding: 9px; background: #f3f5f6; border-radius: 7px; font-size: 13px; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.activity { padding: 5px 14px; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; background: rgba(239,234,226,.94); }
.typing { display: inline-flex; gap: 3px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--green); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }

.attachment-bar { margin: 0 10px 6px; padding: 8px 10px; border-radius: 10px; background: white; border: 1px solid var(--line); display: flex; align-items: center; gap: 8px; font-size: 13px; }
.attachment-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-bar button { border: 0; background: transparent; font-size: 21px; cursor: pointer; }

.composer {
  display: grid;
  grid-template-columns: 42px 1fr 44px;
  gap: 7px;
  align-items: end;
  padding: 8px 9px calc(8px + env(safe-area-inset-bottom));
  background: #f4f6f6;
  border-top: 1px solid var(--line);
}
.composer textarea {
  width: 100%; max-height: 130px; resize: none; border: 1px solid var(--line); border-radius: 22px;
  padding: 10px 14px; outline: 0; background: white; line-height: 1.35;
}
.composer textarea:focus { border-color: #8abfad; box-shadow: 0 0 0 3px rgba(11,122,90,.1); }
.attach-button, .send-button {
  width: 42px; height: 42px; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
}
.attach-button { background: transparent; color: var(--muted); font-size: 28px; }
.send-button { background: var(--green); color: white; font-size: 19px; }
.send-button.stop { background: var(--danger); font-size: 0; }
.send-button.stop::after { content: "■"; font-size: 15px; }
button:disabled { opacity: .45; cursor: default; }

.request-dialog { width: min(92vw, 480px); border: 0; border-radius: 16px; padding: 0; box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.request-dialog::backdrop { background: rgba(15,23,42,.48); }
.request-dialog form { padding: 20px; }
.request-dialog h2 { margin: 0 0 12px; font-size: 20px; }
.request-dialog p { line-height: 1.45; color: #344054; }
.request-dialog pre { max-height: 180px; overflow: auto; background: #f2f4f7; padding: 10px; border-radius: 8px; white-space: pre-wrap; }
.request-dialog label { display: block; margin: 12px 0 5px; font-weight: 650; }
.request-dialog input, .request-dialog select { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 9px; }
.request-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.request-actions button { border: 0; border-radius: 9px; padding: 10px 14px; cursor: pointer; background: #eef2f3; }
.request-actions button.primary { background: var(--green); color: white; }
.request-actions button.danger { background: #fee4e2; color: var(--danger); }

@media (min-width: 761px) {
  body { padding: 18px; }
  .app { height: calc(100dvh - 36px); border-radius: 16px; }
}
