:root {
  color-scheme: dark;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1220;
  color: #e7edf7;
  --panel: #111b2c;
  --panel-soft: #172337;
  --border: rgba(158, 177, 207, .16);
  --muted: #8d9ab0;
  --accent: #68a6ff;
  --green: #58d6a2;
  --danger: #f87979;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 85% 0%, #183152 0, transparent 36%), var(--background, #0b1220); }
button, textarea { font: inherit; }
button { cursor: pointer; border: 0; }
.app-shell { max-width: 1280px; margin: 0 auto; padding: 28px clamp(14px, 3vw, 36px) 42px; }
.topbar, .toolbar, .detail-header, .composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.topbar { margin-bottom: 22px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(24px, 4vw, 34px); letter-spacing: -.04em; }
h2 { font-size: 20px; }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; margin-bottom: 7px; }
.icon-button { width: 40px; height: 40px; border-radius: 12px; background: var(--panel-soft); color: #dce9ff; font-size: 25px; }
.stats-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat-card { background: linear-gradient(135deg, rgba(25, 39, 61, .95), rgba(17, 27, 44, .9)); border: 1px solid var(--border); border-radius: 16px; padding: 16px; }
.stat-card span { color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; font-size: 28px; margin-top: 7px; }
.stat-card.accent strong { color: var(--accent); }
.toolbar { margin-bottom: 12px; }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--panel); border: 1px solid var(--border); }
.segment { padding: 8px 13px; border-radius: 8px; color: var(--muted); background: transparent; font-size: 12px; }
.segment.active { color: #fff; background: #28446d; }
.connection { color: var(--green); font-size: 12px; }
.content-grid { display: grid; grid-template-columns: minmax(260px, 360px) minmax(0, 1fr); gap: 14px; min-height: 570px; }
.conversation-panel, .detail-panel { min-width: 0; background: rgba(17, 27, 44, .88); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; }
.conversation-list { padding: 7px; }
.conversation-item { width: 100%; text-align: left; color: inherit; background: transparent; border-radius: 13px; padding: 14px; margin-bottom: 3px; transition: background .15s ease; }
.conversation-item:hover, .conversation-item.selected { background: #1b2b45; }
.item-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.item-time, .item-preview, .muted { color: var(--muted); font-size: 12px; }
.item-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 8px; }
.badge { min-width: 20px; padding: 2px 6px; border-radius: 99px; text-align: center; background: #2665b4; color: #fff; font-size: 11px; }
.detail-panel { padding: 0; display: flex; flex-direction: column; }
.detail-placeholder { display: grid; place-items: center; align-content: center; text-align: center; height: 100%; padding: 30px; color: var(--muted); }
.placeholder-icon { color: var(--accent); font-size: 52px; margin-bottom: 15px; }
.detail-placeholder h2 { color: #dfe8f7; margin-bottom: 9px; }
.detail-header { padding: 20px 22px; border-bottom: 1px solid var(--border); }
.status-pill { color: var(--green); background: rgba(88, 214, 162, .13); padding: 7px 10px; border-radius: 99px; font-size: 11px; white-space: nowrap; }
.status-pill.closed { color: var(--muted); background: rgba(141, 154, 176, .13); }
.message-list { flex: 1; overflow: auto; min-height: 300px; max-height: 430px; padding: 20px 22px; }
.message { max-width: min(78%, 600px); margin-bottom: 12px; }
.message.customer { margin-right: auto; }
.message.agent { margin-left: auto; }
.message-bubble { padding: 11px 13px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.customer .message-bubble { background: #1d2b40; border-bottom-left-radius: 4px; }
.agent .message-bubble { background: #24548d; border-bottom-right-radius: 4px; }
.message-time { color: var(--muted); font-size: 10px; margin-top: 4px; }
.agent .message-time { text-align: right; }
.composer { padding: 16px 22px 20px; border-top: 1px solid var(--border); }
textarea { width: 100%; resize: vertical; min-height: 54px; color: #edf4ff; background: #0d1727; border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; outline: none; }
textarea:focus { border-color: var(--accent); }
.composer-actions { justify-content: flex-end; margin-top: 10px; }
.primary-button, .secondary-button { padding: 9px 14px; border-radius: 10px; font-size: 12px; font-weight: 650; }
.primary-button { color: #071222; background: var(--accent); }
.secondary-button { color: #d9e5f7; background: #24344c; }
.secondary-button.danger { color: #ffadad; background: rgba(248, 121, 121, .1); }
button:disabled { cursor: not-allowed; opacity: .48; }
.empty-state, .error-state { padding: 40px 18px; color: var(--muted); text-align: center; font-size: 13px; }
.error-state { color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 10px 14px; color: #fff; background: #263b59; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }
@media (max-width: 760px) {
  .app-shell { padding-top: 18px; }
  .content-grid { grid-template-columns: 1fr; min-height: 0; }
  .conversation-panel { max-height: 310px; overflow: auto; }
  .detail-panel { min-height: 560px; }
  .message-list { max-height: none; }
  .detail-placeholder { min-height: 300px; }
}

.view-tabs { display: flex; gap: 6px; margin: 0 0 18px; padding: 4px; border: 1px solid var(--border); border-radius: 13px; background: var(--panel); overflow-x: auto; }
.view-tab { flex: 1; min-width: 72px; padding: 9px 13px; border-radius: 9px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 650; }
.view-tab.active { color: #fff; background: #28446d; }
.dashboard-view, .management-view { margin-bottom: 18px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-size: 21px; }
.health-grid, .metrics-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.health-card, .metric-card { padding: 16px; border: 1px solid var(--border); border-radius: 15px; background: linear-gradient(135deg, rgba(25,39,61,.95), rgba(17,27,44,.9)); }
.health-card span, .metric-card span { display: block; color: var(--muted); font-size: 12px; }
.health-card strong, .metric-card strong { display: block; margin-top: 8px; font-size: 22px; }
.health-card small { display: block; margin-top: 6px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 16px; background: rgba(17,27,44,.88); }
.settings-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.settings-grid label.wide { grid-column: 1 / -1; }
.settings-grid input, .settings-grid textarea, .admin-form input, .admin-form select { width: 100%; box-sizing: border-box; color: #edf4ff; background: #0d1727; border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; outline: none; }
.settings-grid input:focus, .settings-grid textarea:focus, .admin-form input:focus { border-color: var(--accent); }
.settings-grid .toggle-field { display: flex; align-items: center; grid-template-columns: auto 1fr; color: #dce9ff; }
.settings-grid .toggle-field input { width: auto; accent-color: var(--accent); }
.admin-form { display: grid; grid-template-columns: 1fr 140px auto; gap: 8px; margin-bottom: 12px; }
.admins-list { border: 1px solid var(--border); border-radius: 15px; background: rgba(17,27,44,.88); overflow: hidden; }
.admin-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 15px; border-bottom: 1px solid var(--border); }
.admin-row:last-child { border-bottom: 0; }
.admin-row span { display: flex; align-items: center; gap: 10px; }
.admin-row small { padding: 3px 8px; border-radius: 999px; color: var(--accent); background: rgba(103,188,255,.12); text-transform: uppercase; font-size: 10px; }
.danger-link { padding: 5px 9px; border-radius: 8px; color: #ffadad; background: rgba(248,121,121,.1); font-size: 11px; }
@media (max-width: 760px) { .health-grid, .metrics-grid, .settings-grid { grid-template-columns: 1fr 1fr; } .admin-form { grid-template-columns: 1fr 1fr; } .admin-form button { grid-column: 1 / -1; } }
@media (max-width: 470px) { .health-grid, .metrics-grid, .settings-grid { grid-template-columns: 1fr; } .settings-grid label.wide { grid-column: auto; } }
.console-notice { padding: 14px 16px; margin: 0 0 18px; border: 1px solid rgba(103,188,255,.28); border-radius: 12px; color: #bcd9f6; background: rgba(103,188,255,.06); line-height: 1.7; font-size: 13px; }
.console-error { margin-bottom: 16px; padding: 14px; border-radius: 12px; color: var(--danger); background: rgba(248,121,121,.1); }
.console-layout { display: grid; grid-template-columns: 230px minmax(0,1fr); gap: 20px; }
.console-sidebar, .console-card { border: 1px solid var(--border); border-radius: 14px; padding: 18px; background: var(--panel); }
.console-sidebar { align-self: start; }
.console-sidebar h3, .console-card h3 { margin: 0 0 12px; font-size: 15px; }
.console-merchant-list { display: grid; gap: 8px; }
.console-shop { padding: 12px; border: 1px solid transparent; border-radius: 10px; background: #152239; color: #edf4ff; text-align: left; }
.console-shop.selected { border-color: var(--accent); background: #203553; }
.console-shop strong, .console-shop span { display: block; overflow-wrap: anywhere; }
.console-shop span { margin-top: 6px; color: var(--muted); font-size: 11px; }
.console-create { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 15px; }
.console-card { margin-bottom: 14px; }
.console-create summary, .console-card summary { cursor: pointer; font-weight: 650; font-size: 14px; margin-bottom: 14px; }
.console-form { display: grid; gap: 14px; }
.console-two-columns { grid-template-columns: repeat(2,minmax(0,1fr)); }
.console-form label { display: grid; gap: 7px; color: #cedaeb; font-size: 12px; }
.console-form input { width: 100%; min-width: 0; box-sizing: border-box; padding: 11px; border: 1px solid var(--border); border-radius: 9px; background: #0d1727; color: #edf4ff; }
.console-form small { color: var(--muted); line-height: 1.6; }
.console-form .wide { grid-column: 1 / -1; }
.console-form .toggle-field { display: flex; align-items: center; gap: 9px; }
.console-form .toggle-field input { width: auto; accent-color: var(--accent); }
.console-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.console-steps { display: flex; gap: 12px; flex-wrap: wrap; list-style: none; margin: 0 0 18px; padding: 0; color: var(--muted); font-size: 12px; }
.console-bot-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 0; border-top: 1px solid var(--border); margin-top: 16px; }
.console-bot-row p, .console-bot-row small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.console-empty { padding: 18px 0 4px; color: var(--muted); line-height: 1.6; font-size: 12px; }
.console-detail { min-width: 0; }
.console-detail .muted { line-height: 1.65; font-size: 12px; }
.console-detail .status-pill { white-space: nowrap; }
#consoleView button:focus-visible, .console-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 760px) { .console-layout { grid-template-columns: 1fr; } .console-merchant-list { grid-template-columns: repeat(2,minmax(0,1fr)); } .console-bot-row { align-items: flex-start; flex-direction: column; } }
@media (max-width: 470px) { .console-two-columns { grid-template-columns: 1fr; } .console-form .wide { grid-column: auto; } }

/* ============ 角色闸门：非管理员访问遮罩 ============ */
.gate-overlay { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 24px; background: #0b1220; }
.gate-card { max-width: 420px; width: 100%; text-align: center; padding: 32px 24px; border: 1px solid var(--border); border-radius: 16px; background: #101827; }
.gate-icon { font-size: 40px; line-height: 1; margin-bottom: 16px; }
.gate-title { margin: 0 0 12px; font-size: 18px; color: #edf4ff; }
.gate-text { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.gate-hint { margin: 16px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
