:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d9e0ea;
  --text: #172033;
  --muted: #667085;
  --brand: #14866d;
  --brand-dark: #0f6b58;
  --danger: #c43b3b;
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

.agent-page {
  background: #eef1f6;
}

.native-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1f2b3d 0%, #24364f 48%, #149a8f 100%);
}

.native-login-box {
  width: 380px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .22);
  padding: 34px 34px 30px;
}

.native-login-box h1 {
  margin: 0;
  font-size: 26px;
  color: #1f2b3d;
  text-align: center;
}

.native-login-box p {
  margin: 10px 0 28px;
  color: #8a96a8;
  text-align: center;
}

.native-login-box label {
  display: block;
  margin: 14px 0 8px;
  color: #5d6b7d;
}

.native-login-box input {
  width: 100%;
  height: 42px;
  border: 1px solid #d9dee8;
  border-radius: 3px;
  padding: 0 12px;
}

.native-login-box button {
  width: 100%;
  height: 42px;
  margin-top: 22px;
  border-radius: 3px;
  background: #149a8f;
}

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

.admin-menu {
  background: #202b3c;
  color: #c4cedc;
}

.admin-logo {
  height: 58px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.menu-item {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 22px;
  text-align: left;
  background: transparent;
  color: #c4cedc;
  border-left: 4px solid transparent;
}

.menu-item:hover,
.menu-item.active {
  background: #172132;
  color: #fff;
  border-left-color: #149a8f;
}

.admin-main {
  min-width: 0;
  display: grid;
  grid-template-rows: 58px 1fr;
}

.admin-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: #fff;
  border-bottom: 1px solid #dfe5ee;
}

.admin-top strong {
  margin-right: 14px;
  font-size: 18px;
}

.admin-top span {
  color: #149a8f;
  font-size: 13px;
}

.plain-btn,
.mini-btn,
.table-btn,
.danger-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: 3px;
  background: #149a8f;
  color: #fff;
}

.plain-btn {
  background: #f4f6fa;
  color: #42526a;
  border: 1px solid #d8dfe9;
}

.danger-btn,
.table-btn.danger {
  background: #d9534f;
}

.admin-content {
  padding: 16px;
  overflow: auto;
}

.admin-view {
  display: none;
  height: 100%;
}

.admin-view.active {
  display: block;
}

.native-chat {
  height: calc(100vh - 90px);
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 260px;
  background: #fff;
  border: 1px solid #dfe5ee;
}

.native-list,
.native-tools {
  min-width: 0;
  border-right: 1px solid #dfe5ee;
  background: #fbfcfe;
  overflow: auto;
}

.native-tools {
  border-right: 0;
  border-left: 1px solid #dfe5ee;
}

.list-tabs,
.tool-title {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid #dfe5ee;
  font-weight: 700;
}

.tab {
  height: 30px;
  padding: 0 10px;
  background: transparent;
  color: #42526a;
  border-radius: 3px;
}

.tab.active {
  background: #149a8f;
  color: #fff;
}

.native-conv {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  text-align: left;
  background: #fff;
  color: #263548;
  border-bottom: 1px solid #edf0f5;
}

.native-conv:hover,
.native-conv.active {
  background: #edf8f6;
}

.conv-avatar,
.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e9eef5;
  color: #fff;
  font-weight: 700;
  overflow: hidden;
}

.avatar-img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: cover;
}

.conv-info {
  min-width: 0;
}

.conv-info strong,
.conv-info small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-info small {
  margin-top: 5px;
  color: #8a96a8;
}

.native-conv em {
  color: #149a8f;
  font-style: normal;
  font-size: 12px;
}

.native-dialog,
.dialog-inner {
  min-width: 0;
  min-height: 0;
}

.dialog-inner {
  height: 100%;
  display: grid;
  grid-template-rows: 50px 1fr 150px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid #dfe5ee;
  background: #fff;
}

.dialog-head span {
  margin-left: 8px;
  color: #8a96a8;
  font-size: 13px;
}

.native-messages {
  background: #f4f7fb;
}

.native-composer {
  border-top: 1px solid #dfe5ee;
  background: #fff;
}

.native-composer textarea {
  width: 100%;
  height: 104px;
  border: 0;
  resize: none;
  outline: none;
  padding: 12px;
}

.composer-actions {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-top: 1px solid #edf0f5;
  color: #8a96a8;
  font-size: 13px;
}

.composer-actions button {
  width: 82px;
  height: 32px;
  border-radius: 3px;
}

.native-reply {
  display: block;
  width: calc(100% - 20px);
  margin: 10px;
  padding: 10px;
  text-align: left;
  background: #fff;
  color: #42526a;
  border: 1px solid #dfe5ee;
  border-radius: 3px;
  line-height: 1.5;
}

.native-reply:hover {
  border-color: #149a8f;
  color: #149a8f;
}

.msg {
  gap: 10px;
  align-items: flex-start;
}

.msg.mine {
  flex-direction: row-reverse;
}

.layui-card-like {
  background: #fff;
  border: 1px solid #dfe5ee;
}

.card-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid #dfe5ee;
  font-weight: 700;
}

.native-table {
  width: 100%;
  border-collapse: collapse;
}

.native-table th,
.native-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #edf0f5;
  text-align: left;
  font-size: 14px;
}

.native-table th {
  background: #f8fafc;
  color: #5d6b7d;
}

.native-form {
  padding: 18px;
}

.native-form label {
  display: block;
  margin: 14px 0 8px;
  color: #5d6b7d;
}

.native-form input,
.native-form select,
.native-form textarea,
.access-code textarea {
  width: min(560px, 100%);
  border: 1px solid #d9dee8;
  border-radius: 3px;
  padding: 9px 10px;
  background: #fff;
}

.native-form textarea {
  height: 220px;
}

.native-form button {
  display: block;
  width: 110px;
  height: 36px;
  margin-top: 18px;
  border-radius: 3px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  border-bottom: 1px solid #edf0f5;
}

.inline-form input,
.inline-form select {
  width: 180px;
  height: 36px;
}

.inline-form textarea {
  width: min(680px, 100%);
  height: 90px;
}

.inline-form button {
  margin-top: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  padding: 18px;
}

.stat-card {
  padding: 18px;
  background: #f8fafc;
  border: 1px solid #dfe5ee;
  border-radius: 4px;
}

.stat-card strong {
  display: block;
  color: #149a8f;
  font-size: 30px;
  line-height: 1;
}

.stat-card span {
  display: block;
  margin-top: 10px;
  color: #5d6b7d;
}

.access-code {
  padding: 18px;
}

.access-code p {
  margin: 16px 0 8px;
  color: #5d6b7d;
}

.access-code code {
  display: block;
  width: min(760px, 100%);
  padding: 12px;
  background: #f5f7fb;
  border: 1px solid #dfe5ee;
  color: #1f2b3d;
}

.access-code textarea {
  height: 88px;
}

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

  .admin-logo {
    font-size: 0;
    padding: 0;
    justify-content: center;
  }

  .admin-logo::after {
    content: "客服";
    font-size: 15px;
  }

  .menu-item {
    padding: 0 8px;
    text-align: center;
    font-size: 12px;
  }

  .native-chat {
    grid-template-columns: 240px 1fr;
  }

  .native-tools {
    display: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}

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

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

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 56px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: #162033;
  color: #fff;
}

.brand {
  font-weight: 700;
}

.status {
  color: #c9d4e5;
  font-size: 13px;
}

.visitor-wrap {
  max-width: 760px;
  width: 100%;
  margin: 24px auto;
  padding: 0 14px;
}

.chat-box {
  height: calc(100vh - 104px);
  height: calc(100dvh - 104px);
  min-height: 520px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

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

.messages {
  overflow: auto;
  padding: 18px;
}

.msg {
  margin: 0 0 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.msg.mine {
  justify-content: flex-end;
  flex-direction: row-reverse;
}

.bubble {
  max-width: min(74%, 620px);
  padding: 10px 12px;
  border-radius: 6px;
  background: #edf1f6;
  line-height: 1.5;
  word-break: break-word;
}

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

.chat-link {
  color: #0b65c2;
  text-decoration: underline;
  word-break: break-all;
}

.mine .chat-link {
  color: #fff;
}

.msg .avatar {
  flex: 0 0 auto;
}

.messages .msg {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.messages .msg:not(.mine) {
  justify-content: flex-start;
  flex-direction: row;
}

.messages .msg:not(.mine) .avatar {
  order: 1;
}

.messages .msg:not(.mine) .bubble {
  order: 2;
}

.messages .msg.mine {
  justify-content: flex-end;
  flex-direction: row;
}

.messages .msg.mine .bubble {
  order: 1;
}

.messages .msg.mine .avatar {
  order: 2;
}

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

.mine .meta {
  color: rgba(255, 255, 255, .75);
}

.msg.pending {
  opacity: .78;
}

.msg.failed .bubble {
  outline: 1px solid var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: 64px 1fr 92px;
  gap: 10px;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: #fff;
}

.tool-btn {
  height: 40px;
  background: #f4f6fa;
  color: #42526a;
  border: 1px solid #d8dfe9;
}

.chat-image {
  display: block;
  max-width: min(280px, 62vw);
  max-height: 360px;
  border-radius: 4px;
  object-fit: contain;
}

.composer input,
.login input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  padding: 0 12px;
  outline: none;
}

.composer button,
.login button {
  height: 40px;
}

.agent-layout {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 320px 1fr 240px;
  min-width: 900px;
}

.sidebar,
.replybar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
}

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

.pane-title {
  height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.conv {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.conv.active,
.conv:hover {
  background: #eef8f5;
}

.conv-name {
  font-weight: 700;
  margin-bottom: 6px;
}

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

.workspace {
  min-width: 0;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.reply {
  margin: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  line-height: 1.5;
}

.login {
  max-width: 360px;
  margin: 80px auto;
  background: #fff;
  border: 1px solid var(--line);
  padding: 22px;
}

.login h1 {
  margin: 0 0 18px;
  font-size: 22px;
}

.login label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

@media (max-width: 760px) {
  .visitor-wrap {
    margin: 0;
    padding: 0;
  }

  .chat-box {
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
    min-height: 0;
    border-left: 0;
    border-right: 0;
  }
}

@media (max-width: 720px) {
  .agent-page {
    overflow-x: hidden;
  }

  body {
    min-width: 0;
  }

  .topbar {
    height: 50px;
    padding: 0 12px;
  }

  .visitor-wrap {
    height: calc(100vh - 50px);
    height: calc(100dvh - 50px);
  }

  .visitor-wrap .chat-box {
    height: 100%;
    grid-template-rows: 48px 1fr 58px;
  }

  .chat-head {
    padding: 0 12px;
  }

  .chat-head strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }

  .messages {
    padding: 12px;
  }

  .bubble {
    max-width: 82%;
  }

  .composer {
    grid-template-columns: 52px minmax(0, 1fr) 68px;
    gap: 8px;
    padding: 9px;
    padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px));
    position: sticky;
    bottom: 0;
  }

  .tool-btn {
    height: 40px;
    padding: 0;
  }

  .composer input {
    height: 40px;
    font-size: 16px;
  }

  .composer button {
    height: 40px;
  }

  .chat-image {
    max-width: 68vw;
    max-height: 260px;
  }

  .native-login {
    padding: 18px;
  }

  .native-login-box {
    width: 100%;
    padding: 28px 20px 24px;
  }

  .native-login-box input {
    font-size: 16px;
  }

  .admin-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: block;
  }

  .admin-menu {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0;
    overflow-x: auto;
    background: #202b3c;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .admin-logo {
    flex: 0 0 auto;
    width: auto;
    height: 46px;
    padding: 0 12px;
    border-bottom: 0;
    border-right: 1px solid rgba(255, 255, 255, .08);
    font-size: 14px;
  }

  .admin-logo::after {
    content: none;
  }

  .menu-item {
    flex: 0 0 auto;
    width: auto;
    height: 46px;
    padding: 0 12px;
    border-left: 0;
    border-bottom: 3px solid transparent;
    text-align: center;
    font-size: 13px;
  }

  .menu-item.active {
    border-left-color: transparent;
    border-bottom-color: #149a8f;
  }

  .admin-main {
    display: block;
  }

  .admin-top {
    height: 50px;
    padding: 0 12px;
  }

  .admin-top strong {
    display: inline-block;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    font-size: 16px;
  }

  .admin-content {
    min-height: calc(100vh - 96px);
    min-height: calc(100dvh - 96px);
    padding: 0;
    overflow: visible;
  }

  #view-chat.active {
    height: calc(100vh - 96px);
    height: calc(100dvh - 96px);
    overflow: hidden;
  }

  .native-chat {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 154px minmax(0, 1fr);
    border: 0;
  }

  .native-list,
  .native-tools {
    border-right: 0;
    border-left: 0;
  }

  .native-list {
    max-height: none;
    min-height: 0;
    overflow: auto;
    border-bottom: 1px solid #dfe5ee;
    -webkit-overflow-scrolling: touch;
  }

  .native-tools {
    display: none;
  }

  .list-tabs,
  .tool-title {
    height: 42px;
    padding: 0 8px;
  }

  .tab {
    padding: 0 8px;
    font-size: 13px;
  }

  .native-conv {
    grid-template-columns: 36px 1fr auto;
    padding: 10px;
  }

  .conv-avatar,
  .avatar {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .native-dialog {
    min-height: 0;
    overflow: hidden;
  }

  .dialog-inner {
    height: 100%;
    min-height: 0;
    grid-template-rows: 46px minmax(0, 1fr) auto;
  }

  .dialog-head {
    padding: 0 10px;
  }

  .dialog-head strong {
    display: inline-block;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .native-messages {
    overflow: auto;
    padding: 12px;
    padding-bottom: 18px;
    -webkit-overflow-scrolling: touch;
  }

  .native-composer textarea {
    height: 76px;
    font-size: 16px;
  }

  .composer-actions {
    min-height: 46px;
    height: auto;
    padding: 0 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
    flex-wrap: wrap;
  }

  .composer-actions span {
    flex: 1 1 100%;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .composer-actions button {
    flex: 1 1 0;
    min-width: 76px;
  }

  .native-reply {
    width: calc(100% - 16px);
    margin: 8px;
  }

  .layui-card-like {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-left: 0;
    border-right: 0;
  }

  .card-head {
    gap: 10px;
    padding: 0 12px;
  }

  .native-table {
    min-width: 680px;
  }

  .native-table th,
  .native-table td {
    padding: 10px;
    font-size: 13px;
  }

  .native-form {
    padding: 14px;
  }

  .native-form input,
  .native-form select,
  .native-form textarea,
  .access-code textarea {
    width: 100%;
    font-size: 16px;
  }

  .native-form button {
    width: 100%;
  }

  .inline-form {
    display: block;
  }

  .inline-form input,
  .inline-form select,
  .inline-form textarea {
    width: 100%;
    margin-bottom: 10px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
  }

  .access-code {
    padding: 14px;
  }

  .access-code code {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Final chat alignment override: visitor/customer own messages on the right. */
.messages .msg {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.messages .msg:not(.mine) {
  justify-content: flex-start;
  flex-direction: row;
}

.messages .msg:not(.mine) .avatar {
  order: 1;
}

.messages .msg:not(.mine) .bubble {
  order: 2;
}

.messages .msg.mine {
  justify-content: flex-end;
  flex-direction: row;
}

.messages .msg.mine .bubble {
  order: 1;
}

.messages .msg.mine .avatar {
  order: 2;
}
