:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e5e5e0;
  --text: #1a1a18;
  --muted: #6b6b66;
  --accent: #2f6fed;
  --accent-hover: #2459c4;
  --user-bubble: #efefec;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
.hidden { display: none !important; }

/* Login */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.brand {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.brand.small { font-size: 18px; }
.brand-mark {
  display: inline-block;
  background: var(--text);
  color: #fff;
  font-size: 0.72em;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 7px;
  margin-right: 6px;
  vertical-align: 2px;
}
.login-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
}
input[type="email"], input[type="password"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.btn-primary {
  width: 100%;
  margin-top: 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.form-error {
  background: #fdeeee;
  border: 1px solid #f3c2c2;
  color: #a33;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  margin-bottom: 4px;
}

/* App layout */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.btn-new {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-new:hover { background: var(--bg); }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--user-bubble); font-weight: 600; }
.conv-empty { color: var(--muted); font-size: 13.5px; padding: 12px; }
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-line { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* Thread */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 12px;
}
.thread-inner { max-width: 760px; margin: 0 auto; }
.msg { margin-bottom: 20px; }
.msg .who {
  font-size: 12.5px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg.user { text-align: right; }
.msg.user .bubble {
  display: inline-block;
  background: var(--user-bubble);
  border-radius: 14px;
  padding: 9px 14px;
  max-width: 80%;
  text-align: left;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant .body {
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 100%;
}
.msg.assistant .body p { margin: 0 0 10px; }
.thread-welcome {
  color: var(--muted);
  text-align: center;
  margin-top: 18vh;
}
.thread-welcome h2 { color: var(--text); font-weight: 650; margin-bottom: 6px; }

/* Typing indicator: subtle, no glow */
.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #b9b9b3;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* Composer */
.composer-wrap {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 24px 10px;
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  background: #fff;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  border: none;
  resize: none;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 140px;
  background: transparent;
  color: var(--text);
}
.composer textarea:focus { outline: none; }
.btn-send {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--text);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}
.btn-send:disabled { opacity: 0.35; cursor: default; }
.composer-hint {
  max-width: 760px;
  margin: 8px auto 2px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .sidebar { width: 210px; }
}
