:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #182229;
  --border: #222d34;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-hover: #06cf9c;
  --bubble-in: #1f2c33;
  --bubble-out: #005c4b;
  --danger: #f15c6d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 18px; margin-top: 8px; }

/* ----- Login ----- */
#login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
#login-form {
  background: var(--panel);
  padding: 40px 36px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
#login-form h1 {
  margin: 0 0 4px;
  font-size: 22px; letter-spacing: -0.5px;
}
#login-form p { margin: 0 0 24px; }
#login-form input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
}
#login-form button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: 0;
  color: white;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
#login-form button:hover { background: var(--accent-hover); }

/* ----- App layout ----- */
#app { display: flex; height: 100vh; }
#sidebar {
  width: 360px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex; flex-direction: column;
}
#sidebar header {
  padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
#sidebar header h2 { margin: 0; font-size: 17px; }
#sidebar header p { margin: 2px 0 0; }
#sidebar #search {
  margin: 12px 16px;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
#convo-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; flex: 1;
}
.convo {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: center;
}
.convo:hover { background: var(--panel-2); }
.convo.active { background: var(--panel-2); }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #005c4b 0%, #00a884 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0;
}
.convo-body { flex: 1; min-width: 0; }
.convo-row {
  display: flex; justify-content: space-between; gap: 8px;
}
.convo-name { font-weight: 500; }
.convo-time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.convo-preview {
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13px;
}
.convo-preview .direction { color: #6a7a83; }

/* ----- Thread ----- */
#thread {
  flex: 1;
  display: flex; flex-direction: column;
  background: #0a131a;
  background-image: radial-gradient(circle at top left, #0e1c24 0%, #0a131a 100%);
}
.empty {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
#thread-view { display: flex; flex-direction: column; height: 100%; }
#thread-header {
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#thread-header h3 { margin: 0; }
#thread-header p { margin: 2px 0 0; }
#messages {
  flex: 1; overflow-y: auto;
  padding: 24px 20%; display: flex; flex-direction: column; gap: 6px;
}
.msg {
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 70%;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.in {
  background: var(--bubble-in);
  align-self: flex-start;
  border-top-left-radius: 0;
}
.msg.out {
  background: var(--bubble-out);
  align-self: flex-end;
  border-top-right-radius: 0;
}
.msg.bot { border: 1px dashed rgba(255,255,255,0.15); }
.msg-img { display: block; max-width: 100%; border-radius: 6px; margin-bottom: 6px; }
.msg-meta {
  display: block; font-size: 11px; color: var(--muted); margin-top: 4px;
}

#reply-form {
  display: flex; gap: 12px; padding: 14px 20px;
  background: var(--panel); border-top: 1px solid var(--border);
}
#reply {
  flex: 1; resize: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit; font-size: 14px;
}
#reply-form button {
  padding: 0 22px;
  background: var(--accent);
  border: 0; color: white;
  border-radius: 8px; cursor: pointer; font-weight: 600;
}
#reply-form button:hover { background: var(--accent-hover); }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}
button.ghost:hover { color: var(--text); border-color: var(--muted); }

@media (max-width: 768px) {
  #sidebar { width: 100%; }
  #messages { padding: 16px; }
}
