:root {
  --bg: #000;
  --bg-secondary: #1c1c1e;
  --bg-tertiary: #2c2c2e;
  --bg-input: #2c2c2e;
  --bg-hover: #3a3a3c;
  --text: #fff;
  --text-secondary: #8e8e93;
  --text-tertiary: #636366;
  --accent: #007aff;
  --accent-hover: #0056cc;
  --accent-light: rgba(0,122,255,.15);
  --bubble-own: #007aff;
  --bubble-other: #2c2c2e;
  --border: #2c2c2e;
  --danger: #ff453a;
  --success: #34c759;
  --sidebar-w: 340px;
  --header-h: 56px;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

/* ── Auth ── */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.auth-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(0,122,255,.25), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(88,86,214,.15), transparent),
    var(--bg);
}

.auth-card {
  position: relative;
  width: min(400px, 92vw);
  background: rgba(28,28,30,.85);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo-icon {
  width: 56px; height: 56px;
  margin: 0 auto .75rem;
  background: linear-gradient(135deg, var(--accent), #5856d6);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem; font-weight: 700;
}
.auth-logo h1 { font-size: 1.75rem; letter-spacing: .04em; }
.auth-logo p { color: var(--text-secondary); font-size: .85rem; margin-top: .25rem; }

.auth-tabs {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 1.25rem;
}
.auth-tab {
  flex: 1;
  padding: .55rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  font-family: inherit;
  transition: all .2s;
}
.auth-tab.active { background: var(--bg-hover); color: var(--text); }

.field { margin-bottom: .85rem; }
.field label {
  display: block;
  font-size: .75rem;
  color: var(--text-secondary);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field input {
  width: 100%;
  padding: .75rem 1rem;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }

.auth-error { color: var(--danger); font-size: .8rem; min-height: 1.2em; margin: .5rem 0; }
.auth-link {
  display: block;
  text-align: center;
  margin-top: 1rem;
  color: var(--text-secondary);
  font-size: .8rem;
  text-decoration: none;
}
.auth-link:hover { color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: .85rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-text {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: .8rem; font-family: inherit;
}
.btn-text:hover { color: var(--danger); }

/* ── Layout ── */
.app { display: flex; height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1rem;
  height: var(--header-h);
}
.sidebar-header h1 { font-size: 1.25rem; font-weight: 700; }
.sidebar-actions { display: flex; gap: .25rem; }

.search-wrap { padding: 0 .75rem .5rem; }
.search-wrap input,
#user-search {
  width: 100%;
  padding: .55rem .85rem;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 10px;
  color: var(--text);
  font-size: .875rem;
  outline: none;
}
.search-wrap input::placeholder, #user-search::placeholder { color: var(--text-tertiary); }

.chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1rem;
  cursor: pointer;
  transition: background .12s;
  border-left: 3px solid transparent;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent-light); border-left-color: var(--accent); }

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem;
}
.chat-item-name {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time { font-size: .7rem; color: var(--text-secondary); flex-shrink: 0; }
.chat-item-preview {
  font-size: .8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: .15rem;
}

.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  min-width: 0;
}
.user-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Avatar ── */
.avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #5856d6);
}
.avatar.sm { width: 40px; height: 40px; font-size: .85rem; }
.avatar.xs { width: 32px; height: 32px; font-size: .75rem; }

/* ── Main / Chat ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: .5rem;
}
.empty-icon { font-size: 3rem; opacity: .5; }
.empty-state h2 { color: var(--text); font-weight: 600; }

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h2 {
  font-size: .95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle { font-size: .75rem; color: var(--text-secondary); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  scroll-behavior: smooth;
}

.msg-date {
  text-align: center;
  font-size: .7rem;
  color: var(--text-secondary);
  margin: .75rem 0;
  padding: .2rem .65rem;
  background: var(--bg-tertiary);
  border-radius: 10px;
  align-self: center;
}

.msg-row {
  display: flex;
  gap: .5rem;
  max-width: 75%;
  animation: msgIn .2s ease;
}
.msg-row.own { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.other { align-self: flex-start; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-bubble {
  padding: .55rem .85rem;
  border-radius: 18px;
  font-size: .9rem;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
}
.msg-row.own .msg-bubble {
  background: var(--bubble-own);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.other .msg-bubble {
  background: var(--bubble-other);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-sender {
  font-size: .7rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: .2rem;
}
.msg-meta {
  font-size: .65rem;
  opacity: .6;
  text-align: right;
  margin-top: .2rem;
}
.msg-row.other .msg-meta { text-align: left; }

.msg-reply {
  font-size: .75rem;
  opacity: .75;
  border-left: 2px solid rgba(255,255,255,.4);
  padding-left: .5rem;
  margin-bottom: .35rem;
}

.msg-image {
  max-width: 260px;
  max-height: 260px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
}
.msg-file {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem;
  background: rgba(0,0,0,.15);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  font-size: .85rem;
}
.msg-file:hover { background: rgba(0,0,0,.25); }

.msg-actions {
  display: none;
  gap: .15rem;
  align-self: center;
}
.msg-row:hover .msg-actions { display: flex; }
.msg-action-btn {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .75rem;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ── Composer ── */
.reply-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}
.reply-content { flex: 1; min-width: 0; }
.reply-label { font-size: .7rem; color: var(--accent); font-weight: 600; display: block; }
#reply-text {
  font-size: .8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .65rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1;
  background: var(--bg-input);
  border: none;
  border-radius: 20px;
  padding: .65rem 1rem;
  color: var(--text);
  font-size: .9rem;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  outline: none;
  line-height: 1.4;
}
.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(.92); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(420px, 100%);
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; }
.modal-body { padding: 1rem; overflow-y: auto; flex: 1; }
.modal-tabs {
  display: flex;
  border-top: 1px solid var(--border);
}
.modal-tab {
  flex: 1;
  padding: .75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: .875rem;
}
.modal-tab.active { color: var(--accent); background: var(--accent-light); }

.user-results { margin-top: .75rem; }
.user-result {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .5rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
}
.user-result:hover { background: var(--bg-hover); }
.user-result-info { flex: 1; }
.user-result-name { font-weight: 600; font-size: .9rem; }
.user-result-username { font-size: .8rem; color: var(--text-secondary); }

.selected-users {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin: .75rem 0;
}
.user-tag {
  display: flex;
  align-items: center;
  gap: .35rem;
  background: var(--accent-light);
  color: var(--accent);
  padding: .25rem .55rem;
  border-radius: 20px;
  font-size: .8rem;
}
.user-tag button {
  background: none; border: none; color: inherit; cursor: pointer; font-size: .9rem;
}

#group-name {
  width: 100%;
  padding: .65rem .85rem;
  background: var(--bg-input);
  border: none;
  border-radius: 10px;
  color: var(--text);
  margin-bottom: .5rem;
  outline: none;
}

/* ── Info drawer ── */
.info-drawer {
  position: fixed;
  top: 0; right: 0;
  width: min(320px, 90vw);
  height: 100dvh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 90;
  display: flex;
  flex-direction: column;
  animation: slideIn .2s ease;
}
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.info-content { padding: 1rem; overflow-y: auto; flex: 1; }
.info-member {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .mobile-only { display: flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(0);
    transition: transform .25s ease;
  }
  .sidebar.hidden-mobile { transform: translateX(-100%); }
  .main { width: 100%; }
  .msg-row { max-width: 88%; }
}

.typing-indicator {
  font-size: .75rem;
  color: var(--text-secondary);
  padding: .25rem 1rem;
  font-style: italic;
}
