/* =============================================
   Chat — Medieval style
   ============================================= */

/* ---- Full chat page ---- */

.chat-container {
  max-width: 800px;
  margin: 20px auto;
  padding: 28px 32px;
  background-color: var(--cloud-bg);
  background-image: var(--dirt-texture-url);
  background-repeat: repeat;
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  color: var(--text);
}

.chat-with-sidebar {
  max-width: 1060px;
  display: flex;
  gap: 0;
}

.chat-with-sidebar .chat-main {
  flex: 1;
  min-width: 0;
  padding-right: 24px;
}

.chat-container h1 {
  text-align: center;
  margin: 0 0 28px 0;
  font-family: "Cinzel", serif;
  color: var(--papyrus-text);
  font-size: 1.8rem;
  letter-spacing: 1px;
}

/* Name setup panel */
.chat-name-setup {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  padding: 20px;
  margin-bottom: 20px;
}

.chat-name-setup h2 {
  margin: 0 0 14px 0;
  font-family: "Cinzel", serif;
  color: var(--papyrus-text);
  font-size: 1.1rem;
  letter-spacing: 0.5px;
}

.chat-name-setup form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Gift-drop form has many controls — let them wrap and shrink rather than
   pushing the Send button off-screen on narrow/portrait viewports. */
.chat-name-setup form select {
  flex: 1 1 130px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.9rem;
}

.chat-name-setup form button,
.chat-form button {
  flex: 0 0 auto;
}

/* Shared input style */
.chat-name-setup input,
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-name-setup input:focus,
.chat-form input:focus {
  border-color: #c8960c;
}

/* Shared button style */
.chat-name-setup button,
.chat-form button {
  padding: 9px 20px;
  background: linear-gradient(to bottom, #e6ce6a 0%, #c8960c 50%, #b7892b 100%);
  border: 1px solid #b7892b;
  border-radius: 2px;
  color: #1a0a00;
  cursor: pointer;
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  transition: opacity 0.2s;
}

.chat-name-setup button:hover,
.chat-form button:hover {
  opacity: 0.85;
}

.chat-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message area */
.chat-messages {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  padding: 14px;
  min-height: 300px;
  max-height: 500px;
  overflow-y: auto;
}

.chat-message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-message {
  background: rgba(0, 0, 0, 0.15);
  padding: 10px 12px;
  border-left: 3px solid #c8960c;
  border-radius: 0 2px 2px 0;
}

.chat-message-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.chat-message-meta {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: wrap;
}

.chat-username {
  font-weight: 700;
  color: #c8960c;
  font-size: 0.88rem;
}

.chat-time {
  font-size: 0.75rem;
  color: var(--text);
  opacity: 0.45;
  margin-left: 8px;
}

.chat-admin-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  background: rgba(224, 200, 130, 0.15);
  color: #e0c882;
  border: 1px solid rgba(224, 200, 130, 0.3);
  vertical-align: middle;
}

.chat-message-admin {
  border-left-color: #e0c882;
}

.chat-discord-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  font-size: 0.75rem;
  color: #5865f2;
  vertical-align: middle;
}

.chat-premium-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 0.68rem;
  color: #f5c45e;
  background: rgba(245, 196, 94, 0.12);
  border: 1px solid rgba(245, 196, 94, 0.35);
  vertical-align: middle;
}

.chat-message-premium {
  border-left-color: #f5c45e;
}

.chat-edited-mark {
  font-size: 0.72rem;
  color: var(--text);
  opacity: 0.45;
  margin-left: 8px;
  font-style: italic;
}

.chat-message-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chat-edit-btn,
.chat-delete-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 2px 4px;
  transition: color 0.2s;
}

.chat-edit-btn:hover {
  color: #c8960c;
}

.chat-delete-btn:hover {
  color: #e74c3c;
}

.chat-message-discord {
  border-left-color: #5865f2;
}

.chat-text {
  margin: 6px 0 0 0;
  word-break: break-word;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.55;
}

.chat-text.hidden {
  display: none;
}

.chat-edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.chat-edit-form.hidden {
  display: none;
}

.chat-edit-form input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.chat-edit-form input:focus {
  border-color: #c8960c;
}

.chat-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.chat-edit-save-btn,
.chat-edit-cancel-btn {
  padding: 7px 14px;
  border-radius: 2px;
  cursor: pointer;
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.4px;
}

.chat-edit-save-btn {
  background: linear-gradient(to bottom, #e6ce6a 0%, #c8960c 50%, #b7892b 100%);
  border: 1px solid #b7892b;
  color: #1a0a00;
}

.chat-edit-cancel-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--surface-border);
  color: var(--text);
}

.chat-empty {
  text-align: center;
  color: var(--text);
  opacity: 0.45;
  margin: 50px 0;
  font-style: italic;
  font-size: 0.9rem;
}

.chat-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- Mini Chat ---- */

.chat-mini {
  background-color: var(--cloud-bg);
  background-image: var(--dirt-texture-url);
  background-repeat: repeat;
  border: 1px solid var(--surface-border);
  border-radius: 2px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  width: 300px;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
}

.chat-mini-cg {
  display: none;
}

@media (max-width: 1000px) {
  .chat-mini-cg {
    display: flex;
  }
}

@media (max-width: 1024px) {
  .chat-mini {
    width: 100%;
  }
}

.chat-mini-header {
  border-bottom: 1px solid var(--surface-border);
  padding-bottom: 6px;
}

.chat-mini-header h3 {
  margin: 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "Cinzel", serif;
  color: var(--papyrus-text);
}

.chat-mini-messages {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
}

.chat-mini-message {
  background: rgba(0, 0, 0, 0.15);
  padding: 5px 8px;
  border-left: 2px solid #c8960c;
  border-radius: 0 2px 2px 0;
}

.chat-mini-username {
  font-weight: 700;
  color: #c8960c;
  font-size: 11px;
}

.chat-mini-text {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: var(--text);
  word-break: break-word;
  line-height: 1.3;
}

.chat-mini-empty {
  text-align: center;
  color: var(--text);
  opacity: 0.45;
  margin: 10px 0;
  font-size: 11px;
  font-style: italic;
}

.chat-mini-line {
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.15);
  border-left: 2px solid #c8960c;
  border-radius: 0 2px 2px 0;
  text-align: left;
}

.chat-mini-user {
  font-weight: 700;
  color: #c8960c;
  font-size: 12px;
  margin-right: 5px;
  flex-shrink: 0;
}

.chat-mini-admin {
  border-left-color: #e0c882;
}

.chat-mini-admin-icon {
  color: #e0c882;
  font-size: 9px;
  margin-left: 3px;
}

.chat-mini-msg {
  font-size: 12px;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: break-word;
  line-height: 1.3;
  flex: 1;
  max-width: 30vw;
}

.chat-mini-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  background: linear-gradient(to bottom, #e6ce6a 0%, #c8960c 50%, #b7892b 100%);
  border: 1px solid #b7892b;
  border-radius: 2px;
  color: #1a0a00;
  text-decoration: none;
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: opacity 0.2s ease;
  text-transform: uppercase;
}

.chat-mini-cta:hover {
  opacity: 0.85;
}

.chat-mini-title {
  margin: 0;
  font-size: 13px;
  font-family: "Cinzel", serif;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--papyrus-text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--surface-border);
}

@media (max-width: 800px) {
  .chat-mini {
    margin-top: 10px;
  }

  .chat-mini-msg {
    max-width: none;
  }
}

/* ---- Chat Online Sidebar ---- */

.chat-online-sidebar {
  width: 220px;
  flex-shrink: 0;
  border-left: 1px solid var(--surface-border);
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 560px;
  overflow-y: auto;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Cinzel", serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--papyrus-text);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--surface-border);
  margin-bottom: 8px;
}

.chat-sidebar-header i {
  color: #c8960c;
  font-size: 0.8rem;
}

.chat-sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 3px;
  transition: background 0.15s;
}

.chat-sidebar-user:hover {
  background: rgba(255, 255, 255, 0.04);
}

.chat-sidebar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-sidebar-dot-away {
  background-color: #d4a817;
  opacity: 0.7;
}

.chat-sidebar-dot-offline {
  background-color: rgba(120, 90, 60, 0.35);
}

.chat-sidebar-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-sidebar-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  text-decoration: none;
}

.chat-sidebar-name:hover {
  color: #c8960c;
}

.chat-sidebar-status {
  font-size: 0.65rem;
  color: var(--text);
  opacity: 0.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-sidebar-status i {
  font-size: 0.55rem;
}

.chat-sidebar-away {
  opacity: 0.6;
}

.chat-sidebar-offline {
  opacity: 0.45;
}

.chat-sidebar-divider {
  height: 1px;
  background: var(--surface-border);
  margin: 6px 0;
}

.chat-sidebar-section-label {
  font-size: 0.65rem;
  font-family: "Cinzel", serif;
  color: var(--papyrus-text);
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  margin-bottom: 2px;
}

.chat-sidebar-empty {
  font-size: 0.78rem;
  color: var(--text);
  opacity: 0.4;
  font-style: italic;
  padding: 12px 6px;
  text-align: center;
}

/* Larger screens: make the full chat page fill the viewport height so the
   message list scrolls internally instead of growing the document on each
   new message. Navbar (~64px) + container margins (40px) are subtracted. */
@media (min-width: 769px) {
  .chat-container.chat-with-sidebar {
    box-sizing: border-box;
    height: calc(100vh - 104px);
    height: calc(100dvh - 104px);
    overflow: hidden;
  }

  .chat-with-sidebar .chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .chat-with-sidebar .chat-main > div {
    /* ChatContent wrapper — let it fill remaining height under the heading */
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .chat-with-sidebar .chat-content {
    flex: 1;
    min-height: 0;
  }

  .chat-with-sidebar .chat-messages {
    flex: 1;
    min-height: 0;
    max-height: none;
  }

  .chat-with-sidebar .chat-online-sidebar {
    max-height: none;
  }
}

/* Mobile: compact horizontal strip */
@media (max-width: 768px) {
  .chat-with-sidebar {
    flex-direction: column;
  }

  .chat-with-sidebar .chat-main {
    padding-right: 0;
  }

  .chat-online-sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--surface-border);
    padding-left: 0;
    padding-top: 12px;
    margin-top: 16px;
    max-height: none;
    overflow-y: visible;
  }

  .chat-sidebar-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0;
  }

  .chat-sidebar-user {
    padding: 4px 8px;
    gap: 6px;
    flex: 0 0 auto;
  }

  .chat-sidebar-info {
    flex-direction: row;
    align-items: center;
    gap: 5px;
  }

  .chat-sidebar-status {
    font-size: 0.6rem;
  }

  .chat-sidebar-divider {
    display: none;
  }

  .chat-sidebar-section-label {
    width: 100%;
    padding: 4px 6px 2px;
  }
}

/* ── Premium chat images ─────────────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.chat-input-row .chat-form {
  flex: 1 1 auto;
}
/* Premium "send image" button (a label wrapping a hidden file input). */
.chat-image-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 100%;
  min-height: 38px;
  border-radius: 8px;
  background: var(--surface-2, rgba(255, 255, 255, 0.08));
  border: 1px solid var(--surface-border, rgba(255, 255, 255, 0.15));
  color: var(--text, #eee);
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.15s ease, transform 0.1s ease;
}
.chat-image-btn:hover {
  background: var(--surface-3, rgba(255, 255, 255, 0.16));
}
.chat-image-btn:active {
  transform: scale(0.94);
}
/* Rendered image inside a chat/DM message. */
.chat-image-link {
  display: inline-block;
  margin-top: 6px;
  max-width: 100%;
}
.chat-image {
  display: block;
  max-width: min(320px, 100%);
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--surface-border, rgba(0, 0, 0, 0.2));
  background: rgba(0, 0, 0, 0.1);
}

/* ── Fullscreen image lightbox (chat/DM images) ──────────────────────────── */
.cwl-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
  animation: cwl-lightbox-fade 0.15s ease;
}
@keyframes cwl-lightbox-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.cwl-image-lightbox-img {
  max-width: 95vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
  cursor: default;
}
.cwl-image-lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  z-index: 1;
  transition: background 0.15s ease, transform 0.1s ease;
}
.cwl-image-lightbox-close:hover {
  background: rgba(0, 0, 0, 0.85);
}
.cwl-image-lightbox-close:active {
  transform: scale(0.92);
}
/* The clickable chat image gets a zoom-in cursor to hint it opens. */
.chat-image-link {
  cursor: zoom-in;
}
