:root {
  --bg: #111214;
  --panel: #17181b;
  --panel-alt: #1e2023;
  --border: #2a2c30;
  --text: #eef0f2;
  --text-dim: #9a9ea5;
  --accent-blue: #3aa0ff;
  --accent-green: #35b06a;
  --accent-red: #f0473f;
  --bubble-in: #24262a;
  --bubble-out: #234a72;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

/* ---- Chat list ---- */
.chat-list {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-list-header h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#refresh-btn {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.15s ease;
}
#refresh-btn:hover { background: #26282c; }
#refresh-btn.spin { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.account-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.account-switcher select {
  flex: 1;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
}
.add-account-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  flex-shrink: 0;
}
.add-account-btn:hover { background: #26282c; }

.chats {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}
.chat-item:hover { background: var(--panel-alt); }
.chat-item.active { background: #202a36; }

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-item-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.chat-item-preview {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-blue);
  margin-left: 6px;
}

.empty-state, .error-state {
  padding: 24px 16px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}
.error-state { color: var(--accent-red); }

/* ---- Thread ---- */
.thread {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.thread-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 60%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}

.msg.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
}

.auth-gate {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 24px;
}
.auth-gate h2 { margin: 0; font-size: 20px; }
.auth-gate p { margin: 0; color: var(--text-dim); max-width: 360px; }
.auth-btn {
  display: inline-block;
  background: var(--accent-blue);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 24px;
  margin-top: 8px;
}
.auth-btn:hover { filter: brightness(1.08); }

.msg-time {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-dim);
}

.send-form {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.send-form button[type="button"] {
  background: linear-gradient(135deg, #7c5cff, #3aa0ff);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.send-form button[type="button"]:hover { filter: brightness(1.1); }
.send-form button[type="button"]:disabled { opacity: 0.6; cursor: default; }

.send-form input {
  flex: 1;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
}
.send-form input:focus { outline: 2px solid var(--accent-blue); }

.send-form button {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
}
.send-form button:hover { filter: brightness(1.08); }
