:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e3e6ea;
  --text: #1f2329;
  --muted: #6b7280;
  --accent: #1677ff;
  --accent-soft: #e8f1ff;
  --danger: #d93026;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f24;
    --panel-2: #20242a;
    --line: #2c3138;
    --text: #e6e8eb;
    --muted: #9aa1aa;
    --accent: #4c9aff;
    --accent-soft: #1d2c44;
    --danger: #ff6b61;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

input, select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* ---------- 登录 ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 45%),
    var(--bg);
}

.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card .brand {
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 13px;
}

.login-card h1 {
  margin: 8px 0 20px;
  font-size: 24px;
  font-weight: 600;
}

.login-card label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
}

.login-card button {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.login-card button:hover { filter: brightness(1.05); }

.login-card .error {
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(217, 48, 38, 0.1);
  color: var(--danger);
  font-size: 13px;
}

.login-card .hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- 后台骨架 ---------- */

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .brand {
  font-weight: 600;
  font-size: 15px;
}

.topbar .brand span {
  color: var(--muted);
  font-weight: 400;
  margin-left: 6px;
  font-size: 13px;
}

.topbar .user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 20px 24px;
}

.ghost {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

.ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 统计卡 ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
}

.stat-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stat-wide { grid-column: span 2; }
.stat-wide .stat-value { font-size: 14px; font-weight: 500; }

/* ---------- 工作区 ---------- */

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 190px);
  min-height: 520px;
}

.sidebar, .content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar { padding: 14px; gap: 10px; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.muted { color: var(--muted); font-size: 12px; }

.search, .select { width: 100%; }

.conv-list {
  flex: 1;
  overflow: auto;
  margin: 2px -6px 0;
  padding: 0 6px;
}

.conv-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.conv-item:hover { background: var(--panel-2); }

.conv-item.active {
  background: var(--accent-soft);
  border-color: rgba(22, 119, 255, 0.25);
}

.conv-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.content { padding: 14px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0 10px;
}

.filters .search { flex: 1 1 160px; width: auto; }

.date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.date input { padding: 6px 8px; }

.msg-list {
  flex: 1;
  overflow: auto;
  padding-right: 4px;
}

.msg {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel-2);
}

.msg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.msg-head .sender {
  font-weight: 600;
  font-size: 13px;
}

.msg-head .time {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
}

.badge-attach {
  background: rgba(107, 114, 128, 0.12);
  color: var(--muted);
}

.conv-tag {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.6;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 10px;
}

.empty {
  padding: 40px 10px;
  text-align: center;
  color: var(--muted);
}

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

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar { max-height: 320px; }
  .content { min-height: 480px; }
  .stat-wide { grid-column: auto; }
}
