:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #dce3ea;
  --text: #17212b;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #b45309;
  --danger: #b91c1c;
  --visitor: #eef6ff;
  --agent: #eaf8f4;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

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

.login-card {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #fff;
}

.login-card h1 {
  margin-bottom: 8px;
}

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

.visitor-page {
  background:
    linear-gradient(135deg, rgba(15, 118, 110, .08), rgba(180, 83, 9, .08)),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

button:disabled:hover {
  background: var(--primary);
}

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

.visitor-content {
  width: min(640px, 100%);
}

.visitor-content h1 {
  max-width: 560px;
  margin: 0;
  font-size: 36px;
  line-height: 1.18;
}

.visitor-copy {
  max-width: 560px;
  margin: 16px 0 22px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.service-link {
  min-width: 132px;
}

.floating-service {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  box-shadow: 0 14px 36px rgba(15, 23, 42, .22);
  font-weight: 700;
}

.service-widget {
  position: fixed;
  right: 24px;
  bottom: 104px;
  z-index: 30;
  display: none;
  flex-direction: column;
  width: min(420px, calc(100vw - 32px));
  height: min(680px, calc(100vh - 128px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
}

.service-widget.open {
  display: flex;
}

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

.service-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  color: var(--text);
  background: #f8fafc;
}

.service-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fbfdff;
}

.faq-accordion {
  padding: 0 0 14px;
  background: #fff;
}

.help-tabs {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.help-tab {
  position: relative;
  border-radius: 0;
  padding: 13px 0 12px;
  color: var(--muted);
  background: transparent;
}

.help-tab:hover {
  color: var(--primary);
  background: transparent;
}

.help-tab.active {
  color: var(--text);
}

.help-tab.active::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--primary);
  content: "";
}

.quick-question-list {
  margin: 26px 22px 8px;
  border: 1px solid #d6d6d6;
  background: #fff;
}

.quick-question {
  display: block;
  width: 100%;
  border-bottom: 1px solid #d6d6d6;
  border-radius: 0;
  padding: 7px 12px;
  color: #0891a1;
  text-align: left;
  background: #fff;
  line-height: 1.25;
}

.quick-question:last-child {
  border-bottom: 0;
}

.quick-question:hover {
  color: #0f766e;
  background: #f4fbfb;
}

.about-box {
  margin: 26px 22px 8px;
  border: 1px solid #d6d6d6;
  padding: 14px;
  color: var(--muted);
  line-height: 1.7;
  background: #fff;
}

.about-box p {
  margin: 0;
}

.chat-divider {
  position: sticky;
  top: 0;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #f8fafc;
  font-size: 13px;
}

.widget-messages {
  min-height: 180px;
  max-height: 280px;
  padding: 14px;
}

.widget-composer {
  flex: 0 0 auto;
}

button.ghost {
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
}

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

button.ghost:disabled:hover {
  color: var(--muted);
  border-color: var(--line);
  background: transparent;
}

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

textarea {
  min-height: 86px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

.page {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(320px, 1fr);
  gap: 18px;
  width: min(1120px, calc(100% - 32px));
  margin: 24px auto;
}

.admin-layout {
  display: grid;
  grid-template-columns: 300px minmax(360px, 1fr) 360px;
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-width: 0;
}

.faq-panel,
.chat-panel,
.admin-chat,
.faq-admin,
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 48px);
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

h2 {
  font-size: 19px;
}

.status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 12px;
  background: #f8fafc;
}

.status.online {
  color: var(--primary-dark);
  border-color: #99d5ca;
  background: #edfdf9;
}

.faq-list,
.session-list {
  overflow: auto;
  padding: 14px;
}

.faq-item,
.session-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  margin-bottom: 10px;
  background: #fff;
}

.faq-item h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.faq-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-wrap;
}

.faq-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.faq-actions button {
  padding: 7px 10px;
}

.session-item {
  display: block;
  width: 100%;
  color: var(--text);
  text-align: left;
  background: #fff;
}

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

.session-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

.badge {
  min-width: 24px;
  border-radius: 999px;
  padding: 2px 7px;
  color: #fff;
  text-align: center;
  font-size: 12px;
  background: var(--accent);
}

.session-preview {
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 18px;
  background: #fbfdff;
}

.message {
  max-width: min(76%, 680px);
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.visitor {
  margin-right: auto;
  background: var(--visitor);
}

.message.agent {
  margin-left: auto;
  background: var(--agent);
}

.visitor-page .message.visitor {
  margin-right: 0;
  margin-left: auto;
}

.visitor-page .message.agent {
  margin-right: auto;
  margin-left: 0;
}

.visitor-page .message {
  max-width: 50%;
  padding: 7px 9px;
}

.visitor-page .message-meta {
  margin-bottom: 4px;
  font-size: 11px;
}

.visitor-page .widget-messages {
  padding: 10px 16px;
}

.message-meta {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.faq-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 14px;
}

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

  .faq-panel,
  .chat-panel,
  .admin-chat,
  .faq-admin,
  .sidebar {
    min-height: auto;
  }

  .messages {
    min-height: 380px;
  }
}

@media (max-width: 560px) {
  .page {
    width: calc(100% - 20px);
    margin: 10px auto;
  }

  .admin-layout {
    padding: 10px;
  }

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

  .message {
    max-width: 92%;
  }

  .visitor-page .message {
    max-width: 50%;
  }

  .visitor-content h1 {
    font-size: 28px;
  }

  .floating-service {
    right: 16px;
    bottom: 16px;
  }

  .service-widget {
    right: 10px;
    bottom: 88px;
    width: calc(100vw - 20px);
    height: calc(100vh - 108px);
  }
}
