.community-body {
  min-height: 100vh;
}


/* =========================================================
   MAIN PAGE
========================================================= */

.community-main {
  min-width: 0;
  padding: 32px;
}

.community-header {
  margin-bottom: 24px;
}

.community-header h1 {
  margin: 4px 0 8px;
  font-size: clamp(2rem, 3vw, 3rem);
}

.community-header p {
  margin: 0;
  color: var(--muted);
}


/* =========================================================
   BACK TO DASHBOARD
========================================================= */

.community-back-nav {
  margin-top: 38px;
}

.community-back-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;

  border: 1px solid var(--line);
  border-radius: 10px;

  background: #101a31;
  color: #f7f9ff;

  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;

  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.community-back-link:hover {
  background: #162340;
  border-color: rgba(107, 231, 255, 0.3);
  transform: translateY(-1px);
}

.community-back-link span {
  color: var(--cyan);
  font-size: 1.1rem;
}


/* =========================================================
   COMMUNITY WORKSPACE
========================================================= */

.community-layout {
  display: grid;

  grid-template-columns:
    220px
    minmax(0, 1fr)
    250px;

  height: min(70vh, 720px);
  min-height: 560px;

  border: 1px solid var(--border);
  border-radius: 18px;

  overflow: hidden;

  background: rgba(11, 18, 34, 0.97);

  box-shadow:
    0 18px 60px rgba(0, 0, 0, 0.18);
}


/* =========================================================
   CHANNELS + MEMBERS SIDEBARS
========================================================= */

.community-channels,
.community-members {
  padding: 20px;

  background: rgba(
    8,
    15,
    29,
    0.97
  );
}

.community-channels {
  border-right:
    1px solid var(--border);
}

.community-members {
  border-left:
    1px solid var(--border);
}

.community-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 12px;

  margin-bottom: 18px;
}

.community-panel-title h2 {
  margin: 3px 0 0;
  font-size: 1rem;
}

.community-icon-button {
  width: 34px;
  height: 34px;

  border:
    1px solid var(--border);

  border-radius: 10px;

  background: #0e1729;
  color: inherit;

  cursor: pointer;

  transition:
    background 0.18s ease,
    border-color 0.18s ease;
}

.community-icon-button:hover {
  background: #16213a;
  border-color:
    rgba(107, 231, 255, 0.3);
}


/* =========================================================
   CHANNEL LIST
========================================================= */

.community-channel-list {
  display: grid;
  gap: 6px;
}

.community-channel {
  display: flex;
  align-items: center;

  gap: 10px;

  width: 100%;

  padding: 10px 12px;

  border: 0;
  border-radius: 10px;

  background: transparent;
  color: var(--muted);

  text-align: left;
  font: inherit;

  cursor: pointer;

  transition:
    background 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.community-channel:hover {
  background:
    rgba(63, 104, 180, 0.10);

  color: #fff;
}

.community-channel.active {
  background:
    rgba(63, 104, 180, 0.20);

  color: #fff;

  box-shadow:
    inset 2px 0 var(--cyan);
}

.community-channel:active {
  transform: scale(0.99);
}


/* =========================================================
   CHAT
========================================================= */

.community-chat {
  display: grid;

  grid-template-rows:
    auto
    minmax(0, 1fr)
    auto;

  min-width: 0;

  background: #0a1222;
}

.community-chat-header {
  display: flex;

  align-items: center;
  justify-content: space-between;

  gap: 18px;

  padding: 17px 20px;

  border-bottom:
    1px solid var(--border);

  background: #0d1628;
}

.community-chat-header h2 {
  margin: 2px 0 0;
  font-size: 1.05rem;
}

.community-status {
  font-size: 0.82rem;
  color: var(--muted);
}

.community-status::before {
  content: '';

  display: inline-block;

  width: 7px;
  height: 7px;

  margin-right: 7px;

  border-radius: 50%;

  background: #4ff0b7;

  box-shadow:
    0 0 9px
    rgba(79, 240, 183, 0.55);
}


/* =========================================================
   MESSAGE AREA
========================================================= */

.community-messages {
  min-height: 0;

  overflow-y: auto;

  padding: 20px 22px;

  background:
    radial-gradient(
      circle at 50% 30%,
      rgba(60, 104, 180, 0.05),
      transparent 45%
    );
}

.community-messages::-webkit-scrollbar {
  width: 7px;
}

.community-messages::-webkit-scrollbar-track {
  background: transparent;
}

.community-messages::-webkit-scrollbar-thumb {
  background: #24324a;
  border-radius: 20px;
}


/* =========================================================
   EMPTY CHANNEL
========================================================= */

.community-empty-state {
  display: grid;

  place-items: center;

  align-content: center;

  min-height: 100%;

  padding: 30px;

  text-align: center;

  color: var(--muted);
}

.community-empty-state span {
  font-size: 2rem;
  color: var(--accent);
}

.community-empty-state h3 {
  margin: 12px 0 6px;
  color: #fff;
}

.community-empty-state p {
  margin: 0;
  max-width: 430px;
}


/* =========================================================
   MESSAGES
========================================================= */

.community-message {
  display: grid;

  grid-template-columns:
    42px
    minmax(0, 1fr);

  gap: 12px;

  padding: 10px 0;
}

.community-message + .community-message {
  margin-top: 2px;
}

.community-message-avatar {
  width: 42px;
  height: 42px;

  display: grid;
  place-items: center;

  border-radius: 12px;

  background:
    linear-gradient(
      135deg,
      #4bd5ed,
      #7775ff
    );

  background-repeat: no-repeat;

  color: #07111f;

  font-weight: 800;
}

.community-message-body {
  min-width: 0;
}

.community-message-meta {
  display: flex;

  align-items: baseline;

  gap: 8px;
}

.community-message-meta strong {
  color: #fff;
  font-size: 0.92rem;
}

.community-message-meta time {
  color: var(--muted);
  font-size: 0.72rem;
}

.community-message-body p {
  margin: 4px 0 0;

  color: #dce5f5;

  line-height: 1.5;

  overflow-wrap: anywhere;
}


/* =========================================================
   MESSAGE COMPOSER
========================================================= */

.community-composer {
  display: grid;

  grid-template-columns:
    minmax(0, 1fr)
    auto;

  align-items: end;

  gap: 12px;

  padding: 14px 16px;

  border-top:
    1px solid var(--border);

  background: #0b1426;
}

.community-composer textarea {
  width: 100%;

  resize: none;

  min-height: 48px;
  max-height: 120px;

  padding: 13px 15px;

  border:
    1px solid #283752;

  border-radius: 11px;

  background: #101b30;

  color: #fff;

  font: inherit;

  outline: none;

  box-shadow:
    inset 0 1px 0
    rgba(255, 255, 255, 0.02);

  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}

.community-composer textarea::placeholder {
  color: #68758f;
}

.community-composer textarea:hover {
  background: #121e35;
}

.community-composer textarea:focus {
  background: #121e35;

  border-color:
    rgba(107, 231, 255, 0.65);

  box-shadow:
    0 0 0 3px
    rgba(107, 231, 255, 0.07);
}

#communitySendButton {
  min-width: 76px;
  min-height: 48px;

  border-radius: 10px;
}


/* =========================================================
   MEMBERS
========================================================= */

.community-member-list {
  display: grid;
  gap: 4px;
}

.community-member-empty {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.community-member {
  display: grid;

  grid-template-columns:
    38px
    minmax(0, 1fr)
    auto;

  align-items: center;

  gap: 10px;

  padding: 9px 8px;

  border-radius: 10px;

  transition:
    background 0.18s ease;
}

.community-member:hover {
  background:
    rgba(63, 104, 180, 0.09);
}

.community-member.is-current-user {
  background:
    rgba(107, 231, 255, 0.04);
}

.community-member-avatar {
  width: 38px;
  height: 38px;

  display: grid;
  place-items: center;

  border-radius: 10px;

  background:
    linear-gradient(
      135deg,
      #4bd5ed,
      #7775ff
    );

  background-repeat: no-repeat;

  color: #07111f;

  font-weight: 800;
  font-size: 0.75rem;
}

.community-member-info {
  display: flex;
  flex-direction: column;

  min-width: 0;
}

.community-member-info strong {
  color: #fff;

  font-size: 0.84rem;

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;
}

.community-member-info small {
  margin-top: 2px;

  color: var(--muted);

  font-size: 0.69rem;
}

.community-member-online {
  width: 8px;
  height: 8px;

  border-radius: 50%;

  background: #4ff0b7;

  box-shadow:
    0 0 10px
    rgba(79, 240, 183, 0.65);
}


/* =========================================================
   SIDEBAR SIGN OUT
========================================================= */

.community-signout {
  appearance: none;

  border: 0;

  background: transparent;

  color: #8290b5;

  font: inherit;

  font-size: 0.78rem;

  cursor: pointer;

  padding: 4px 0 4px 48px;

  text-align: left;

  transition:
    color 0.18s ease;
}

.community-signout:hover {
  color: #67e8f9;
}

.community-signout:focus-visible {
  outline:
    2px solid #67e8f9;

  outline-offset: 4px;

  border-radius: 4px;
}


/* =========================================================
   RESPONSIVE
========================================================= */

@media (max-width: 1200px) {
  .community-layout {
    grid-template-columns:
      210px
      minmax(0, 1fr)
      220px;
  }
}


@media (max-width: 1050px) {
  .community-layout {
    grid-template-columns:
      200px
      minmax(0, 1fr);
  }

  .community-members {
    display: none;
  }
}


@media (max-width: 760px) {
  .community-main {
    padding: 18px;
  }

  .community-layout {
    height: auto;
    min-height: 0;

    grid-template-columns:
      1fr;
  }

  .community-channels {
    border-right: 0;

    border-bottom:
      1px solid var(--border);
  }

  .community-channel-list {
    display: flex;

    overflow-x: auto;

    padding-bottom: 4px;
  }

  .community-channel {
    width: auto;
    flex: 0 0 auto;
  }

  .community-chat {
    min-height: 520px;
  }

  .community-composer {
    grid-template-columns:
      minmax(0, 1fr)
      auto;
  }
}


@media (max-width: 520px) {
  .community-main {
    padding: 12px;
  }

  .community-header h1 {
    font-size: 2rem;
  }

  .community-layout {
    border-radius: 13px;
  }

  .community-chat-header {
    padding: 14px;
  }

  .community-messages {
    padding: 16px;
  }

  .community-composer {
    padding: 12px;
  }

  #communitySendButton {
    min-width: 64px;
  }
}
/* =========================================================
   COMMUNITY LAYOUT STABILITY FIX
   Keep this block at the VERY BOTTOM of community.css
========================================================= */

/* Prevent the whole page from becoming the chat scrollbar */
html,
body {
  height: 100%;
}

body.dashboard-body.community-body {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

/* Keep the StreamVerse sidebar locked to the viewport */
.community-body > .sidebar {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

/* Main Community area stays inside the remaining viewport */
.community-main {
  height: 100vh;
  min-height: 0;

  display: flex;
  flex-direction: column;

  padding: 26px 30px 28px;

  overflow: hidden;
}

/* Header should only use the space it needs */
.community-header {
  flex: 0 0 auto;
  margin-bottom: 20px;
}

.community-header h1 {
  margin-top: 2px;
}

/* Main 3-column workspace */
.community-layout {
  flex: 1 1 auto;

  display: grid;

  grid-template-columns:
    220px
    minmax(0, 1fr)
    250px;

  width: 100%;
  height: auto;
  min-height: 0;

  overflow: hidden;

  border: 1px solid var(--border);
  border-radius: 18px;

  background: rgba(11, 18, 34, 0.97);
}

/* All three columns stay INSIDE the grid */
.community-channels,
.community-chat,
.community-members {
  min-width: 0;
  min-height: 0;
}

/* Side columns */
.community-channels,
.community-members {
  height: 100%;
  overflow-y: auto;

  padding: 20px;

  background: #09111f;
}

.community-channels {
  border-right: 1px solid var(--border);
}

.community-members {
  border-left: 1px solid var(--border);
}

/* Chat itself never expands the entire page */
.community-chat {
  height: 100%;
  min-height: 0;

  display: grid;

  grid-template-rows:
    auto
    minmax(0, 1fr)
    auto;

  overflow: hidden;

  background: #0a1222;
}

/* Header stays fixed */
.community-chat-header {
  min-height: 66px;
  flex-shrink: 0;
}

/* THIS is the section that scrolls */
.community-messages {
  min-height: 0;
  height: 100%;

  overflow-y: auto;
  overflow-x: hidden;

  padding: 20px 22px;

  overscroll-behavior: contain;
}

/* Composer stays permanently at bottom of chat */
.community-composer {
  position: relative;

  display: grid;

  grid-template-columns:
    minmax(0, 1fr)
    auto;

  align-items: center;

  gap: 12px;

  width: 100%;

  padding: 13px 15px;

  border-top: 1px solid #22314a;

  background: #0a1427;

  box-shadow:
    0 -10px 28px rgba(3, 8, 18, 0.18);
}

/* Much more solid typing box */
.community-composer textarea {
  box-sizing: border-box;

  width: 100%;

  min-height: 48px;
  max-height: 110px;

  padding: 13px 15px;

  resize: none;

  border: 1px solid #2b3c5a;
  border-radius: 11px;

  background: #111d33;

  color: #f7f9ff;

  outline: none;

  font: inherit;
}

.community-composer textarea:hover {
  background: #142139;
}

.community-composer textarea:focus {
  background: #142139;

  border-color: rgba(107, 231, 255, 0.7);

  box-shadow:
    0 0 0 3px rgba(107, 231, 255, 0.07);
}

#communitySendButton {
  align-self: stretch;

  min-width: 72px;
  min-height: 48px;
}

/* Members stay neatly contained */
.community-member-list {
  min-height: 0;
  overflow-y: auto;
}

/* =========================================================
   RESPONSIVE
========================================================= */

/*
 * Keep all THREE desktop columns for considerably longer.
 * Your previous 1200px breakpoint was triggering too early.
 */
@media (max-width: 1150px) {
  .community-layout {
    grid-template-columns:
      200px
      minmax(0, 1fr)
      220px;
  }
}

/* Only hide Members once space actually gets tight */
@media (max-width: 900px) {
  .community-layout {
    grid-template-columns:
      190px
      minmax(0, 1fr);
  }

  .community-members {
    display: none;
  }
}

/* Mobile/tablet */
@media (max-width: 760px) {
  body.dashboard-body.community-body {
    overflow: auto;
    height: auto;
  }

  .community-main {
    height: auto;
    min-height: 100vh;

    overflow: visible;

    padding: 18px;
  }

  .community-layout {
    display: grid;

    grid-template-columns: 1fr;

    height: auto;
    min-height: 0;

    overflow: visible;
  }

  .community-channels {
    height: auto;

    border-right: 0;
    border-bottom: 1px solid var(--border);

    overflow: visible;
  }

  .community-channel-list {
    display: flex;

    overflow-x: auto;

    gap: 6px;
  }

  .community-channel {
    flex: 0 0 auto;
    width: auto;
  }

  .community-chat {
    height: 620px;
  }
}

/* Create Channel: scoped so existing workspace and Presence layout stay intact. */
#newChannelButton[hidden] { display: none !important; }
.community-create-dialog {
  width: min(480px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 28px;
  color: var(--text);
  background: linear-gradient(145deg, var(--panel2), var(--ink));
  border: 1px solid rgba(107, 231, 255, .3);
  border-radius: 18px;
}
.community-create-dialog form { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.community-create-dialog h2 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 1.7rem; }
.community-create-dialog p { margin: 0 0 10px; }
.community-create-dialog label { margin-top: 8px; font-size: .9rem; color: var(--text); font-weight: 600; }
.community-create-dialog label span, .community-create-dialog small { color: var(--muted); font-weight: 400; }
.community-create-dialog input, .community-create-dialog textarea {
  box-sizing: border-box; width: 100%; margin: 0; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--ink);
  color: var(--text); font: inherit;
}
.community-create-dialog textarea { resize: vertical; min-height: 90px; }
.community-create-dialog :focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.community-create-dialog .community-create-error { color: #ffb4bd; font-size: .9rem; margin: 0; }
.community-create-error:empty { display: none; }
.community-create-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.community-create-dialog button:disabled { opacity: .6; cursor: wait; }
/* =========================================================
   RULES CHANNEL PRESENTATION
========================================================= */

.community-rules-card {
  max-width: 900px;
  margin: 18px auto 40px;
  padding: 26px 28px;

  border: 1px solid var(--border);
  border-radius: 16px;

  background: rgba(15, 25, 47, 0.96);

  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.14);

  color: #dce5f5;

  overflow-wrap: anywhere;
}

.community-rules-card h2 {
  margin: 0 0 18px;

  color: var(--cyan);

  font-size: 1.35rem;
  line-height: 1.25;
}

.community-rules-card p {
  margin: 0 0 18px;

  color: #dce5f5;

  line-height: 1.7;
}

.community-rules-list {
  margin: 0;
  padding-left: 1.35rem;

  display: grid;
  gap: 14px;
}

.community-rules-list li {
  padding-left: 4px;

  color: #dce5f5;

  line-height: 1.7;
}

.community-rules-list strong {
  color: #ffffff;
}

.community-rules-card a {
  color: var(--cyan);
}
/* =========================================================
   RULES + READ-ONLY POLISH
========================================================= */

.community-rules-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 6px 10px;
  border: 1px solid rgba(107, 231, 255, 0.25);
  border-radius: 999px;
  background: rgba(107, 231, 255, 0.07);
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.community-rules-footer {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.community-rules-footer a {
  color: var(--cyan);
  font-weight: 600;
  text-decoration: none;
}

.community-rules-footer a:hover {
  text-decoration: underline;
}

.community-channel-permission {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  margin-bottom: 7px;
}

.community-channel-permission-status {
  color: var(--muted);
  font-size: 0.76rem;
}

.community-channel-permission-button {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101a31;
  color: var(--cyan);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.community-channel-permission-button:hover {
  background: #162340;
  border-color: rgba(107, 231, 255, 0.35);
}

.community-channel-permission-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.community-create-dialog .community-readonly-option {
  display: flex;
  align-items: center;
  gap: 10px;
}

.community-create-dialog #createChannelReadOnly {
  width: auto;
}

.community-composer textarea:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* =========================================================
   COMMUNITY GUEST STATE
========================================================= */

.community-body [hidden] {
  display: none !important;
}

.community-checking .sidebar-bottom,
.community-is-guest .sidebar-bottom,
.community-checking .community-back-nav,
.community-is-guest .community-back-nav {
  display: none;
}

.community-guest {
  margin: auto;
  max-width: 680px;
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(135deg, var(--panel2), var(--panel));
}

.community-guest h2 {
  margin: 12px 0;
  font: 700 clamp(1.8rem, 4vw, 2.7rem) 'Space Grotesk', sans-serif;
}

.community-guest p {
  color: var(--muted);
  line-height: 1.7;
}

.community-guest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 26px 0;
}

.community-guest-actions .button {
  min-width: 120px;
  justify-content: center;
}

.community-guest-developer {
  font-size: 0.88rem;
}

.community-guest-developer a {
  color: var(--cyan);
}

.community-session-status {
  color: var(--muted);
}

body.community-is-guest {
  overflow-y: auto;
}

.community-is-guest .community-main {
  overflow-y: auto;
}

@media (max-width: 760px) {
  /* Match the portal's offscreen sidebar offset so it cannot cover chat on narrow screens. */
  .community-body > .sidebar { width: 250px; box-sizing: border-box; }
}
