:root {
  --chat-bg: #ffffff;
  --chat-panel: #ffffff;
  --chat-soft: #f5f5f5;
  --chat-border: #e5e5e5;
  --chat-text: #171717;
  --chat-muted: #737373;
  --chat-primary: #ff6600;
  --chat-primary-soft: rgba(255, 102, 0, 0.12);
  --chat-shadow: 0 18px 48px rgba(15, 23, 42, 0.12);
  color-scheme: light;
}

.dark {
  --chat-bg: #000000;
  --chat-panel: #0a0a0a;
  --chat-soft: #171717;
  --chat-border: #262626;
  --chat-text: #f5f5f5;
  --chat-muted: #a3a3a3;
  --chat-primary-soft: rgba(255, 102, 0, 0.18);
  --chat-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  color-scheme: dark;
}

.mod-chat-page {
  min-height: 100vh;
  margin: 0;
  background: var(--chat-bg);
  color: var(--chat-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

.mod-chat-page * {
  box-sizing: border-box;
}

.mod-chat-page-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.mod-chat-page-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
}

.mod-chat-page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--chat-text);
  background: var(--chat-soft);
  text-decoration: none;
}

.mod-chat-page-link svg,
.mod-chat-icon-btn svg,
.mod-chat-send-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.mod-chat-shell {
  width: 100%;
  min-height: 0;
}

.mod-chat-drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
}

.mod-chat-drawer-open {
  overflow: hidden;
}

.mod-chat-drawer.is-open {
  pointer-events: auto;
}

.mod-chat-drawer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  opacity: 0;
  background: rgba(0, 0, 0, 0.48);
  transition: opacity 0.24s ease;
}

.mod-chat-drawer.is-open .mod-chat-drawer-backdrop {
  opacity: 1;
}

.mod-chat-drawer-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: min(78vh, 680px);
  padding: 12px 10px calc(10px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.2, 0.85, 0.24, 1);
  touch-action: pan-y;
  will-change: transform;
}

.mod-chat-drawer.is-open .mod-chat-drawer-card {
  transform: translateY(0);
}

.mod-chat-drawer-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
}

.mod-chat-drawer .mod-chat-shell {
  height: 100%;
  max-width: 620px;
  margin: 0 auto;
}

.mod-chat-page .mod-chat-shell {
  height: calc(100vh - 56px - env(safe-area-inset-top));
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}

.mod-chat-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  background: var(--chat-panel);
  box-shadow: var(--chat-shadow);
}

.mod-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--chat-border);
}

.mod-chat-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.mod-chat-logo {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border-radius: 11px;
  background: #ff6600;
}

.mod-chat-logo span {
  position: absolute;
  inset: 0;
}

.mod-chat-logo span:nth-child(1) {
  background: #2f80ed;
  clip-path: polygon(0 0, 58% 0, 58% 100%, 0 100%);
}

.mod-chat-logo span:nth-child(2) {
  background: #24c6dc;
  clip-path: polygon(0 58%, 100% 58%, 100% 100%, 0 100%);
}

.mod-chat-logo span:nth-child(3) {
  background: #ffe14d;
  clip-path: polygon(58% 0, 100% 0, 100% 58%, 58% 58%);
}

.mod-chat-heading {
  min-width: 0;
}

.mod-chat-kicker {
  display: block;
  color: var(--chat-muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.mod-chat-title {
  margin: 0;
  color: var(--chat-text);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.1;
}

.mod-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.mod-chat-icon-btn,
.mod-chat-send-btn,
.mod-chat-mini-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  color: var(--chat-text);
  background: var(--chat-soft);
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.mod-chat-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
}

.mod-chat-close-btn {
  display: none;
}

.mod-chat-drawer .mod-chat-close-btn {
  display: inline-flex;
}

.mod-chat-icon-btn:active,
.mod-chat-send-btn:active,
.mod-chat-mini-btn:active {
  transform: scale(0.96);
}

.mod-chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 10px;
  background:
    radial-gradient(circle at 15% 0%, var(--chat-primary-soft), transparent 24rem),
    var(--chat-panel);
  scrollbar-width: thin;
  scrollbar-color: var(--chat-border) transparent;
}

.mod-chat-list::-webkit-scrollbar {
  width: 5px;
}

.mod-chat-list::-webkit-scrollbar-track {
  background: transparent;
}

.mod-chat-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--chat-border);
}

.mod-chat-loading,
.mod-chat-empty,
.mod-chat-status {
  margin: 14px;
  padding: 12px;
  border-radius: 12px;
  color: var(--chat-muted);
  background: var(--chat-soft);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}

.mod-chat-status {
  flex: 0 0 auto;
}

.mod-chat-status a {
  color: var(--chat-primary);
  font-weight: 800;
}

.mod-chat-status-error {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.mod-chat-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 8px 4px;
}

.mod-chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--chat-soft);
}

.mod-chat-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mod-chat-bubble {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  background: var(--chat-soft);
}

.mod-chat-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  margin-bottom: 4px;
}

.mod-chat-user {
  min-width: 0;
  overflow: hidden;
  color: var(--chat-text) !important;
  font-size: 13px;
  font-weight: 850;
  line-height: 1.15;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mod-chat-date {
  flex: 0 0 auto;
  color: var(--chat-muted);
  font-size: 11px;
  font-weight: 600;
}

.mod-chat-text {
  color: var(--chat-text);
  font-size: 13px;
  line-height: 1.38;
  word-break: break-word;
}

.mod-chat-text p {
  margin: 0 0 6px;
}

.mod-chat-text p:last-child {
  margin-bottom: 0;
}

.mod-chat-text img,
.mod-chat-text iframe {
  max-width: 100%;
  border-radius: 10px;
}

.mod-chat-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.mod-chat-mini-btn {
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  color: var(--chat-muted);
  font-size: 11px;
  font-weight: 800;
}

.mod-chat-mini-btn:hover {
  color: var(--chat-text);
  background: var(--chat-primary-soft);
}

.mod-chat-form {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px 42px;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-panel);
}

.mod-chat-form textarea {
  display: block;
  width: 100%;
  min-height: 42px;
  max-height: 116px;
  resize: none;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 11px 13px;
  color: var(--chat-text);
  background: var(--chat-soft);
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  outline: none;
}

.mod-chat-form textarea::placeholder {
  color: var(--chat-muted);
}

.mod-chat-form textarea:focus {
  border-color: var(--chat-primary);
}

.mod-chat-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: #fff;
  background: var(--chat-primary);
}

.mod-chat-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  color: var(--chat-muted);
  background: var(--chat-soft);
  cursor: pointer;
}

.mod-chat-tool-btn svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.mod-chat-emoji-panel {
  position: absolute;
  right: 58px;
  bottom: calc(100% + 8px);
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  background: var(--chat-panel);
  box-shadow: var(--chat-shadow);
}

.mod-chat-emoji-panel[hidden] {
  display: none !important;
}

.mod-chat-emoji-panel button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--chat-soft);
  cursor: pointer;
  font-size: 18px;
}

.mod-chat-send-btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.mod-chat-nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #ff6600;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 12px;
}

.mod-chat-nav-badge.is-mention {
  background: #06b6d4;
}

.dark .mod-chat-nav-badge {
  border-color: #000;
}

nav button.menu-item {
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.mod-chat-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
}

.mod-chat-modal-card {
  width: min(560px, 100%);
  max-height: min(74vh, 640px);
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  background: var(--chat-panel);
  box-shadow: var(--chat-shadow);
}

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

.mod-chat-modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
}

.mod-chat-modal-body {
  max-height: calc(min(74vh, 640px) - 62px);
  overflow-y: auto;
  padding: 10px;
}

@media (min-width: 768px) {
  .mod-chat-drawer-card {
    left: 50%;
    right: auto;
    width: min(620px, calc(100% - 32px));
    transform: translate(-50%, 105%);
  }

  .mod-chat-drawer.is-open .mod-chat-drawer-card {
    transform: translate(-50%, 0);
  }

  .mod-chat-page .mod-chat-shell {
    max-width: 760px;
    margin: 0 auto;
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .mod-chat-panel {
    min-height: 560px;
    border-radius: 18px;
  }
}
