/* Premium community chat page.
   Visual-only layer; keeps existing /chat IDs, routes, Socket.IO events, and
   Discord relay hooks intact. */
.chat-page {
  background:
    radial-gradient(circle at top left, rgba(245, 158, 11, 0.08), transparent 28rem),
    radial-gradient(circle at 82% 12%, rgba(59, 130, 246, 0.10), transparent 26rem),
    #111827;
}

.chat-page-main {
  isolation: isolate;
}

.chat-shell {
  --chat-shell-min-height: clamp(16rem, calc(100dvh - 2rem), 26rem);
  display: flex;
  flex-direction: column;
  height: max(var(--chat-shell-min-height), var(--chat-shell-height, calc(100dvh - 14rem)));
  min-height: var(--chat-shell-min-height);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015)),
    rgba(17, 24, 39, 0.84);
  border-color: rgba(255, 255, 255, 0.12);
}

.chat-shell-header {
  flex: 0 0 auto;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-status-rail {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  min-width: 0;
}

.chat-shell-copy {
  min-width: 0;
  color: rgba(203, 213, 225, 0.82);
  font-size: 0.82rem;
  line-height: 1.2;
}

.chat-sync-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: #dbeafe;
  font-size: 0.82rem;
  font-weight: 800;
}

.chat-shell-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
  padding: 0.28rem 0.55rem;
  border: 1px solid rgba(34, 197, 94, 0.28);
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.10);
  color: #bbf7d0;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.chat-status-dot {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.65);
  animation: chat-status-pulse 1.8s infinite;
}

@keyframes chat-status-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 0.45rem rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.chat-safety-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 0 0 auto;
  margin: 0.6rem 0.75rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid rgba(248, 113, 113, 0.42);
  border-left: 3px solid #ef4444;
  border-radius: 0.7rem;
  background:
    linear-gradient(135deg, rgba(127, 29, 29, 0.84), rgba(153, 27, 27, 0.64)),
    rgba(127, 29, 29, 0.88);
  box-shadow: 0 10px 24px -22px rgba(239, 68, 68, 0.8);
  color: #fff;
}

.chat-safety-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.12);
  color: #fde68a;
  font-size: 0.95rem;
}

.chat-safety-card p {
  min-width: 0;
  margin: 0;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.83rem;
  line-height: 1.32;
}

.chat-safety-note {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.35rem;
  color: rgba(254, 226, 226, 0.88) !important;
  font-size: 0.72rem;
}

.chat-admin-panel,
.chat-load-more {
  flex: 0 0 auto;
  margin: 0 0.75rem 0.6rem;
  border-radius: 0.7rem;
}

.chat-admin-panel {
  padding: 1rem;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.42);
  color: #fff;
}

.chat-admin-panel h4 {
  margin: 0 0 0.75rem;
  font-weight: 800;
}

.chat-admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chat-danger-btn,
.chat-secondary-btn,
.chat-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.35rem;
  border-radius: 0.65rem;
  font-weight: 800;
  transition: transform 0.16s ease, filter 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.chat-danger-btn {
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(220, 38, 38, 0.82);
  color: white;
}

.chat-danger-btn-secondary {
  background: rgba(127, 29, 29, 0.55);
}

.chat-secondary-btn {
  width: 100%;
  flex: 0 0 auto;
  padding: 0.42rem 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.75);
  color: #dbeafe;
}

.chat-danger-btn:hover,
.chat-secondary-btn:hover,
.chat-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.7rem 0.75rem;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.38), rgba(15, 23, 42, 0.62)),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 14px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  scroll-padding: 1rem;
}

.chat-log.chat-messages::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.7);
}

.chat-log.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.55);
  border: 1px solid rgba(15, 23, 42, 0.7);
}

.chat-log.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(251, 191, 36, 0.55);
}

.chat-message-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.6rem;
  max-width: 94%;
  margin: 0 0 0.55rem;
  padding: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 0.78rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.065), rgba(255, 255, 255, 0.025)),
    rgba(30, 41, 59, 0.86);
  box-shadow: 0 16px 36px -28px rgba(0, 0, 0, 0.85);
  color: #e5e7eb;
}

.chat-message-card:hover {
  border-color: rgba(251, 191, 36, 0.22);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.03)),
    rgba(30, 41, 59, 0.94);
}

.chat-message-own {
  margin-left: auto;
  border-color: rgba(245, 158, 11, 0.28);
  background:
    linear-gradient(180deg, rgba(245, 158, 11, 0.11), rgba(245, 158, 11, 0.045)),
    rgba(30, 41, 59, 0.9);
}

.chat-message-discord {
  border-color: rgba(96, 165, 250, 0.26);
  background:
    linear-gradient(180deg, rgba(59, 130, 246, 0.12), rgba(59, 130, 246, 0.035)),
    rgba(30, 41, 59, 0.88);
}

.chat-message-avatar-wrap {
  position: relative;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
}

.chat-message-avatar {
  width: 2rem;
  height: 2rem;
  object-fit: cover;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: rgba(15, 23, 42, 0.95);
}

.chat-source-badge {
  position: absolute;
  right: -0.15rem;
  bottom: -0.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95rem;
  height: 0.95rem;
  border: 2px solid rgba(17, 24, 39, 0.96);
  border-radius: 999px;
  background: #5865f2;
  color: white;
  font-size: 0.55rem;
}

.chat-message-body {
  min-width: 0;
}

.chat-message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.32rem;
  min-width: 0;
  margin-bottom: 0.22rem;
}

.chat-message-author {
  min-width: 0;
  max-width: min(28rem, 100%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 800;
}

.chat-message-source {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.12rem 0.45rem;
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  color: #bfdbfe;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.chat-message-time {
  margin-left: auto;
  color: rgba(148, 163, 184, 0.9);
  font-size: 0.75rem;
  white-space: nowrap;
}

.chat-shell .chat-message-content {
  color: #e5e7eb;
  font-size: 0.92rem;
  line-height: 1.42;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-shell .chat-message-content strong {
  color: #f8fafc;
}

.chat-shell .chat-message-content em,
.chat-shell .chat-message-content u {
  color: inherit;
}

.chat-inline-code {
  background-color: rgba(15, 23, 42, 0.72);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.22);
}

.chat-admin-inline {
  margin-left: 0.15rem;
}

.chat-message-card:hover .chat-admin-inline {
  opacity: 1;
}

.chat-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 0.55rem;
  background: rgba(220, 38, 38, 0.84);
  color: white;
}

.chat-empty-state {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 1.5rem;
  color: rgba(203, 213, 225, 0.8);
  text-align: center;
}

.chat-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.055);
  color: rgba(251, 191, 36, 0.9);
  font-size: 1.45rem;
}

.chat-empty-state h4 {
  margin: 0;
  color: #f8fafc;
  font-weight: 900;
}

.chat-empty-state p {
  margin: 0;
  max-width: 26rem;
}

.chat-typing-indicator {
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  padding: 0.42rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.8);
  color: rgba(203, 213, 225, 0.9);
  font-size: 0.86rem;
  font-style: italic;
}

.chat-typing-indicator:not(.hidden) {
  display: flex;
}

.chat-typing-pulse {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: #60a5fa;
  animation: pulse 1.4s infinite;
}

.chat-composer {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  padding: 0.55rem 0.75rem 0.5rem;
  background:
    linear-gradient(180deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.98));
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 -18px 36px -32px rgba(0, 0, 0, 0.95);
}

.chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: end;
}

.chat-input {
  width: 100%;
  min-height: 2.35rem;
  max-height: 5.8rem;
  padding: 0.55rem 0.7rem;
  resize: none;
  border: 1px solid rgba(148, 163, 184, 0.36);
  border-radius: 0.65rem;
  background: rgba(248, 250, 252, 0.98);
  color: #0f172a;
  line-height: 1.4;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.chat-input:focus,
#modal-message-input:focus {
  border-color: rgba(245, 158, 11, 0.82);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.chat-send-btn {
  min-width: 5.2rem;
  padding: 0.52rem 0.85rem;
  border: 1px solid rgba(217, 119, 6, 0.8);
  background: linear-gradient(180deg, #f59e0b, #d97706);
  color: #1c1206;
  box-shadow: 0 12px 22px -18px rgba(245, 158, 11, 0.9);
}

.chat-send-btn:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.chat-composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.38rem;
  color: rgba(148, 163, 184, 0.94);
}

.chat-formatting-help {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-width: 0;
  font-size: 0.7rem;
}

.chat-formatting-help span {
  font-weight: 800;
}

.chat-formatting-help code {
  padding: 0.08rem 0.32rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(226, 232, 240, 0.9);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.68rem;
}

.chat-character-count {
  flex: 0 0 auto;
  color: rgba(148, 163, 184, 0.94);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.chat-character-count-warn {
  color: #facc15;
}

.chat-character-count-danger {
  color: #f87171;
}

.chat-readonly-notice {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 2.4rem;
  padding: 0.55rem 0.7rem;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 0.85rem;
  background: rgba(15, 23, 42, 0.65);
  color: rgba(203, 213, 225, 0.88);
  font-style: italic;
}

@media (max-width: 640px) {
  .chat-page-main {
    margin-top: 1rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .chat-shell-header,
  .chat-log,
  .chat-composer {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
    padding-bottom: calc(0.65rem + var(--safe-bottom, 0px));
  }

  .chat-status-rail {
    gap: 0.35rem 0.5rem;
  }

  .chat-safety-card {
    margin: 0.5rem 0.65rem;
    padding: 0.45rem 0.55rem;
  }

  .chat-safety-note {
    display: none;
  }

  .chat-message-card {
    max-width: 100%;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.55rem;
    border-radius: 0.72rem;
  }

  .chat-message-avatar-wrap,
  .chat-message-avatar {
    width: 1.9rem;
    height: 1.9rem;
  }

  .chat-message-meta {
    gap: 0.28rem;
  }

  .chat-message-time {
    margin-left: 0.2rem;
    width: auto;
  }

  .chat-input-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.45rem;
  }

  .chat-send-btn {
    width: auto;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .chat-send-btn span {
    display: none;
  }

  .chat-composer-footer {
    align-items: center;
    flex-direction: row;
  }
}

@media (max-height: 720px) {
  .chat-shell-header {
    padding-top: 0.42rem;
    padding-bottom: 0.42rem;
  }

  .chat-safety-card {
    margin-top: 0.42rem;
    margin-bottom: 0.42rem;
  }

  .chat-composer {
    padding-top: 0.45rem;
    padding-bottom: 0.42rem;
  }

  .chat-formatting-help span {
    display: none;
  }
}

@media (max-height: 520px) {
  .chat-shell-header {
    padding: 0.25rem 0.5rem;
  }

  .chat-shell-copy {
    display: none;
  }

  .chat-shell-status {
    padding: 0.18rem 0.45rem;
    font-size: 0.68rem;
  }

  .chat-sync-label {
    font-size: 0.74rem;
  }

  .chat-safety-card {
    align-items: center;
    gap: 0.35rem;
    margin: 0.25rem 0.5rem;
    padding: 0.28rem 0.45rem;
  }

  .chat-safety-icon,
  .chat-safety-note,
  .chat-composer-footer {
    display: none;
  }

  .chat-safety-card p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.72rem;
  }

  .chat-log {
    padding: 0.35rem 0.5rem;
  }

  .chat-composer {
    padding: 0.35rem 0.5rem;
  }

  .chat-input {
    min-height: 2.75rem;
    padding: 0.38rem 0.55rem;
    font-size: 1rem;
  }

  .chat-send-btn {
    min-height: 2.75rem;
    padding: 0.35rem 0.55rem;
  }
}
