:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel2: #1e222e;
  --border: #2a2f3d;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --accent: #5b8cff;
  --accent2: #7a5bff;
  --user-bubble: #2b3a6e;
  --bot-bubble: #1e222e;
  --err: #ff5b6a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { display: flex; flex-direction: column; }

.view { flex: 1; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* --- login --- */
#login-view { align-items: center; justify-content: center; padding: 24px; }
.login-box {
  width: 100%; max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
}
.login-box h1 { font-size: 28px; margin-bottom: 4px; }
.subtitle { color: var(--muted); margin-bottom: 24px; }
.login-box input, .login-box button { width: 100%; margin-top: 12px; }

input {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
}
input:focus { border-color: var(--accent); }

button {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  cursor: pointer;
}
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; font-weight: 600; }
button:active { opacity: 0.8; }

.error { color: var(--err); margin-top: 12px; font-size: 14px; }

/* --- chat --- */
header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.title { flex: 1; }
.name { font-weight: 700; font-size: 17px; }
.status { color: var(--muted); font-size: 13px; }
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #34c759; margin-right: 5px; }
#logout-btn { font-size: 18px; background: none; border: none; color: var(--muted); padding: 8px; }

#messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  max-width: 84%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: var(--bot-bubble); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.bubble.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 4px 8px; }
.bubble.divider { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 6px 12px; border: none; }
.bubble.typing { color: var(--muted); font-style: italic; }

footer {
  display: flex; gap: 8px;
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: calc(12px + env(safe-area-inset-top));
}
footer input { flex: 1; }
footer button { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; font-size: 18px; padding: 0 20px; }

#scroll-down-btn {
  position: fixed;
  right: 16px;
  bottom: 84px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
