/* ============================================================
   TrailChat — Anonymous chat UI
   Setup → Matching → Active chat, with dark mode support
   ============================================================ */

.chat-container {
  max-width: 880px;
  padding-bottom: 2rem;
}

.navbar__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-toggle:hover {
  border-color: var(--color-brand);
  transform: rotate(-12deg);
}

.chat-container > div {
  margin-top: 2rem;
}

/* ---------- Setup ---------- */
.chat-setup__card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--color-shadow);
  padding: 2.5rem 2rem;
  max-width: 520px;
  margin: 0 auto;
  text-align: center;
}

.chat-setup__icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.chat-setup__title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--color-brand-dark);
  margin: 0 0 0.5rem;
}

[data-theme="dark"] .chat-setup__title {
  color: var(--color-gold);
}

.chat-setup__desc {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin: 0 0 1.75rem;
  line-height: 1.6;
}

.chat-setup__card .form-group {
  text-align: left;
}

.chat-setup__card .form-actions {
  justify-content: stretch;
  margin-top: 1.75rem;
}

.chat-setup__card .form-actions .btn {
  width: 100%;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin: 0.4rem 0 0;
}

.chat-notice {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: rgba(22, 97, 195, 0.08);
  border: 1px solid rgba(22, 97, 195, 0.25);
  color: var(--color-brand);
  font-size: 0.9rem;
  margin: 0 0 1.25rem;
}

.chat-notice--error {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.3);
  color: #b91c1c;
}

/* ---------- Matching / loading ---------- */
.chat-loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--color-shadow);
  padding: 3rem 2rem;
  text-align: center;
}

.chat-loading__spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(22, 97, 195, 0.18);
  border-top-color: var(--color-brand);
  animation: tc-spin 0.9s linear infinite;
}

@keyframes tc-spin {
  to {
    transform: rotate(360deg);
  }
}

.chat-loading__text {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-brand-dark);
  margin: 0;
}

[data-theme="dark"] .chat-loading__text {
  color: var(--color-text);
}

.chat-loading__timer {
  font-family: monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-gold-dark);
  letter-spacing: 1px;
}

/* ---------- Active chat ---------- */
.chat-active-screen {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 190px);
  min-height: 420px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--color-shadow);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--color-brand-dark);
  color: #fff;
  flex-shrink: 0;
}

[data-theme="dark"] .chat-header {
  background: #0a2f6e;
}

.chat-header__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.chat-header__avatar {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-gold);
  color: #3d2c00;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
}

.chat-header__info {
  min-width: 0;
}

.chat-header__name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__school {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 44vw;
}

.chat-header__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.chat-timer {
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  letter-spacing: 0.5px;
}

.btn--danger {
  background: #dc2626;
  color: #fff;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  border-radius: var(--radius);
}

.btn--danger:hover {
  background: #b91c1c;
  color: #fff;
}

/* ---------- Messages ---------- */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background: var(--color-bg);
}

.msg {
  max-width: 75%;
  padding: 0.6rem 0.95rem;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg--them {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
  color: var(--color-text);
}

.msg--me {
  align-self: flex-end;
  background: var(--color-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg__text {
  display: block;
  white-space: pre-wrap;
}

.msg__time {
  display: block;
  font-size: 0.68rem;
  margin-top: 0.25rem;
  opacity: 0.65;
  text-align: right;
}

.chat-system {
  align-self: center;
  text-align: center;
  font-size: 0.83rem;
  color: var(--color-text-muted);
  background: rgba(22, 97, 195, 0.07);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  margin: 0.5rem auto;
  max-width: 90%;
}

/* ---------- Input ---------- */
.chat-input-form {
  flex-shrink: 0;
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.chat-input-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--color-bg);
  color: var(--color-text);
}

.chat-input-form input:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(22, 97, 195, 0.15);
}

.chat-input-form .btn {
  border-radius: var(--radius-xl);
  padding: 0.75rem 1.5rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .chat-container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .chat-active-screen {
    height: calc(100vh - 170px);
  }

  .msg {
    max-width: 86%;
  }

  .chat-header__school {
    max-width: 40vw;
  }

  .navbar__right .btn--outline-sm {
    padding: 0.45rem 0.7rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 420px) {
  .chat-header__school {
    max-width: 34vw;
  }

  .chat-setup__card {
    padding: 1.75rem 1.25rem;
  }
}
