:root {
  --wecom-green: #07c160;
  --wecom-green-dark: #06ad56;
  --bubble-self: #95ec69;
  --bubble-other: #ffffff;
  --bg-sidebar: #f7f7f7;
  --bg-chat: #ededed;
  --border: #e0e0e0;
  --text-primary: #191919;
  --text-secondary: #888;
  --text-muted: #b2b2b2;
  --sidebar-w: 360px;
  --header-h: 56px;
  --topbar-h: 48px;
  --font: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-chat);
  height: 100vh;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.topbar-wecom-hint {
  margin-left: 16px;
  padding: 4px 10px;
  border-radius: 6px;
  background: #fff7e6;
  color: #ad6800;
  font-size: 12px;
}
.topbar-wecom-hint a { color: #d48806; font-weight: 600; }

.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--wecom-green), #059669);
  border-radius: 6px;
  display: grid; place-items: center;
  color: #fff; font-size: 14px; font-weight: 700;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--text-secondary); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { font-size: 12px; color: var(--text-secondary); }
.btn-text {
  background: none; border: none; cursor: pointer;
  font-size: 13px; color: var(--text-secondary); font-family: inherit;
}
.btn-text:hover { color: var(--wecom-green-dark); }

.app-body { display: flex; flex: 1; overflow: hidden; min-height: 0; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-tools {
  padding: 12px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.search-box {
  display: flex; align-items: center;
  background: #ededed; border-radius: 6px;
  padding: 7px 10px; gap: 6px;
}
.search-box input {
  border: none; background: transparent;
  font-size: 13px; flex: 1; outline: none; font-family: inherit;
}
.search-box svg { opacity: .4; flex-shrink: 0; }

.filter-section {
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.filter-row { display: flex; align-items: center; gap: 8px; }
.filter-label { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }
.filter-trigger {
  flex: 1; display: flex; align-items: center; justify-content: space-between;
  gap: 6px; padding: 7px 10px; background: #ededed;
  border: 1px solid transparent; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-family: inherit;
  min-width: 0;
}
.filter-trigger.open { background: #fff; border-color: var(--wecom-green); }
.filter-trigger-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-trigger-hint { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.filter-trigger svg { flex-shrink: 0; opacity: .45; transition: transform .2s; }
.filter-trigger.open svg { transform: rotate(180deg); }

.filter-dropdown {
  display: none; position: absolute; left: 12px; right: 12px;
  top: calc(100% - 4px); background: #fff;
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 50; overflow: hidden;
}
.filter-dropdown.open { display: flex; flex-direction: column; }
.filter-search {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-bottom: 1px solid #f0f0f0; background: #fafafa;
}
.filter-search input {
  border: none; background: transparent; font-size: 13px;
  flex: 1; outline: none; font-family: inherit;
}
.filter-options { max-height: 240px; overflow-y: auto; }
.filter-option {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; cursor: pointer; font-size: 13px;
}
.filter-option:hover { background: #f5f5f5; }
.filter-option.active { background: #e8f8ef; color: var(--wecom-green-dark); font-weight: 500; }
.filter-option.hidden { display: none; }
.filter-option-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.filter-option-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-option-check {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid #ccc; flex-shrink: 0;
}
.filter-option.active .filter-option-check {
  border-color: var(--wecom-green); background: var(--wecom-green);
  box-shadow: inset 0 0 0 2px #fff;
}
.filter-option-count { font-size: 11px; color: var(--text-muted); margin-left: 8px; }
.filter-empty { padding: 20px; text-align: center; font-size: 12px; color: var(--text-muted); display: none; }
.filter-empty.show { display: block; }
.filter-backdrop { display: none; position: fixed; inset: 0; z-index: 40; }
.filter-backdrop.show { display: block; }

.date-filter-row { align-items: flex-start; margin-top: 10px; }
.date-presets {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.date-chip {
  border: 1px solid transparent;
  background: #ededed;
  color: var(--text-primary);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
}
.date-chip:hover { background: #e4e4e4; }
.date-chip.active {
  background: #e8f8ef;
  color: var(--wecom-green-dark);
  border-color: #b7e6c9;
  font-weight: 500;
}
.date-custom-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  margin-top: 8px;
}
.date-custom-row[hidden] { display: none !important; }
.date-custom-row input[type="date"] {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  box-sizing: border-box;
}
.date-sep { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.date-apply {
  flex-shrink: 0;
  border: none;
  background: var(--wecom-green);
  color: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.date-apply:hover { filter: brightness(0.96); }

.conv-list { flex: 1; overflow-y: auto; }
.conv-list-status {
  padding: 10px 12px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-sidebar);
  flex-shrink: 0;
}
.conv-list-status[hidden] { display: none !important; }
.conv-empty { padding: 40px 16px; text-align: center; font-size: 13px; color: var(--text-muted); }

.conv-item {
  display: flex; gap: 12px; padding: 12px 16px;
  cursor: pointer; border-bottom: 1px solid #f0f0f0;
  transition: background .12s; position: relative;
}
.conv-item:hover { background: #ebebeb; }
.conv-item.active { background: #d9d9d9; }
.conv-item.active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--wecom-green);
}

.avatar {
  width: 44px; height: 44px; border-radius: 6px;
  flex-shrink: 0; display: grid; place-items: center;
  font-size: 18px; font-weight: 600; color: #fff;
  background-size: cover; background-position: center;
}

.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.conv-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; margin-left: 8px; }
.conv-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.tag-mini { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: #eef6ff; color: #2563eb; }
.tag-staff { background: #f0fdf4; color: #059669; }

.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--bg-chat); min-width: 0; min-height: 0; }
.chat-header {
  height: var(--header-h); background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 12px;
  flex-shrink: 0;
}
.chat-header .avatar { width: 36px; height: 36px; font-size: 15px; }
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { font-size: 15px; font-weight: 600; }
.chat-title p { font-size: 11px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 当前会话标题栏：重置上文是一次性按钮，点过就变成「下一条按新对话」 */
.chat-reset { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chat-reset .btn-secondary:disabled { background: #fff7e6; border-color: #ffd591; color: #d46b08; opacity: 1; cursor: default; }

.chat-messages {
  flex: 1 1 auto;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 16px 20px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.chat-messages.has-opendata {
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.chat-timeline-mount {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
}

.chat-messages.has-opendata .wecom-timeline-inner {
  width: 100%;
  height: 100%;
}

.chat-timeline-mount iframe {
  width: 100% !important;
  max-width: 100% !important;
  border: none;
  display: block;
}

.chat-notice {
  align-self: center;
  max-width: 92%;
  margin: 0 0 12px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}
.chat-notice a { font-weight: 600; }
.chat-notice-info { background: #f5f5f5; color: #666; }
.chat-notice-warn { background: #fff7e6; color: #ad6800; }
.chat-notice-error { background: #fff1f0; color: #cf1322; }

.chat-placeholder { margin: auto; color: var(--text-muted); font-size: 14px; }
.chat-tip {
  margin: 12px 16px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff8e6;
  color: #8a6d1d;
  font-size: 13px;
  line-height: 1.5;
}
.chat-tip-warn {
  background: #fff1f0;
  color: #a8071a;
  border: 1px solid #ffccc7;
}

.bubble.encrypted { background: #f0f0f0 !important; color: #888; font-size: 13px; box-shadow: none; }
.bubble.media-rich { padding: 6px; max-width: min(100%, 360px); }
.bubble-media { display: block; max-width: 100%; max-height: 360px; border-radius: 4px; }
.bubble-audio { display: block; width: min(240px, 100%); margin: 2px 0; }
.bubble-transcript { margin-top: 6px; padding: 4px 6px 2px; font-size: 13px; line-height: 1.45; color: #191919; white-space: pre-wrap; }
.bubble-file { color: #576b95; text-decoration: none; word-break: break-all; }
.bubble-file:hover { text-decoration: underline; }

.date-divider { text-align: center; font-size: 11px; color: var(--text-muted); margin: 16px 0 12px; }
.date-divider span { background: rgba(0,0,0,.06); padding: 2px 10px; border-radius: 4px; }

.msg-row { display: flex; gap: 10px; align-items: flex-start; max-width: min(82%, 640px); margin-bottom: 16px; }
.msg-row.self { flex-direction: row-reverse; margin-left: auto; }
.msg-row .avatar { width: 36px; height: 36px; font-size: 14px; flex-shrink: 0; }
.msg-content { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: 100%; flex: 1; }
.msg-row.self .msg-content { align-items: flex-end; }
.msg-name { font-size: 11px; color: var(--text-muted); padding: 0 4px; }

.bubble {
  padding: 10px 14px; border-radius: 6px;
  font-size: 14px; line-height: 1.55;
  word-break: break-word; overflow-wrap: anywhere;
  max-width: 100%;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.msg-row:not(.self) .bubble { background: var(--bubble-other); border-top-left-radius: 2px; }
.msg-row.self .bubble { background: var(--bubble-self); border-top-right-radius: 2px; }
.bubble.revoked { background: rgba(0,0,0,.04) !important; color: var(--text-muted); font-style: italic; font-size: 12px; box-shadow: none; }
.bubble.media { color: var(--text-secondary); font-size: 13px; }

.msg-time { font-size: 10px; color: var(--text-muted); padding: 0 4px; }

.chat-footer {
  height: 40px; background: #f5f5f5; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-muted);
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .sidebar { width: 100%; max-width: 100%; }
  .chat-panel { display: none; }
  .chat-panel.show { display: flex; position: absolute; inset: var(--topbar-h) 0 0 0; z-index: 5; }
}

.opendata-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #f0f0f0;
  color: var(--text-secondary);
}
.opendata-badge.warn { background: #fff7e6; color: #ad6800; }
.opendata-badge.err { background: #fff1f0; color: #cf1322; }
.opendata-badge.ok { background: #f6ffed; color: #389e0d; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none !important; }
.modal-card {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-hint {
  font-size: 12px; line-height: 1.55; color: var(--text-secondary);
  background: #f7f7f7; border-radius: 6px; padding: 10px 12px;
}
.modal-hint code {
  font-size: 11px; background: #eee; padding: 1px 4px; border-radius: 3px;
}
.opendata-status {
  font-size: 13px; line-height: 1.5;
  padding: 10px 12px; border-radius: 6px;
  background: #fafafa; border: 1px solid var(--border);
  white-space: pre-wrap;
}
.opendata-status.ok { border-color: #b7eb8f; background: #f6ffed; }
.opendata-status.warn { border-color: #ffe58f; background: #fffbe6; }
.opendata-status.err { border-color: #ffa39e; background: #fff1f0; }
.modal-label { font-size: 12px; color: var(--text-secondary); }
.modal-textarea {
  width: 100%; resize: vertical; min-height: 72px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-size: 12px; font-family: Consolas, monospace;
  outline: none;
}
.modal-textarea:focus { border-color: var(--wecom-green); }
.modal-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-primary {
  border: none; border-radius: 6px; padding: 7px 14px; cursor: pointer;
  background: var(--wecom-green); color: #fff; font-size: 13px; font-family: inherit;
}
.btn-primary:hover { background: var(--wecom-green-dark); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary {
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 14px; cursor: pointer;
  background: #fff; color: var(--text-primary); font-size: 13px; font-family: inherit;
}
.btn-secondary:hover { border-color: var(--wecom-green); color: var(--wecom-green-dark); }
.btn-secondary:disabled { opacity: .55; cursor: not-allowed; }
.opendata-log {
  font-size: 11px; background: #111; color: #d6ffd6;
  padding: 10px; border-radius: 6px; max-height: 140px; overflow: auto;
  white-space: pre-wrap; word-break: break-all;
}
.opendata-ext-row {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  background: #f7f7f7;
}
.opendata-ext-row.on { color: #389e0d; background: #f6ffed; }
.opendata-ext-row.off { color: #ad6800; background: #fffbe6; }

.modal-card-wide { width: min(820px, 96vw); }
.modal-check-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; margin: 4px 0 8px;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 720px) {
  .filter-grid { grid-template-columns: 1fr; }
}
.check-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  padding: 6px;
}
.check-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.check-list label:hover { background: #f5faf7; }
.check-list .muted { color: var(--text-secondary); font-size: 11px; }
.check-list .empty { color: var(--text-secondary); padding: 12px; font-size: 12px; }
.msg-origin {
  font-size: 11px;
  margin-left: 6px;
  color: #888;
}
.msg-origin.ai { color: #1a73e8; }
.msg-origin.human { color: #e67e22; }
