:root {
  --nav: #ffffff;
  --blue: #1763ff;
  --green: #03b637;
  --red: #f04444;
  --text: #1d2939;
  --muted: #768397;
  --line: #e5e8ef;
  --bg: #f4f7fb;
  --card: #fff;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: grid; grid-template-columns: 278px 1fr; color: var(--text); background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.admin-sidebar { min-height: 100vh; padding: 48px 0 20px; background: var(--nav); color: #13233a; border-right: 1px solid #e6edf5; box-shadow: 8px 0 26px rgba(15, 23, 42, .04); }
.sidebar-brand { display: block; min-height: 56px; padding: 0 32px; margin-bottom: 48px; color: #1594df; }
.sidebar-brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 27px; font-weight: 900; letter-spacing: 0; }
.sidebar-nav { display: grid; gap: 8px; }
.side-item { width: 100%; min-height: 50px; border: 0; border-radius: 0; background: transparent; color: #13233a; text-align: left; padding: 0 32px 0 52px; font-size: 17px; font-weight: 500; }
.side-item:hover { color: #1594df; background: #f7f9fc; }
.side-item.active { background: #f2f4f7; color: #13233a; font-weight: 800; box-shadow: inset 4px 0 0 #1594df; }

.admin-main { min-width: 0; }
.admin-top { display: flex; justify-content: space-between; align-items: center; height: 72px; padding: 0 28px; background: #fff; border-bottom: 1px solid #e8eef6; box-shadow: 0 2px 16px rgba(16, 35, 66, .04); color: var(--muted); }
.admin-user { display: flex; align-items: center; gap: 12px; color: var(--text); }
.admin-user span { color: #8a95a6; font-size: 13px; }
.admin-user strong { font-size: 16px; }
.admin-user .avatar { display: none; }
.admin-user button { border: 0; border-radius: 8px; background: #f04444; color: #fff; padding: 9px 15px; font-weight: 800; }

.panel { display: none; padding: 24px 26px; }
.panel.active { display: block; }
.card { min-height: 268px; padding: 24px; border-radius: 8px; background: var(--card); box-shadow: 0 12px 34px rgba(16, 35, 66, .06); }
.dashboard-card { min-height: 268px; padding: 24px; border-radius: 8px; background: var(--card); box-shadow: 0 12px 34px rgba(16, 35, 66, .06); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.head-left { display: flex; align-items: center; gap: 12px; }
h2 { margin: 0; font-size: 18px; }
.visit-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.visit-summary article { min-height: 118px; display: grid; align-content: space-between; border: 1px solid #dbe5f3; border-radius: 8px; padding: 18px; background: linear-gradient(180deg, #ffffff, #f7fbff); }
.visit-summary span { color: #64748b; font-weight: 800; }
.visit-summary strong { color: #0f172a; font-size: 34px; line-height: 1; }
.dashboard-card h3 { margin: 18px 0 12px; font-size: 16px; }
.agent-stat-list { display: grid; gap: 10px; }
.agent-stat-row { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.5fr); gap: 18px; align-items: center; border: 1px solid #e2e8f0; border-radius: 8px; padding: 14px 16px; background: #fff; }
.agent-stat-row strong, .agent-stat-row span { display: block; }
.agent-stat-row span { margin-top: 4px; color: #7b8493; font-size: 13px; }
.agent-stat-row dl { display: grid; grid-template-columns: repeat(3, auto minmax(42px, 1fr)); gap: 4px 10px; align-items: baseline; margin: 0; }
.agent-stat-row dt { color: #7b8493; font-size: 12px; }
.agent-stat-row dd { margin: 0; color: #1763ff; font-size: 20px; font-weight: 900; }
.empty-dashboard { min-height: 96px; display: grid; place-items: center; border: 1px dashed #cbd5e1; border-radius: 8px; color: #94a3b8; background: #f8fafc; }
.hidden { display: none !important; }

table { width: 100%; margin-top: 16px; border-collapse: separate; border-spacing: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
th, td { padding: 14px 12px; border-bottom: 1px solid var(--line); text-align: center; font-size: 14px; vertical-align: middle; }
th { background: #f7f8fb; color: #475467; font-weight: 800; }
tr:last-child td { border-bottom: 0; }

.face { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: #dbeafe; }
.key { color: #667085; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; color: #667085; }
.status-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #05c752; }
.status-dot.off::before { background: #98a2b3; }
.pill { border: 0; border-radius: 6px; padding: 8px 11px; color: #fff; font-size: 13px; }
.primary, .success { border: 0; border-radius: 7px; min-height: 34px; padding: 0 14px; color: #fff; font-weight: 800; }
.primary { background: var(--blue); }
.success { background: var(--green); }
.danger { background: var(--red); }
.embed { background: #0f766e; }
.light { background: #f3f6fb; color: #344054; border: 1px solid #dbe2ed; }
.ghost { min-height: 32px; border: 0; border-radius: 6px; background: #f3f6fb; color: #344054; padding: 0 12px; }
.ops { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.link-cell { display: flex; justify-content: center; gap: 8px; }
.unread-badge { display: inline-grid; place-items: center; min-width: 28px; height: 24px; padding: 0 8px; border-radius: 999px; background: #f04444; color: #fff; font-size: 12px; font-weight: 900; }
.unread-badge.empty { background: #eef2f7; color: #98a2b3; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tag { display: inline-flex; gap: 5px; align-items: center; min-height: 28px; border-radius: 6px; background: #eef5ff; color: var(--blue); padding: 0 10px; }
.tag button { border: 0; background: transparent; color: #ff5a5a; }
.muted-tag { background: #f2f4f7; color: #98a2b3; }
.content-cell { max-width: 430px; text-align: left; line-height: 1.55; word-break: break-word; }
.empty-text { color: #98a2b3; font-weight: 400; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 22px; background: rgba(0,0,0,.46); backdrop-filter: blur(4px); }
.modal.hidden { display: none; }
.modal-card { position: relative; width: min(640px, 100%); max-height: calc(100vh - 44px); overflow-y: auto; border-radius: 12px; background: #fff; box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.modal-card.wide { width: min(720px, 100%); }
.modal-card h2 { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-card label { display: grid; gap: 8px; padding: 0 20px; margin-top: 18px; font-weight: 700; }
.modal-card input, .modal-card textarea, .modal-card select { width: 100%; min-height: 42px; border: 1px solid #d2d8e3; border-radius: 8px; padding: 0 12px; color: #344054; }
.modal-card textarea { padding: 12px; resize: vertical; line-height: 1.5; }
.modal-close { position: absolute; top: 14px; right: 18px; border: 0; background: transparent; color: #8a95a6; font-size: 24px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 0 20px; }
.two-col label { padding: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 36px; padding: 16px 20px; border-top: 1px solid var(--line); background: #fff; }
.fit { margin: 10px 20px 0; }
.tag-box { min-height: 52px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; padding: 10px; }
.toast { position: fixed; right: 24px; bottom: 24px; transform: translateY(14px); opacity: 0; background: #101828; color: #fff; padding: 10px 14px; border-radius: 6px; transition: .18s; }
.toast.show { transform: translateY(0); opacity: 1; }
.qr-card { width: min(420px, 100%); }
.qr-body { display: grid; justify-items: center; gap: 14px; padding: 22px; }
.qr-body img { width: 190px; height: 190px; border: 1px solid var(--line); border-radius: 8px; }
.qr-body input { width: 100%; min-height: 40px; border: 1px solid #d2d8e3; border-radius: 8px; padding: 0 10px; }
.embed-card { width: min(1040px, 100%); }
.embed-layout { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(300px, .86fr); gap: 18px; padding: 18px 20px 0; }
.embed-config { border: 1px solid var(--line); border-radius: 8px; padding: 0 0 18px; background: #fbfcff; }
.embed-config label { margin-top: 14px; }
.two-col.compact { padding: 0 14px; gap: 12px; }
.embed-config > label { padding: 0 14px; }
.embed-preview { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #f8fafc; }
.embed-preview-page { position: relative; min-height: 250px; overflow: hidden; border-radius: 8px; background: linear-gradient(180deg, #fff, #eef4fb); border: 1px solid #e1e8f2; }
.preview-line { width: 68%; height: 18px; margin: 24px; border-radius: 999px; background: #d8e1ee; }
.preview-line.short { width: 42%; margin-top: -10px; }
.preview-box { position: absolute; display: grid; place-items: center; min-width: 58px; min-height: 46px; padding: 0 14px; border-radius: 999px; color: #fff; font-weight: 900; box-shadow: 0 16px 34px rgba(15,23,42,.18); }
.preview-box.pos-right-bottom { right: 18px; bottom: 18px; }
.preview-box.pos-left-bottom { left: 18px; bottom: 18px; }
.preview-box.pos-right-center { right: 18px; top: 50%; transform: translateY(-50%); }
.preview-box.pos-left-center { left: 18px; top: 50%; transform: translateY(-50%); }
.preview-box.mode-iframe { inset: 58px 28px 24px; border-radius: 8px; min-height: auto; }
.preview-box.mode-drawer { top: 0; right: 0; bottom: 0; width: 36%; min-height: auto; border-radius: 0; }
.preview-box.mode-bottomBar { left: 0; right: 0; bottom: 0; border-radius: 0; }
.embed-tabs { display: flex; gap: 8px; padding: 18px 20px 0; }
.embed-tabs button { min-height: 36px; border: 1px solid #d7e0ec; border-radius: 7px; background: #fff; color: #344054; padding: 0 13px; font-weight: 800; }
.embed-tabs button.active { border-color: var(--blue); color: var(--blue); background: #eef5ff; }
.embed-tab-panel { display: none; padding: 14px 20px 20px; }
.embed-tab-panel.active { display: block; }
.embed-tab-panel textarea { width: 100%; min-height: 156px; border: 1px solid #d2d8e3; border-radius: 8px; padding: 12px; background: #0f172a; color: #d8e8ff; font-family: Consolas, ui-monospace, monospace; font-size: 13px; line-height: 1.55; resize: vertical; }
.modal-actions.inline { margin-top: 12px; padding: 0; border: 0; }
.embed-guide { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.embed-guide article { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #fff; }
.embed-guide strong { color: #13233a; }
.embed-guide span { color: #667085; line-height: 1.7; }
.chat-modal { padding: 14px; overflow: hidden; }
.chat-card { width: min(1480px, 100%); height: calc(100vh - 28px); display: grid; grid-template-rows: auto minmax(0, 1fr); padding: 0; overflow: hidden; }
.chat-card iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.direct-chat-card { max-height: none; }
.direct-chat-card > h2 { min-height: 58px; padding: 16px 20px; }
.admin-chat-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr) 292px; min-height: 0; height: 100%; overflow: hidden; background: #fff; }
.admin-chat-sidebar { min-height: 0; overflow: hidden; border-right: 1px solid var(--line); background: #f5f6f9; }
.admin-chat-sidebar .group-title { width: 100%; height: 38px; border: 0; border-bottom: 1px solid #e3e7ef; background: #fff; color: #667085; text-align: left; padding: 0 12px; font-weight: 700; }
.admin-chat-sidebar .group-title:hover { background: #f8fbff; color: var(--blue); }
.admin-chat-sidebar .session-row { position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr) 48px; grid-template-rows: 20px 20px; align-items: center; gap: 0 8px; width: 100%; min-height: 66px; padding: 8px 8px; border: 0; border-bottom: 1px solid #e5e8ee; background: transparent; text-align: left; }
.admin-chat-sidebar .session-row.active { background: #dbe8ff; }
.admin-chat-sidebar .session-row.ended { background: #f8fafc; }
.admin-chat-sidebar .session-row .avatar { grid-row: span 2; }
.admin-chat-sidebar .session-row strong, .admin-chat-sidebar .session-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-chat-sidebar .session-row small, .admin-chat-sidebar .session-row time { color: #7b8493; font-size: 12px; }
.admin-chat-sidebar .session-row time { justify-self: end; }
.admin-chat-main { display: grid; grid-template-rows: 56px minmax(0, 1fr) 30px 92px; min-width: 0; min-height: 0; overflow: hidden; background: #fff; }
.admin-chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.admin-chat-head .ghost { min-height: 34px; border: 0; border-radius: 8px; background: #f1f5fb; color: #344054; padding: 0 14px; font-weight: 800; }
.admin-chat-head .ghost:hover { background: #e8f1ff; color: var(--blue); }
.admin-chat-head strong, .admin-chat-head span { display: block; }
.admin-chat-head span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.admin-chat-flow { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 28px; }
.admin-chat-tools { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.admin-chat-tools button { min-height: 24px; border: 0; border-radius: 6px; background: transparent; color: #667085; padding: 0 8px; }
.admin-chat-tools button:hover { background: #f1f5fb; color: var(--blue); }
.admin-chat-tools button.recording { background: #fff1f1; color: #e54848; font-weight: 800; }
.admin-chat-composer { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 10px; padding: 10px 12px; background: #fff; }
.admin-chat-composer textarea { min-width: 0; resize: none; border: 0; outline: 0; padding: 6px 0; color: #344054; }
.admin-chat-composer button { align-self: end; min-height: 36px; border: 0; border-radius: 8px; background: linear-gradient(180deg, #2f7cff, #1763ff); color: #fff; font-weight: 900; box-shadow: 0 8px 18px rgba(23,99,255,.18); }
.admin-chat-composer button span { font-size: 12px; }
.admin-chat-profile { min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-left: 1px solid var(--line); background: #fff; }
.admin-chat-profile .customer-tabs { display: none; grid-template-columns: repeat(3, 1fr); height: 44px; border-bottom: 1px solid var(--line); }
.admin-chat-profile .customer-tabs button { min-width: 0; border: 0; background: #fff; color: #344054; font-weight: 800; font-size: 15px; white-space: nowrap; }
.admin-chat-profile .customer-tabs button.active { color: var(--blue); box-shadow: inset 0 -2px 0 var(--blue); }
.admin-chat-profile section { padding: 14px 14px; border-bottom: 1px solid #edf0f5; }
.admin-chat-profile .customer-title { margin-bottom: 12px; }
.admin-chat-profile .customer-title > div { display: none; }
.admin-chat-profile > section:first-of-type { display: none; }
.admin-chat-profile label { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 8px; align-items: center; margin-bottom: 9px; color: #4b5565; font-size: 13px; }
.admin-chat-profile input, .admin-chat-profile textarea { width: 100%; min-width: 0; border: 1px solid #dce1ea; border-radius: 6px; background: #fff; padding: 8px 9px; color: #3a4555; }
.admin-chat-profile textarea { min-height: 62px; resize: none; }
.side-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.side-section-head h2 { font-size: 17px; }
.side-section-head small { color: #8a95a6; font-size: 12px; }
.chat-source-card { background: #fff; }
.source-main { display: grid; gap: 5px; margin-bottom: 12px; padding: 12px; border: 1px solid #dce6f3; border-radius: 8px; background: linear-gradient(180deg, #f7fbff, #fff); }
.source-main strong { color: #102342; font-size: 17px; }
.source-main span { color: #667085; font-size: 12px; line-height: 1.45; word-break: break-all; }
.source-grid { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 7px 8px; font-size: 12px; }
.source-grid span { color: #8a95a6; }
.source-grid b { min-width: 0; color: #344054; line-height: 1.35; word-break: break-all; }
.quick-reply-settings { background: #fbfcff; }
.quick-reply-list { display: grid; gap: 8px; margin-bottom: 10px; }
.quick-reply-item { display: grid; grid-template-columns: minmax(0, 1fr) 32px; gap: 6px; align-items: stretch; }
.quick-reply-use { min-width: 0; border: 1px solid #dbe4f2; border-radius: 7px; background: #fff; padding: 8px 9px; text-align: left; }
.quick-reply-use:hover { border-color: #a9c4ff; background: #f6f9ff; }
.quick-reply-use strong { display: inline-flex; min-height: 22px; align-items: center; margin-bottom: 4px; padding: 0 7px; border-radius: 999px; background: #eef5ff; color: var(--blue); font-size: 12px; }
.quick-reply-use span { display: -webkit-box; overflow: hidden; color: #344054; font-size: 13px; line-height: 1.45; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.quick-reply-delete { border: 0; border-radius: 7px; background: #fff1f1; color: #e54848; font-size: 12px; font-weight: 800; }
.quick-reply-delete:hover { background: #ffe2e2; }
.quick-reply-form { display: grid; gap: 8px; padding-top: 10px; border-top: 1px dashed #d8e0ec; }
.quick-reply-form input,
.quick-reply-form textarea { width: 100%; border: 1px solid #dce1ea; border-radius: 6px; background: #fff; padding: 8px 9px; color: #344054; font-size: 13px; }
.quick-reply-form textarea { min-height: 58px; resize: vertical; }
.quick-reply-form button { min-height: 34px; border: 0; border-radius: 7px; background: #102342; color: #fff; font-weight: 800; }
.service-records h2 { font-size: 17px; margin-bottom: 10px; }
.record-row { display: grid; gap: 2px; padding: 8px 0; border-top: 1px solid #eef2f6; color: #344054; font-size: 13px; line-height: 1.45; }
.record-row:first-child { border-top: 0; }
.record-row span:first-child { color: #8a95a6; font-size: 12px; }
.admin-chat-shell .avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-size: 14px; font-weight: 800; background: #49b892; }
.admin-chat-shell .green { background: #49b892; }
.admin-chat-shell .blue { background: #5896cb; }
.admin-chat-shell .system-avatar { background: #f59e0b; }
.admin-chat-shell .chat-bubble { width: fit-content; max-width: min(520px, 100%); padding: 10px 13px; border-radius: 5px; background: #cfe1ff; line-height: 1.55; font-size: 14px; }
.admin-chat-line.agent .chat-bubble { background: #eef0f3; }
.admin-chat-line.system-reply .chat-bubble { background: #fff7e6; border: 1px solid #ffd59a; }
.admin-chat-shell .system-label { display: inline-flex; align-items: center; min-height: 20px; margin-bottom: 4px; padding: 0 7px; border-radius: 999px; background: #fff0d4; color: #b45309; font-size: 12px; }
.admin-chat-shell .sender-name { margin-bottom: 4px; color: #6b7280; font-size: 12px; text-align: right; }
.admin-chat-shell .chat-media-image { display: block; max-width: 260px; border-radius: 6px; }
.admin-chat-shell .chat-media-audio { width: 240px; max-width: 100%; }
.admin-chat-shell .chat-media-video { display: block; width: 300px; max-width: 100%; border-radius: 6px; }
.admin-chat-shell .chat-media-link { color: #2563eb; text-decoration: underline; word-break: break-all; }
.admin-chat-shell .chat-media-rich { max-width: 360px; line-height: 1.65; }
.admin-chat-line { display: grid; grid-template-columns: 38px minmax(0, auto); gap: 8px; align-items: start; width: fit-content; max-width: 62%; margin-bottom: 14px; }
.admin-chat-line.agent { grid-template-columns: minmax(0, auto) 38px; margin-left: auto; }
.admin-chat-line .avatar { margin-top: 3px; }
.admin-chat-line .chat-bubble { width: fit-content; max-width: min(520px, 100%); }
.admin-chat-tip { margin: 10px auto 18px; color: #98a2b3; font-size: 13px; text-align: center; }
.emoji-popover { position: fixed; z-index: 100; display: grid; grid-template-columns: repeat(5, 38px); gap: 6px; width: 238px; padding: 10px; border: 1px solid #dce4ef; border-radius: 10px; background: #fff; box-shadow: 0 18px 44px rgba(15, 23, 42, .16); }
.emoji-popover button { display: grid; place-items: center; width: 38px; height: 34px; border: 0; border-radius: 8px; background: #f7f9fc; font-size: 18px; }
.emoji-popover button:hover { background: #eaf2ff; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .admin-sidebar { min-height: auto; display: flex; gap: 8px; align-items: center; overflow-x: auto; padding: 12px; }
  .sidebar-brand { min-width: 190px; margin: 0 10px 0 0; padding: 0; }
  .sidebar-brand strong { font-size: 19px; }
  .sidebar-nav { display: flex; gap: 8px; }
  .side-item { min-width: 118px; margin: 0; padding: 0 14px; border-radius: 8px; }
  .side-item.active { box-shadow: inset 0 -3px 0 #1594df; }
  .visit-summary, .agent-stat-row { grid-template-columns: 1fr; }
  .agent-stat-row dl { grid-template-columns: repeat(3, auto 1fr); }
  .card { overflow-x: auto; }
  table { min-width: 1200px; }
  .two-col { grid-template-columns: 1fr; }
  .embed-layout, .embed-guide { grid-template-columns: 1fr; }
  .embed-card { width: min(720px, 100%); }
}
.console-login-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.16), transparent 34%),
    #f3f7fb;
}

.console-login-gate form {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid #d9e5f2;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.14);
}

.console-login-gate span {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: #2563eb;
  font-weight: 900;
}

.console-login-gate h1 {
  margin: 18px 0 8px;
}

.console-login-gate p {
  margin: 0 0 22px;
  color: #64748b;
  line-height: 1.7;
}

.console-login-gate label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: #344054;
}

.console-login-gate input {
  border: 1px solid #d0d9e8;
  border-radius: 6px;
  padding: 11px 12px;
}

.console-login-gate em {
  display: block;
  min-height: 20px;
  margin-bottom: 10px;
  color: #d92d20;
  font-style: normal;
}

.console-login-gate button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 12px;
  color: #fff;
  background: #2563eb;
  font-weight: 800;
}

.console-login-gate a {
  display: block;
  margin-top: 14px;
  color: #2563eb;
  text-align: center;
  text-decoration: none;
  font-weight: 800;
}

/* Responsive workspace and chat console */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.admin-main,
.card,
.dashboard-card,
.modal-card,
.admin-chat-shell,
.admin-chat-main {
  min-width: 0;
}

@media (max-width: 1180px) {
  body {
    grid-template-columns: 236px 1fr;
  }

  .admin-sidebar {
    padding-top: 34px;
  }

  .sidebar-brand {
    padding: 0 24px;
    margin-bottom: 34px;
  }

  .side-item {
    padding-left: 34px;
  }

  .admin-chat-shell {
    grid-template-columns: 210px minmax(0, 1fr) 260px;
  }
}

@media (max-width: 900px) {
  html,
  body {
    min-height: 100dvh;
  }

  body {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
  }

  .admin-sidebar {
    position: sticky;
    top: 0;
    z-index: 12;
    min-height: auto;
    max-width: 100vw;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid #e6edf5;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .06);
    scrollbar-width: none;
  }

  .admin-sidebar::-webkit-scrollbar {
    display: none;
  }

  .sidebar-brand {
    flex: 0 0 auto;
    min-width: 142px;
    max-width: 190px;
    min-height: 42px;
    display: flex;
    align-items: center;
    margin: 0 4px 0 0;
    padding: 0 4px;
  }

  .sidebar-brand strong {
    display: block;
    font-size: 18px;
  }

  .sidebar-nav {
    display: flex;
    gap: 8px;
  }

  .side-item {
    flex: 0 0 auto;
    width: auto;
    min-width: auto;
    min-height: 40px;
    border-radius: 7px;
    padding: 0 14px;
    white-space: nowrap;
    font-size: 14px;
  }

  .side-item.active {
    box-shadow: inset 0 -3px 0 #1594df;
  }

  .admin-top {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .admin-top > span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  .admin-user {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .admin-user strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-user button {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 0 14px;
  }

  .panel {
    padding: 12px;
  }

  .card,
  .dashboard-card {
    min-height: auto;
    padding: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .card-head {
    gap: 10px;
    padding-bottom: 12px;
  }

  .card-head h2 {
    font-size: 17px;
  }

  .head-left {
    min-width: 0;
  }

  .visit-summary {
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 14px 0;
  }

  .visit-summary article {
    min-height: 92px;
    padding: 14px;
  }

  .visit-summary strong {
    font-size: 30px;
  }

  .agent-stat-row {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .agent-stat-row dl {
    grid-template-columns: repeat(3, auto minmax(36px, 1fr));
    gap: 4px 8px;
  }

  table {
    min-width: 1080px;
  }

  th,
  td {
    padding: 12px 10px;
    font-size: 13px;
  }

  .ops {
    gap: 6px;
  }

  .pill,
  .primary,
  .success,
  .ghost {
    min-height: 36px;
  }

  .modal {
    align-items: end;
    justify-items: stretch;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
  }

  .modal-card h2 {
    padding: 16px 52px 14px 16px;
    font-size: 18px;
  }

  .modal-card label {
    padding: 0 16px;
  }

  .two-col,
  .two-col.compact,
  .embed-layout,
  .embed-guide {
    grid-template-columns: 1fr;
  }

  .two-col,
  .two-col.compact {
    padding: 0 16px;
  }

  .two-col label {
    padding: 0;
  }

  .fit {
    margin-left: 16px;
    margin-right: 16px;
  }

  .modal-actions {
    position: sticky;
    bottom: 0;
    margin-top: 18px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: #fff;
  }

  .modal-actions button {
    flex: 1;
  }

  .embed-card {
    width: 100%;
  }

  .embed-layout {
    gap: 12px;
    padding: 14px 16px 0;
  }

  .embed-config > label {
    padding: 0 16px;
  }

  .embed-preview-page {
    min-height: 190px;
  }

  .embed-tabs {
    overflow-x: auto;
    padding: 14px 16px 0;
    scrollbar-width: none;
  }

  .embed-tabs::-webkit-scrollbar {
    display: none;
  }

  .embed-tabs button {
    flex: 0 0 auto;
  }

  .embed-tab-panel {
    padding: 14px 16px 18px;
  }

  .chat-modal {
    padding: 0;
  }

  .chat-card {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    grid-template-rows: 50px minmax(0, 1fr);
  }

  .direct-chat-card > h2 {
    min-height: 50px;
    padding: 13px 52px 10px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 16px;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-card .modal-close {
    top: 8px;
    right: 10px;
    z-index: 2;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #f1f5fb;
    font-size: 22px;
  }

  .admin-chat-shell {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 142px minmax(0, 1fr) 210px;
    overflow: hidden;
  }

  .admin-chat-sidebar {
    min-height: 0;
    overflow-y: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-chat-sidebar .group-title {
    position: sticky;
    top: 0;
    z-index: 1;
    height: 34px;
    font-size: 13px;
  }

  .admin-chat-sidebar .session-row {
    min-height: 56px;
    grid-template-columns: 34px minmax(0, 1fr) 44px;
    grid-template-rows: 18px 18px;
    padding: 7px 8px;
  }

  .admin-chat-main {
    min-height: 0;
    grid-template-rows: 56px minmax(0, 1fr) 32px 82px;
    overflow: hidden;
  }

  .admin-chat-head {
    padding: 0 10px;
  }

  .admin-chat-head > div:first-child {
    min-width: 0;
  }

  .admin-chat-head strong,
  .admin-chat-head span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-chat-head > div:last-child {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
  }

  .admin-chat-head .ghost {
    min-height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  .admin-chat-flow {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 10px;
  }

  .admin-chat-line {
    max-width: 86%;
    margin-bottom: 10px;
  }

  .admin-chat-shell .chat-bubble {
    max-width: min(270px, 100%);
    padding: 9px 11px;
    font-size: 14px;
  }

  .admin-chat-tools {
    padding: 0 8px;
  }

  .admin-chat-composer {
    grid-template-columns: minmax(0, 1fr) 78px;
    gap: 8px;
    padding: 8px;
  }

  .admin-chat-composer button {
    min-height: 36px;
  }

  .admin-chat-profile {
    min-height: 0;
    overflow-y: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .admin-chat-profile section {
    padding: 12px;
  }

  .source-grid {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: auto;
    text-align: center;
  }

  .console-login-gate {
    min-height: 100dvh;
    padding: 16px;
  }

  .console-login-gate form {
    padding: 22px;
    border-radius: 8px;
  }
}

@media (max-width: 560px) {
  .card-head,
  .head-left {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-head > button,
  .head-left > button {
    width: 100%;
  }

  .agent-stat-row dl {
    grid-template-columns: auto 1fr;
  }

  .admin-chat-shell {
    grid-template-rows: 118px minmax(0, 1fr) 176px;
  }

  .admin-chat-head {
    gap: 8px;
  }

  .admin-chat-head span {
    max-width: 160px;
  }

  .admin-chat-head .ghost {
    padding: 0 8px;
    font-size: 12px;
  }

  .admin-chat-line {
    max-width: 92%;
  }

  .admin-chat-shell .avatar {
    width: 32px;
    height: 32px;
  }

  .admin-chat-line,
  .admin-chat-line.agent {
    grid-template-columns: 34px minmax(0, auto);
    gap: 6px;
  }

  .admin-chat-line.agent {
    grid-template-columns: minmax(0, auto) 34px;
  }

  .emoji-popover {
    left: 8px !important;
    right: 8px;
    width: auto;
    grid-template-columns: repeat(6, 1fr);
  }

  .emoji-popover button {
    width: 100%;
  }
}

@media (max-width: 390px) {
  .sidebar-brand {
    min-width: 124px;
  }

  .side-item {
    padding: 0 11px;
  }

  .admin-chat-head > div:last-child {
    gap: 4px;
  }

  .admin-chat-head .ghost {
    padding: 0 6px;
  }

  .admin-chat-composer {
    grid-template-columns: minmax(0, 1fr) 68px;
  }
}
