/* Floating chatbox + full chat page */

.ks-chatbox {
  position: fixed;
  z-index: 9000;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.65rem;
  pointer-events: none;
}

.ks-chatbox--left {
  left: 1rem;
  align-items: flex-start;
}

.ks-chatbox--right {
  right: 1rem;
}

.ks-chatbox-panel {
  pointer-events: auto;
  width: min(360px, calc(100vw - 2rem));
  max-height: min(520px, calc(100vh - 6rem));
  display: none;
  flex-direction: column;
  background: linear-gradient(165deg, #221c15, #120e0a);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.ks-chatbox--open .ks-chatbox-panel {
  display: flex;
}

.ks-chatbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
}

.ks-chatbox-title {
  color: var(--gold-light);
  font-family: var(--font-heading);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.ks-chatbox-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}

.ks-chatbox-close:hover {
  color: var(--gold-light);
}

.ks-chatbox-channels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  max-height: 88px;
  overflow-y: auto;
}

.ks-chatbox-channel {
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.ks-chatbox-channel:hover,
.ks-chatbox-channel.active {
  border-color: rgba(212, 168, 83, 0.45);
  color: var(--gold-light);
}

.ks-chatbox-messages {
  flex: 1;
  min-height: 200px;
  max-height: 320px;
  overflow-y: auto;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.ks-chatbox-msg header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.15rem;
}

.ks-chatbox-msg strong {
  color: var(--gold-light);
  font-size: 0.78rem;
}

.ks-chatbox-msg time {
  font-size: 0.68rem;
  color: var(--text-dim);
}

.ks-chatbox-msg p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
}

.ks-chatbox-loading {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 1rem 0;
}

.ks-chatbox-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.55rem 0.65rem;
  border-top: 1px solid var(--border);
}

.ks-chatbox-form input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
}

.ks-chatbox-form .btn {
  padding: 0.45rem 0.75rem;
  font-size: 0.75rem;
}

.ks-chatbox-hint {
  margin: 0;
  padding: 0 0.65rem 0.55rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
}

.ks-chatbox-hint a {
  color: var(--gold-light);
}

.ks-chatbox-toggle {
  pointer-events: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 39, 0.35);
  background: linear-gradient(160deg, #2a2218, #16120e);
  color: var(--gold-light);
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transition: transform var(--transition), border-color var(--transition);
}

.ks-chatbox-toggle:hover {
  transform: scale(1.05);
  border-color: rgba(212, 168, 83, 0.6);
}

/* Full page chat */
.chat-page-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.chat-page-channels {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.chat-page-channels h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 0.65rem;
}

.chat-page-channel {
  display: flex;
  gap: 0.55rem;
  padding: 0.55rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  margin-bottom: 0.25rem;
  transition: background var(--transition);
}

.chat-page-channel:hover,
.chat-page-channel.active {
  background: rgba(212, 168, 83, 0.1);
  color: var(--text);
}

.chat-page-channel strong {
  display: block;
  color: var(--gold-light);
  font-size: 0.88rem;
}

.chat-page-channel small {
  display: block;
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.35;
}

.chat-page-main {
  background: linear-gradient(160deg, #221c15, #16120e);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

.chat-page-head {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.chat-page-head h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--gold-light);
}

.chat-page-head p {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.chat-page-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 55vh;
}

.chat-msg {
  padding: 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.chat-msg-head {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.chat-msg-head strong {
  color: var(--gold-light);
  font-size: 0.85rem;
}

.chat-msg-head time {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.chat-msg p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-page-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.chat-page-form input {
  flex: 1;
}

.chat-page-login,
.chat-page-empty {
  padding: 1.5rem;
  color: var(--text-dim);
  text-align: center;
}

@media (max-width: 768px) {
  .chat-page-layout {
    grid-template-columns: 1fr;
  }

  .ks-chatbox--left,
  .ks-chatbox--right {
    bottom: 0.75rem;
  }

  .ks-chatbox--left {
    left: 0.75rem;
  }

  .ks-chatbox--right {
    right: 0.75rem;
  }
}

/* Avoid overlap with music player on same side */
.ks-chatbox--right .ks-chatbox-toggle {
  margin-bottom: 0;
}

body:has(.music-player--right) .ks-chatbox--right {
  bottom: 5.5rem;
}

body:has(.music-player--left) .ks-chatbox--left {
  bottom: 5.5rem;
}
