* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0a0b0f;
  --bg-elevated: #14161d;
  --bg-elevated-2: #1c1f29;
  --border: #262a36;
  --accent: #6d5dfc;
  --accent-2: #8b7cff;
  --accent-gradient: linear-gradient(135deg, #6d5dfc 0%, #a855f7 100%);
  --text: #f2f2f5;
  --text-dim: #8b8d98;
  --text-faint: #55575f;
  --success: #34d399;
  --danger: #f0576a;
  --radius: 18px;
  --radius-sm: 12px;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

input, button, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---------- AUTH ---------- */

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(109,93,252,0.18), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(168,85,247,0.14), transparent 45%),
    var(--bg);
}

.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 14px;
  box-shadow: 0 8px 24px rgba(109,93,252,0.4);
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-hint {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 5px;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  margin-top: 6px;
  box-shadow: 0 8px 20px rgba(109,93,252,0.35);
  transition: transform 0.1s, opacity 0.15s;
}

.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.6; }

.switch-mode {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

.switch-mode b { color: var(--accent-2); font-weight: 600; }

.error-banner {
  background: rgba(240,87,106,0.12);
  border: 1px solid rgba(240,87,106,0.3);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  display: none;
}

.error-banner.show { display: block; }

/* ---------- BANNED SCREEN ---------- */

.banned-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.banned-box {
  text-align: center;
  max-width: 340px;
}

.banned-icon {
  font-size: 56px;
  margin-bottom: 20px;
}

.banned-box h1 {
  font-size: 22px;
  margin-bottom: 10px;
  color: var(--danger);
}

.banned-box p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 24px;
}

/* ---------- CHAT LAYOUT ---------- */

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.view.active { display: flex; }

/* -- list view -- */

.list-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.list-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-header-top h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.me-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.avatar.large { width: 64px; height: 64px; font-size: 24px; }

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.search-box input:focus { outline: none; border-color: var(--accent); }

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 15px;
  pointer-events: none;
}

.list-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.list-section-label {
  padding: 14px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.conv-item, .search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.1s;
}

.conv-item:active, .search-result-item:active { background: var(--bg-elevated); }

.conv-avatar-wrap { position: relative; flex-shrink: 0; }

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text-faint);
  border: 2px solid var(--bg);
}

.status-dot.online { background: var(--success); }

.conv-body { flex: 1; min-width: 0; }

.conv-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.conv-name { font-weight: 600; font-size: 15px; }

.conv-time { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }

.conv-preview {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 30px;
  text-align: center;
  color: var(--text-faint);
}

.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.6; }
.empty-state p { font-size: 14px; }

/* -- chat view -- */

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:active { background: var(--bg-elevated-2); }

.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 700; font-size: 15px; }
.chat-header-status { font-size: 12px; color: var(--text-dim); }
.chat-header-status.online { color: var(--success); }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

.msg {
  max-width: 76%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}

.msg.mine {
  background: var(--accent-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.theirs {
  background: var(--bg-elevated-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg.system {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 12.5px;
  margin: 6px auto;
  text-align: center;
}

.msg .time {
  display: inline-block;
  font-size: 10px;
  opacity: 0.65;
  margin-left: 8px;
  vertical-align: bottom;
}

.day-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-faint);
  margin: 14px 0 8px;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.input-bar textarea {
  flex: 1;
  resize: none;
  max-height: 100px;
  padding: 11px 16px;
  border-radius: 22px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.3;
}

.input-bar textarea:focus { outline: none; border-color: var(--accent); }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(109,93,252,0.4);
}

.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.4; box-shadow: none; }

.admin-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  background: var(--accent-gradient);
  padding: 1px 6px;
  border-radius: 6px;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: uppercase;
}

.connection-banner {
  text-align: center;
  font-size: 12px;
  padding: 6px;
  background: rgba(240,87,106,0.12);
  color: var(--danger);
  display: none;
}

.connection-banner.show { display: block; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
