* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f2f4f7;
  --accent: #1f6f54;
  --accent-dark: #175540;
  --bubble-user: #1f6f54;
  --bubble-assistant: #ffffff;
  --text: #1d2530;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

/* ---- Login ---- */
#login-view {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  padding: 2.5rem;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08);
  width: min(380px, 92vw);
  text-align: center;
}
.login-card h1 { font-size: 1.25rem; margin-bottom: .5rem; }
.login-card p { color: #5a6472; margin-bottom: 1.25rem; }
.login-card form { display: flex; gap: .5rem; }
.login-card input {
  flex: 1;
  min-width: 0;
  padding: .7rem .9rem;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  font-size: 1.1rem;
  letter-spacing: .3em;
  text-align: center;
}
.login-card button {
  padding: .7rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dark); }
.error { color: #c0392b; margin-top: .9rem; min-height: 1.2em; font-size: .9rem; }

/* ---- Chat ---- */
#chat-view { height: 100%; display: flex; flex-direction: column; }
header {
  background: #fff;
  border-bottom: 1px solid #e3e8ee;
  padding: .8rem 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
header button {
  border: 1px solid #cfd6df;
  background: #fff;
  border-radius: 8px;
  padding: .4rem .8rem;
  cursor: pointer;
  font-size: .85rem;
  color: #444;
}
header button:hover { background: #f2f4f7; }

main#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: .7rem 1rem;
  border-radius: 14px;
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: break-word;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--bubble-assistant);
  border: 1px solid #e3e8ee;
  border-bottom-left-radius: 4px;
}
.bubble p + p, .bubble p + ul, .bubble ul + p, .bubble p + ol,
.bubble p + pre, .bubble pre + p { margin-top: .6em; }
.bubble ul, .bubble ol { padding-left: 1.3em; }
.bubble code {
  background: #eef1f5;
  border-radius: 4px;
  padding: .1em .35em;
  font-size: .88em;
}
.bubble pre {
  background: #1d2530;
  color: #e6edf3;
  padding: .8rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: .85em;
}
.bubble pre code { background: none; padding: 0; color: inherit; }
.tool-note {
  font-size: .8rem;
  color: #7a8494;
  font-style: italic;
  padding-left: .5rem;
}
.typing::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

footer {
  background: #fff;
  border-top: 1px solid #e3e8ee;
  padding: .8rem 1.2rem calc(.8rem + env(safe-area-inset-bottom));
}
#chat-form {
  display: flex;
  gap: .6rem;
  max-width: 860px;
  margin: 0 auto;
}
#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #cfd6df;
  border-radius: 10px;
  padding: .65rem .9rem;
  font: inherit;
  max-height: 10rem;
}
#chat-input:focus, .login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  width: 3rem;
  font-size: 1.1rem;
  cursor: pointer;
}
#send-btn:disabled { background: #a9b6b0; cursor: default; }
