:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d8dee8;
  --line-strong: #c7d0de;
  --text: #172033;
  --muted: #64748b;
  --primary: #409eff;
  --primary-dark: #2f7fd0;
  --primary-soft: #ecf5ff;
  --danger: #c43d3d;
  --danger-soft: #fff0f0;
  --warning: #d9850d;
  --shadow: 0 12px 30px rgba(22, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

body.agent-page {
  height: 100vh;
  overflow: hidden;
}

body.admin-page {
  height: 100vh;
  overflow: hidden;
  min-height: 100vh;
  background: #eef2f7;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 0 16px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.plain-button {
  border-color: var(--line-strong);
  color: var(--text);
  background: #fff;
}

.plain-button:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.12);
}

textarea {
  resize: none;
  line-height: 1.5;
  overflow-y: auto;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.visitor-shell {
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-window {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  position: relative;
  width: min(100%, 760px);
  height: min(760px, calc(100vh - 48px));
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.user-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.user-title h1,
.brand-block h1,
.empty-state h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.user-title p,
.brand-block p,
.empty-state p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.visitor-meta {
  margin-top: 2px !important;
  font-size: 12px !important;
}

.avatar,
.message-avatar,
.session-avatar {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  background: #409eff;
  font-weight: 700;
}

.avatar {
  width: 36px;
  height: 36px;
}

.avatar img,
.message-avatar img,
.session-avatar img,
.profile-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: contain;
  padding: 2px;
  background: #fff;
}

.notice-bar {
  min-height: 32px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border: 1px solid #bfd2ee;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.online {
  color: #2f8f46;
  border-color: #b9e6c5;
  background: #edf9f0;
}

.status-pill.offline {
  color: var(--muted);
  border-color: var(--line);
  background: var(--surface-soft);
}

.status-dot-inline {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(103, 194, 58, 0.14);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background: #f7f9fc;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(76%, 680px);
}

.message-row.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.system {
  max-width: 100%;
  align-self: center;
}

.message-avatar {
  width: 30px;
  height: 30px;
  font-size: 13px;
}

.message-content {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.mine .message-content {
  justify-items: end;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
}

.read-state {
  color: #67c23a;
  font-size: 12px;
}

.mine .read-state {
  text-align: right;
}

.message-state-line {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  width: 100%;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.sent-time {
  color: var(--muted);
}

.bubble {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(22, 34, 51, 0.05);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.link-card {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 6px;
  padding: 0 12px;
  color: var(--primary);
  background: #fff;
  text-decoration: none;
  font-weight: 700;
}

.link-card::before {
  content: "🔗";
  margin-right: 6px;
}

.mine .link-card {
  color: var(--primary-dark);
}

.message-context-menu {
  position: fixed;
  z-index: 50;
  min-width: 116px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}

.message-context-menu::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  background: #fff;
  transform: translateX(-50%) rotate(45deg);
}

.message-context-menu button {
  width: 100%;
  min-height: 34px;
  border: 0;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
}

.message-context-menu button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.mine .bubble {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.system .bubble {
  color: var(--muted);
  border-color: var(--line);
  background: #fff;
  box-shadow: none;
  font-size: 12px;
}

.message-image {
  display: block;
  max-width: 240px;
  max-height: 220px;
  border-radius: 6px;
  cursor: zoom-in;
  object-fit: contain;
}

.mine .message-image {
  background: #fff;
}

.typing-line {
  min-height: 24px;
  margin: 0;
  padding: 0 18px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
}

.composer-tools {
  display: flex;
  gap: 8px;
  padding: 8px 12px 0;
  border-top: 1px solid var(--line);
  background: #fff;
}

.tool-button {
  min-height: 32px;
  border-color: var(--line-strong);
  color: var(--text);
  background: #fff;
  padding: 0 12px;
}

.tool-button:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.tool-button.active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.composer {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer textarea {
  min-height: 48px;
  max-height: 136px;
  padding-top: 11px;
  padding-bottom: 11px;
}

.composer button[type="submit"] {
  min-height: 48px;
  padding: 0 18px;
}

.icon-button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-color: var(--line-strong);
  color: var(--text);
  background: #fff;
  font-size: 18px;
}

.icon-button:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

.image-icon-button {
  display: inline-grid;
  place-items: center;
}

.picture-icon {
  position: relative;
  display: block;
  width: 20px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.picture-icon::before {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.picture-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  bottom: 3px;
  width: 10px;
  height: 7px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: skewX(-28deg);
}

.icon-button.loading .picture-icon {
  display: none;
}

.icon-button.loading::after {
  content: "...";
  font-size: 14px;
  letter-spacing: 0;
}

.emoji-panel {
  position: absolute;
  left: 12px;
  bottom: 74px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, 38px);
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.emoji-panel button {
  min-height: 34px;
  padding: 0;
  border-color: var(--line);
  color: var(--text);
  background: #fff;
  font-size: 18px;
}

.visitor-shell .composer {
  position: relative;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
}

.visitor-shell .composer .icon-button {
  grid-row: 1;
  width: 36px;
  min-height: 36px;
  border-color: transparent;
  background: transparent;
}

.visitor-shell .composer .image-icon-button {
  grid-column: 2;
  justify-self: start;
}

.visitor-shell .composer textarea {
  grid-column: 1 / -1;
  grid-row: 2;
  min-height: 78px;
  max-height: 126px;
  border-radius: 10px;
  padding: 14px 92px 14px 14px;
}

.visitor-shell .composer button[type="submit"] {
  position: absolute;
  right: 26px;
  bottom: 28px;
  min-width: 60px;
  min-height: 30px;
  margin: 0;
  border-color: transparent;
  border-radius: 999px;
  padding: 0 13px;
  color: #fff;
  background: rgba(64, 158, 255, 0.36);
  font-size: 14px;
  z-index: 1;
}

.visitor-shell .composer button[type="submit"]:hover {
  border-color: transparent;
  background: rgba(64, 158, 255, 0.5);
}

.visitor-shell .composer button[type="submit"].has-text {
  background: #409eff;
}

.visitor-shell .composer button[type="submit"].has-text:hover {
  background: #2f7fd0;
}

.visitor-shell .emoji-panel {
  left: 12px;
  bottom: 150px;
}

.agent-auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(100%, 380px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
}

.login-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-card button {
  min-height: 44px;
}

.admin-auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.admin-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
}

.admin-header,
.admin-route,
.admin-list-panel,
.admin-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-header h1,
.admin-panel-head h2 {
  margin: 0;
}

.admin-header p,
.admin-route p {
  margin: 4px 0 0;
  color: var(--muted);
}

.admin-route {
  display: grid;
  grid-template-columns: minmax(220px, 360px) auto minmax(0, 1fr);
  align-items: end;
  gap: 12px;
  padding: 14px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 300px;
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}

.admin-list-panel,
.admin-detail {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.admin-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.admin-list-panel > input,
.admin-detail > textarea {
  margin: 12px;
  width: calc(100% - 24px);
}

.admin-session-list,
.admin-messages,
.admin-blacklist {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

.admin-session-item {
  display: grid;
  gap: 4px;
  min-height: 82px;
  border-color: var(--line);
  color: var(--text);
  background: #fff;
  text-align: left;
}

.admin-session-item:hover,
.admin-session-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.admin-session-item span,
.admin-session-item em,
.admin-message-item span,
.blacklist-item span {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.admin-session-avatar {
  color: #fff !important;
}

.admin-message-item,
.blacklist-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.admin-message-item p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-danger-zone {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.form-error {
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.agent-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  background: #eef2f7;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  min-height: 0;
  padding: 14px 12px;
  border-right: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
}

.brand-block {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 2px 2px 0;
}

.brand-block h1 {
  font-size: 18px;
}

.brand-block p {
  margin-top: 2px;
  font-size: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #409eff;
  box-shadow: 0 0 0 5px rgba(64, 158, 255, 0.12);
}

.desk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
}

.desk-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.danger-text {
  color: var(--danger);
}

.danger-text:hover {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.agent-profile {
  display: grid;
  gap: 16px;
}

.agent-profile label {
  min-width: 0;
}

.agent-profile button:not(.profile-avatar) {
  min-height: 38px;
  padding: 0 12px;
}

.profile-avatar {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  min-height: 58px;
  border-radius: 50%;
  padding: 0;
  color: #fff;
  background: #409eff;
  overflow: hidden;
}

.profile-avatar span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.session-search {
  display: block;
}

.session-search input {
  height: 36px;
  padding-left: 34px;
  background:
    linear-gradient(transparent, transparent),
    #fff;
}

.session-search {
  position: relative;
}

.session-search::after {
  content: "";
  position: absolute;
  left: 11px;
  bottom: 11px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  opacity: 0.72;
}

.session-search::before {
  content: "";
  position: absolute;
  left: 23px;
  bottom: 8px;
  width: 7px;
  height: 2px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.72;
  transform: rotate(45deg);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px;
  background: var(--surface-soft);
}

.filter {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  color: var(--text);
  background: transparent;
}

.filter.active,
.filter:hover {
  color: var(--primary);
  border-color: #fff;
  background: #fff;
  box-shadow: 0 2px 8px rgba(22, 34, 51, 0.07);
}

.session-list {
  display: grid;
  align-content: start;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.empty-list {
  margin: 18px 0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.session-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  position: relative;
  align-items: start;
  gap: 9px;
  width: 100%;
  min-height: 80px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 46px 8px 10px;
  color: var(--text);
  text-align: left;
  background: #fff;
  overflow: hidden;
}

.session-item:hover {
  border-color: #b7c7dc;
  background: #f8fafc;
}

.session-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.session-item.online {
  border-left: 1px solid var(--line);
}

.session-item.offline {
  border-left: 1px solid var(--line);
  opacity: 0.86;
}

.session-item.online .session-avatar::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #22c55e;
}

.session-item.offline .session-avatar::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #94a3b8;
}

.session-avatar {
  position: relative;
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.session-body {
  display: grid;
  gap: 2px;
  min-width: 0;
  max-height: 64px;
  overflow: hidden;
}

.session-top,
.session-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.session-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 2px;
}

.session-snippet {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-origin {
  overflow: hidden;
  color: #7b8798;
  font-size: 11px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-bottom {
  max-height: 18px;
  overflow: hidden;
}

.session-bottom .message-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.presence-pill.online {
  color: var(--primary-dark);
}

.presence-pill.online .presence-dot {
  background: #409eff;
  box-shadow: 0 0 0 4px rgba(64, 158, 255, 0.12);
}

.presence-pill.offline {
  color: var(--muted);
}

.presence-pill.offline .presence-dot {
  background: #94a3b8;
}

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  min-height: 20px;
  border-radius: 999px;
  padding: 0 7px;
  color: #fff;
  background: var(--warning);
  font-size: 12px;
  font-weight: 700;
}

.load-more {
  min-height: 34px;
  border-color: var(--line);
  color: var(--primary);
  background: #fff;
}

.load-more:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.workspace.quick-open {
  grid-template-columns: minmax(0, 1fr) 300px;
}

.empty-state {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.agent-chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  position: relative;
  height: 100vh;
  min-height: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: none;
}

.quick-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
  border-left: 1px solid var(--line);
  background: #fff;
}

.quick-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 66px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.quick-panel h2 {
  margin: 0;
  font-size: 18px;
}

.quick-panel header div {
  display: flex;
  gap: 12px;
}

.text-button {
  min-height: auto;
  border: 0;
  padding: 0;
  color: var(--primary);
  background: transparent;
}

.text-button:hover {
  color: var(--primary-dark);
  background: transparent;
}

.quick-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.quick-empty {
  margin: 30px 0 0;
  color: var(--muted);
  line-height: 1.7;
  text-align: center;
}

.quick-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 8px;
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  background: #fff;
  text-align: left;
}

.quick-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.quick-content {
  grid-column: 1 / -1;
  display: -webkit-box;
  overflow: hidden;
  color: var(--text);
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.quick-meta {
  color: var(--muted);
  font-size: 12px;
}

.quick-delete {
  color: var(--danger);
  font-size: 12px;
}

.agent-topbar {
  min-height: 66px;
  padding: 12px 18px;
}

.active-user-title {
  align-items: flex-start;
}

.active-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.active-title-row h1 {
  overflow: hidden;
  max-width: 42vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-messages {
  min-height: 0;
  padding: 22px clamp(26px, 7vw, 128px);
  background: #f5f7fb;
}

.agent-chat .composer {
  grid-template-columns: 1fr;
}

.agent-composer {
  display: grid;
  gap: 0;
  align-items: stretch;
  padding: 0;
  border-top: 1px solid var(--line);
  background: #fff;
}

.agent-composer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px 6px;
}

.agent-composer-toolbar .icon-button {
  width: 34px;
  min-height: 34px;
  font-size: 17px;
}

.agent-composer-toolbar .tool-button {
  min-height: 34px;
}

.composer-tip {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.agent-composer-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: stretch;
  gap: 12px;
  padding: 0 14px 14px;
}

.agent-composer textarea {
  min-height: 118px;
  max-height: 180px;
  border-color: transparent;
  padding: 12px 0;
  box-shadow: none;
}

.agent-composer textarea:focus {
  border-color: transparent;
  box-shadow: none;
}

.agent-composer .send-button {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 118px;
  padding: 0 12px;
  border-radius: 6px;
}

.agent-composer .send-button span {
  font-weight: 700;
}

.agent-composer .send-button small {
  display: block;
  margin-top: 4px;
  opacity: 0.76;
  font-size: 12px;
}

.agent-chat .emoji-panel {
  left: 14px;
  bottom: 198px;
}

.profile-modal-card {
  width: min(100%, 460px);
}

.profile-setting {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 2px 20px 0;
}

.profile-setting p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.header-actions .plain-button,
.header-actions .ghost-button {
  min-width: 74px;
  min-height: 34px;
  padding: 0 12px;
  line-height: 1;
  white-space: nowrap;
}

.ghost-button {
  border-color: #f0b8b8;
  color: var(--danger);
  background: var(--danger-soft);
}

.ghost-button:hover {
  border-color: var(--danger);
  color: #fff;
  background: var(--danger);
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 76px 16px 24px;
  background: rgba(15, 23, 42, 0.72);
}

.image-viewer img {
  width: auto;
  height: auto;
  max-width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 96px);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  transform-origin: center center;
  transition: transform 0.12s ease;
}

.viewer-toolbar {
  position: absolute;
  top: 16px;
  right: 18px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.viewer-toolbar button {
  min-height: 34px;
  border-color: rgba(255, 255, 255, 0.42);
  padding: 0 12px;
  color: #fff;
  background: rgba(15, 23, 42, 0.75);
}

.viewer-toolbar button:hover {
  border-color: #fff;
  background: rgba(15, 23, 42, 0.92);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.55);
}

.modal-card {
  display: grid;
  gap: 18px;
  width: min(100%, 560px);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-card.profile-modal-card {
  width: min(100%, 460px);
}

.modal-card header,
.modal-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface-soft);
}

.modal-card header {
  border-bottom: 1px solid var(--line);
}

.modal-card footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.modal-card h2 {
  margin: 0;
  font-size: 18px;
}

.modal-card label {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 20px;
}

.modal-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  padding: 0 20px;
}

.modal-card label span,
.modal-row > span {
  margin: 0;
  text-align: right;
  font-size: 14px;
  color: var(--muted);
  line-height: 38px;
}

.modal-row .plain-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.modal-row .picture-icon {
  width: 18px;
  height: 14px;
}

.modal-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.modal-close {
  min-height: 32px;
  border: 0;
  padding: 0 4px;
  color: var(--muted);
  background: transparent;
  font-size: 28px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
  background: transparent;
}

.workspace.quick-open {
  grid-template-columns: minmax(0, 1fr) 8px var(--quick-panel-width, 300px);
}

.workspace-resizer {
  width: 8px;
  height: 100vh;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: #f1f5f9;
  cursor: col-resize;
}

.workspace-resizer:hover,
body.resizing .workspace-resizer {
  background: #dbeafe;
}

body.resizing {
  cursor: col-resize;
  user-select: none;
}

.emoji-icon {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.emoji-icon::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 7px 0 0 currentColor;
}

.emoji-icon::after {
  content: "";
  position: absolute;
  left: 5px;
  bottom: 4px;
  width: 7px;
  height: 4px;
  border-bottom: 2px solid currentColor;
  border-radius: 0 0 999px 999px;
}

.message-video {
  display: block;
  width: min(320px, 64vw);
  max-height: 260px;
  border-radius: 6px;
  background: #0f172a;
}

.mine .message-video {
  background: #0f172a;
}

.admin-session-list {
  gap: 10px;
  padding: 14px 12px 18px;
}

.admin-session-item {
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  min-height: 92px;
  padding: 12px;
  margin: 0;
  line-height: 1.35;
}

.admin-session-avatar {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  background: #409eff;
  font-weight: 700;
}

.admin-session-content {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.admin-session-content strong,
.admin-session-content span,
.admin-session-content em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: #f5f7fb;
}

.admin-message-item {
  display: grid;
  gap: 5px;
  max-width: min(74%, 680px);
  border: 0;
  padding: 0;
  background: transparent;
}

.admin-message-item.visitor {
  align-self: flex-start;
}

.admin-message-item.agent {
  align-self: flex-end;
  justify-items: end;
}

.admin-message-item.system {
  align-self: center;
  max-width: 100%;
}

.admin-message-item .admin-bubble {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(22, 34, 51, 0.05);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.admin-message-item.agent .admin-bubble {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.admin-message-item.system .admin-bubble {
  color: var(--muted);
  border-style: dashed;
  background: #fff;
}

.admin-message-item .message-image,
.admin-message-item .message-video {
  max-width: min(320px, 52vw);
}

.blacklist-modal-card {
  width: min(100%, 620px);
}

.blacklist-manage {
  display: grid;
  align-content: start;
  gap: 10px;
  max-height: 56vh;
  overflow-y: auto;
  padding: 0 20px;
}

.blacklist-manage-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.blacklist-manage-item div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.blacklist-manage-item span,
.blacklist-manage-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
}

.route-modal-card {
  width: min(100%, 520px);
}

.route-hint {
  padding: 0 20px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  transform: translate(-50%, 16px);
  border-radius: 999px;
  padding: 10px 16px;
  color: #fff;
  background: rgba(15, 23, 42, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.desk-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.desk-actions button {
  min-width: 0;
  padding: 0 8px;
  font-size: 13px;
}

.agent-composer-main {
  grid-template-columns: minmax(0, 1fr) 76px;
  align-items: end;
}

.agent-composer .send-button {
  min-height: 36px;
  align-self: end;
  margin-bottom: 8px;
  padding: 0 12px;
}

.agent-composer .send-button small {
  display: none;
}

@media (max-width: 860px) {
  body.agent-page,
  body.admin-page {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .agent-shell {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr);
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .workspace.quick-open {
    grid-template-columns: minmax(0, 1fr);
  }

  .workspace-resizer {
    display: none !important;
  }

  .quick-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 25;
    display: grid;
    height: min(360px, 62vh);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 50px rgba(23, 32, 51, 0.18);
  }

  .sidebar {
    height: auto;
    max-height: none;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .session-list {
    max-height: 42vh;
    overflow-y: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 1fr);
    min-height: 420px;
    padding: 0;
    overflow: visible;
  }

  .empty-state {
    margin: 24px auto;
  }

  .agent-chat {
    height: auto;
    min-height: 70vh;
    max-height: none;
    grid-template-rows: auto minmax(320px, 1fr) auto auto;
  }

  .agent-topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 10px 12px;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .header-actions .plain-button,
  .header-actions .ghost-button {
    flex: 1 1 96px;
  }

  .agent-messages {
    max-height: 52vh;
    overflow-y: auto;
  }

  .agent-composer-toolbar {
    flex-wrap: wrap;
  }

  .composer-tip {
    display: none;
  }

  .admin-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 12px;
  }

  .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-header-actions {
    width: 100%;
  }

  .admin-header-actions button {
    flex: 1;
  }

  .admin-layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .admin-list-panel,
  .admin-detail {
    min-height: 360px;
    max-height: none;
  }

  .admin-session-list,
  .admin-blacklist {
    max-height: 45vh;
    overflow-y: auto;
  }

  .admin-messages {
    max-height: 54vh;
    overflow-y: auto;
  }

  .admin-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-actions button {
    flex: 1 1 120px;
  }

  .modal {
    align-items: start;
    overflow-y: auto;
    padding: 16px;
  }

  .modal-card {
    margin: 16px 0;
    min-height: 0;
  }

}

@media (max-width: 560px) {
  .visitor-shell {
    padding: 10px;
  }

  .chat-window {
    height: calc(100vh - 20px);
    min-height: 0;
  }

  .chat-topbar {
    min-height: 54px;
    padding: 8px 10px;
  }

  .user-title {
    gap: 8px;
  }

  .user-title h1 {
    font-size: 18px;
  }

  .user-title p {
    font-size: 12px;
  }

  .avatar {
    width: 34px;
    height: 34px;
  }

  .composer {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 10px 12px 12px;
  }

  .composer textarea {
    min-height: 70px;
    max-height: 118px;
    border-radius: 10px;
    padding: 14px 88px 14px 14px;
  }

  .composer button[type="submit"] {
    min-width: 60px;
    min-height: 30px;
    border-color: transparent;
    border-radius: 999px;
    padding: 0 13px;
    color: #fff;
    background: rgba(64, 158, 255, 0.36);
    font-size: 14px;
    z-index: 1;
  }

  .icon-button {
    width: 38px;
    min-height: 38px;
  }

  .composer .icon-button {
    align-self: start;
    grid-row: 1;
    width: 34px;
    min-height: 34px;
    border-color: transparent;
    background: transparent;
  }

  .composer .image-icon-button {
    grid-column: 2;
    justify-self: start;
  }

  .composer textarea {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .composer button[type="submit"] {
    grid-column: 3;
    grid-row: 2;
  }

  .visitor-shell .composer button[type="submit"] {
    position: absolute;
    right: 24px;
    bottom: 28px;
    margin: 0;
  }

  .agent-profile {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .agent-profile button:not(.profile-avatar) {
    min-height: 34px;
  }

  .message-row {
    max-width: 92%;
  }

  .message-image {
    max-width: 190px;
  }

  .emoji-panel {
    left: 8px;
    bottom: 58px;
  }

.visitor-shell .emoji-panel {
  left: 12px;
  bottom: 146px;
}

  .agent-messages {
    padding-left: 12px;
    padding-right: 12px;
  }

  .modal-card label,
  .modal-row {
    grid-template-columns: 1fr;
  }

  .modal-card label span,
  .modal-row > span {
    text-align: left;
    line-height: 1.4;
  }
}

/* Refinements */
body.visitor-shell,
body.agent-page,
body.admin-page {
  background:
    radial-gradient(circle at top left, rgba(64, 158, 255, 0.12), transparent 34vw),
    linear-gradient(180deg, #f6f8fc 0%, #eef3f9 100%);
}

.chat-window,
.login-card,
.modal-card {
  box-shadow: 0 18px 50px rgba(23, 32, 51, 0.1);
}

.login-card {
  border-color: #e2e8f0;
  padding: 30px;
}

.login-card h1 {
  letter-spacing: 0;
}

.chat-topbar {
  background: rgba(255, 255, 255, 0.96);
}

.sidebar {
  padding: 16px 12px;
  gap: 10px;
}

.brand-block {
  padding: 0 4px;
}

.brand-block h1 {
  font-size: 21px;
}

.agent-self-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 58px;
  border: 1px solid #e0e7f1;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  text-align: left;
}

.agent-self-card:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.agent-self-avatar {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border-radius: 50%;
  color: #fff;
  background: #409eff;
  font-weight: 700;
}

.agent-self-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 2px;
  border-radius: inherit;
  background: #fff;
}

.agent-self-card span:last-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.agent-self-card strong {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-self-card small {
  color: #2f8f46;
  font-size: 12px;
}

.desk-actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.desk-actions button {
  min-width: 0;
  min-height: 32px;
  padding: 0 6px;
  font-size: 13px;
  white-space: nowrap;
}

.session-item.blacklisted {
  border-color: #f1b5b5;
  background: #fff7f7;
}

.session-item.blacklisted.active {
  border-color: var(--danger);
  background: #fff2f2;
  box-shadow: inset 3px 0 0 var(--danger);
}

.session-flags {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.blacklist-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 7px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  border-color: #c7d3e3;
}

.emoji-icon {
  width: 22px;
  height: 22px;
  border-width: 2px;
  color: #172033;
}

.emoji-icon::before {
  top: 6px;
  left: 6px;
  width: 3px;
  height: 3px;
  box-shadow: 7px 0 0 currentColor;
}

.emoji-icon::after {
  left: 5px;
  bottom: 5px;
  width: 9px;
  height: 5px;
  border: 0;
  border-bottom: 2px solid currentColor;
  border-radius: 0 0 12px 12px;
}

.video-icon-button,
.image-icon-button,
.emoji-icon-button {
  display: inline-grid;
  place-items: center;
}

.video-icon {
  position: relative;
  display: block;
  width: 24px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 5px;
}

.video-icon::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 4px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 7px solid currentColor;
}

.video-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: -5px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.4;
}

.icon-button.loading .video-icon {
  display: none;
}

.visitor-shell .composer {
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  border-top-color: #dce3ee;
}

.visitor-shell .composer textarea {
  border-color: #d7e0ec;
  background: #fbfdff;
}

.agent-composer-toolbar {
  border-bottom: 1px solid #eef2f7;
}

.agent-composer-main {
  grid-template-columns: minmax(0, 1fr) 76px;
  align-items: end;
}

.agent-composer textarea {
  min-height: 104px;
  padding: 12px 2px;
}

.agent-composer .send-button {
  min-height: 36px;
  align-self: end;
  margin-bottom: 10px;
  padding: 0 12px;
}

.agent-composer .send-button small {
  display: none;
}

@media (max-width: 560px) {
  .visitor-shell .composer textarea {
    grid-column: 1 / -1;
  }
}
