:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --border: #e2e2e6;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --bubble-user: #2f6fed;
  --bubble-user-text: #ffffff;
  --bubble-joe: #eef0f4;
  --bubble-joe-text: #1c1c1e;
  --error: #c62828;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --panel: #1f2024;
    --text: #f2f2f4;
    --muted: #9a9aa2;
    --border: #303138;
    --accent: #5b8dff;
    --accent-text: #0a0a0c;
    --bubble-user: #5b8dff;
    --bubble-user-text: #0a0a0c;
    --bubble-joe: #2a2b31;
    --bubble-joe-text: #f2f2f4;
    --error: #ff6b6b;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

header.topbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

header.topbar .brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.02em;
}

header.topbar .subtitle {
  font-size: 13px;
  color: var(--muted);
}

header.topbar button.logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
header.topbar button.logout:hover {
  color: var(--text);
  border-color: var(--muted);
}

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg .who {
  font-size: 11px;
  color: var(--muted);
  padding: 0 4px;
}

.msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
  font-size: 14.5px;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--bubble-joe);
  color: var(--bubble-joe-text);
  border-bottom-left-radius: 4px;
}

.msg.error .bubble {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}

.typing {
  align-self: flex-start;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 4px;
}

footer.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

footer.composer textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 160px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.4;
}
footer.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

footer.composer button.send {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  height: 42px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
footer.composer button.send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-card h1 {
  margin: 0 0 2px;
  font-size: 22px;
}
.login-card .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}
.login-card input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.login-card button {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:disabled {
  opacity: 0.6;
  cursor: default;
}
.login-card .error {
  color: var(--error);
  font-size: 13px;
  min-height: 18px;
  margin-top: 10px;
}

@media (max-width: 480px) {
  .app { max-width: 100%; }
  header.topbar h1 { font-size: 16px; }
}
