:root {
  --blue: #0b3d91;
  --gold: #f2b705;
  --red: #c8102e;
  --bg: #f4f6fb;
  --bot-bg: #ffffff;
  --text: #1a1f36;
  --muted: #5b6480;
  --border: #e2e6f0;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--blue);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 14px) 10px calc(env(safe-area-inset-left) + 14px);
  border-bottom: 3px solid var(--gold);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: var(--gold);
  color: var(--blue);
  font-weight: 800;
  font-size: 22px;
  display: grid; place-items: center;
}
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 19px; line-height: 1.1; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: #d7defa; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.new-chat {
  flex: none;
  background: rgba(255,255,255,0.14);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
}
.new-chat:active { background: rgba(255,255,255,0.28); }

/* messages */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.msg { max-width: 90%; padding: 11px 14px; border-radius: 16px; line-height: 1.5; font-size: 15.5px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.msg.bot h1, .msg.bot h2, .msg.bot h3 { font-size: 16px; margin: 10px 0 4px; color: var(--blue); }
.msg.bot p { margin: 6px 0; }
.msg.bot ul, .msg.bot ol { margin: 6px 0; padding-left: 20px; }
.msg.bot li { margin: 2px 0; }
.msg.bot a { color: var(--blue); text-decoration: underline; word-break: break-all; }
.msg.bot hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.msg.bot code { background: #eef1f8; padding: 1px 5px; border-radius: 5px; font-size: 90%; }
.msg.bot pre { background: #eef1f8; padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg.bot table { border-collapse: collapse; width: 100%; font-size: 14px; }
.msg.bot th, .msg.bot td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }

/* typing indicator */
.typing { display: inline-flex; gap: 5px; align-items: center; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* composer */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px calc(env(safe-area-inset-right) + 10px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 10px);
  background: #fff;
  border-top: 1px solid var(--border);
}
.input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font: inherit;
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  line-height: 1.4;
  outline: none;
}
.input:focus { border-color: var(--blue); }
.send {
  flex: none;
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.send:disabled { opacity: .5; cursor: default; }
.send:active:not(:disabled) { filter: brightness(.9); }
