/* ─── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f0f11;
  --bg2:        #1a1a1f;
  --bg3:        #252530;
  --border:     #2e2e3a;
  --brand-red:  #ED1B24;
  --accent:     #7c6ef5;
  --accent-h:   #6a5de0;
  --text:       #e8e8f0;
  --text-muted: #888899;
  --bubble-out: #2b2050;
  --bubble-in:  #1e1e28;
  --error:      #e05555;
  --radius:     12px;
  --radius-sm:  8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }

/* ─── Auth page ──────────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.2;
  color: var(--text);
}

.auth-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
  color: var(--text);
}

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text-muted); }

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  display: flex; align-items: center;
}
.btn-ghost:hover { color: var(--text); background: var(--bg3); }
.btn-sm { font-size: 13px; }

.error-msg {
  background: rgba(224,85,85,0.12);
  border: 1px solid rgba(224,85,85,0.35);
  color: #f08080;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-top: 12px;
}

/* spinner */
.btn-spinner::after {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Chat layout ────────────────────────────────────────────────────────── */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-header-logo {
  width: 38px; height: 38px;
  background: var(--brand-red);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
  flex-shrink: 0;
}
.chat-header-title { font-weight: 600; font-size: 15px; }
.chat-header-sub { font-size: 12px; color: var(--text-muted); }

/* ─── Chat main (scrollable) ─────────────────────────────────────────────── */
.chat-main {
  flex: 1 1 auto;
  min-height: 0;          /* CRITICAL: allows flex child to shrink so overflow-y works */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.message-list {
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 6px;
  flex: 1 1 auto;         /* grow to fill space, but can shrink */
  justify-content: flex-end;
}

/* ─── Bubbles ────────────────────────────────────────────────────────────── */
.msg-row {
  display: flex;
  max-width: 78%;
}
.msg-row.outgoing { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.incoming { align-self: flex-start; }

.bubble {
  border-radius: 16px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}
.outgoing .bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
  color: var(--text);
}
.incoming .bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text);
}

.bubble-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.msg-read { color: var(--accent); font-size: 11px; }

/* file bubble */
.file-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.file-icon {
  width: 36px; height: 36px;
  background: var(--bg3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.file-info { min-width: 0; }
.file-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.file-size { font-size: 11px; color: var(--text-muted); }

/* image bubble */
.img-bubble img {
  max-width: 220px;
  max-height: 200px;
  border-radius: 10px;
  display: block;
  cursor: pointer;
}

/* date separator */
.date-sep {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 0;
  user-select: none;
}

/* load more */
.load-more-wrapper { text-align: center; padding: 8px 0; }

/* ─── Footer / input area ────────────────────────────────────────────────── */
.chat-footer {
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.attach-btn {
  flex-shrink: 0;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s;
}
.attach-btn:hover { color: var(--text); background: var(--bg3); }

.input-wrapper {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  min-height: 38px;
  display: flex;
  align-items: center;
}
.input-wrapper:focus-within { border-color: var(--accent); }

#messageInput {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}
#messageInput::placeholder { color: var(--text-muted); }

.btn-send {
  flex-shrink: 0;
  width: 38px; height: 38px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s, opacity 0.15s;
}
.btn-send:hover:not(:disabled) { background: var(--accent-h); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.upload-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 0 0;
}
.upload-preview[hidden],
#uploadCancelBtn[hidden] {
  display: none !important;
}
.upload-progress {
  height: 2px;
  background: var(--bg3);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.upload-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-card { padding: 28px 20px; }
  .msg-row { max-width: 90%; }
}
