:root {
  --brand: #003b90;
  --brand-mid: #0355c9;
  --brand-light: #4a8fd4;
  --brand-bg: #f0f4fa;
  --brand-soft: #e8effa;
  --surface: #ffffff;
  --text: #1c2b42;
  --text-secondary: #5c6b80;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0, 35, 90, 0.06);
  --shadow-md: 0 8px 32px rgba(0, 35, 90, 0.1);
  --radius: 8px;
  --sidebar-w: 280px;
}

*, *::before, *::after { box-sizing: border-box; }

.chat-page {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--brand-bg);
  -webkit-font-smoothing: antialiased;
}

/* ========== Layout ========== */
.chat-layout {
  display: flex;
  min-height: 100vh;
}

/* ========== PC Sidebar ========== */
.chat-sidebar {
  display: none;
  flex-direction: column;
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 28px 24px 24px;
  color: #fff;
  background: linear-gradient(180deg, #002a66 0%, var(--brand) 50%, #024da8 100%);
}

.sidebar-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 32px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  transition: color 0.2s;
}

.sidebar-home:hover { color: #fff; }

.sidebar-brand {
  text-align: center;
  padding-bottom: 24px;
}

.sidebar-brand img {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  padding: 10px;
  background: #fff;
  border-radius: 50%;
  object-fit: contain;
}

.sidebar-brand h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.sidebar-brand p {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.7);
}

.sidebar-divider {
  height: 1px;
  margin: 0 0 20px;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-block h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.55);
}

.sidebar-block p {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.85);
}

.sidebar-contacts {
  list-style: none;
  margin: 24px 0;
  padding: 0;
}

.sidebar-contacts li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-contacts li:last-child { border-bottom: 0; }

.sidebar-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1) center no-repeat;
  background-size: 18px;
}

.sidebar-icon.phone {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 24 24'%3E%3Cpath d='M6.6 10.8c1.4 2.8 3.8 5.1 6.6 6.6l2.2-2.2c.3-.3.7-.4 1-.2 1.1.4 2.3.6 3.6.6.6 0 1 .4 1 1V20c0 .6-.4 1-1 1-9.4 0-17-7.6-17-17 0-.6.4-1 1-1h3.5c.6 0 1 .4 1 1 0 1.3.2 2.5.6 3.6.1.3 0 .7-.2 1L6.6 10.8z'/%3E%3C/svg%3E");
}

.sidebar-icon.mail {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 24 24'%3E%3Cpath d='M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4-8 5-8-5V6l8 5 8-5v2z'/%3E%3C/svg%3E");
}

.sidebar-contacts em {
  display: block;
  font-style: normal;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 2px;
}

.sidebar-contacts a {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  text-decoration: none;
}

.sidebar-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
}

.sidebar-links a {
  padding: 6px 12px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  transition: background 0.2s;
}

.sidebar-links a:hover { background: rgba(255, 255, 255, 0.18); }

.sidebar-copy {
  margin: 16px 0 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
}

/* ========== Main chat panel ========== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  background: var(--surface);
}

.chat-main-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.chat-back-mobile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: -4px;
  color: var(--text);
  text-decoration: none;
  border-radius: 50%;
  transition: background 0.15s;
}

.chat-back-mobile:active { background: var(--brand-soft); }

.chat-agent {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-agent-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 5px;
  background: var(--brand-soft);
  border-radius: 50%;
  border: 1px solid var(--border);
}

.chat-agent-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-agent-info {
  min-width: 0;
}

.chat-agent-info strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.chat-agent-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-agent-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}

.chat-head-badge {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: #15803d;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 999px;
}

/* ========== Messages ========== */
.chat-body {
  flex: 1;
  min-height: 0;
  background: #f8fafc;
  overflow: hidden;
}

.chat-messages {
  height: 100%;
  overflow-y: auto;
  padding: 20px 16px;
  -webkit-overflow-scrolling: touch;
}

.chat-date-tip {
  width: fit-content;
  margin: 0 auto 20px;
  padding: 4px 14px;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
  animation: msgIn 0.35s ease;
}

.chat-msg.user { flex-direction: row-reverse; }

.chat-msg-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
}

.chat-msg-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.chat-msg-avatar.user {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  border-color: transparent;
}

.chat-msg .bubble-wrap {
  max-width: min(480px, calc(100% - 52px));
}

.chat-msg .bubble {
  display: inline-block;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  border-radius: 4px 12px 12px 12px;
}

.chat-msg.bot .bubble {
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.chat-msg.user .bubble {
  color: #fff;
  background: var(--brand-mid);
  border-radius: 12px 4px 12px 12px;
}

.chat-msg .time {
  margin-top: 4px;
  padding: 0 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.chat-msg.user .time { text-align: right; }

.chat-typing {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.chat-typing .dots {
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 4px 12px 12px 12px;
  box-shadow: var(--shadow-sm);
}

.chat-typing .dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #cbd5e1;
  animation: dotBounce 1.2s infinite;
}

.chat-typing .dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing .dots span:nth-child(3) { animation-delay: 0.3s; }

/* ========== Footer / Input ========== */
.chat-footer {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.chat-quick-wrap {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.chat-quick-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.chat-quick {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chat-quick::-webkit-scrollbar { display: none; }

.chat-quick button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--brand);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.chat-quick button:hover {
  border-color: var(--brand-light);
  background: var(--brand-soft);
}

.chat-quick button svg { opacity: 0.7; flex-shrink: 0; }

.chat-compose {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px 0;
}

.chat-compose textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: none;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-compose textarea:focus {
  background: var(--surface);
  border-color: var(--brand-mid);
  box-shadow: 0 0 0 3px rgba(3, 85, 201, 0.1);
}

.chat-compose textarea::placeholder { color: var(--text-muted); }

.chat-compose button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 72px;
  height: 40px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.chat-compose button:hover { background: var(--brand-mid); }

.chat-compose button .send-icon { display: none; }

.chat-compose-tip {
  margin: 6px 16px 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

.chat-card {
  margin-top: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.chat-card a {
  color: var(--brand-mid);
  text-decoration: none;
  font-weight: 500;
}

.chat-msg .bubble a {
  color: var(--brand-mid);
  text-decoration: underline;
}

.chat-msg.user .bubble a { color: #fff; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ========== PC 专属 ========== */
@media screen and (min-width: 1025px) {
  .chat-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    background:
      radial-gradient(ellipse 80% 60% at 20% 20%, rgba(3, 85, 201, 0.08), transparent),
      radial-gradient(ellipse 60% 50% at 80% 80%, rgba(0, 59, 144, 0.06), transparent),
      #e8edf4;
  }

  .chat-layout {
    width: 100%;
    max-width: 960px;
    min-height: 640px;
    height: min(720px, calc(100vh - 64px));
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(0, 59, 144, 0.06);
  }

  .chat-sidebar {
    display: flex;
  }

  .chat-main {
    min-height: 0;
  }

  .chat-back-mobile { display: none; }

  .chat-main-head {
    height: 60px;
    padding: 0 24px;
  }

  .chat-agent-avatar {
    width: 44px;
    height: 44px;
  }

  .chat-agent-info strong { font-size: 16px; }

  .chat-head-badge { display: none; }

  .chat-messages {
    padding: 24px 28px;
  }

  .chat-msg .bubble-wrap { max-width: 420px; }

  .chat-quick-wrap {
    padding: 14px 24px 10px;
  }

  .chat-quick {
    flex-wrap: wrap;
    overflow: visible;
  }

  .chat-quick button {
    flex: 0 0 auto;
  }

  .chat-compose {
    padding: 14px 24px 0;
  }

  .chat-compose textarea {
    min-height: 44px;
    font-size: 14px;
  }

  .chat-compose button {
    height: 44px;
  }

  .chat-compose-tip {
    margin: 8px 24px 14px;
  }
}

/* ========== 移动端专属 ========== */
@media screen and (max-width: 1024px) {
  .chat-page {
    background: var(--surface);
  }

  .chat-layout {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .chat-main {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .chat-main-head {
    height: 52px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    background: var(--brand);
    border-bottom: 0;
    box-shadow: none;
  }

  .chat-back-mobile {
    color: #fff;
  }

  .chat-back-mobile:active {
    background: rgba(255, 255, 255, 0.15);
  }

  .chat-agent-avatar {
    width: 36px;
    height: 36px;
    padding: 4px;
    background: #fff;
    border: 0;
  }

  .chat-agent-info strong {
    font-size: 15px;
    color: #fff;
  }

  .chat-agent-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.75);
  }

  .chat-agent-status i {
    background: #86efac;
    box-shadow: 0 0 0 2px rgba(134, 239, 172, 0.3);
  }

  .chat-head-badge {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
  }

  .chat-body {
    background: #f1f5f9;
  }

  .chat-messages {
    padding: 16px 12px;
  }

  .chat-msg .bubble {
    font-size: 15px;
  }

  .chat-msg .bubble-wrap {
    max-width: calc(100% - 48px);
  }

  .chat-quick-wrap {
    padding: 10px 12px 8px;
  }

  .chat-quick button {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 999px;
    background: var(--surface);
  }

  .chat-compose {
    padding: 10px 12px 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .chat-compose textarea {
    min-height: 44px;
    font-size: 15px;
    border-radius: 22px;
    padding: 11px 16px;
  }

  .chat-compose button {
    min-width: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
  }

  .chat-compose button .send-text { display: none; }
  .chat-compose button .send-icon { display: block; }

  .chat-compose-tip { display: none; }
}
