:root {
  --ink: #17213f;
  --muted: #7b8498;
  --line: #e7ebf3;
  --panel: #ffffff;
  --bg: #f4f7fc;
  --blue: #2563eb;
  --blue2: #133a9c;
  --green: #16a56d;
  --red: #d93655;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
a { color: var(--blue); text-decoration: none; }
.hidden { display: none !important; }
.btn { border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); padding: 9px 14px; cursor: pointer; font-weight: 700; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(23,33,63,.08); }
.btn.primary { color: #fff; border-color: var(--blue); background: linear-gradient(135deg, var(--blue), var(--blue2)); }
.btn.danger { color: #fff; border-color: var(--red); background: var(--red); }
.btn.danger-lite { color: var(--red); background: #fff1f3; border-color: #ffd5dc; }
.muted { color: var(--muted); font-size: 13px; }
.error { min-height: 22px; color: var(--red); font-size: 13px; margin-top: 10px; }

/* login */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left,#dbeafe,transparent 40%),var(--bg); }
.login-card { width: min(420px,100%); background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 30px; box-shadow: 0 28px 80px rgba(23,33,63,.14); }
.login-card img { width: 220px; max-width: 100%; display: block; margin: 0 auto 18px; }
.login-card h1 { text-align: center; margin: 0 0 8px; }
.login-card p { text-align: center; color: var(--muted); margin: 0 0 20px; }
.login-card label, .settings-form label { display: grid; gap: 7px; color: #526079; font-size: 13px; margin-top: 13px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--ink); background: #fff; outline: none; }
input:focus, textarea:focus, select:focus { border-color: #8eb4ff; box-shadow: 0 0 0 3px #e7efff; }
.login-card .btn { width: 100%; margin-top: 18px; }

/* console */
.console-page { overflow: hidden; }
.topbar { height: 68px; display: flex; justify-content: space-between; align-items: center; padding: 0 22px; background: #fff; border-bottom: 1px solid var(--line); }
.brand-mini { display: flex; align-items: center; gap: 10px; }
.brand-mini img { width: 38px; height: 38px; border-radius: 12px; }
.brand-mini strong { font-size: 20px; }
.brand-mini span { color: var(--muted); font-size: 13px; }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.console-grid { height: calc(100vh - 68px); display: grid; grid-template-columns: 190px 1fr; }
.side-nav { background: #101a3a; padding: 14px 10px; }
.nav-item { width: 100%; color: #ccd5f0; background: transparent; border: 0; border-radius: 10px; padding: 12px; text-align: left; cursor: pointer; margin-bottom: 5px; }
.nav-item:hover, .nav-item.active { background: #243562; color: #fff; }
.content { min-width: 0; overflow: auto; padding: 22px; }
.panel { max-width: 1540px; margin: 0 auto; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.section-head h1 { margin: 0 0 6px; font-size: 27px; }
.section-head p { margin: 0; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(4,minmax(150px,1fr)); gap: 14px; margin-bottom: 18px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 30px; margin-top: 7px; color: var(--blue2); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.card-title { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.card-title h2 { margin: 0; font-size: 17px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 680px; }
th, td { padding: 11px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 700; background: #fbfcfe; }
.mini-input { min-width: 130px; margin-top: 6px; padding: 7px 8px; border-radius: 8px; font-size: 12px; }
.avatar-edit-cell { min-width: 230px; }
.agent-avatar-preview { width: 44px; height: 44px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #fff; vertical-align: middle; margin-right: 8px; }
.agent-avatar { max-width: 210px; }
.mini-upload { display: inline-flex; margin-top: 6px; padding: 7px 10px; font-size: 12px; }
.inline-check { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.inline-check input { width: auto; }
.agent-save, .admin-save, .agent-toggle, .admin-toggle { margin: 2px; }
.status-online { color: var(--green); font-weight: 800; }
.status-offline { color: var(--muted); }
.url-cell { max-width: 300px; overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: repeat(5,minmax(140px,1fr)); gap: 10px; align-items: center; }
.form-grid .btn { min-height: 42px; }
.quick-editor { display: grid; grid-template-columns: 240px 1fr auto; gap: 12px; align-items: start; }
.quick-editor textarea { min-height: 170px; }
.conversation-layout { display: grid; grid-template-columns: 300px minmax(420px,1fr) 270px; gap: 14px; min-height: 680px; }
.conversation-list-card, .conversation-detail, .conversation-info { min-width: 0; display: flex; flex-direction: column; }
.conversation-list { overflow: auto; min-height: 0; }
.conversation-item { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 12px 8px; cursor: pointer; }
.conversation-item.active { background: #eef5ff; }
.conversation-item strong { display: block; }
.conversation-item small { display: block; color: var(--muted); margin-top: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.detail-head { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.detail-head h2 { margin: 0 0 5px; font-size: 18px; }
.transfer-box { display: flex; gap: 7px; align-items: center; padding: 7px; border: 1px solid #dce7ff; border-radius: 12px; background: #f6f9ff; }
.transfer-label { white-space: nowrap; color: var(--blue2); font-size: 12px; font-weight: 800; }
.detail-messages { flex: 1; min-height: 420px; overflow: auto; padding: 14px 3px; }
.detail-messages.empty { display: grid; place-items: center; color: var(--muted); }
.message { display: flex; flex-direction: column; align-items: flex-start; margin: 11px 0; }
.message.mine { align-items: flex-end; }
.message-bubble { max-width: min(76%, 620px); padding: 10px 12px; border-radius: 12px; background: #f2f5fa; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.message.mine .message-bubble { color: #fff; background: linear-gradient(135deg,var(--blue),var(--blue2)); }
.message-meta { margin-top: 4px; color: var(--muted); font-size: 11px; }
.message-media { max-width: min(76%, 420px); border-radius: 12px; border: 1px solid var(--line); }
.message-video { max-width: min(76%, 420px); border-radius: 12px; background: #111; }
.message-media-link { display: inline-block; margin-top: 5px; font-size: 12px; }
.quick-replies { display: flex; gap: 6px; overflow: auto; padding: 8px 0; }
.quick-replies button { flex: 0 0 auto; border: 1px solid #dce7ff; border-radius: 999px; background: #f6f9ff; color: var(--blue2); padding: 7px 10px; cursor: pointer; }
.composer { border-top: 1px solid var(--line); padding-top: 10px; }
.composer-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 8px; }
.info-list { display: grid; gap: 10px; color: #4d5a71; font-size: 13px; overflow-wrap: anywhere; }
.info-list b { color: var(--ink); }
.customer-note-box { display: grid; gap: 8px; padding: 12px; border: 1px solid #dce7ff; border-radius: 14px; background: #f7fbff; }
.customer-note-box textarea { min-height: 110px; resize: vertical; font-size: 13px; background: #fff; }
.customer-note-box .btn { justify-self: start; padding: 8px 12px; }
.backup-result { white-space: pre-wrap; color: var(--green); background: #f1fff8; border-radius: 10px; padding: 10px; min-height: 0; }
.settings-form { max-width: 760px; }
.settings-form .check { display: flex; align-items: center; gap: 8px; }
.settings-form .check input { width: auto; }
.settings-actions { display: flex; gap: 8px; margin-top: 18px; }
.console-toast { position: fixed; right: 22px; top: 82px; z-index: 9999; max-width: min(360px,calc(100vw - 44px)); padding: 11px 15px; border-radius: 12px; color: #fff; background: var(--green); box-shadow: 0 18px 45px rgba(23,33,63,.18); opacity: 0; transform: translateY(-8px); pointer-events: none; transition: .18s ease; font-size: 14px; font-weight: 700; }
.console-toast.error { background: var(--red); }
.console-toast.show { opacity: 1; transform: translateY(0); }

/* customer */
.customer-v2 { background: linear-gradient(135deg,#e8efff,#f9fbff); }
.customer-shell { width: min(560px,100%); height: 100vh; margin: 0 auto; display: grid; grid-template-rows: auto auto minmax(0,1fr) auto auto; background: #fff; box-shadow: 0 0 50px rgba(23,33,63,.12); }
.customer-top { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: #fff; background: linear-gradient(135deg,#14245f,#2563eb 58%,#33d5e4); }
.customer-top img { width: 48px; height: 48px; object-fit: cover; border-radius: 15px; background: #fff; }
.customer-top h1 { margin: 0; font-size: 19px; }
.customer-top p { margin: 4px 0 0; font-size: 12px; opacity: .9; }
.online-dot { margin-left: auto; font-size: 12px; background: rgba(255,255,255,.17); padding: 5px 8px; border-radius: 999px; }
.customer-notice { min-height: 38px; padding: 10px 14px; color: #35507d; background: #f2f7ff; font-size: 13px; }
.customer-messages { min-height: 0; overflow: auto; padding: 14px; background: #f6f8fc; }
.customer-quick { display: flex; gap: 7px; overflow: auto; padding: 8px 12px 0; background: #fff; }
.customer-quick button { flex: 0 0 auto; border: 1px solid #dce7ff; border-radius: 999px; background: #f6f9ff; color: var(--blue2); padding: 7px 10px; cursor: pointer; }
.customer-compose { padding: 8px 12px 12px; border-top: 1px solid var(--line); background: #fff; }
.consent-line { display: none; color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.consent-line input { width: auto; vertical-align: middle; }
.compose-row { display: flex; gap: 7px; align-items: flex-end; }
.compose-row textarea { flex: 1; min-width: 0; min-height: 42px; max-height: 120px; resize: none; }
.media-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; height: 40px; padding: 0 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--blue2); background: #f8fbff; cursor: pointer; font-size: 12px; }
.emoji-panel { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 -10px 30px rgba(23,33,63,.08); }
.emoji-panel button { height: 34px; border: 0; border-radius: 9px; background: #f6f9ff; cursor: pointer; font-size: 20px; line-height: 1; }
.emoji-panel button:hover { background: #eaf1ff; transform: translateY(-1px); }
.customer-foot { display: none; text-align: right; color: var(--muted); font-size: 11px; margin-top: 7px; }
.customer-shell .message-row { width: 100%; display: flex; align-items: flex-start; gap: 8px; }
.customer-shell .message.mine .message-row { justify-content: flex-end; }
.customer-shell .message-stack { max-width: 84%; display: flex; flex-direction: column; align-items: flex-start; }
.customer-shell .message.mine .message-stack { align-items: flex-end; }
.customer-shell .message-avatar { width: 34px; height: 34px; flex: 0 0 34px; object-fit: cover; border-radius: 11px; padding: 3px; background: #fff; border: 1px solid #dfe8fb; box-shadow: 0 4px 14px rgba(23,33,63,.08); }
.customer-shell .message-bubble { max-width: 100%; }
.customer-shell .message-media, .customer-shell .message-video { max-width: 100%; }

/* responsive */
@media (max-width: 1080px) {
  .conversation-layout { grid-template-columns: 260px minmax(360px,1fr); }
  .conversation-info { grid-column: 1 / -1; min-height: 110px; }
  .form-grid { grid-template-columns: repeat(2,minmax(140px,1fr)); }
}
@media (max-width: 760px) {
  .console-page { overflow: auto; }
  .topbar { padding: 0 12px; }
  .brand-mini span { display: none; }
  .console-grid { height: auto; min-height: calc(100vh - 68px); grid-template-columns: 1fr; }
  .side-nav { display: flex; gap: 5px; overflow-x: auto; padding: 8px; }
  .nav-item { min-width: 90px; text-align: center; }
  .content { padding: 12px; }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .conversation-layout { grid-template-columns: 1fr; min-height: 0; }
  .conversation-list-card { min-height: 260px; }
  .conversation-detail { min-height: 620px; }
  .conversation-info { grid-column: auto; }
  .quick-editor { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .section-head { align-items: stretch; flex-direction: column; }
}
