:root {
  --navy: #1e3a5f;
  --navy-dark: #152a45;
  --gold: #c9a227;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1f2937;
  --muted: #64748b;
  --selected: #f5ebe0;
  --out-bubble: #dbeafe;
  --in-bubble: #ffffff;
  --wechat: #07c160;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }

.app {
  display: grid;
  grid-template-columns: 220px 320px 1fr 300px;
  grid-template-rows: 48px 1fr;
  grid-template-areas:
    "sidebar top top top"
    "sidebar inbox chat profile";
  height: 100vh;
}

.sidebar { grid-area: sidebar; background: var(--navy); color: #fff; display: flex; flex-direction: column; padding: 20px 0; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 20px 24px; }
.brand-icon { width: 36px; height: 36px; border-radius: 8px; background: var(--gold); color: var(--navy-dark); display: grid; place-items: center; font-weight: 700; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text span { font-size: 12px; opacity: 0.8; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 12px 20px;
  position: relative;
  font-size: 14px;
}
.nav-item.active {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 4px;
  background: var(--gold);
  border-radius: 0 4px 4px 0;
}
.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  text-align: center;
  margin-left: 6px;
}

.sidebar-footer { padding: 16px 20px; font-size: 12px; opacity: 0.75; line-height: 1.6; border-top: 1px solid rgba(255,255,255,0.1); }

.topbar { grid-area: top; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 20px; font-size: 13px; color: var(--muted); }
.online { color: #16a34a; }
.online::before { content: "● "; }

.inbox-panel, .chat-panel, .profile-panel { background: var(--panel); border-right: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.profile-panel { border-right: none; padding: 16px; gap: 16px; overflow-y: auto; }
.inbox-panel { grid-area: inbox; }
.chat-panel { grid-area: chat; background: #fafbfc; }

.panel-header, .chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.panel-header h1, .chat-header h2 { margin: 0; font-size: 18px; }
.chat-header-main { display: flex; align-items: center; gap: 12px; }
.chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: #e2e8f0;
  flex-shrink: 0;
}
.chat-avatar.placeholder {
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  background: #dbeafe;
}
.channels { margin: 6px 0 0; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tag.wechat { background: #dcfce7; color: #15803d; }
.tag.telegram { background: #dbeafe; color: #1d4ed8; }

.header-actions { display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}
.btn.ghost { background: transparent; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.secondary { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.search-box { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.tabs { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.tab {
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.tab.active { background: var(--selected); color: var(--text); font-weight: 600; }

.conversation-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conversation-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.conversation-item:hover { background: #f8fafc; }
.conversation-item.active { background: var(--selected); }
.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: #e2e8f0;
}
.conv-avatar.placeholder {
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  background: #dbeafe;
}
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.conv-name { font-weight: 600; font-size: 14px; }
.conv-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.conv-preview { font-size: 13px; color: var(--muted); margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; margin-left: auto; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg-system { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0; }
.msg-row { display: flex; flex-direction: column; max-width: 72%; }
.msg-row.out { align-self: flex-end; align-items: flex-end; }
.msg-row.in { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-row.in .bubble { background: var(--in-bubble); border: 1px solid var(--border); }
.msg-row.out .bubble { background: var(--out-bubble); }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 4px; }

.composer { border-top: 1px solid var(--border); background: var(--panel); padding: 12px 16px 16px; }
.composer-tools { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tool { border: none; background: #f1f5f9; border-radius: 6px; padding: 6px 10px; font-size: 12px; cursor: pointer; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer-row textarea {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 14px; }
.card dl { margin: 0; display: grid; grid-template-columns: 92px 1fr; gap: 8px 10px; font-size: 13px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; font-weight: 500; }
.link { display: inline-block; margin-top: 12px; font-size: 13px; color: var(--navy); text-decoration: none; }

.ai-box { background: #f8fafc; border-radius: 10px; padding: 12px; font-size: 13px; line-height: 1.6; }
.ai-meta { margin-top: 10px; font-size: 12px; color: var(--muted); }
.confidence { float: right; color: #16a34a; font-weight: 600; }

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  padding: 40px;
  text-align: center;
}

.typing { margin: 4px 0 0; font-size: 12px; color: #16a34a; min-height: 18px; }

@media (max-width: 1200px) {
  .app {
    grid-template-columns: 200px 280px 1fr;
    grid-template-areas:
      "sidebar top top"
      "sidebar inbox chat";
  }
  .profile-panel { display: none; }
}
