:root {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-solid: #ffffff;
  --ink: #18212f;
  --muted: #667085;
  --line: #d8e0ea;
  --primary: #2176ff;
  --primary-dark: #155bd1;
  --mint: #00a884;
  --rose: #ef476f;
  --amber: #f9a826;
  --shadow: 0 24px 70px rgba(35, 54, 86, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(140deg, rgba(33, 118, 255, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(0, 168, 132, 0.16), transparent 32%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  height: min(820px, calc(100vh - 32px));
  min-height: 620px;
  margin: 16px auto;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: rgba(250, 252, 255, 0.78);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-close,
.panel-toggle {
  display: none;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
}

.brand h1,
.brand p,
.chat-header h2,
.chat-header p,
.empty-state h3,
.empty-state p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.profile-card,
.room-card,
.rooms-card,
.members,
.admin-panel {
  padding: 16px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.join-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(10px);
}

.join-overlay.hidden {
  display: none;
}

.profile-card {
  display: grid;
  gap: 12px;
}

.join-dialog {
  width: min(420px, 100%);
  border-radius: 22px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.22);
}

.join-dialog h2 {
  margin: 3px 0 2px;
  font-size: 26px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  background: #f8fafc;
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
}

select {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  appearance: none;
}

textarea {
  min-height: 48px;
  max-height: 130px;
  resize: none;
  padding: 13px 14px;
  border-radius: 15px;
}

input:focus,
textarea:focus {
  border-color: rgba(33, 118, 255, 0.7);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(33, 118, 255, 0.12);
}

.primary-btn,
.send-btn,
.mini-btn,
.danger-btn,
.ghost-danger-btn {
  border: 0;
  font-weight: 800;
  transition: transform 140ms ease, background 140ms ease, opacity 140ms ease;
}

.primary-btn,
.send-btn,
.mini-btn {
  color: #fff;
  background: var(--primary);
}

.primary-btn {
  height: 44px;
  border-radius: 12px;
}

.send-btn {
  width: 78px;
  height: 48px;
  border-radius: 15px;
}

.mini-btn {
  min-width: 48px;
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 12px;
}

.danger-btn,
.ghost-danger-btn {
  color: var(--rose);
  background: rgba(239, 71, 111, 0.1);
}

.danger-btn {
  width: 100%;
  height: 40px;
  border-radius: 12px;
}

.ghost-danger-btn {
  min-width: 48px;
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 12px;
}

.primary-btn:hover,
.send-btn:hover,
.mini-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.send-btn:disabled,
textarea:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.section-title strong {
  color: var(--ink);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill,
.mobile-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin-top: 14px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(0, 168, 132, 0.1);
  color: #087a63;
  font-size: 13px;
  font-weight: 800;
}

.dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 5px rgba(0, 168, 132, 0.12);
}

.members {
  min-height: 0;
  flex: 1;
}

#userList,
#roomList {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  gap: 10px;
  overflow: auto;
  max-height: 100%;
}

#userList li,
#roomList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #f7f9fc;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.member-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#roomList li div:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

#roomList strong,
#roomList span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#roomList span {
  color: var(--muted);
  font-size: 12px;
}

.room-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.admin-panel {
  display: grid;
  gap: 12px;
}

.admin-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 11px;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}

.chat-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 28px auto;
  background: rgba(255, 255, 255, 0.62);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 26px 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.chat-header h2 {
  margin-top: 4px;
  font-size: 24px;
}

.mobile-status {
  display: none;
  margin-top: 0;
}

.panel-toggle {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  padding: 8px 12px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 24px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  color: var(--ink);
  font-size: 24px;
}

.empty-state p {
  margin-top: 8px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 78%;
  align-items: flex-end;
}

.message.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.bubble {
  min-width: 0;
  padding: 12px 14px;
  border-radius: 18px 18px 18px 6px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(35, 54, 86, 0.08);
}

.message.own .bubble {
  border-color: transparent;
  border-radius: 18px 18px 6px 18px;
  background: var(--primary);
  color: #fff;
}

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message.own .meta {
  color: rgba(255, 255, 255, 0.78);
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.message-actions button {
  border: 0;
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(239, 71, 111, 0.12);
  color: var(--rose);
  font-size: 12px;
  font-weight: 800;
}

.message.own .message-actions button {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.48;
}

.system {
  align-self: center;
  max-width: 90%;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(102, 112, 133, 0.1);
  color: var(--muted);
  font-size: 12px;
}

.attachment {
  display: grid;
  gap: 8px;
}

.attachment img,
.attachment video {
  display: block;
  max-width: min(420px, 58vw);
  max-height: 300px;
  border-radius: 12px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.08);
}

.attachment audio {
  width: min(320px, 58vw);
}

.file-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.file-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 10px;
  background: rgba(33, 118, 255, 0.12);
  color: var(--primary);
}

.message.own .file-icon {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.typing {
  padding: 0 26px;
  color: var(--muted);
  font-size: 13px;
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
  background: rgba(250, 252, 255, 0.86);
}

.tools {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(33, 118, 255, 0.5);
}

.icon-btn.recording {
  background: rgba(239, 71, 111, 0.12);
  border-color: rgba(239, 71, 111, 0.5);
  color: var(--rose);
}

.emoji-panel {
  position: absolute;
  left: 20px;
  bottom: 84px;
  z-index: 5;
  width: min(360px, calc(100vw - 40px));
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 18px 50px rgba(35, 54, 86, 0.18);
}

.emoji-panel[hidden] {
  display: none;
}

.emoji-panel button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 22px;
}

.emoji-panel button:hover {
  background: #eef3f8;
}

@media (max-width: 820px) {
  body {
    background: var(--bg);
  }

  .shell {
    width: 100vw;
    height: 100vh;
    min-height: 0;
    margin: 0;
    grid-template-columns: 1fr;
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    display: none;
  }

  .sidebar.open {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(340px, calc(100vw - 42px));
    display: flex;
    box-shadow: 18px 0 50px rgba(15, 23, 42, 0.2);
  }

  .sidebar-close {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    font-size: 22px;
    line-height: 1;
  }

  .chat-panel {
    grid-template-rows: auto minmax(0, 1fr) 24px auto;
  }

  .chat-header {
    padding: 16px;
  }

  .chat-header h2 {
    font-size: 19px;
  }

  .mobile-status {
    display: inline-flex;
    white-space: nowrap;
  }

  .panel-toggle {
    display: inline-flex;
  }

  .messages {
    padding: 16px;
    gap: 12px;
  }

  .message {
    max-width: 92%;
  }

  .attachment img,
  .attachment video {
    max-width: 70vw;
    max-height: 240px;
  }

  .attachment audio {
    width: 68vw;
  }

  .composer {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px 12px 14px;
  }

  .tools {
    grid-column: 1 / -1;
  }

  textarea {
    min-height: 46px;
  }

  .send-btn {
    width: 64px;
  }

  .emoji-panel {
    left: 12px;
    bottom: 128px;
  }
}
