@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e8ecf3;
  --border-light: #f0f2f7;
  --text: #1a1d29;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --primary-dark: #5a4bd1;
  --accent: #fd79a8;
  --green: #00b894;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-w: 280px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== Auth Pages ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f8f9fc 0%, #eef1f8 50%, #f0eeff 100%);
}

/* Decorative Background */
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.bg-decoration .circle {
  position: absolute;
  border-radius: 50%;
  opacity: .35;
}
.bg-decoration .c1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, var(--primary-light), transparent 70%);
  top: -150px; right: -100px;
  animation: floatA 12s ease-in-out infinite;
}
.bg-decoration .c2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  bottom: -100px; left: -80px;
  animation: floatB 15s ease-in-out infinite;
}
.bg-decoration .c3 {
  width: 250px; height: 250px;
  background: radial-gradient(circle, #74b9ff, transparent 70%);
  top: 40%; left: 5%;
  animation: floatA 10s ease-in-out infinite reverse;
}
.bg-decoration .c4 {
  width: 200px; height: 200px;
  background: radial-gradient(circle, var(--green), transparent 70%);
  bottom: 20%; right: 10%;
  animation: floatB 13s ease-in-out infinite;
}
.bg-decoration .dots {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--primary) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: .05;
}

@keyframes floatA {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(30px, -30px) scale(1.05); }
}
@keyframes floatB {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-25px, 25px) scale(1.08); }
}

/* Auth Card */
.auth-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 44px 40px 36px;
  width: 420px;
  max-width: 92vw;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(108,92,231,.08);
  animation: cardIn .5s ease;
}
@keyframes cardIn {
  from { opacity:0; transform:translateY(24px) scale(.97); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.auth-header {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 8px 24px rgba(108,92,231,.25);
}
.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.auth-header p {
  color: var(--text-2);
  font-size: 14px;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 18px;
  border: 1px solid;
}
.alert-error {
  background: #fff0f0;
  color: #e74c3c;
  border-color: #ffd5d5;
}

/* Form */
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon {
  position: absolute;
  left: 14px;
  font-size: 16px;
  opacity: .6;
  pointer-events: none;
}
.input-wrap input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: border-color .25s, box-shadow .25s;
}
.input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(108,92,231,.1);
}
.input-wrap input::placeholder { color: var(--text-3); }

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(108,92,231,.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(108,92,231,.35);
}
.btn-primary:active { transform: translateY(0); }

.auth-footer {
  text-align: center;
  margin-top: 22px;
  font-size: 14px;
  color: var(--text-2);
}
.auth-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.auth-footer a:hover { text-decoration: underline; }

/* ===== Chat Layout ===== */
.app-container {
  display: flex;
  height: 100vh;
  background: var(--bg);
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  transition: transform .3s ease;
}
.sidebar-brand {
  padding: 28px 24px 20px;
  text-align: center;
  position: relative;
}
.sidebar-brand::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.brand-icon {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 6px 20px rgba(108,92,231,.2);
}
.sidebar-brand h2 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.online-section {
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.online-section.collapsed .user-list {
  display: none;
}
.online-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 24px 12px;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}
.online-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
.online-header strong { color: var(--text); }

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
}
.user-list::-webkit-scrollbar { width: 4px; }
.user-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.user-list::-webkit-scrollbar-track { background: transparent; }

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  transition: background .2s;
  cursor: pointer;
}
.user-item:hover { background: var(--surface-2); }
.user-avatar-sm {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.user-item-info { flex: 1; min-width: 0; }
.user-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.user-item-status {
  font-size: 12px;
  color: var(--green);
  font-weight: 500;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
}
.current-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.current-user-info {
  display: flex;
  flex-direction: column;
}
.current-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.current-user-status {
  font-size: 11px;
  color: var(--green);
  font-weight: 500;
}
.logout-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  text-decoration: none;
  transition: background .2s;
  opacity: .5;
}
.logout-btn:hover {
  background: var(--border);
  opacity: 1;
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.chat-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-2);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.menu-toggle:hover { background: var(--surface-2); color: var(--text); }
.chat-header-info h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.chat-header-meta {
  font-size: 12px;
  color: var(--text-3);
}
.chat-header-actions {
  margin-left: auto;
  position: relative;
}
.status-indicator {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

/* ---- Messages ---- */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(108,92,231,.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(253,121,168,.03) 0%, transparent 50%),
    var(--bg);
}
.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }

.loading-msg {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 40px 0;
}

/* Message */
.msg {
  display: flex;
  gap: 10px;
  max-width: 80%;
  animation: msgIn .3s ease;
}
@keyframes msgIn {
  from { opacity:0; transform:translateY(8px); }
  to   { opacity:1; transform:translateY(0); }
}
.msg.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.msg.own .msg-body { align-items: flex-end; }
.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  padding: 0 4px;
}
.msg.own .msg-head { flex-direction: row-reverse; }
.msg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.msg-time {
  font-size: 11px;
  color: var(--text-3);
}
.msg-bubble {
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}
.msg:not(.own) .msg-bubble {
  border-bottom-left-radius: 4px;
}
.msg.own .msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(108,92,231,.2);
}

/* System message */
.system-msg {
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  padding: 8px 0;
  font-weight: 500;
  position: relative;
}
.system-msg::before,
.system-msg::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 24px;
  height: 1px;
  background: var(--border);
}
.system-msg::before { left: calc(50% + 60px); }
.system-msg::after { right: calc(50% + 60px); }

/* ---- Input Area ---- */
.input-area {
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
}
.input-area::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 18px;
  border: 2px solid var(--border);
  transition: border-color .25s, box-shadow .25s;
}
.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(108,92,231,.08);
}
.input-wrapper textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  outline: none;
  line-height: 1.5;
  padding: 8px 0;
  min-height: 24px;
  max-height: 96px;
}
.input-wrapper textarea::placeholder { color: var(--text-3); }
.input-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.char-count {
  font-size: 11px;
  color: var(--text-3);
  min-width: 20px;
  text-align: center;
  font-weight: 500;
}
.send-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s;
  flex-shrink: 0;
}
.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108,92,231,.3);
}
.send-btn:active { transform: translateY(0); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---- Tool Buttons ---- */
.tool-btn {
  width: 36px; height: 36px;
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s;
  line-height: 1;
}
.tool-btn:hover {
  background: var(--border);
}

/* ---- Emoji Picker ---- */
.emoji-picker {
  position: absolute;
  bottom: 80px;
  left: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  display: none;
  z-index: 30;
  max-width: 320px;
}
.emoji-picker.open { display: block; animation: pickerIn .2s ease; }
@keyframes pickerIn {
  from { opacity:0; transform:translateY(8px) scale(.96); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.emoji-item {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.emoji-item:hover { background: var(--surface-2); }

/* ---- Image Preview ---- */
.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.image-preview img {
  max-height: 80px;
  max-width: 140px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  box-shadow: var(--shadow-sm);
}
.preview-close {
  width: 28px; height: 28px;
  border: none; border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.preview-close:hover { background: var(--border); }

/* ---- Image in message ---- */
.msg-bubble { padding: 10px 16px; }
.msg.own .msg-bubble { padding: 10px 16px; }
.msg-text { line-height: 1.55; }
.msg-image { margin-top: 6px; }
.msg-image img {
  max-width: 220px;
  max-height: 220px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: block;
  transition: opacity .2s;
  box-shadow: var(--shadow-sm);
}
.msg-image img:hover { opacity: .85; }
.msg.own .msg-image img {
  box-shadow: 0 2px 10px rgba(108,92,231,.25);
}

/* ---- Sidebar Search ---- */
.sidebar-search {
  padding: 8px 16px 12px;
}
.search-wrap {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0 4px 0 12px;
  border: 2px solid transparent;
  transition: border-color .25s, box-shadow .25s;
}
.search-wrap:focus-within {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(108,92,231,.15);
}
.search-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
}
.search-wrap input::placeholder { color: var(--text-3); }
.search-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, transform .1s;
  line-height: 1.4;
}
.search-btn:hover { background: #5a4bd1; }
.search-btn:active { transform: scale(.96); }

/* ---- Conversation List ---- */
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-section { margin-bottom: 4px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); }
.conv-item.active .conv-name { color: var(--primary); font-weight: 700; }

.conv-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* ---- Modals ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity .3s, visibility .3s;
}
.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 92vw;
  animation: modalIn .3s ease;
}
.modal-box.sm { width: 400px; }
.modal-box.md { width: 520px; }
@keyframes modalIn {
  from { opacity:0; transform:translateY(16px) scale(.97); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  width: 30px; height: 30px;
  border: none; border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.modal-close:hover { background: var(--border); }
.modal-body { padding: 18px 20px 20px; }
.modal-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  padding: 20px 0;
}

/* ---- Color Picker ---- */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.color-swatch {
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color .2s, transform .2s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--text); transform: scale(1.15); }

/* ---- Group Settings ---- */
#gsBody .form-group { margin-bottom: 12px; }
#gsBody .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
#gsBody .form-group input[type="text"],
#gsBody .form-group input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
}
#gsBody .form-group input:focus { border-color: var(--primary); }
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500 !important;
}
.checkbox-label input { width: auto !important; }

/* ---- Request Items ---- */
.request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: 6px;
}
.request-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.req-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.request-user small { color: var(--text-3); font-size: 12px; }
.request-actions { display: flex; gap: 4px; }
.req-btn {
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.req-btn.approve { background: #d4edda; color: #155724; }
.req-btn.approve:hover { background: #b8dfc6; }
.req-btn.reject { background: #f8d7da; color: #721c24; }
.req-btn.reject:hover { background: #f1c0c0; }

/* ---- Form inside modals ---- */
#profileForm .form-group,
#groupForm .form-group {
  margin-bottom: 14px;
}
#profileForm .form-group label,
#groupForm .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
#profileForm input[type="text"],
#profileForm textarea,
#groupForm input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .25s;
}
#profileForm input:focus,
#profileForm textarea:focus,
#groupForm input:focus {
  border-color: var(--primary);
}
#profileForm textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}
#profileForm input[disabled] { opacity: .7; }
.hint {
  font-size: 12px;
  color: var(--text-3);
  margin: -6px 0 14px;
}

/* ---- Responsive ---- */
/* ===== Friend Request Bar ===== */
.friend-request-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin: 0 8px 8px;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity .2s;
}
.friend-request-bar:hover {
  opacity: .9;
}
.req-badge {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ===== Search Result Cards ===== */
.search-section { margin-bottom: 4px; }
.search-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 4px 6px;
}
.search-user-card,
.search-group-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  transition: background .2s;
  cursor: default;
}
.search-user-card:hover,
.search-group-card:hover {
  background: var(--border);
}
.search-group-card { cursor: pointer; }
.search-card-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.search-card-avatar img { width: 100%; height: 100%; object-fit: cover; }
.search-card-info {
  flex: 1;
  min-width: 0;
}
.search-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.search-card-code {
  font-size: 12px;
  color: var(--text-3);
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.search-card-bio {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.search-add-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.search-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108,92,231,.3);
}
.search-card-self {
  font-size: 12px;
  color: var(--text-3);
  background: var(--border);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}
.search-empty {
  text-align: center;
  padding: 24px 0;
}
.search-empty-icon {
  font-size: 32px;
  display: block;
  margin-bottom: 8px;
  opacity: .5;
}
.search-empty p {
  font-size: 14px;
  color: var(--text-3);
}

/* ===== Friend Picker (create group) ===== */
.friend-picker {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
}
.friend-picker::-webkit-scrollbar { width: 4px; }
.friend-picker::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.friend-pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
  font-size: 14px;
}
.friend-pick-item:hover {
  background: var(--surface-2);
}
.friend-pick-item input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
}
.pick-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

/* ===== Profile Card Improvements ===== */
.profile-card {
  text-align: center;
}
.profile-avatar-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.profile-avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  border: 3px solid var(--surface);
  outline: 2px solid var(--border);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.profile-code {
  font-size: 14px;
  color: var(--text-3);
  margin: 2px 0 8px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface-2);
  display: inline-block;
  padding: 2px 12px;
  border-radius: 12px;
}
.profile-bio {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 280px;
  margin: 4px auto 12px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.profile-bio-empty {
  color: var(--text-3);
  font-style: italic;
  background: transparent;
}
.profile-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.profile-add-btn {
  width: 100%;
  margin-top: 12px;
}

/* ===== Header Online Popover ===== */
.header-online {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  transition: background .2s;
  position: relative;
}
.header-online:hover {
  background: var(--border);
}
.online-dot-sm {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
.header-online-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 50;
  animation: popoverIn .2s ease;
}
@keyframes popoverIn {
  from { opacity:0; transform:translateY(-6px); }
  to   { opacity:1; transform:translateY(0); }
}
.header-online-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid var(--border-light);
}
.header-online-item:last-child { border-bottom: none; }
.header-online-item:hover { background: var(--surface-2); }
.hop-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.hop-avatar img { width: 100%; height: 100%; object-fit: cover; }
.hop-name {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* ===== Group create button ===== */
.conv-add-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.conv-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108,92,231,.3);
}
.group-gear {
  margin-left: auto;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.conv-item:hover .group-gear {
  opacity: .6;
}
.group-gear:hover {
  opacity: 1 !important;
  background: var(--border);
}

/* Conversation delete button */
.conv-delete-btn {
  display: none;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  line-height: 22px;
  text-align: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.conv-item:hover .conv-delete-btn {
  display: block;
}
.conv-delete-btn:hover {
  background: #fff0f0;
  color: #e74c3c;
}
.conv-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  padding: 8px 12px 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.conv-section-title span {
  text-transform: uppercase;
  letter-spacing: .3px;
}

@media (max-width: 768px) {
  /* ===== Layout ===== */
  .app-container { height: 100dvh; position: relative; }

  /* Sidebar slide-in */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    width: 280px;
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  /* Sidebar backdrop */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 49;
  }
  .sidebar.open ~ .sidebar-backdrop,
  .sidebar-backdrop.show { display: block; }

  /* Main content full width */
  .main-content { width: 100%; }

  /* ===== Chat header ===== */
  .chat-header {
    padding: 10px 12px;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .chat-header::after { left: 12px; right: 12px; }
  .menu-toggle { display: flex; }
  .chat-header-info h3 { font-size: 15px; }
  .chat-header-meta { font-size: 11px; }
  .chat-header-actions { gap: 8px; }
  .header-online-list {
    position: fixed;
    top: 52px;
    right: 8px;
    width: 200px;
    max-height: 50vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    z-index: 30;
  }
  .header-online-item { padding: 8px 12px; }

  /* ===== Messages ===== */
  .messages-container {
    padding: 8px 8px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .msg { max-width: 90%; margin-bottom: 10px; }
  .msg-avatar { width: 30px; min-width: 30px; height: 30px; }
  .msg-bubble { padding: 8px 12px; font-size: 14px; }
  .msg-name { font-size: 12px; }
  .msg-time { font-size: 10px; }
  .msg-image img { max-width: 160px; max-height: 160px; }

  /* ===== Input area ===== */
  .input-area {
    padding: 8px 12px;
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--surface);
  }
  .input-area::before { left: 12px; right: 12px; }
  .input-wrapper {
    padding: 4px 4px 4px 12px;
    gap: 6px;
    border-radius: var(--radius-md);
  }
  #msgInput {
    font-size: 15px;
    padding: 8px 0;
    min-height: 24px;
  }
  .send-btn { width: 38px; height: 38px; border-radius: 50%; padding: 0; }
  .send-btn svg { width: 18px; height: 18px; }
  .tool-btn { width: 32px; height: 32px; font-size: 16px; }
  .char-count { font-size: 10px; }

  /* ===== Emoji picker ===== */
  .emoji-picker { left: 8px; max-width: calc(100vw - 16px); bottom: 70px; }
  .emoji-grid { grid-template-columns: repeat(8, 1fr); gap: 2px; }
  .emoji-item { font-size: 20px; padding: 4px; }

  /* ===== Sidebar footer ===== */
  .sidebar-footer { padding: 8px 12px; }
  .current-user-name { font-size: 13px; }

  /* ===== Online section ===== */
  .online-section { padding: 8px 12px; }
  .user-item { padding: 6px 8px; }

  /* ===== Modals ===== */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }
  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 85vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin: 0;
  }
  .modal-box.sm,
  .modal-box.md { width: 100% !important; }
  .modal-header { padding: 14px 16px; }
  .modal-header h3 { font-size: 15px; }
  .modal-body { padding: 12px 16px; }

  /* ===== Search modal ===== */
  .search-user-card { padding: 10px 0; }
  .search-card-avatar { width: 36px; height: 36px; }
  .search-card-name { font-size: 13px; }

  /* ===== Profile modal ===== */
  .profile-avatar { width: 60px; height: 60px; }
  .profile-name { font-size: 16px; }
  .form-group input,
  .form-group textarea { font-size: 15px; padding: 10px 12px; }

  /* ===== Friend request modal ===== */
  .request-item { flex-wrap: wrap; gap: 8px; }
  .request-actions { width: 100%; justify-content: flex-end; }

  /* ===== Group settings modal ===== */
  #gsMembers table,
  #gsRequests .request-item { font-size: 13px; }

  /* ===== Toast ===== */
  .chat-toast {
    top: auto;
    bottom: 80px;
    left: 12px;
    right: 12px;
    transform: none;
    max-width: none;
    font-size: 13px;
    padding: 10px 16px;
  }
  @keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* ===== Auth pages ===== */
  .auth-card { padding: 28px 20px 24px; margin: 16px; }
  .auth-header h1 { font-size: 20px; }
  .auth-logo { width: 50px; height: 50px; font-size: 22px; }

  /* ===== Conversation list (sidebar) ===== */
  .conv-item { padding: 8px 12px; }
  .conv-avatar { width: 36px; height: 36px; font-size: 14px; }
  .conv-name { font-size: 13px; }
  .conv-preview { font-size: 11px; }

  /* ===== Recall button always visible on mobile ===== */
  .msg-recall-btn { display: inline-block; font-size: 10px; padding: 1px 6px; }

  /* ===== Color picker ===== */
  .color-swatch { width: 28px; height: 28px; }
}

/* ===== Custom dialog (replaces alert/confirm, no URL shown) ===== */
.custom-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: dialogFadeIn .2s ease;
}
.custom-dialog-box {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px 20px;
  width: 340px;
  max-width: 88vw;
  box-shadow: 0 16px 48px rgba(0,0,0,.2);
  animation: dialogScaleIn .25s ease;
  text-align: center;
}
.custom-dialog-msg {
  font-size: 15px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 22px;
  font-weight: 500;
}
.custom-dialog-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.custom-dialog-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .2s, transform .1s;
  min-width: 80px;
}
.custom-dialog-btn:active { transform: scale(.96); }
.custom-dialog-cancel {
  background: var(--surface-2);
  color: var(--text-2);
}
.custom-dialog-cancel:hover { background: var(--border); }
.custom-dialog-ok {
  background: linear-gradient(135deg, #6c5ce7, #5a4bd1);
  color: #fff;
  box-shadow: 0 4px 14px rgba(108,92,231,.3);
}
.custom-dialog-ok:hover { box-shadow: 0 6px 20px rgba(108,92,231,.4); }

/* Single button mode: hide cancel */
.custom-dialog-overlay.alert-mode .custom-dialog-cancel { display: none; }

@keyframes dialogFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialogScaleIn { from { opacity: 0; transform: scale(.9) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ===== Toast notification ===== */
.chat-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: 90vw;
  text-align: center;
}
.chat-toast-error {
  background: #fff0f0;
  color: #c0392b;
  border: 1px solid #ffd5d5;
}
.chat-toast-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #b8f0c8;
}
.chat-toast-warning {
  background: #fff8e1;
  color: #8b6914;
  border: 1px solid #ffe082;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Recalled message ===== */
.msg.recalled .msg-bubble {
  background: var(--surface-2) !important;
  color: var(--text-3);
  font-style: italic;
  border: 1px dashed var(--border);
  box-shadow: none;
}
.msg.recalled .msg-text,
.msg.recalled .msg-image { display: none; }
.msg-recalled {
  font-size: 13px;
  color: var(--text-3);
  padding: 4px 0;
}

/* ===== Recall button ===== */
.msg-recall-btn {
  display: none;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  font-family: var(--font);
  margin-top: 4px;
  transition: background .2s, color .2s;
}
.msg:hover .msg-recall-btn,
.msg.own .msg-recall-btn { display: inline-block; }
.msg-recall-btn:hover {
  background: #fff0f0;
  color: #e74c3c;
  border-color: #ffd5d5;
}
