:root {
  --bg-deep: #12141a;
  --bg-panel: #181b22;
  --bg-raised: #1e222b;
  --border-soft: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --accent: #e8a94a;
  --accent-dim: #b5822f;
  --text-primary: rgba(255, 255, 255, 0.94);
  --text-secondary: rgba(255, 255, 255, 0.52);
  --text-muted: rgba(255, 255, 255, 0.34);
  --success: #4bbf8c;
  --danger: #e2685f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-deep);
  font-family: var(--font-body);
  color: var(--text-primary);
  overflow: hidden;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(560px 420px at 15% -10%, rgba(232, 169, 74, 0.10), transparent 60%),
    radial-gradient(480px 380px at 100% 100%, rgba(232, 169, 74, 0.06), transparent 60%);
  pointer-events: none;
}

#app { position: relative; z-index: 1; height: 100vh; }
.screen { height: 100%; }
.hidden { display: none !important; }

/* --- AUTH & ONBOARDING --- */
#auth-screen, #onboarding-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 380px;
  padding: 44px 38px;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 44px;
  letter-spacing: -0.5px;
  margin: 0;
  color: var(--accent);
}
.tagline {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 8px 0 32px;
}

.auth-form { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  text-align: left;
  margin: 10px 0 2px;
  font-weight: 500;
}
.field-label:first-child { margin-top: 0; }

input[type="text"], input[type="password"] {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14.5px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent-dim); }
input::placeholder { color: var(--text-muted); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #201304;
  font-weight: 600;
  font-size: 14.5px;
  padding: 12px;
  cursor: pointer;
  margin-top: 18px;
  transition: filter 0.15s, transform 0.1s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}
.btn-secondary.small { padding: 8px 14px; font-size: 13px; }

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  padding: 12px 16px;
}
.btn-ghost:hover { color: var(--text-primary); }

.switch-auth { font-size: 13px; color: var(--text-secondary); margin-top: 18px; }
.switch-auth a { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 500; }
.error { color: var(--danger); font-size: 13px; margin-top: 14px; }

/* --- Onboarding --- */
.onboarding-card { width: 400px; }
.onboarding-title { font-family: var(--font-display); font-weight: 500; font-size: 26px; margin: 0 0 6px; }
.onboarding-sub { color: var(--text-secondary); font-size: 14px; margin: 0 0 28px; }
.onboarding-avatar-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 8px; }
.onboarding-avatar-placeholder { font-style: normal; }
.onboarding-actions { display: flex; gap: 10px; width: 100%; margin-top: 26px; }
.onboarding-actions .btn-primary { flex: 1; margin-top: 0; }
.onboarding-actions .btn-ghost { flex: 0 0 auto; margin-top: 0; }

/* --- Avatars --- */
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(160deg, #ecb567, var(--accent-dim));
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: #201304;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar.small { width: 36px; height: 36px; font-size: 13px; }
.avatar.xl { width: 96px; height: 96px; font-size: 32px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* --- MAIN APP LAYOUT --- */
#main-screen { display: flex; height: 100vh; }

.sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
}

.sidebar-header { display: flex; align-items: center; justify-content: space-between; }
.my-profile { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.my-profile-text { display: flex; flex-direction: column; align-items: flex-start; }
.my-profile-text span:first-child { font-weight: 600; font-size: 14.5px; }
.my-status { font-size: 12px; color: var(--success); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn.ghost { background: transparent; border: none; }

.search-box input { width: 100%; }
.search-results {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.search-result-item, .chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}
.search-result-item:hover, .chat-item:hover { background: var(--bg-raised); }
.chat-item.active { background: var(--bg-raised); border: 1px solid var(--border-soft); }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item-info { display: flex; flex-direction: column; overflow: hidden; flex: 1; }
.chat-item-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-preview { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- CHAT MAIN --- */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-deep); }
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-state-inner { text-align: center; }
.empty-title { font-family: var(--font-display); font-weight: 500; font-size: 22px; margin: 0 0 6px; color: var(--text-secondary); }
.empty-sub { color: var(--text-muted); font-size: 13.5px; margin: 0; }

.chat-window { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-panel);
}
.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-title { font-weight: 600; font-size: 15px; }
.chat-status { font-size: 12px; color: var(--text-secondary); }

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

.message-row { display: flex; }
.message-row.mine { justify-content: flex-end; }

.bubble {
  max-width: 60%;
  padding: 10px 15px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.45;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
}
.message-row.mine .bubble {
  background: var(--accent);
  border: none;
  color: #201304;
}
.bubble img { max-width: 260px; border-radius: 12px; display: block; margin-top: 4px; }
.bubble .meta { font-size: 10.5px; opacity: 0.6; margin-top: 4px; text-align: right; }

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-panel);
}
.composer input[type="text"] { flex: 1; }
.send-btn { padding: 11px 22px; margin-top: 0; }

/* --- MODAL --- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.modal-content {
  width: 380px;
  padding: 26px;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title { font-family: var(--font-display); font-weight: 500; font-size: 20px; margin: 0 0 6px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; justify-content: flex-end; }
.modal-actions .btn-primary { margin-top: 0; }
.selected-members { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12.5px;
  display: flex; align-items: center; gap: 6px;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }

@media (max-width: 720px) {
  #main-screen { flex-direction: column; }
  .sidebar { width: 100%; height: 100%; border-right: none; }
  .chat-main { display: none; }
}