:root {
  color-scheme: light;
  --bg: #eef3f7;
  --panel: #ffffff;
  --panel-soft: #f7fafc;
  --line: #d7e0ea;
  --text: #152233;
  --muted: #657386;
  --brand: #17789b;
  --brand-dark: #0f5f7c;
  --green: #1f9d61;
  --amber: #b7791f;
  --visitor: #eef3f8;
  --admin: #daf2e5;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--brand-dark);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  outline: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 108, 148, 0.16);
}

textarea {
  resize: vertical;
}

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

.chat-shell,
.login-panel {
  width: min(100%, 720px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(31, 41, 51, 0.08);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-header h1,
.chat-header h2,
.login-panel h1,
.panel-head h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

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

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 6px 10px;
  background: #e7f8ee;
  color: #17633a;
  font-size: 13px;
  font-weight: 700;
}

.status::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  content: "";
}

.status.is-offline {
  background: #f1f3f5;
  color: #667085;
}

.status.is-offline::before {
  background: #98a2b3;
}

.visitor-chat .support-status {
  justify-content: center;
  gap: 7px;
  min-height: 32px;
  border: 1px solid #86efac;
  padding: 5px 12px;
  background: #dcfce7;
  color: #166534;
  font-size: 14px;
  font-weight: 800;
  line-height: 20px;
  white-space: nowrap;
}

.visitor-chat .support-status::before {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  background: currentColor;
}

.visitor-chat .support-status.is-offline {
  border-color: #fca5a5;
  background: #fee2e2;
  color: #991b1b;
}

.admin-notice {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid rgba(31, 157, 97, 0.3);
  border-radius: 8px;
  padding: 10px 16px;
  background: #ecfdf5;
  box-shadow: 0 18px 38px rgba(21, 34, 51, 0.16);
  color: #166534;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.admin-notice.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.messages {
  display: flex;
  height: 440px;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 20px;
}

.message {
  max-width: 78%;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
}

.message.visitor {
  align-self: flex-start;
  background: var(--visitor);
}

.message.admin {
  align-self: flex-end;
  background: var(--admin);
}

.message p,
.empty {
  margin: 0;
  overflow-wrap: anywhere;
}

.empty {
  align-self: center;
  color: var(--muted);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 10px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

.composer input,
.composer textarea,
.login-form input {
  padding: 11px 12px;
}

.admin-page {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.18)),
    linear-gradient(180deg, #f5f7fb 0%, #e9eef4 100%);
}

.login-panel {
  margin: 12vh auto 0;
  padding: 24px;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr 1fr 96px;
  gap: 10px;
  margin-top: 18px;
}

.admin-console {
  width: min(1680px, 100%);
  margin: 0 auto;
}

.admin-layout-polished {
  display: grid;
  height: calc(100vh - 36px);
  min-height: 650px;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 14px;
}

.workbench-sidebar {
  display: grid;
  min-width: 0;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid rgba(23, 38, 51, 0.1);
  border-radius: 8px;
  background: #17202a;
  color: #ffffff;
  box-shadow: 0 22px 58px rgba(38, 54, 72, 0.16);
}

.sidebar-brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #0f8a75;
  color: #ffffff;
  font-weight: 900;
}

.sidebar-brand strong,
.sidebar-foot strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot span {
  display: block;
  margin-top: 3px;
  color: #aab8c5;
  font-size: 12px;
  line-height: 1.35;
}

.sidebar-nav {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
}

.sidebar-nav-item {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  background: transparent;
  color: #c6d2dc;
  font-size: 14px;
  font-weight: 800;
  text-align: left;
}

.sidebar-nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.sidebar-nav-item.active {
  background: rgba(15, 138, 117, 0.18);
  color: #ffffff;
  box-shadow: inset 3px 0 0 #30c69f;
}

.mobile-nav-dropdown {
  display: none;
  position: relative;
}

.mobile-menu-button {
  display: grid;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.mobile-menu-button:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.14);
}

.mobile-menu-button span,
.mobile-menu-button span::before,
.mobile-menu-button span::after {
  display: block;
  width: 15px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.mobile-menu-button span {
  position: relative;
}

.mobile-menu-button span::before,
.mobile-menu-button span::after {
  position: absolute;
  left: 0;
}

.mobile-menu-button span::before {
  top: -5px;
}

.mobile-menu-button span::after {
  top: 5px;
}

.mobile-function-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  display: grid;
  min-width: 132px;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 6px;
  background: #17202a;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.22);
}

.mobile-function-menu[hidden] {
  display: none;
}

.mobile-nav-item {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: #c6d2dc;
  font-size: 14px;
  font-weight: 800;
  text-align: left;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
  background: rgba(15, 138, 117, 0.22);
  color: #ffffff;
}

.sidebar-foot {
  padding: 14px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.workbench-main {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  min-height: 64px;
  border: 1px solid rgba(137, 155, 177, 0.24);
  border-radius: 8px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 18px 42px rgba(48, 65, 86, 0.08);
}

.panel-kicker {
  color: #0f766e;
  font-size: 12px;
  font-weight: 900;
}

.admin-stat-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-stat-row span,
.site-count-label {
  min-height: 34px;
  border: 1px solid rgba(15, 118, 110, 0.14);
  border-radius: 999px;
  padding: 8px 12px;
  background: #f8fbfa;
  color: #516173;
  font-size: 13px;
  font-weight: 800;
}

.availability-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 36px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  padding: 8px 14px;
  background: #f3fbf7;
  color: #0f6b58;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
}

.availability-toggle::before {
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #22c55e;
  content: "";
}

.availability-toggle:hover {
  border-color: rgba(15, 118, 110, 0.32);
  background: #e7f8f2;
  color: #0b695b;
}

.availability-toggle.is-offline {
  border-color: rgba(148, 163, 184, 0.32);
  background: #f4f6f8;
  color: #667085;
}

.availability-toggle.is-offline::before {
  background: #98a2b3;
}

.availability-toggle.is-offline:hover {
  border-color: rgba(102, 112, 133, 0.34);
  background: #eceff3;
  color: #344054;
}

.availability-toggle:disabled {
  cursor: progress;
  opacity: 0.72;
}

.admin-stat-row strong {
  color: #132536;
  font-size: 15px;
}

.desktop-logout-button {
  margin-left: 4px;
}

.mobile-logout-button {
  display: none;
}

.sidebar-brand .mobile-logout-button {
  align-self: start;
  min-height: 30px;
  border-color: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.sidebar-brand .mobile-logout-button:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.14);
}

.admin-grid {
  display: grid;
  width: 100%;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.workbench-chat-layout {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
}

.workbench-visitor-panel {
  display: grid;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
}

.workbench-thread-list {
  min-height: 0;
}

.back-to-visitors {
  display: none;
}

#androidConfigRow[hidden] { display: none; }

#adminPanel[data-active-view="workbench"] [data-view-panel]:not([data-view-panel="chat"]),
#adminPanel[data-active-view="sites"] [data-view-panel]:not([data-view-panel="sites"]),
#adminPanel[data-active-view="threads"] [data-view-panel]:not([data-view-panel="threads"]),
#adminPanel[data-active-view="settings"] [data-view-panel]:not([data-view-panel="settings"]) {
  display: none;
}

#adminPanel[data-active-view="sites"] .admin-grid,
#adminPanel[data-active-view="threads"] .admin-grid,
#adminPanel[data-active-view="settings"] .admin-grid {
  align-content: start;
}

#adminPanel[data-active-view="sites"] .site-panel,
#adminPanel[data-active-view="threads"] .thread-panel,
#adminPanel[data-active-view="settings"] .settings-panel {
  width: min(760px, 100%);
}

.workspace-panel,
.thread-panel,
.site-panel,
.settings-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(137, 155, 177, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 20px 46px rgba(48, 65, 86, 0.09);
}

.workspace-panel.panel-focused {
  border-color: rgba(15, 138, 117, 0.46);
  box-shadow:
    0 0 0 3px rgba(15, 138, 117, 0.1),
    0 20px 46px rgba(48, 65, 86, 0.11);
}

.site-panel,
.thread-panel,
.settings-panel {
  display: grid;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.settings-panel {
  align-self: start;
  max-height: calc(100vh - 128px);
  overflow-y: auto;
  grid-template-rows: auto minmax(0, max-content);
}

.settings-form {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: #fbfcfd;
}

.settings-form + .settings-form {
  border-top: 1px solid var(--line);
}

.cleanup-status {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.6;
}

.cleanup-status [role="status"] {
  color: #b91c1c;
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 14px;
  align-items: center;
  border: 1px solid #e0e7ee;
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(28, 42, 56, 0.05);
}

.settings-row strong {
  display: block;
  font-size: 15px;
  line-height: 1.35;
}

.settings-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.settings-row input[type="checkbox"] {
  justify-self: end;
  width: 22px;
  height: 22px;
  accent-color: var(--brand);
}

.widget-icon-row {
  align-items: start;
}

.widget-icon-settings {
  display: grid;
  gap: 10px;
}

.widget-icon-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.widget-icon-choice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 54px;
  border: 1px solid #d8e2ec;
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
  cursor: pointer;
}

.widget-icon-choice:has(input:checked) {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(18, 183, 245, 0.14);
}

.widget-icon-choice input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand);
}

.widget-icon-choice strong {
  font-size: 13px;
}

.widget-icon-swatch {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  background: #e7f7fd;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.custom-swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#widgetIconUploadInput {
  min-height: 40px;
  border: 1px solid #d8e2ec;
  border-radius: 8px;
  padding: 8px;
  background: #ffffff;
}

.settings-row input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.settings-row select,
.settings-row textarea {
  min-height: 40px;
  padding: 8px 10px;
}

.settings-row textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.55;
}

.settings-action-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.settings-save-button {
  justify-self: end;
  min-width: 128px;
  min-height: 40px;
}

.site-form {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.site-form input,
.site-form button {
  min-height: 38px;
  padding: 8px 10px;
}

.site-compact-form {
  padding: 12px;
  background: #f6f8fb;
}

.site-compact-form input {
  min-height: 38px;
  border-color: #dfe6ee;
  background: #ffffff;
  font-size: 14px;
}

.site-compact-form button {
  min-height: 38px;
  background: #0f8a75;
  font-size: 14px;
}

.site-compact-form button:hover {
  background: #0b695b;
}

.site-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 12px;
  background: #fbfcfd;
}

.site-item {
  display: grid;
  gap: 8px;
  border: 1px solid #e0e7ee;
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(28, 42, 56, 0.05);
}

.site-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.site-status {
  border-radius: 999px;
  padding: 4px 8px;
  background: #e7f8f2;
  color: #0f6b58;
  font-size: 12px;
  font-weight: 900;
}

.site-id {
  overflow: hidden;
  color: #8390a0;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-name {
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-domain {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.embed-code {
  display: block;
  overflow: hidden;
  border: 1px solid #dfe6ee;
  border-radius: 6px;
  padding: 8px 9px;
  background: #f7fafc;
  color: #526276;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.embed-code-warning {
  margin: 0;
  border-left: 3px solid #d97706;
  padding: 8px 10px;
  background: #fffbeb;
  color: #92400e;
  font-size: 12px;
  line-height: 1.45;
}

.embed-code-warning[hidden] {
  display: none;
}

.copy-button {
  min-height: 34px;
  border-color: #cfdbe7;
  font-size: 13px;
}

.site-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.danger-button {
  min-height: 34px;
  border: 1px solid #f0c9c9;
  background: #fff5f5;
  color: #b42318;
  font-size: 13px;
}

.danger-button:hover {
  border-color: #e89a9a;
  background: #ffe8e8;
  color: #971b12;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 70px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.panel-head h2 {
  margin: 2px 0 0;
  font-size: 19px;
  letter-spacing: 0;
  line-height: 1.2;
}

.filter-bar {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #f6f8fb;
}

.filter-bar select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.ghost-button:hover {
  background: #f1f5f9;
}

.thread-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 10px;
  background: #fbfcfd;
}

.thread-item {
  display: grid;
  width: 100%;
  min-height: 66px;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.thread-item:hover,
.thread-item.active {
  border-color: rgba(15, 138, 117, 0.22);
  background: #edf8f5;
  box-shadow:
    inset 3px 0 0 #0f8a75,
    0 10px 24px rgba(22, 48, 58, 0.08);
}

.thread-item.has-unread {
  border-color: rgba(220, 38, 38, 0.24);
  background: #fff7f7;
}

.thread-item.has-unread:hover,
.thread-item.has-unread.active {
  background: #fff1f1;
  box-shadow:
    inset 3px 0 0 #dc2626,
    0 10px 24px rgba(128, 34, 34, 0.08);
}

.thread-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: #273849;
  color: #ffffff;
  font-size: 14px;
  font-weight: 900;
}

.thread-body {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.thread-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: max-content;
}

.thread-site-badge {
  flex: 0 1 auto;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(15, 138, 117, 0.12);
  color: #0b695b;
  font-size: 12px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-count {
  flex: 0 0 auto;
  color: #8390a0;
  font-size: 12px;
  font-weight: 800;
}

.thread-unread-badge {
  display: grid;
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  padding: 0 7px;
  background: #dc2626;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.admin-chat {
  width: 100%;
  min-width: 0;
}

.qq-chat {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.qq-chat .chat-header {
  min-height: 72px;
  background: #ffffff;
}

.admin-chat .chat-header {
  align-items: center;
  padding: 16px 18px;
}

.admin-chat .chat-header > div:not(.chat-status-strip) {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 10px;
}

.admin-chat .chat-header h2 {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  max-width: 48vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chat .chat-header p {
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chat .chat-header .chat-status-strip {
  margin-left: auto;
}

.chat-status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.chat-status-strip span {
  min-height: 30px;
  border: 1px solid #d7e6df;
  border-radius: 999px;
  padding: 6px 10px;
  background: #f3fbf7;
  color: #0f6b58;
  font-size: 12px;
  font-weight: 900;
}

.thread-body .visitor-presence,
.chat-status-strip .visitor-presence {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  gap: 6px;
  border: 1px solid #86efac;
  border-radius: 999px;
  padding: 5px 10px;
  background: #dcfce7;
  color: #166534;
  font-size: 13px;
  font-weight: 800;
  line-height: 20px;
  white-space: nowrap;
}

.visitor-presence::before {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.thread-body .visitor-presence {
  padding: 1px 7px;
  font-size: 11px;
  line-height: 18px;
}

.visitor-presence.is-offline,
.visitor-presence.is-unknown {
  border-color: #cbd5e1;
  background: #f1f5f9;
  color: #475569;
}

.visitor-presence[hidden] {
  display: none;
}

.qq-chat .messages {
  height: auto;
  min-height: 0;
  gap: 14px;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0)),
    #edf2f6;
}

.chat-empty-state {
  display: grid;
  align-self: center;
  justify-items: center;
  gap: 9px;
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.empty-illustration {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 1px solid rgba(15, 138, 117, 0.16);
  border-radius: 8px;
  background: #ffffff;
  color: #0f8a75;
  box-shadow: 0 14px 32px rgba(35, 52, 68, 0.08);
  font-size: 22px;
  font-weight: 900;
}

.chat-empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.qq-chat .message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.admin-chat .message-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.admin-chat .message-actions button {
  width: auto;
  min-width: 44px;
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  cursor: pointer;
}

.admin-chat .message-actions button:disabled { opacity: .5; cursor: wait; }
.admin-chat .message-actions button:focus-visible { outline: 2px solid #008f7a; outline-offset: 2px; }

.qq-chat .message-row.admin {
  flex-direction: row-reverse;
}

.visitor-chat .message-row.visitor {
  flex-direction: row-reverse;
}

.visitor-chat .message-row.admin {
  flex-direction: row;
}

.qq-avatar {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: #667889;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.qq-chat .message-row.admin .qq-avatar {
  background: #0f8a75;
}

.visitor-chat .message-row.visitor .qq-avatar {
  background: #0f8a75;
}

.visitor-chat .message-row.admin .qq-avatar {
  background: #667889;
}

.qq-bubble {
  max-width: min(560px, calc(100% - 56px));
  border-radius: 6px;
  padding: 10px 12px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(31, 41, 51, 0.08);
  line-height: 1.5;
}

.message-time {
  display: block;
  margin-bottom: 4px;
  color: #7b8794;
  font-size: 11px;
  line-height: 1.2;
  user-select: none;
}

.qq-chat .message-row.admin .message-time,
.visitor-chat .message-row.visitor .message-time {
  text-align: right;
}

.qq-chat .message-row.admin .qq-bubble {
  background: #d8f5e7;
}

.read-receipt-status {
  align-self: flex-end;
  margin: 0 2px 2px;
  color: #8390a0;
  font-size: 12px;
  line-height: 1.2;
  user-select: none;
}

.pending-message-status {
  align-self: flex-end;
  margin: 0 2px 2px;
  color: #8390a0;
  font-size: 12px;
  line-height: 1.2;
  user-select: none;
}

.pending-message-status.failed {
  color: #b42318;
  font-weight: 800;
}

.visitor-chat .message-row.visitor .qq-bubble {
  background: #d8f5e7;
}

.visitor-chat .message-row.admin .qq-bubble {
  background: #ffffff;
}

.greeting-message .qq-bubble {
  border: 1px solid #d7e6df;
}

.qq-bubble.image-bubble {
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.qq-chat .message-row.admin .qq-bubble.image-bubble,
.visitor-chat .message-row.visitor .qq-bubble.image-bubble,
.visitor-chat .message-row.admin .qq-bubble.image-bubble {
  background: transparent;
}

.qq-bubble.image-bubble .message-time {
  width: fit-content;
  margin-bottom: 5px;
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.72);
}

.qq-chat .message-row.admin .qq-bubble.image-bubble .message-time,
.visitor-chat .message-row.visitor .qq-bubble.image-bubble .message-time {
  margin-left: auto;
}

.qq-bubble p {
  margin: 0;
  overflow-wrap: anywhere;
}

.visitor-chat {
  width: min(100%, 720px);
  height: min(760px, calc(100vh - 48px));
  min-height: 560px;
}

.admin-chat .qq-composer,
.visitor-chat .qq-composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  padding: 12px 14px;
  background: #ffffff;
}

.qq-toolbar {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0;
}

.qq-tool-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: var(--text);
}

.qq-tool-button:hover {
  background: #eef3f8;
}

.image-picker-button {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  place-items: center;
  padding: 0;
}

.image-tool-icon,
.emoji-tool-icon {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.emoji-picker-button {
  display: inline-grid;
  width: 44px;
  min-width: 44px;
  place-items: center;
  padding: 0;
}

.image-action-menu,
.emoji-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  z-index: 30;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(31, 41, 51, 0.16);
}

.image-action-menu[hidden],
.emoji-panel[hidden] {
  display: none;
}

.image-action-menu {
  left: 0;
  display: grid;
  min-width: 128px;
  overflow: hidden;
  padding: 4px;
}

.image-action-option {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 38px;
  border: 0;
  border-radius: 4px;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.image-action-option:hover {
  background: #eef3f8;
}

.image-action-option-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 4px;
  background: #e7f6fd;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
}

.emoji-panel {
  right: 0;
  width: min(286px, calc(100vw - 32px));
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
}

.qq-emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 34px);
  gap: 4px;
  justify-content: start;
}

.qq-emoji-item {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 4px;
  background: #fff8dc;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.qq-emoji-item:hover {
  border-color: #f2c94c;
  background: #fff0b8;
}

.qq-emoji-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35em;
  margin: 0 1px;
  font-size: 1.22em;
  line-height: 1;
  vertical-align: -0.16em;
}

.qq-input-area {
  min-height: 38px;
  max-height: 92px;
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: none;
}

.composer textarea.qq-input-area {
  padding: 8px 10px;
}

.qq-input-area:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 108, 148, 0.16);
}

.qq-send-row {
  display: flex;
  justify-content: flex-end;
  padding: 0;
}

.qq-send-button {
  min-width: 76px;
  min-height: 38px;
  border-radius: 4px;
  background: var(--brand);
}

.qq-send-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:hover {
  background: #f1f5f9;
}

.chat-image {
  display: block;
  width: min(320px, 100%);
  height: auto;
  aspect-ratio: 4 / 3;
  max-width: min(320px, 100%);
  max-height: 260px;
  border-radius: 6px;
  background: transparent;
  cursor: zoom-in;
  object-fit: contain;
}

.chat-image.is-expanded {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 9999;
  width: auto;
  height: auto;
  aspect-ratio: auto;
  max-width: min(86vw, 920px);
  max-height: min(86vh, 760px);
  border-radius: 8px;
  background: transparent;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.26);
  cursor: zoom-out;
  transform: translate(-50%, -50%);
}

.hidden {
  display: none;
}

@media (max-width: 1180px) {
  .admin-layout-polished {
    grid-template-columns: 150px minmax(0, 1fr);
  }

  .workbench-chat-layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }

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

  .admin-stat-row span {
    padding-inline: 10px;
  }
}

@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
  .page,
  .admin-page {
    padding: 8px;
  }

  .admin-page {
    height: 100vh;
    min-height: 100vh;
    height: 100dvh;
    min-height: 100dvh;
    height: var(--admin-viewport-height, 100dvh);
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow: hidden;
  }

  .chat-shell,
  .login-panel {
    width: 100%;
  }

  .messages {
    height: min(58vh, 430px);
  }

  .composer,
  .login-form {
    grid-template-columns: 1fr;
  }

  .admin-chat .qq-composer,
  .visitor-chat .qq-composer {
    grid-template-columns: 40px minmax(0, 1fr) 40px minmax(66px, auto);
    gap: 6px;
    align-items: center;
    padding: 8px;
  }

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

  .admin-layout-polished {
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    overflow: hidden;
  }

  .workbench-main {
    height: 100%;
    min-height: 0;
    gap: 8px;
    overflow: hidden;
  }

  .workbench-sidebar {
    grid-template-rows: auto;
    position: relative;
    z-index: 30;
    overflow: visible;
  }

  .sidebar-brand {
    grid-template-columns: 34px 38px minmax(0, 1fr) auto;
    padding: 10px 12px;
  }

  .mobile-nav-dropdown {
    display: block;
  }

  .mobile-function-menu {
    position: absolute;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .desktop-logout-button {
    display: none;
  }

  .mobile-logout-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-nav,
  .sidebar-foot {
    display: none;
  }

  .admin-grid {
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    overflow: hidden;
  }

  .workbench-chat-layout {
    height: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    gap: 8px;
    overflow: hidden;
  }

  #adminPanel:not([data-mobile-view="chat"]) .admin-chat,
  #adminPanel[data-mobile-view="chat"] .workbench-visitor-panel {
    display: none;
  }

  .back-to-visitors {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 6px 8px;
    border-color: transparent;
    font-size: 14px;
    line-height: 20px;
    white-space: nowrap;
    touch-action: manipulation;
  }

  .back-to-visitors:active {
    background: #e2e8f0;
  }

  .admin-stat-row {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .admin-stat-row span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 6px 8px;
    text-align: center;
  }

  .availability-toggle {
    min-height: 30px;
    padding: 6px 10px;
    font-size: 13px;
  }

  .panel-kicker {
    font-size: 11px;
  }

  .workspace-panel,
  .thread-panel,
  .site-panel,
  .settings-panel {
    box-shadow: none;
  }

  .panel-head {
    min-height: 0;
    padding: 12px;
  }

  .panel-head h2 {
    font-size: 20px;
  }

  .site-list,
  .thread-list,
  .workbench-thread-list {
    gap: 4px;
    max-height: 240px;
    padding: 6px;
  }

  .workbench-thread-list {
    height: 100%;
    max-height: none;
    overflow-y: auto;
    border: 1px solid rgba(215, 224, 234, 0.9);
    border-radius: 8px;
    background: #ffffff;
  }

  .thread-item {
    min-height: 44px;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    gap: 6px;
    align-items: center;
    padding: 6px 8px;
  }

  .thread-avatar {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    font-size: 13px;
  }

  .thread-body {
    display: flex;
    align-items: center;
    gap: 2px;
  }

  .thread-site-badge {
    max-width: 96px;
    padding: 2px 7px;
    font-size: 11px;
    line-height: 1.25;
  }

  .thread-count {
    font-size: 11px;
  }

  .thread-meta {
    justify-content: flex-end;
    gap: 4px;
  }

  .settings-row {
    grid-template-columns: 1fr;
  }

  .settings-row input[type="checkbox"] {
    justify-self: start;
  }

  .settings-save-button {
    justify-self: stretch;
  }

  .admin-shell {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .qq-chat .chat-header {
    min-height: 0;
    padding: 12px;
  }

  .admin-chat .chat-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 4px 8px;
    align-items: center;
    padding: 6px 8px;
  }

  .admin-chat .chat-header > div:not(.chat-status-strip) {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 8px;
  }

  .admin-chat .chat-header h2 {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    font-size: 18px;
    line-height: 24px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-chat .chat-header p {
    display: none;
    overflow: hidden;
    flex: 1 1 auto;
    margin: 0;
    font-size: 14px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-chat .chat-header .chat-status-strip {
    justify-self: end;
    align-self: center;
    gap: 6px;
  }

  .admin-chat .chat-header .visitor-presence {
    min-height: 28px;
    padding: 3px 8px;
    font-size: 12px;
    line-height: 20px;
  }

  .chat-status-strip span {
    min-height: 28px;
    padding: 5px 8px;
  }

  .qq-chat .messages {
    height: auto;
    min-height: 0;
    gap: 8px;
    overflow-y: auto;
    padding: 12px;
  }

  .admin-chat.qq-chat .messages {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .admin-chat.qq-chat .message-row {
    gap: 8px;
  }

  .admin-chat.qq-chat .qq-bubble {
    padding: 8px 10px;
    line-height: 1.35;
  }

  .admin-chat.qq-chat .message-time {
    margin-bottom: 2px;
  }

  .admin-chat.qq-chat .chat-image {
    max-height: 220px;
  }

  .chat-empty-state {
    gap: 6px;
  }

  .empty-illustration {
    width: 50px;
    height: 50px;
  }

  .image-picker-button,
  .emoji-picker-button {
    width: 40px;
    min-width: 40px;
  }

  .qq-send-button {
    min-width: 66px;
  }

  .qq-chat {
    height: 100%;
    min-height: 0;
    max-height: 100%;
  }

  .visitor-chat {
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    min-height: 0;
  }

  .qq-bubble {
    max-width: calc(100% - 48px);
  }
}
