:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --soft: #f8fafc;
  --line: #dde3ea;
  --line-strong: #cbd5e1;
  --text: #17202a;
  --muted: #697586;
  --green: #07c160;
  --green-dark: #05964a;
  --blue: #2563eb;
  --danger: #c2410c;
  --sidebar: #18212f;
  --sidebar-soft: #223044;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.hidden { display: none !important; }

.login-shell {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

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

.login-panel p {
  margin: 0 0 20px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 12px;
}

.field-input,
.login-form input,
.editor-panel input,
.editor-panel textarea,
.profile-form input,
.composer textarea,
.visitor-remark-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  outline: none;
  background: #fff;
}

.field-input:focus,
.login-form input:focus,
.editor-panel input:focus,
.editor-panel textarea:focus,
.profile-form input:focus,
.composer textarea:focus,
.visitor-remark-row input:focus {
  border-color: var(--green);
}

.login-form button,
.primary-button,
.composer button[type="submit"] {
  background: var(--green);
  color: #fff;
  border-radius: 6px;
  padding: 10px 14px;
}

.login-form button:hover,
.primary-button:hover,
.composer button[type="submit"]:hover {
  background: var(--green-dark);
}

.secondary-button,
.file-button,
.tool-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 13px;
}

.secondary-button:hover,
.file-button:hover,
.tool-button:hover,
.ghost-button:hover,
.icon-button:hover {
  background: #eef2f7;
}

.error-text,
.status-text.error,
#remarkStatus.error {
  color: var(--danger);
}

.error-text {
  min-height: 20px;
  margin-top: 12px;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  overflow: hidden;
}

.main-sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: #e5edf6;
}

.brand-block {
  height: 72px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-mark,
.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
  font-weight: 700;
}

.sidebar-avatar {
  display: block;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,0.18);
  background: #0f172a;
}

.brand-block strong {
  display: block;
  max-width: 136px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-block span {
  display: block;
  margin-top: 3px;
  color: #94a3b8;
  font-size: 12px;
}

.visitor-entry-card {
  margin: 12px 10px 4px;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.54);
}

.visitor-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #cbd5e1;
  font-size: 13px;
}

.sidebar-copy-button {
  min-height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  background: #16c56f;
  color: #fff;
  font-size: 12px;
}

.sidebar-copy-button:disabled {
  cursor: not-allowed;
  background: rgba(148, 163, 184, 0.32);
  color: #94a3b8;
}

.visitor-url-text {
  display: block;
  margin-top: 9px;
  max-height: 46px;
  overflow: hidden;
  border-radius: 6px;
  padding: 8px;
  background: rgba(2, 6, 23, 0.32);
  color: #93c5fd;
  font-size: 12px;
  line-height: 1.45;
  text-decoration: none;
  word-break: break-all;
}

.visitor-entry-card.empty .visitor-url-text {
  color: #94a3b8;
}

.visitor-qr-wrap {
  display: flex;
  justify-content: center;
  margin-top: 10px;
  padding: 8px;
  border-radius: 8px;
  background: #fff;
}

.visitor-entry-card.empty .visitor-qr-wrap {
  display: none;
}

#visitorQrCanvas {
  width: 132px;
  height: 132px;
  display: block;
}

.visitor-url-hint {
  min-height: 18px;
  margin: 8px 0 0;
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.5;
}

.visitor-url-hint:empty {
  display: none;
}

.main-nav {
  display: grid;
  gap: 6px;
  padding: 14px 10px;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--sidebar-soft);
  color: #fff;
}

.logout-button {
  margin: auto 10px 12px;
  min-height: 38px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: #e5edf6;
}

.workspace {
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

.view {
  display: none;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.active-view {
  display: block;
}

.page-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.page-header h1,
.pane-header h2,
.section-title-row h2 {
  margin: 0;
}

.page-header h1 {
  font-size: 22px;
}

.page-header p,
.pane-header p,
.section-title-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  padding: 18px 22px 0;
}

.metric-card,
.profile-panel,
.editor-panel,
.content-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.profile-panel,
.editor-panel {
  margin: 18px 22px;
  padding: 16px;
}

.section-title-row,
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.profile-form {
  display: grid;
  grid-template-columns: minmax(220px, 320px);
  gap: 12px;
  margin-top: 14px;
}

.avatar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-preview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fafc;
  object-fit: cover;
}

.status-text {
  min-height: 18px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.chat-view.active-view {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 320px;
  overflow: hidden;
}

.conversation-pane,
.quick-side-panel,
.chat-panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.conversation-pane,
.quick-side-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.quick-side-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.pane-header {
  min-height: 64px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.pane-header h2 {
  font-size: 16px;
}

.conversation-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  background: #eef3f5;
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 12px;
  margin: 4px 0;
  text-align: left;
  background: transparent;
  border-radius: 8px;
  color: var(--text);
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--panel);
}

.conversation-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  grid-column: 1 / -1;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  display: inline-grid;
  place-items: center;
}

.presence {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
}

.presence.online { background: #dff8e8; color: #057a3a; }
.presence.offline { background: #e5eaf0; color: #64748b; }
.presence.unknown { background: #eef2f7; color: var(--muted); }

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-header {
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  background: var(--panel);
}

.chat-header h2 {
  margin: 0;
  font-size: 18px;
  word-break: break-all;
}

.visitor-name-button {
  max-width: min(680px, 100%);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  text-align: left;
  word-break: break-all;
}

.visitor-name-button:not(:disabled):hover { color: var(--green-dark); }
.visitor-name-button:disabled { cursor: default; opacity: 1; }

.chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}

.visitor-remark-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  max-width: 620px;
}

.visitor-remark-row input {
  width: min(320px, 100%);
  min-width: 160px;
  height: 32px;
  padding: 6px 9px;
}

.visitor-remark-row button {
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  background: #edf2f7;
  color: var(--text);
  white-space: nowrap;
}

#remarkStatus {
  min-width: 44px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 24px 24px;
  background: #f8fafc;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin-top: 20vh;
}

.empty-state.inline {
  margin: 16px 0;
  text-align: center;
}

.message-row {
  display: flex;
  align-items: flex-start;
  margin: 8px 0;
}

.message-row.inbound,
.message-row.bot,
.message-row.platform-agent { justify-content: flex-start; }
.message-row.outbound { justify-content: flex-end; }
.message-row.system { justify-content: center; margin: 14px 0; }

.message-stack {
  display: flex;
  max-width: min(560px, 70%);
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
}

.message-row.outbound .message-stack { align-items: flex-end; }
.message-row.image .message-stack,
.message-row.video .message-stack { max-width: min(420px, 70%); }
.message-row.link .message-stack { max-width: min(360px, 70%); }
.message-row.system .message-stack { width: auto; max-width: none; align-items: center; }

.meta {
  margin: 0 8px 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.message-row.outbound .meta { text-align: right; }

.bubble {
  width: fit-content;
  max-width: 100%;
  min-height: 0;
  padding: 8px 11px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.outbound .bubble {
  background: #d9fdd3;
  border-color: #b6e6b0;
}

.bot .bubble,
.platform-agent .bubble {
  background: #eef2ff;
  color: #334155;
}

.message-row.image .bubble,
.message-row.video .bubble { padding: 6px; }
.message-row.system .bubble {
  width: auto;
  max-width: none;
  padding: 2px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
}
.message-row.system .meta { display: none; }

.media-preview {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 6px;
  background: #0f172a;
}

.message-row.video .media-preview {
  width: min(360px, 100%);
  max-height: 260px;
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.link-card {
  display: grid;
  gap: 4px;
  min-width: min(280px, 100%);
  color: var(--text);
  text-decoration: none;
}

.link-card strong { color: var(--blue); }
.link-card span {
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.reply-panel {
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer {
  padding: 10px 12px 12px;
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 10px;
}

.composer-tools {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.composer textarea {
  resize: none;
  min-height: 48px;
}

.quick-side-panel .content-card-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
}


.quick-send-card {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.quick-send-body {
  min-width: 0;
}

.quick-send-text {
  margin: 0;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.quick-send-media {
  display: block;
  width: 100%;
  max-height: 170px;
  border-radius: 6px;
  object-fit: contain;
  background: #0f172a;
  border: 1px solid var(--line);
}

img.quick-send-media {
  object-fit: cover;
}

.quick-send-caption {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.quick-send-button {
  width: 100%;
  min-height: 34px;
  border-radius: 6px;
  background: #16c56f;
  color: #fff;
  font-size: 13px;
}

.quick-send-button:disabled {
  cursor: not-allowed;
  background: #e2e8f0;
  color: var(--muted);
}

.content-card-head.compact-head {
  grid-template-columns: auto minmax(0, 1fr);
}

.content-card-head.compact-head span {
  justify-self: end;
}

.manage-view {
  padding-bottom: 24px;
}

.editor-panel {
  display: grid;
  gap: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.check-row input {
  width: auto;
}

.add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.add-row textarea {
  resize: vertical;
  min-height: 78px;
}

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

.content-card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 0 22px 22px;
}

.content-card-list.compact {
  grid-template-columns: 1fr;
  padding: 10px;
  align-content: start;
  align-items: start;
}

.content-card {
  min-width: 0;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.content-card-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.content-card-head strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content-card-head span,
.content-order,
.content-send-hint {
  color: var(--muted);
  font-size: 12px;
}

.content-order {
  min-width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #eef2f7;
}

.content-text {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.content-media {
  width: 100%;
  max-height: 180px;
  border-radius: 6px;
  object-fit: contain;
  background: #0f172a;
  border: 1px solid var(--line);
}

img.content-media {
  object-fit: cover;
}

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

.content-actions button {
  min-height: 30px;
  padding: 0 9px;
  border-radius: 6px;
  background: #edf2f7;
  color: var(--text);
  font-size: 12px;
}

.content-actions button:hover { background: #e2e8f0; }
.content-actions button[data-action="delete"]:hover {
  color: var(--danger);
  background: #fff1ed;
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
  .brand-block { justify-content: center; padding: 12px 8px; }
  .brand-block > div:last-child { display: none; }
  .visitor-entry-card { display: none; }
  .nav-item { text-align: center; padding: 0 6px; font-size: 13px; }
  .logout-button { font-size: 13px; }
  .chat-view.active-view { grid-template-columns: 260px minmax(360px, 1fr) 280px; }
}

@media (max-width: 920px) {
  html,
  body { overflow: auto; }
  .app-shell {
    min-height: 100vh;
    height: auto;
    grid-template-columns: 1fr;
  }
  .main-sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .brand-block {
    width: auto;
    min-width: 72px;
    border-bottom: 0;
  }
  .main-nav {
    display: flex;
    flex: 1 0 auto;
    padding: 8px;
  }
  .nav-item { min-width: 76px; }
  .logout-button { margin: 8px; min-width: 64px; }
  .view { height: auto; min-height: calc(100vh - 56px); }
  .chat-view.active-view {
    grid-template-columns: 1fr;
    grid-template-rows: 260px 65vh 360px;
    overflow: visible;
  }
  .conversation-pane,
  .quick-side-panel { border: 0; border-bottom: 1px solid var(--line); }
  .metrics-grid { grid-template-columns: 1fr; }
  .content-card-list { grid-template-columns: 1fr; }
  .add-row { grid-template-columns: 1fr; }
  .message-stack,
  .message-row.image .message-stack,
  .message-row.video .message-stack,
  .message-row.link .message-stack { max-width: 84%; }
}
