:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  background: #ededed;
  color: #111827;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.chat-app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  min-height: 520px;
  background: #ededed;
}

.chat-app.support-layout {
  grid-template-columns: 336px minmax(0, 1fr);
}

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}

.support-panel {
  min-width: 0;
  height: 100dvh;
  overflow-y: auto;
  border-right: 1px solid #d6d8dc;
  background: #f7f8fa;
  padding: 18px 16px 22px;
}

.support-panel[hidden] {
  display: none;
}

.support-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 5px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 700;
}

.support-panel h2,
.support-panel h3 {
  margin: 0;
  color: #111827;
}

.support-panel h2 {
  font-size: 20px;
  line-height: 1.2;
}

.support-mode-badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 6px;
  color: #075e32;
  background: #d9f7df;
  font-size: 12px;
  font-weight: 800;
}

.support-section {
  padding: 14px 0;
  border-top: 1px solid #e0e2e6;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: #111827;
  font-size: 14px;
  font-weight: 800;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #cfd4dc;
  cursor: pointer;
  transition: background 0.18s ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.28);
  content: "";
  transition: transform 0.18s ease;
}

.switch input:checked + span {
  background: #07c160;
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.support-textarea,
.support-input {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  outline: none;
  background: #fff;
  color: #111827;
}

.support-textarea {
  min-height: 82px;
  resize: vertical;
  padding: 10px;
  font-size: 14px;
  line-height: 1.45;
}

.support-input {
  height: 38px;
  margin-top: 8px;
  padding: 0 10px;
  font-size: 13px;
}

.support-textarea:focus,
.support-input:focus {
  border-color: #07c160;
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.12);
}

.primary-button,
.secondary-button,
.danger-button,
.mini-button {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  height: 38px;
  margin-top: 9px;
}

.primary-button {
  color: #fff;
  background: #07c160;
}

.secondary-button {
  color: #111827;
  background: #e5e7eb;
}

.danger-button {
  color: #fff;
  background: #dc2626;
}

.mini-button {
  flex: 0 0 auto;
  min-width: 48px;
  height: 28px;
  padding: 0 10px;
  color: #374151;
  background: #e5e7eb;
  font-size: 12px;
}

.primary-button:hover {
  background: #05ad56;
}

.secondary-button:hover,
.mini-button:hover {
  background: #d1d5db;
}

.danger-button:hover {
  background: #b91c1c;
}

.secondary-button:disabled {
  color: #9ca3af;
  cursor: default;
}

.scheduled-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.scheduled-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border-radius: 7px;
  background: #fff;
  border: 1px solid #e5e7eb;
}

.scheduled-main {
  min-width: 0;
  flex: 1 1 auto;
}

.scheduled-main p {
  margin: 0;
  overflow: hidden;
  color: #111827;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scheduled-main span,
.empty-state {
  color: #6b7280;
  font-size: 12px;
}

.selected-user-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.selected-user-top h3 {
  font-size: 15px;
}

.selected-user-top p {
  margin: 4px 0 0;
  color: #6b7280;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.user-facts {
  display: grid;
  gap: 7px;
  margin: 0;
}

.user-facts div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
}

.user-facts dt {
  color: #6b7280;
  font-size: 12px;
}

.user-facts dd {
  margin: 0;
  color: #111827;
  font-size: 12px;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px clamp(14px, 2vw, 28px);
  background: rgba(247, 247, 247, 0.96);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px);
}

.group-identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.group-avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 10px;
  object-fit: cover;
  background: #fff;
  border: 1px solid rgba(17, 24, 39, 0.08);
  box-shadow: 0 8px 20px rgba(17, 24, 39, 0.08);
}

.group-copy {
  min-width: 0;
}

.group-copy h1 {
  margin: 0;
  overflow: hidden;
  color: #111827;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-copy p {
  margin: 4px 0 0;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.2;
}

.support-pill {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  color: #0f5132;
  background: #d9f7df;
  border: 1px solid #b7ebc2;
  font-size: 12px;
  font-weight: 700;
}

.support-pill[data-mode="error"] {
  color: #7f1d1d;
  background: #fee2e2;
  border-color: #fecaca;
}

.support-pill[data-mode="neutral"] {
  color: #374151;
  background: #e5e7eb;
  border-color: #d1d5db;
}

.message-stage {
  min-height: 0;
  overflow: hidden;
}

.messages {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px clamp(12px, 2vw, 28px) 22px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar,
.support-panel::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb,
.support-panel::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
  border-radius: 999px;
}

.time-chip,
.system-chip {
  width: fit-content;
  max-width: min(520px, calc(100vw - 32px));
  margin: 10px auto;
  padding: 5px 10px;
  border-radius: 8px;
  color: #fff;
  background: rgba(0, 0, 0, 0.22);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

.system-chip {
  color: #4b5563;
  background: rgba(255, 255, 255, 0.72);
}

.message {
  display: flex;
  gap: 9px;
  max-width: 100%;
  margin: 15px 0;
  align-items: flex-start;
}

.message.outgoing {
  justify-content: flex-end;
}

.message-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  font-size: 14px;
  font-weight: 800;
}

button.message-avatar {
  cursor: pointer;
}

button.message-avatar:disabled {
  cursor: default;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message.outgoing .message-avatar {
  order: 2;
  background: linear-gradient(135deg, #2ecf70, #14a44d);
}

.message-body {
  width: min(620px, calc(100vw - 96px));
  min-width: 0;
  max-width: min(620px, calc(100vw - 96px));
}

.support-layout .message-body {
  width: min(620px, calc(100vw - 432px));
  max-width: min(620px, calc(100vw - 432px));
}

.message.outgoing .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-name {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 5px;
  color: #6b7280;
  font-size: 12px;
  line-height: 1;
}

.message.outgoing .message-name {
  justify-content: flex-end;
}

.staff-badge,
.user-id-chip {
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
}

.staff-badge {
  color: #fff;
  background: #07c160;
}

.user-id-chip {
  color: #4b5563;
  background: #e5e7eb;
}

.bubble {
  position: relative;
  display: inline-block;
  max-width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.message.incoming .bubble::before,
.message.service .bubble::before {
  position: absolute;
  top: 13px;
  left: -6px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-right: 7px solid #fff;
  border-bottom: 6px solid transparent;
  content: "";
}

.message.outgoing .bubble {
  background: #95ec69;
}

.message.outgoing .bubble::after {
  position: absolute;
  top: 13px;
  right: -6px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 7px solid #95ec69;
  content: "";
}

.bubble-text {
  margin: 0;
  color: #111827;
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-all;
}

.bubble-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, max-content));
  gap: 8px;
  margin-top: 8px;
}

.bubble-images:first-child {
  margin-top: 0;
}

.bubble-image {
  display: block;
  width: min(220px, 54vw);
  max-height: 280px;
  border: 0;
  border-radius: 5px;
  object-fit: cover;
  cursor: zoom-in;
  background: rgba(255, 255, 255, 0.64);
}

.message-actions {
  margin-top: 5px;
}

.message.outgoing .message-actions {
  text-align: right;
}

.revoke-button {
  height: 24px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  color: #6b7280;
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  font-size: 12px;
}

.revoke-button:hover {
  color: #b91c1c;
  background: #fee2e2;
}

.composer {
  padding: 10px clamp(10px, 2vw, 22px) calc(10px + env(safe-area-inset-bottom));
  background: #f7f7f7;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.pending-images {
  display: flex;
  gap: 9px;
  max-height: 94px;
  margin-bottom: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.pending-card {
  position: relative;
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: #e5e7eb;
}

.pending-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-image {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(17, 24, 39, 0.72);
  cursor: pointer;
}

.mute-notice {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  color: #7f1d1d;
  background: #fee2e2;
  font-size: 13px;
  font-weight: 700;
}

.composer-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
}

.icon-button,
.send-button {
  height: 40px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  color: #374151;
  background: #e5e7eb;
  font-size: 25px;
  line-height: 1;
}

.icon-button:hover {
  background: #d1d5db;
}

.icon-button:disabled,
.send-button:disabled {
  cursor: default;
}

.icon-button:disabled {
  color: #9ca3af;
  background: #edf0f3;
}

#messageInput {
  min-height: 40px;
  max-height: 126px;
  resize: none;
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  outline: none;
  color: #111827;
  background: #fff;
  font-size: 15px;
  line-height: 1.4;
}

#messageInput:disabled {
  color: #9ca3af;
  background: #f3f4f6;
}

#messageInput:focus {
  border-color: #07c160;
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.15);
}

.send-button {
  padding: 0 17px;
  color: #fff;
  background: #07c160;
  font-weight: 700;
}

.send-button:disabled {
  color: rgba(255, 255, 255, 0.8);
  background: #9ca3af;
  cursor: default;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.82);
}

.image-viewer[hidden] {
  display: none;
}

.image-viewer img {
  max-width: 96vw;
  max-height: 92dvh;
  border-radius: 8px;
  object-fit: contain;
}

.viewer-close {
  position: fixed;
  top: 18px;
  right: 18px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
  font-size: 30px;
  line-height: 1;
}

@media (max-width: 860px) {
  .chat-app.support-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 238px minmax(0, 1fr);
  }

  .support-panel {
    height: 238px;
    border-right: 0;
    border-bottom: 1px solid #d6d8dc;
    display: flex;
    gap: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px;
  }

  .support-panel__header,
  .support-section {
    width: 260px;
    flex: 0 0 auto;
    margin: 0;
    border-top: 0;
    border-right: 1px solid #e0e2e6;
    padding: 0 14px 0 0;
  }

  .support-panel__header {
    width: 210px;
    flex-direction: column;
  }

  .support-layout .message-body {
    width: calc(100vw - 96px);
    max-width: calc(100vw - 96px);
  }
}

@media (max-width: 560px) {
  .chat-app {
    min-height: 100dvh;
  }

  .chat-app.support-layout {
    grid-template-rows: 230px minmax(0, 1fr);
  }

  .chat-header {
    min-height: 64px;
  }

  .group-avatar {
    width: 42px;
    height: 42px;
  }

  .support-pill {
    display: none;
  }

  .messages {
    padding-inline: 10px;
  }

  .message-body,
  .support-layout .message-body {
    width: calc(100vw - 88px);
    max-width: calc(100vw - 88px);
  }

  .bubble {
    padding: 9px 11px;
  }

  .send-button {
    padding-inline: 13px;
  }
}
