/* online-chat 前端样式 — 设计系统
   Typography: Plus Jakarta Sans | Primary: #0891B2 | Background: #ECFEFF */

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

:root {
  --primary: #0891B2;
  --primary-dark: #0E7490;
  --primary-light: #22D3EE;
  --primary-bg: #ECFEFF;
  --cta: #059669;
  --cta-dark: #047857;
  --danger: #DC2626;
  --danger-dark: #B91C1C;
  --text: #164E63;
  --text-strong: #0F172A;
  --text-muted: #475569;
  --border: #E2E8F0;
  --surface: #FFFFFF;
  --surface-alt: #F8FAFC;
  --bubble-mine: #0891B2;
  --bubble-peer: #FFFFFF;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --z-dropdown: 20;
  --z-modal: 50;
  --z-toast: 60;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Plus Jakarta Sans', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-strong);
  background: var(--primary-bg);
}

button { font-family: inherit; font-size: inherit; border: none; background: none; }
input, textarea { font-family: inherit; font-size: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 通用控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 200ms, color 200ms, box-shadow 200ms, opacity 200ms;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-cta { background: var(--cta); color: #fff; }
.btn-cta:hover:not(:disabled) { background: var(--cta-dark); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text-strong); }

.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 14px; }
.btn-block { width: 100%; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-strong);
  transition: border-color 200ms, box-shadow 200ms;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.15);
}
.field .field-row { display: flex; gap: 8px; }
.field .field-row input { flex: 1; }

.error-text {
  display: none;
  font-size: 14px;
  color: var(--danger);
  margin-top: 8px;
}
.error-text.show { display: block; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.badge:empty, .badge[data-count="0"] { display: none; }

.avatar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  user-select: none;
}
.avatar.avatar-group { background: linear-gradient(135deg, var(--cta), #34D399); border-radius: 10px; }

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #CBD5E1;
  border: 2px solid #fff;
}
.dot.online { background: var(--cta); }

.icon { width: 20px; height: 20px; flex-shrink: 0; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Toast ---------- */

#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 340px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--primary);
  font-size: 14px;
  color: var(--text-strong);
  animation: toast-in 250ms ease-out;
}
.toast.toast-success { border-left-color: var(--cta); }
.toast.toast-error { border-left-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; color: var(--text-strong); }
.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 200ms, color 200ms;
}
.modal-close:hover { background: var(--surface-alt); color: var(--text-strong); }
.modal-body { padding: 20px; overflow-y: auto; }

/* ---------- 认证页 ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, var(--primary-bg) 0%, #CFFAFE 50%, var(--primary-bg) 100%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}
.auth-brand .brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
}
.auth-brand h1 { font-size: 24px; font-weight: 700; color: var(--text-strong); }
.auth-sub { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }

.auth-tabs {
  display: flex;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  min-height: 40px;
  border-radius: 6px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 200ms, color 200ms, box-shadow 200ms;
}
.auth-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.auth-tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

.auth-form { display: none; }
.auth-form.active { display: block; }

/* ---------- 聊天主界面 ---------- */

.chat-app {
  display: flex;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

/* 侧栏 */
.sidebar {
  display: flex;
  flex-direction: column;
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header .me-info { flex: 1; min-width: 0; }
.sidebar-header .me-info .me-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-header .me-info .me-email {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 200ms, color 200ms;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--primary); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.icon-btn .badge { position: absolute; top: 2px; right: 2px; }

.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); }
.sidebar-tab {
  flex: 1;
  min-height: 44px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 200ms, border-color 200ms;
}
.sidebar-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.sidebar-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.sidebar-tab:hover:not(.active) { color: var(--text-strong); }

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

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  transition: background-color 200ms;
}
.list-item:hover { background: var(--surface-alt); }
.list-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.list-item.active { background: var(--primary-bg); }
.list-item .item-main { flex: 1; min-width: 0; }
.list-item .item-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .item-sub {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.owner-tag {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-bg);
  border: 1px solid var(--primary-light);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 18px;
}

/* 会话区 */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-alt);
}
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}
.chat-welcome svg { width: 64px; height: 64px; color: var(--primary-light); }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.chat-header .chat-title { flex: 1; min-width: 0; }
.chat-header .chat-title h2 {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header .chat-title .chat-status { font-size: 13px; color: var(--text-muted); }

.msg-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-loading {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 0;
}

.msg-row { display: flex; margin-bottom: 8px; gap: 10px; }
.msg-row.mine { flex-direction: row-reverse; }
.msg-row .avatar { width: 36px; height: 36px; font-size: 14px; }
.msg-body { max-width: 62%; display: flex; flex-direction: column; }
.msg-row.mine .msg-body { align-items: flex-end; }
.msg-sender { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; padding: 0 4px; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}
.msg-row:not(.mine) .msg-bubble {
  background: var(--bubble-peer);
  color: var(--text-strong);
  border-top-left-radius: 4px;
}
.msg-row.mine .msg-bubble {
  background: var(--bubble-mine);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg-row.pending .msg-bubble { opacity: 0.6; }
.msg-row.failed .msg-bubble { background: var(--danger); }
.msg-time { font-size: 11px; color: var(--text-muted); margin-top: 3px; padding: 0 4px; }

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.chat-input-bar textarea {
  flex: 1;
  max-height: 120px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: none;
  background: var(--surface-alt);
  color: var(--text-strong);
  transition: border-color 200ms, box-shadow 200ms;
}
.chat-input-bar textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.15);
}

/* 连接状态条 */
.conn-banner {
  display: none;
  padding: 8px 16px;
  background: #FEF3C7;
  color: #92400E;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}
.conn-banner.show { display: block; }

/* 搜索/申请 结果列表 */
.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; }
.result-item .item-main { flex: 1; min-width: 0; }
.result-item .item-name { font-weight: 600; font-size: 15px; }
.result-item .item-sub { font-size: 13px; color: var(--text-muted); }
.result-actions { display: flex; gap: 8px; flex-shrink: 0; }

.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input {
  flex: 1;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 200ms, box-shadow 200ms;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.15);
}

.modal-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.modal-tab {
  min-height: 36px;
  padding: 6px 16px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  cursor: pointer;
  transition: background-color 200ms, color 200ms;
}
.modal-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.modal-tab.active { background: var(--primary); color: #fff; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }
.pager .pager-info { font-size: 14px; color: var(--text-muted); }

/* ---------- 管理面板 ---------- */

.admin-page { min-height: 100vh; padding: 24px 16px; }
.admin-container { max-width: 1024px; margin: 0 auto; }
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.admin-header h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-strong);
}
.admin-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.admin-table th {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.admin-table td { color: var(--text-strong); }
.admin-table tbody tr { transition: background-color 200ms; }
.admin-table tbody tr:hover { background: var(--surface-alt); }
.admin-table .table-wrap { overflow-x: auto; }
.admin-card .table-wrap { overflow-x: auto; }
.admin-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
}

/* ---------- 响应式 ---------- */

@media (max-width: 768px) {
  .sidebar { width: 280px; }
  .msg-body { max-width: 78%; }
}

@media (max-width: 640px) {
  .chat-app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: 100%;
    border-right: none;
  }
  .chat-main {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10;
  }
  body.chat-open .chat-main { display: flex; }
  body.chat-open .sidebar { display: none; }
  .back-btn { display: flex !important; }
}

.back-btn { display: none; }
