:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #687782;
  --line: #dce5ea;
  --accent: #168b7d;
  --accent-dark: #0e665c;
  --warn: #b95021;
  --soft: #e7f4f2;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
input {
  font: inherit;
}

.chat-only-page {
  height: 100vh;
  overflow: hidden;
  background: #f3f6f8;
}

.chat-only-shell {
  height: 100vh;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 24px;
}

.panel-head p,
.chat-work-head p {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.bottom-chat {
  width: min(860px, 100%);
  height: min(760px, calc(100vh - 48px));
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(20, 35, 45, 0.08);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
}

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

.bottom-chat .chat-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  position: relative;
  z-index: 2;
}

.chat-title-row strong {
  white-space: nowrap;
}

.chat-title-row span {
  color: #7a4c00;
  background: #fff1b8;
  border-radius: 999px;
  padding: 3px 8px;
  font-weight: 700;
}

.chat-topic {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  color: var(--accent-dark);
  background: var(--soft);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 20px;
  white-space: nowrap;
}

.customer-sound-toggle {
  position: absolute;
  right: 16px;
  top: 50%;
  z-index: 2;
  width: 38px;
  height: 38px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 50%;
  color: var(--accent-dark);
  background: var(--soft);
  cursor: pointer;
  font-weight: 800;
}

.customer-sound-toggle.is-off {
  color: var(--muted);
  background: #eef3f5;
}

.chat-top span,
.socket-state,
.ticket-item small,
.message small,
.admin-message small {
  color: var(--muted);
  font-size: 13px;
}

.bottom-chat .chat-title-row span {
  color: #7a4c00;
  background: #fff1b8;
  font-weight: 700;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.ghost-button,
.primary-button,
.danger-button,
.file-button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.icon-button {
  width: 38px;
  padding: 0;
  color: var(--accent-dark);
  background: var(--soft);
}

.ghost-button,
.file-button {
  color: var(--accent-dark);
  background: var(--soft);
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.file-button input {
  display: none;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.settings-form > .primary-button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  line-height: 1;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.danger-button {
  color: var(--warn);
  background: #fff0e9;
}

.text-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.messages,
.admin-messages {
  min-height: 330px;
  max-height: min(430px, calc(100vh - 260px));
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bottom-chat .messages {
  min-height: 0;
  max-height: none;
  height: 100%;
  overscroll-behavior: contain;
}

.message,
.admin-message {
  max-width: min(76%, 620px);
  padding: 11px 13px;
  border-radius: 8px;
  background: #eef3f5;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.message.customer,
.admin-message.admin {
  align-self: flex-end;
  color: #fff;
  background: var(--accent);
}

.message.service,
.admin-message.customer {
  align-self: flex-start;
}

.message p,
.admin-message p {
  margin: 4px 0;
  white-space: pre-wrap;
}

.message-image {
  display: block;
  max-width: 220px;
  max-height: 240px;
  margin-top: 8px;
  border-radius: 8px;
  object-fit: cover;
}

.message-video {
  display: block;
  width: min(280px, 100%);
  max-height: 260px;
  margin-top: 8px;
  border-radius: 8px;
  background: #000;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 14px 18px 16px;
  border-top: 1px solid var(--line);
}

.messenger-composer {
  display: grid;
  grid-template-columns: 40px 1fr 42px;
  align-items: end;
  gap: 8px;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
}

.settings-form input[type="text"],
.settings-form input:not([type]),
.settings-form input[type="password"],
.settings-form input[type="number"],
.settings-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

.settings-form input[readonly] {
  color: var(--muted);
  background: #f6f9fa;
}

.database-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.messenger-composer textarea {
  min-height: 42px;
  max-height: 96px;
  resize: none;
  border-radius: 999px;
  padding: 11px 15px;
  line-height: 20px;
  overflow-y: auto;
}

.plus-button,
.send-arrow {
  width: 40px;
  height: 40px;
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-weight: 800;
  flex: 0 0 auto;
}

.plus-button {
  color: var(--accent-dark);
  background: var(--soft);
  font-size: 26px;
  line-height: 1;
}

.plus-button input {
  display: none;
}

.send-arrow {
  color: #fff;
  background: var(--accent);
}

.send-arrow:hover {
  background: var(--accent-dark);
}

.send-arrow svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transform: translateX(1px);
}

.composer-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.image-chip {
  max-width: 145px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent-dark);
  background: var(--soft);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
}

output {
  display: block;
  min-height: 18px;
  padding: 0 18px 14px;
  color: var(--warn);
  font-size: 13px;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  padding: 16px;
}

.admin-module-sidebar {
  min-height: calc(100vh - 32px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(20, 35, 45, 0.08);
  padding: 18px;
}

.admin-brand p,
.admin-brand h1 {
  margin: 0;
}

.admin-brand p {
  color: var(--accent);
  font-weight: 700;
}

.admin-brand h1 {
  margin-top: 6px;
}

.admin-module-nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.admin-module-nav button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
  text-align: left;
}

.admin-module-nav button.is-active,
.admin-module-nav button:hover {
  color: var(--accent-dark);
  background: var(--soft);
}

.admin-sidebar-actions {
  display: grid;
  gap: 10px;
}

.admin-workspace {
  min-width: 0;
}

.admin-view.is-active {
  min-height: calc(100vh - 32px);
}

.admin-view[hidden] {
  display: none !important;
}

#view-service.is-active {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 16px;
}

#view-frontend {
  max-width: 760px;
}

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

.admin-login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(20, 35, 45, 0.08);
}

.admin-login-card p,
.admin-login-card h1 {
  margin: 0;
}

.admin-login-card p {
  color: var(--accent);
  font-weight: 700;
}

.login-hint {
  color: var(--muted);
  background: var(--soft);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 13px;
}

.admin-login-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.admin-login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

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

.ticket-list-panel,
.admin-chat-panel,
.settings-panel {
  min-height: calc(100vh - 32px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(20, 35, 45, 0.08);
}

#view-frontend .settings-panel {
  min-height: auto;
}

.panel-head h1,
.panel-head h2,
.chat-work-head h2 {
  margin: 0;
}

.socket-state {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.ticket-list {
  max-height: calc(100vh - 140px);
  overflow: auto;
}

.ticket-item {
  width: 100%;
  display: block;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
  background: #fff;
  cursor: pointer;
}

.ticket-item.is-active,
.ticket-item:hover {
  background: var(--soft);
}

.ticket-item.is-waiting strong::after {
  content: "待回复";
  display: inline-block;
  margin-left: 8px;
  color: #fff;
  background: var(--warn);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}

.ticket-item p {
  margin: 6px 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-messages {
  min-height: calc(100vh - 250px);
  max-height: calc(100vh - 250px);
}

.admin-message {
  position: relative;
}

.admin-message .danger-button {
  margin-top: 8px;
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.settings-form {
  display: grid;
  gap: 14px;
  padding: 18px 20px;
}

.settings-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.auto-image-preview {
  display: grid;
  gap: 10px;
}

.auto-image-preview img {
  width: 100%;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.EasyMDEContainer {
  color: var(--ink);
}

.EasyMDEContainer .CodeMirror {
  border-color: var(--line);
  border-radius: 0 0 8px 8px;
}

.EasyMDEContainer .CodeMirror-code {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.editor-toolbar {
  border-color: var(--line);
  border-radius: 8px 8px 0 0;
}

.editor-preview,
.editor-preview-side {
  background: #fff;
}

.editor-preview img,
.editor-preview-side img {
  max-width: 100%;
  border-radius: 8px;
}

.markdown-live-preview {
  display: grid;
  gap: 8px;
}

.markdown-live-preview strong {
  color: var(--muted);
}

#autoReplyLivePreview {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  line-height: 1.6;
}

#autoReplyLivePreview img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  object-fit: contain;
}

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

@media (max-width: 980px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-module-sidebar {
    min-height: auto;
  }

  #view-service {
    grid-template-columns: 1fr;
  }

  .ticket-list-panel,
  .admin-chat-panel,
  .settings-panel {
    min-height: auto;
  }

  .admin-messages {
    min-height: 360px;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .chat-only-shell {
    place-items: start stretch;
    padding: 0;
  }

  .bottom-chat {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .messages,
  .admin-messages {
    max-height: calc(100vh - 235px);
  }

  .admin-shell {
    padding: 10px;
  }

  .chat-top,
  .panel-head,
  .chat-work-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .bottom-chat .chat-top {
    align-items: center;
    flex-direction: row;
    justify-content: flex-start;
  }

  .chat-topic {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
  }

  .customer-sound-toggle {
    right: 12px;
    width: 34px;
    height: 34px;
  }

  .message,
  .admin-message {
    max-width: 92%;
  }
}
