/* Chat World — text-only, red / black / white */

.cw-body { --cw-max: 1100px; }
.cw-main { max-width: var(--cw-max); }
.cw-hero { margin-bottom: 28px; }

.cw-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 20px;
  align-items: stretch;
}

.cw-side,
.cw-chat {
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.cw-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 10px 0 6px;
}

.cw-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--site-input, #0a0a0a);
  color: var(--text);
  font: inherit;
}
.cw-input:focus {
  outline: 2px solid rgba(255, 0, 0, 0.45);
  border-color: #ff0000;
}
.cw-input:disabled { opacity: 0.45; }
.cw-input--grow { flex: 1; min-width: 0; }

.cw-status {
  margin-top: 4px;
  font-size: 0.85rem;
  color: var(--dim);
  line-height: 1.4;
}
.cw-status.is-live { color: #ff4d4d; }
.cw-status.is-poll { color: #ffaa66; }

.cw-dm-threads { margin-top: 18px; }
.cw-dm-threads h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  margin-bottom: 8px;
}
.cw-dm-threads ul {
  list-style: none;
  max-height: 160px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  margin: 0;
}
.cw-dm-threads li {
  font-size: 0.88rem;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--card-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.cw-dm-threads li:hover,
.cw-dm-threads li.is-active {
  border-color: rgba(255, 0, 0, 0.55);
}
.cw-peer-av {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 0, 0, 0.4);
  flex-shrink: 0;
}

.cw-chat {
  display: flex;
  flex-direction: column;
  min-height: 420px;
}
.cw-chat-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.cw-tab {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}
.cw-tab.is-active {
  color: #fff;
  background: #ff0000;
  border-color: #ff0000;
}
.cw-tab:disabled { opacity: 0.4; cursor: not-allowed; }

.cw-messages {
  flex: 1;
  overflow: auto;
  max-height: 52vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
  margin-bottom: 12px;
}
.cw-messages.hidden { display: none; }

.cw-msg {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px 10px;
  align-items: start;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--card-alt);
  border: 1px solid var(--border);
}
.cw-msg--sys {
  display: block;
  grid-template-columns: 1fr;
  font-size: 0.82rem;
  color: var(--dim);
  text-align: center;
  background: transparent;
  border-style: dashed;
}
.cw-msg-av {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 0, 0, 0.45);
  cursor: pointer;
  background: #111;
}
.cw-msg-body { min-width: 0; }
.cw-msg-body strong {
  display: block;
  font-size: 0.88rem;
  margin-bottom: 2px;
}
.cw-msg-body p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}
.cw-msg time {
  font-size: 0.72rem;
  color: var(--dim);
  white-space: nowrap;
}
.cw-msg-actions {
  grid-column: 2 / -1;
  display: flex;
  gap: 8px;
}
.cw-msg-actions button {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: #ff6b6b;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.cw-msg-actions button:hover { color: #ff0000; text-decoration: underline; }
.cw-edited {
  font-size: 0.7rem;
  color: var(--dim);
  margin-left: 6px;
  font-weight: 500;
}

.cw-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.cw-error {
  margin-top: 8px;
  color: #ff6b6b;
  font-size: 0.85rem;
}
.cw-error.hidden { display: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 13000;
  background: #111;
  color: #fff;
  border: 1px solid rgba(255, 0, 0, 0.5);
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-size: 0.88rem;
}
.toast.hidden { display: none; }

@media (max-width: 900px) {
  .cw-main {
    width: 100%;
    max-width: 100%;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    box-sizing: border-box;
  }
  .cw-layout { grid-template-columns: 1fr; gap: 14px; }
  .cw-messages { max-height: min(48vh, 360px); }
  .cw-side, .cw-chat {
    padding: 14px;
    min-width: 0;
  }
  .cw-form {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }
  .cw-form .dx-btn,
  .cw-form button {
    width: 100%;
    min-height: 44px;
  }
  .cw-hero { text-align: center; }
}
