:root {
  color-scheme: light;
  --bg: #f7f9fc;
  --panel: #ffffff;
  --soft: #eef3f9;
  --ink: #141b27;
  --muted: #738297;
  --line: #e0e7f0;
  --accent: #e30613;
  --accent-dark: #b9000a;
  --blue: #14235c;
  --green: #28c99a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 86px minmax(300px, 390px) 1fr;
}

.sidebarCollapsed .app {
  grid-template-columns: 86px 0 1fr;
}

.rail {
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: #ffffff;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  padding: 26px 0;
}

.xmLogo {
  width: 62px;
  height: auto;
  display: block;
}

.railIcons {
  display: grid;
  gap: 44px;
  align-content: start;
  padding-top: 56px;
}

.railIcon {
  width: 44px;
  height: 44px;
  border: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: transparent;
  color: #708096;
  font-size: 23px;
  font-weight: 700;
}

.railIcon.active,
.railIcon.support {
  color: var(--green);
  background: #eef8f5;
}

.sidebar {
  padding: 26px 24px;
  background: #ffffff;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: padding 160ms ease;
}

.sidebarCollapsed .sidebar {
  padding-left: 0;
  padding-right: 0;
  border-right: 0;
}

.sideView {
  min-width: 248px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.sideView[hidden] {
  display: none;
}

#roomsView {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--green);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: 25px;
  line-height: 1.22;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.summary {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.65;
}

.adminBadge {
  display: none;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.adminBadge:has(span:not(:empty)) {
  display: grid;
}

.adminBadge button {
  padding: 8px 10px;
  background: var(--blue);
}

.formActions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.secondaryButton {
  color: var(--blue);
  background: var(--soft);
}

.secondaryButton:hover {
  background: #dfe7f1;
}

.homeStats {
  display: grid;
  gap: 14px;
}

.homeStats div {
  padding: 18px;
  border-radius: 24px;
  background: var(--soft);
}

.homeStats span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.homeStats strong {
  font-size: 24px;
}

.field,
.shareBox,
.adminPanel,
.roomSettings {
  display: grid;
  gap: 10px;
}

.roomNameHeader,
.roomNameRow {
  display: grid;
  align-items: center;
  gap: 8px;
}

.roomNameHeader {
  grid-template-columns: 1fr 32px;
}

.roomNameRow {
  grid-template-columns: minmax(0, 1fr) 58px;
}

.roomsToolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 4;
}

.searchField {
  min-width: 0;
  height: 38px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: #f8fafc;
  color: var(--muted);
}

.searchField span {
  font-size: 16px;
  font-weight: 900;
}

.searchField input {
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.roomSettings {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
}

.roomSettings[hidden] {
  display: none;
}

.field span,
.shareBox span,
.panelHeader span,
.roomNameHeader span {
  font-size: 14px;
  color: var(--muted);
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  outline: none;
  background: #f9fbfd;
  color: var(--ink);
}

input:disabled {
  color: var(--muted);
  background: var(--soft);
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 35, 92, 0.12);
}

.shareRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 10px;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 11px 15px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
}

button:disabled {
  opacity: 0.55;
}

.adminPanel {
  min-height: 0;
  overflow: hidden;
  flex: 1;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
}

.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panelHeader span {
  font-weight: 800;
}

.iconButton {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.groupAddButton {
  background: var(--blue);
}

.groupAddButton:hover {
  background: #0d1846;
}

.saveRoomName,
#copyLink,
.toggleSettingsButton {
  height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

.saveRoomName {
  background: var(--blue);
}

.saveRoomName:hover {
  background: #0d1846;
}

.toggleSettingsButton {
  color: var(--blue);
  background: var(--soft);
}

.toggleSettingsButton:hover {
  background: #dfe7f1;
}

.roomList {
  display: grid;
  gap: 4px;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.roomGroup {
  display: grid;
  gap: 2px;
  align-content: start;
}

.groupHeader {
  display: grid;
  grid-template-columns: 26px 1fr 32px;
  gap: 6px;
  border-radius: 7px;
  transition: background 120ms ease, box-shadow 120ms ease;
}

.groupHeader.dropTarget {
  background: #eef8f5;
  box-shadow: inset 0 0 0 1px rgba(40, 201, 154, 0.45);
}

.roomGroup:has(.adminGroupLabel) .groupHeader {
  grid-template-columns: 26px 1fr 32px;
}

.groupToggle,
.deleteButton {
  width: 26px;
  height: 30px;
  padding: 0;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
}

.deleteButton {
  width: 32px;
  color: var(--accent);
  background: transparent;
  font-size: 18px;
}

.deleteButton:hover {
  background: #fff1f2;
}

.groupName {
  border-color: var(--line);
  background: #f8fafc;
  color: var(--ink);
  font-weight: 800;
  min-height: 30px;
  height: 30px;
  padding: 5px 8px;
  font-size: 13px;
}

.adminGroupLabel {
  display: flex;
  align-items: center;
}

input.groupName {
  border-radius: 6px;
}

.groupRooms {
  min-height: 0;
  display: grid;
  gap: 3px;
  padding: 1px 0 2px 8px;
  border-left: 2px solid #dbe4ef;
}

.groupRooms[hidden] {
  display: none;
}

.roomButton {
  width: 100%;
  text-align: left;
  color: var(--ink);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 32px;
  padding: 6px 8px;
  overflow: hidden;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

.roomButton:hover {
  color: var(--blue);
  background: #f4f7fb;
}

.roomButton span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roomRow {
  display: grid;
  grid-template-columns: 1fr 32px;
  gap: 6px;
}

.roomGroup:has(.adminGroupLabel) .roomRow:not(.deletable) {
  grid-template-columns: 1fr;
}

.roomRow.deletable {
  grid-template-columns: 1fr 32px;
}

.roomRow.dragging {
  opacity: 0.55;
}

.roomButton.active {
  background: var(--blue);
  color: #ffffff;
}

.unreadBadge {
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  line-height: 1;
}

.roomButton.active .unreadBadge {
  background: #ffffff;
  color: var(--accent);
}

.emptyGroup {
  border: 1px dashed #ccd6e2;
  border-radius: 8px;
  padding: 7px 9px;
  color: #9fb0bd;
  font-size: 13px;
}

.roomSearchEmpty {
  margin-top: 2px;
  text-align: center;
  border-style: solid;
}

.chat {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-rows: 76px auto minmax(0, 1fr) auto;
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.mobilePanelToggle {
  display: none;
}

.chatHeader {
  min-height: 100px;
  width: min(940px, calc(100% - 56px));
  margin: 28px auto 0;
  padding: 24px 28px;
  border-radius: 28px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chatActions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.presence {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff1f2;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.presence.online {
  background: #e9f8f3;
  color: #159b75;
}

.visitorInfo {
  max-width: 240px;
  border-radius: 8px;
  padding: 5px 8px;
  background: #f6f8fb;
  color: var(--muted);
  display: grid;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
  line-height: 1.2;
}

.visitorInfo span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visitorInfo[hidden] {
  display: none;
}

.favoriteRoom {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #6f7f94;
  background: var(--soft);
  font-size: 24px;
}

.favoriteRoom.active {
  color: var(--accent);
  background: #fff1f2;
}

.status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status.online {
  background: #e9f8f3;
  color: #159b75;
}

.messages {
  width: min(940px, calc(100% - 56px));
  margin: 24px auto;
  padding: 26px;
  border-radius: 28px;
  background: #ffffff;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.roomRequiredNotice {
  width: min(940px, calc(100% - 56px));
  margin: 24px auto 0;
  padding: 28px;
  border: 2px solid #ffd0d4;
  border-radius: 28px;
  background: #fff1f2;
  color: var(--accent);
  text-align: center;
  box-shadow: 0 18px 44px rgba(227, 6, 19, 0.12);
  display: grid;
  gap: 12px;
}

.roomRequiredNotice strong {
  font-size: 28px;
  font-weight: 900;
}

.roomRequiredNotice span {
  color: #5f6c7d;
  font-size: 15px;
  line-height: 1.65;
}

.noticeLinks {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
  margin-top: 6px;
}

.noticeLinks a {
  color: #667386;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.noticeLinks a + a {
  border-left: 1px solid #d9e1ec;
}

.noticeLinks a:hover {
  color: var(--blue);
  text-decoration: underline;
}

.roomRequiredNotice[hidden] {
  display: none;
}

.message {
  width: min(680px, 86%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 16px;
  background: #f6f8fb;
}

.message.mine {
  align-self: flex-end;
  color: #ffffff;
  background: var(--blue);
  border-color: var(--blue);
}

.meta {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.message.mine .meta {
  color: rgba(255, 255, 255, 0.72);
}

.message p {
  margin-bottom: 0;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.system {
  align-self: center;
  color: var(--muted);
  background: var(--soft);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
}

.system.join {
  color: #087a5f;
  background: #dff8ef;
  border: 1px solid #9ee7ce;
}

.system.leave {
  color: #b42318;
  background: #fff1f2;
  border: 1px solid #ffc9cf;
}

.composer {
  width: min(940px, calc(100% - 56px));
  margin: 0 auto 28px;
  padding: 18px;
  border-radius: 28px;
  background: #ffffff;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.loginOverlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 27, 39, 0.62);
  padding: 20px;
}

.infoPage {
  min-height: 100vh;
  overflow: auto;
  background: #f7f9fc;
}

.infoShell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 52px;
}

.infoHeader,
.infoContent {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 22px;
}

.infoHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px;
  margin-bottom: 16px;
}

.infoHeader img {
  width: 70px;
}

.infoNav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.infoNav a {
  color: var(--blue);
  background: var(--soft);
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.infoContent {
  padding: 30px;
}

.infoContent h1 {
  font-size: 30px;
}

.infoContent h2 {
  margin-top: 24px;
  margin-bottom: 10px;
  font-size: 18px;
}

.infoContent p,
.infoContent li {
  color: #5f6c7d;
  line-height: 1.75;
}

.infoContent a {
  color: var(--blue);
  font-weight: 800;
}

.loginOverlay[hidden] {
  display: none;
}

.loginBox {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  border-radius: 28px;
  padding: 24px;
  background: #ffffff;
}

.loginBox h2 {
  margin: 0;
}

.loginBox .field span {
  color: var(--muted);
}

.loginError {
  min-height: 20px;
  margin: 0;
  color: #b42318;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100vh;
    min-height: 100vh;
  }

  .rail {
    display: none;
  }

  .sidebarCollapsed .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 64px 12px auto;
    z-index: 20;
    max-height: calc(100vh - 86px);
    overflow-y: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: 0 18px 48px rgba(20, 27, 39, 0.18);
    transform: translateY(-120%);
    opacity: 0;
    pointer-events: none;
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .sidebar h1 {
    font-size: 18px;
  }

  .sidebar .summary {
    font-size: 13px;
    line-height: 1.45;
  }

  .field span,
  .shareBox span,
  .panelHeader span,
  .homeStats span {
    font-size: 12px;
  }

  .roomsToolbar {
    grid-template-columns: minmax(0, 1fr) 52px;
    gap: 8px;
  }

  .searchField,
  .toggleSettingsButton {
    height: 38px;
    font-size: 12px;
  }

  .roomSettings {
    padding: 12px;
    border-radius: 16px;
  }

  .shareRow {
    grid-template-columns: minmax(0, 1fr) 52px;
    gap: 8px;
  }

  input {
    padding: 8px 10px;
    font-size: 16px;
    line-height: 1.2;
  }

  button {
    padding: 9px 11px;
  }

  .homeStats {
    gap: 8px;
  }

  .homeStats div {
    padding: 12px;
    border-radius: 16px;
  }

  .homeStats strong {
    font-size: 18px;
  }

  .adminBadge {
    font-size: 13px;
  }

  .adminBadge button,
  .groupAddButton,
  .roomButton,
  .deleteButton,
  .groupToggle {
    font-size: 12px;
  }

  .groupName {
    font-size: 12px;
    padding: 8px 9px;
  }

  .roomList {
    gap: 10px;
  }

  .roomGroup {
    gap: 6px;
  }

  .groupRooms {
    gap: 6px;
  }

  .roomButton {
    padding: 9px 10px;
  }

  .mobilePanelOpen .sidebar {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .chat {
    min-height: 100vh;
    height: 100vh;
    grid-template-rows: 56px auto minmax(0, 1fr) auto;
  }

  .topbar {
    display: flex;
    padding: 0 14px;
  }

  .favoriteRoom {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .mobilePanelToggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    height: 36px;
    padding: 0 14px;
    background: var(--blue);
    border-radius: 999px;
    font-size: 14px;
  }

  .chatHeader,
  .roomRequiredNotice,
  .messages,
  .composer {
    width: calc(100% - 20px);
  }

  .chatHeader {
    min-height: 74px;
    margin-top: 10px;
    padding: 16px 18px;
    border-radius: 22px;
  }

  .chatHeader h2 {
    font-size: 20px;
  }

  .status {
    padding: 7px 10px;
    font-size: 12px;
  }

  .messages {
    margin: 10px auto;
    padding: 14px;
    border-radius: 22px;
  }

  .roomRequiredNotice {
    margin-top: 10px;
    padding: 18px;
    border-radius: 22px;
    line-height: 1.35;
  }

  .roomRequiredNotice strong {
    font-size: 20px;
  }

  .infoShell {
    width: calc(100% - 20px);
    padding: 10px 0 24px;
  }

  .infoHeader {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
    border-radius: 18px;
  }

  .infoContent {
    padding: 20px;
    border-radius: 18px;
  }

  .message {
    width: min(100%, 680px);
    border-radius: 16px;
    padding: 11px 12px;
  }

  .composer {
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 22px;
    grid-template-columns: 1fr 66px;
    gap: 8px;
  }

  .composer input {
    height: 44px;
    padding: 9px 12px;
    font-size: 16px;
  }

  .composer button {
    height: 44px;
    padding: 0;
    border-radius: 12px;
    font-size: 15px;
  }
}
