.chat-page {
  --chat-green: #0f766e;
  --chat-orange: #f97316;
  --chat-cream: #fff7ed;
}

.chat-page main {
  display: grid;
  gap: 14px;
}

.chat-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  border: 1px solid var(--tpl-border);
  border-radius: 24px;
  padding: clamp(22px, 4vw, 34px);
  background:
    linear-gradient(135deg, rgba(255,247,237,0.96), rgba(240,253,250,0.9)),
    var(--tpl-card);
  box-shadow: var(--tpl-shadow);
}

.chat-hero--compact {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-radius: 18px;
  padding: 10px 14px;
}

.chat-hero__text {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.chat-hero__text strong,
.chat-hero__text span,
.chat-hero__text em {
  line-height: 1.2;
}

.chat-hero__text strong {
  border-radius: 999px;
  background: #ffedd5;
  color: #c2410c;
  padding: 5px 9px;
  font-size: 13px;
  font-style: normal;
}

.chat-hero__text span {
  color: var(--tpl-text);
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 950;
}

.chat-hero__text em {
  color: var(--tpl-muted);
  font-size: 15px;
  font-style: normal;
}

body.theme-dark .chat-hero {
  background:
    linear-gradient(135deg, rgba(249,115,22,0.1), rgba(15,118,110,0.12)),
    var(--tpl-card);
}

.chat-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 6px 12px;
  background: #ffedd5;
  color: #c2410c;
  font-size: 14px;
  font-weight: 950;
}

.chat-hero h2 {
  margin: 14px 0 10px;
  color: var(--tpl-text);
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1.08;
  letter-spacing: 0;
}

.chat-hero--compact h2 {
  margin: 6px 0 4px;
  font-size: clamp(30px, 4vw, 42px);
}

.chat-hero p,
.room-card p,
.room-card small,
.chat-status,
.profile-box label,
.profile-box fieldset {
  color: var(--tpl-muted);
}

.chat-hero p {
  margin: 0;
  font-size: 18px;
  line-height: 1.65;
}

.chat-hero--compact p {
  font-size: 16px;
  line-height: 1.45;
}

.chat-hero__actions,
.room-card__actions,
.room-actions,
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-hero__actions {
  margin-top: 0;
}

.chat-primary,
.chat-hero__actions a,
.chat-enter,
.profile-box button[type="submit"],
.message-form button {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  color: #fff;
  min-height: 44px;
  padding: 10px 16px;
  font-weight: 950;
  text-decoration: none;
  cursor: pointer;
}

.chat-stats {
  display: grid;
  gap: 10px;
}

.chat-hero--compact .chat-stats {
  grid-template-columns: repeat(2, minmax(130px, 1fr));
}

.chat-stats div {
  border: 1px solid var(--tpl-border);
  border-radius: 18px;
  background: rgba(255,255,255,0.76);
  padding: 12px;
}

body.theme-dark .chat-stats div { background: rgba(255,255,255,0.06); }

.chat-stats b {
  display: block;
  color: var(--chat-green);
  font-size: 22px;
  font-weight: 950;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.recommended-room .room-card {
  border-color: rgba(15,118,110,0.32);
}

.room-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--tpl-border);
  border-radius: 16px;
  background: var(--tpl-card);
  padding: 14px;
  box-shadow: var(--tpl-shadow);
}

.room-card__top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.room-icon {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 16px;
  background: var(--chat-cream);
  font-size: 22px;
}

.room-card h3 {
  margin: 0;
  color: var(--tpl-text);
  font-size: 19px;
}

.room-card p,
.room-card small {
  margin: 0;
  line-height: 1.5;
}

.room-status,
.room-meta span,
.interest-badge {
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--tpl-soft);
  color: var(--tpl-muted);
  font-size: 12px;
  font-weight: 850;
}

.room-status {
  background: #ecfeff;
  color: #0f766e;
}

.room-presence {
  margin-left: auto;
  border-radius: 999px;
  padding: 5px 9px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.chat-state {
  border: 1px dashed var(--tpl-border);
  border-radius: 18px;
  background: var(--tpl-soft);
  color: var(--tpl-muted);
  padding: 18px;
  text-align: center;
  font-weight: 850;
}

.chat-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.profile-box label {
  display: grid;
  gap: 7px;
  font-weight: 850;
}

.profile-box input,
.profile-box select,
.message-form textarea {
  width: 100%;
  border: 1px solid var(--tpl-border);
  border-radius: 14px;
  background: var(--tpl-card);
  color: var(--tpl-text);
  padding: 12px 13px;
  font: inherit;
  outline: none;
}

.chat-room-back {
  text-decoration: none;
}

.chat-room-page {
  min-height: 100dvh;
  overflow: hidden;
}

.chat-room-page .tpl-header {
  display: none;
}

.chat-room-page .footer {
  display: none;
}

.chat-room-page.chat-page {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  padding: 8px;
}

.chat-room-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 6px;
  height: calc(100dvh - 16px);
  padding-bottom: 0;
}

.chat-room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;
  border: 1px solid var(--tpl-border);
  border-radius: 12px;
  background: var(--tpl-card);
  box-shadow: none;
  padding: 7px 9px;
}

.chat-room-header > div:first-child {
  min-width: 0;
  flex: 1 1 360px;
}

.chat-room-header h1 {
  margin: 0;
  color: var(--tpl-text);
  font-size: 18px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-header p {
  display: none;
}

.chat-room-header .chat-badge {
  min-height: 22px;
  padding: 3px 7px;
  font-size: 11px;
}

.chat-room-page .room-actions {
  flex: 0 0 auto;
}

.chat-room-page .room-actions .chat-soft-btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.room-meta {
  display: none;
}

.room-rules,
.admin-notice,
.ai-host {
  border: 1px solid var(--tpl-border);
  border-radius: 12px;
  background: var(--tpl-soft);
  color: var(--tpl-muted);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.3;
}

.admin-notice {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

body.theme-dark .admin-notice { background: rgba(249,115,22,0.1); color: #fdba74; }

.ai-host {
  border-color: #99f6e4;
  background: #f0fdfa;
  color: #115e59;
  font-weight: 850;
}

body.theme-dark .ai-host { background: rgba(20,184,166,0.1); color: #99f6e4; }

.message-list {
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border: 1px solid var(--tpl-border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,247,237,0.48), rgba(255,255,255,0.64));
  padding: 8px;
  scroll-behavior: smooth;
}

body.theme-dark .message-list { background: rgba(255,255,255,0.04); }

.empty-chat {
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--tpl-muted);
  text-align: center;
  font-weight: 850;
}

.message {
  --chat-user-color: var(--tpl-text);
  max-width: min(760px, 94%);
  border: 1px solid var(--tpl-border);
  border-radius: 11px;
  background: var(--tpl-card);
  padding: 7px 9px;
}

.message.is-admin,
.message.is-ai {
  background: var(--tpl-soft);
}

.message__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.message__name {
  position: relative;
  display: inline-block;
  color: var(--tpl-text);
  font-size: 13px;
  font-weight: 750;
  cursor: help;
}

.message__name::after {
  content: attr(data-profile);
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 30;
  min-width: 150px;
  max-width: 260px;
  border: 1px solid var(--tpl-border);
  border-radius: 10px;
  background: rgba(15,23,42,0.94);
  color: #fff;
  padding: 7px 9px;
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  box-shadow: 0 12px 30px rgba(15,23,42,0.2);
  opacity: 0;
  transform: translateY(3px);
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}

.message__name:hover::after,
.message__name:focus::after {
  opacity: 1;
  transform: translateY(0);
}

.message__avatar {
  display: inline-grid;
  place-items: center;
  width: 21px;
  height: 21px;
  margin-right: 5px;
  border-radius: 999px;
  background: var(--tpl-soft);
  color: var(--tpl-text);
  font-size: 12px;
  vertical-align: middle;
}

.message__time {
  color: var(--tpl-muted);
  font-size: 12px;
}

.message p {
  margin: 0;
  color: var(--chat-user-color);
  font-size: 15px;
  line-height: 1.35;
  font-weight: 650;
}

.message-notice {
  justify-self: center;
  max-width: 90%;
  border: 0;
  border-radius: 999px;
  background: rgba(15,118,110,0.1);
  color: #0f766e;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 850;
}

.message-notice p {
  margin: 0;
  color: inherit;
  line-height: 1.3;
}

.message-actions {
  display: none;
}

.chat-soft-btn,
.message-actions button,
.blocked-list button {
  border: 1px solid var(--tpl-border);
  border-radius: 999px;
  background: var(--tpl-card);
  color: var(--tpl-text);
  min-height: 36px;
  padding: 7px 11px;
  font-weight: 900;
  cursor: pointer;
}

.message-actions button {
  min-height: 30px;
  font-size: 12px;
}

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.message-form--fixed {
  position: static;
  z-index: 20;
  border: 1px solid var(--tpl-border);
  border-radius: 12px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 18px 40px rgba(15,23,42,0.14);
  padding: 6px;
  backdrop-filter: blur(12px);
}

.message-form textarea {
  min-height: 42px;
  max-height: 78px;
  resize: vertical;
}

body.theme-dark .message-form--fixed { background: rgba(17,24,39,0.92); }

.new-message-pill {
  position: sticky;
  bottom: 92px;
  z-index: 21;
  justify-self: center;
  border: 0;
  border-radius: 999px;
  background: #0f766e;
  color: #fff;
  min-height: 36px;
  padding: 7px 14px;
  font-weight: 950;
  cursor: pointer;
}

.profile-dialog {
  width: min(94vw, 520px);
  border: 0;
  border-radius: 22px;
  padding: 0;
  background: transparent;
}

.profile-dialog::backdrop {
  background: rgba(15,23,42,0.48);
  backdrop-filter: blur(4px);
}

.profile-box {
  display: grid;
  gap: 12px;
  border: 1px solid var(--tpl-border);
  border-radius: 22px;
  background: var(--tpl-card);
  color: var(--tpl-text);
  padding: 18px;
  box-shadow: var(--tpl-shadow);
}

.profile-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.profile-box__head h2 {
  margin: 0;
  font-size: 24px;
}

.profile-box__head button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--tpl-border);
  border-radius: 999px;
  background: var(--tpl-card);
  color: var(--tpl-text);
  font-size: 22px;
  cursor: pointer;
}

.profile-box fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  border: 1px solid var(--tpl-border);
  border-radius: 16px;
  padding: 12px;
}

.profile-palette span {
  width: 16px;
  height: 16px;
  display: inline-block;
  border-radius: 999px;
}

.profile-box fieldset label,
.profile-agree {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.blocked-list {
  display: grid;
  gap: 8px;
}

@media (max-width: 980px) {
  .chat-hero {
    grid-template-columns: 1fr;
  }

  .chat-hero--compact .chat-stats {
    grid-template-columns: 1fr 1fr;
  }

  .room-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .chat-page {
    width: min(100% - 20px, 1440px);
  }

  .chat-room-page.chat-page {
    width: 100%;
    padding: 6px;
  }

  .room-grid,
  .message-form {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
    padding: 10px 12px;
  }

  .message-form--fixed {
    bottom: 8px;
  }

  .chat-room-header {
    padding: 6px 8px;
  }

  .chat-room-header h1 {
    font-size: 21px;
  }

  .room-rules,
  .admin-notice,
  .ai-host {
    font-size: 15px;
    padding: 8px 10px;
  }

  .message-list {
    min-height: 0;
    max-height: none;
    gap: 8px;
    padding: 10px;
  }

  .message__name {
    font-size: 16px;
  }

  .message__time {
    font-size: 13px;
  }

  .message p {
    font-size: 18px;
    line-height: 1.45;
  }

  .message__avatar {
    width: 25px;
    height: 25px;
    font-size: 14px;
  }

  .message-form textarea {
    min-height: 74px;
    font-size: 18px;
  }

  .message-form button {
    min-height: 54px;
    font-size: 17px;
  }

  .chat-room-shell {
    height: calc(100dvh - 12px);
  }
}

@media (max-width: 640px) {
  .chat-room-page .message-form {
    grid-template-columns: minmax(0, 1fr) 76px;
    align-items: stretch;
    gap: 7px;
  }

  .chat-room-page .message-form--fixed {
    padding: 6px;
  }

  .chat-room-page .message-form textarea {
    min-height: 60px;
    max-height: 96px;
    font-size: 18px;
    line-height: 1.45;
  }

  .chat-room-page .message-form button {
    min-width: 0;
    min-height: 60px;
    padding: 0 10px;
    border-radius: 18px;
    font-size: 17px;
  }

  .room-presence {
    font-size: 12.5px;
  }
}
