/* ---------- Theme ---------- */
:root {
  --bg: #0f0f10;
  --panel: #1a1a1d;
  --border: #262629;
  --text: #ececec;
  --muted: #9a9aa0;
  --accent: #7c5cff;
  --user: #2a2a2e;
  --online: #3dd68c;
  --offline: #ff5050;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
header {
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

header .right {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

#status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--online);
  display: inline-block;
}

#status.offline {
  background: var(--offline);
}

/* ---------- Chat area ---------- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 160px;
  scroll-behavior: smooth;
}

.inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* ---------- Messages ---------- */
.msg {
  display: flex;
  gap: 14px;
  margin-bottom: 28px;
  animation: fade 0.2s ease;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg.user .avatar {
  background: var(--accent);
  color: #fff;
}

.msg.assistant .avatar {
  background: var(--user);
  color: var(--muted);
  border: 1px solid var(--border);
}

.bubble {
  flex: 1;
  min-width: 0;
}

.bubble .role {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bubble .content {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}

.bubble .content img {
  display: block;
  max-width: 320px;
  margin: 10px 0;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.bubble .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- Empty state ---------- */
.empty {
  padding: 80px 20px;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  color: var(--text);
  font-size: 22px;
  margin-bottom: 8px;
  font-weight: 600;
}

.empty p {
  max-width: 420px;
  margin: 0 auto 20px;
}

.chips {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

.chip {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s;
}

.chip:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* ---------- Composer (input box at the bottom) ---------- */
.composer-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.composer {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

.box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  transition: border-color 0.15s;
}

.box:focus-within,
.box.dragging {
  border-color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 24px;
  max-height: 160px;
  padding: 14px 14px 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  resize: none;
  font: inherit;
}

/* Attached image thumbnail */
.preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 12px 0;
}

.preview:empty {
  display: none;
}

.preview-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-item button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
}

/* Buttons row */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
}

.left-tools {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--user);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  border-color: #3a3a3e;
}

.send {
  height: 34px;
  padding: 0 16px;
  border-radius: 9px;
  border: 0;
  background: var(--text);
  color: #000;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}

.send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.send:not(:disabled):hover {
  transform: translateY(-1px);
}

.hint {
  max-width: 760px;
  width: 100%;
  margin: 8px auto 0;
  padding: 0 20px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

/* ---------- "Thinking" dots ---------- */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.4s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

/* ---------- Animations ---------- */
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* Image size picker in the toolbar */
.size-select {
  height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--user);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.bubble .meta a {
  color: var(--accent);
}

/* ---------- Login and app views ---------- */
/* The flex layouts above would otherwise override the hidden attribute that switches the two views */
[hidden] {
  display: none !important;
}

#app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#login-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.login-card h1 {
  font-size: 18px;
  font-weight: 600;
}

.login-card p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.login-card input {
  height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  outline: 0;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card .send {
  height: 40px;
}

#login-error {
  color: var(--offline);
  font-size: 13px;
  min-height: 1em;
}

.text-btn {
  height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--user);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.text-btn:hover {
  color: var(--text);
}

.error {
  color: var(--offline);
}

header h1,
.text-btn {
  white-space: nowrap;
}

/* Phones: the header keeps just the title and Log out */
@media (max-width: 600px) {
  #stateless-note {
    display: none;
  }
}
