:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --header-bg: #1f6feb;
  --header-fg: #ffffff;
  --bubble-user-bg: #1f6feb;
  --bubble-user-fg: #ffffff;
  --bubble-bot-bg: #ffffff;
  --bubble-bot-fg: #1a1a1a;
  --border: #d9dce1;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
}

#app {
  position: fixed;
  top: 0;
  left: 50%;
  height: var(--app-height, 100dvh);
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#header {
  flex: none;
  padding: env(safe-area-inset-top, 0) 16px 14px;
  padding-top: calc(env(safe-area-inset-top, 0) + 14px);
  background: var(--header-bg);
  color: var(--header-fg);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.4;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-fg);
  border-bottom-right-radius: 4px;
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bubble-bot-bg);
  color: var(--bubble-bot-fg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.bot.pending {
  color: #888;
  font-style: italic;
}

.bubble a {
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
}

.bubble.bot.error {
  border-color: #e0837c;
  color: #a02a20;
}

#composer {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0) + 10px);
  background: #fff;
  border-top: 1px solid var(--border);
}

#input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  font-size: 1rem;
  min-width: 0;
}

#input:focus {
  outline: none;
  border-color: var(--header-bg);
}

#send {
  flex: none;
  padding: 0 20px;
  border: none;
  border-radius: 22px;
  background: var(--header-bg);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#send:disabled {
  opacity: 0.5;
  cursor: default;
}

.hidden {
  display: none !important;
}

#gate {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100dvh;
  padding: 24px;
  text-align: center;
}

#gate h1 {
  margin: 0 0 4px;
}

#gate p {
  margin: 0 0 8px;
  color: #555;
}

#gate-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

#gate-passcode {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

#gate-passcode:focus {
  outline: none;
  border-color: var(--header-bg);
}

#gate-submit {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--header-bg);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.gate-error {
  color: #a02a20;
  font-size: 0.9rem;
  margin: 0;
}
