:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #7b8794;
  --line: #e6e9f0;
  --bubble-theirs: #f1f3f8;
  --shadow: 0 12px 32px rgba(23, 43, 99, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; border: 0; }

input {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
}

input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
  resize: vertical;
}
textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

.btn {
  background: var(--brand);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  transition: background 0.15s;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f6f7fb; color: var(--text); }

/* ------------------------------------------------------- 访客前台 */
.visitor-page { display: flex; align-items: center; justify-content: center; padding: 20px; }

.chat-card {
  width: 100%;
  max-width: 420px;
  height: min(720px, 100%);
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
}

.chat-head .title { font-weight: 600; }
.chat-head .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chat-head .sub.online { color: #16a34a; }

.start-form {
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.start-form label { font-size: 14px; color: var(--muted); }

.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }

.msg {
  max-width: 78%;
  padding: 9px 12px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.mine { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--bubble-theirs); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 2px; }
.msg .meta { display: block; font-size: 11px; opacity: 0.65; margin-top: 4px; }

.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer input { flex: 1; }

.visitor-info {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.welcome-box {
  background: #eef3ff;
  color: var(--brand-dark);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.info-heading { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.notice-list { display: flex; flex-direction: column; gap: 8px; }
.notice-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.notice-item + .notice-item { margin-top: 0; }
.notice-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.notice-body { font-size: 13px; color: #4b5563; line-height: 1.6; white-space: pre-wrap; }
.faq-list { display: flex; flex-direction: column; gap: 6px; }
.faq-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: #fff;
}
.faq-item summary { cursor: pointer; font-size: 14px; font-weight: 500; list-style: none; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::before { content: "Q "; color: var(--brand); font-weight: 700; }
.faq-answer { margin-top: 8px; font-size: 13px; color: #4b5563; line-height: 1.6; white-space: pre-wrap; }

/* ------------------------------------------------------- 客服后台 */
.admin-page { display: flex; height: 100%; }

.login-wrap { margin: auto; width: 100%; max-width: 360px; }
.login-card {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.error-text { color: #dc2626; font-size: 13px; min-height: 18px; }

.console { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.console-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.console-nav .brand { font-weight: 700; font-size: 15px; }
.console-nav .spacer { flex: 1; }
.console-nav .who { font-size: 13px; color: var(--muted); }
.console-nav .who b { color: var(--text); }

.nav-tabs { display: flex; gap: 4px; }
.nav-tabs button {
  padding: 7px 16px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.nav-tabs button:hover { background: #f4f6fb; }
.nav-tabs button.active { background: var(--brand); color: #fff; }

.view { flex: 1; display: flex; min-height: 0; position: relative; }

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar > header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar .who { font-size: 13px; color: var(--muted); }
.sidebar .who b { color: var(--text); }

.tabs { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1;
  padding: 6px 0;
  border-radius: 8px;
  background: #f4f6fb;
  color: var(--muted);
  font-size: 13px;
}
.tabs button.active { background: var(--brand); color: #fff; }

.conv-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 6px; }
.conv-list li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
}
.conv-list li:hover { background: #f6f7fb; }
.conv-list li.active { background: #e8efff; }
.conv-list .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-list .name { font-weight: 600; font-size: 14px; }
.conv-list .time { font-size: 11px; color: var(--muted); }
.conv-list .preview {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-list .badge {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  border-radius: 999px;
  padding: 1px 7px;
}
.conv-list .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-area > header {
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.chat-area .title { font-weight: 600; }
.chat-area .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chat-area .actions { display: flex; gap: 8px; }
.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: #fafbfe;
}
.quick-chip {
  background: #eef3ff;
  color: var(--brand-dark);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-chip:hover { background: #dfe9ff; }

/* ------------------------------------------------------- 内容管理 */
.type-list { list-style: none; margin: 0; padding: 6px; flex: 1; overflow-y: auto; }
.type-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 4px;
}
.type-list li:hover { background: #f6f7fb; }
.type-list li.active { background: #e8efff; color: var(--brand-dark); font-weight: 600; }
.type-list .count {
  font-size: 12px;
  color: var(--muted);
  background: #eef1f6;
  border-radius: 999px;
  padding: 1px 8px;
}
.type-list li.active .count { background: #fff; color: var(--brand); }

.content-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.content-area > header {
  padding: 14px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.content-area .title { font-weight: 600; }
.content-area .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.content-scroll { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; min-height: 0; }

.content-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.content-list li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
}
.content-list li:hover { border-color: #c7d4f5; box-shadow: 0 4px 14px rgba(23, 43, 99, 0.06); }
.content-list li.disabled { opacity: 0.6; }
.content-main { min-width: 0; }
.content-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.content-body {
  font-size: 13px;
  color: #4b5563;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.content-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.content-side .order { font-size: 11px; color: var(--muted); }
.content-side .time { font-size: 11px; color: var(--muted); }
.content-side .tag { font-size: 11px; color: #b45309; border: 1px solid #fcd34d; background: #fffbeb; border-radius: 6px; padding: 0 6px; }

.editor {
  width: 360px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor > header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.editor > header .title { font-weight: 600; }
.editor-form { padding: 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.editor-form > label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.editor-form .form-row { display: flex; gap: 16px; align-items: flex-end; }
.editor-form .form-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.editor-form .form-row input[type="number"] { width: 110px; }
.editor-form .check { flex-direction: row; align-items: center; gap: 8px; }
.editor-form .check input { width: 16px; height: 16px; padding: 0; }
.editor-actions { display: flex; gap: 10px; }
.editor-actions .btn { flex: 1; }

@media (max-width: 760px) {
  .sidebar { width: 42%; }
  .editor { width: 100%; position: absolute; right: 0; top: 0; bottom: 0; box-shadow: var(--shadow); }
  .chat-area .actions .label { display: none; }
}
