:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --panel-soft: #fbfaf6;
  --text: #262522;
  --muted: #777169;
  --faint: #a9a298;
  --border: #e1d7c8;
  --brand: #4f8f62;
  --brand-dark: #3b764f;
  --brand-soft: #e8f3e7;
  --user-soft: #eaf3ff;
  --agent-soft: #f7eddc;
  --success: #3b8d5c;
  --danger: #c24141;
  --shadow: 0 18px 50px rgba(55, 42, 28, 0.07);
  --shadow-soft: 0 10px 30px rgba(55, 42, 28, 0.055);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% -10%, rgba(216, 183, 122, 0.1), transparent 30%),
    linear-gradient(180deg, #fbfaf7 0%, #f6f2ea 100%);
  color: var(--text);
  font-family: Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.room-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.room-sidebar {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid rgba(225, 215, 200, 0.82);
  background: rgba(242, 238, 231, 0.94);
}

.brand,
.user-card,
.chat-header,
.composer-actions,
.message-row,
.room-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-height: 54px;
}

.brand-mark,
.user-avatar,
.message-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 800;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(184, 138, 69, 0.28);
  border-radius: 14px;
  background: linear-gradient(145deg, #fffaf0, #f1ddb7);
  color: #8a622a;
}

.brand-title {
  font-size: 16px;
  font-weight: 750;
}

.brand-subtitle,
.user-meta,
.panel-head p,
.room-meta,
.message-name,
.message-time,
.status {
  color: var(--muted);
  font-size: 12px;
}

.panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(225, 215, 200, 0.78);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.panel-head h1,
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head p {
  margin: 5px 0 0;
  line-height: 1.55;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-soft);
}

.tab {
  height: 34px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(18, 31, 54, 0.08);
}

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

input,
textarea {
  width: 100%;
  border: 1px solid rgba(225, 215, 200, 0.86);
  border-radius: 16px;
  outline: none;
  background: #fff;
  color: var(--text);
}

input {
  height: 38px;
  padding: 0 11px;
}

textarea {
  min-height: 74px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: rgba(79, 143, 98, 0.58);
  box-shadow: 0 0 0 3px rgba(79, 143, 98, 0.12);
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
}

.primary-button {
  border: 1px solid var(--brand);
  background: linear-gradient(180deg, #579d6c, var(--brand));
  color: #fff;
  box-shadow: 0 8px 18px rgba(79, 143, 98, 0.18);
}

.primary-button:hover:not(:disabled) {
  background: var(--brand-dark);
}

.secondary-button {
  border: 1px solid rgba(225, 215, 200, 0.88);
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
}

.icon-button {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid rgba(225, 215, 200, 0.88);
  background: rgba(255, 255, 255, 0.84);
  color: var(--muted);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button:hover:not(:disabled) {
  color: var(--brand-dark);
  background: var(--brand-soft);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status {
  min-height: 18px;
  line-height: 1.5;
}

.status.success {
  color: var(--success);
}

.status.danger {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.mobile-backdrop,
.mobile-menu-head,
.mobile-menu-button {
  display: none;
}

.user-card {
  gap: 10px;
}

.profile-actions {
  display: grid;
  gap: 8px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 14px;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: cover;
}

.user-name {
  font-size: 14px;
  font-weight: 750;
}

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

.room-row {
  width: 100%;
  justify-content: space-between;
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(225, 215, 200, 0.82);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  text-align: left;
}

.room-row.active {
  border-color: rgba(79, 143, 98, 0.42);
  background: var(--brand-soft);
}

.room-name {
  font-size: 13px;
  font-weight: 750;
}

.chat-stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 18%),
    var(--bg);
}

.chat-header {
  justify-content: space-between;
  gap: 18px;
  padding: 18px 26px 14px;
  border-bottom: 1px solid rgba(225, 215, 200, 0.66);
  background: rgba(255, 255, 255, 0.82);
}

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

.chat-header h2 {
  margin: 0;
  font-size: 22px;
}

.chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chat-header .status {
  min-height: 0;
  margin-top: 4px;
  font-size: 12px;
}

.agent-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 6px 26px 7px;
  border-bottom: 1px solid rgba(225, 215, 200, 0.58);
  background: rgba(255, 253, 249, 0.72);
}

.member-strip-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.member-strip-list {
  display: flex;
  align-items: start;
  gap: 10px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.member-chip {
  display: grid;
  justify-items: center;
  gap: 1px;
  width: 48px;
  min-width: 48px;
}

.member-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(221, 212, 199, 0.72);
  border-radius: 50%;
  background: var(--agent-soft);
  color: #9a6a22;
  font-size: 13px;
  font-weight: 850;
  overflow: hidden;
}

.member-avatar img,
.message-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: cover;
}

.member-chip.user-member .member-avatar {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.member-name,
.member-role {
  max-width: 58px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-name {
  color: var(--text);
  font-size: 11px;
  font-weight: 750;
}

.member-role {
  color: var(--faint);
  font-size: 10px;
}

.messages {
  display: grid;
  align-content: start;
  gap: 16px;
  min-height: 0;
  overflow: auto;
  padding: 22px 28px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.64);
}

.message-row {
  gap: 11px;
  align-items: flex-start;
  max-width: 760px;
}

.message-row.mine {
  justify-self: end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-dark);
  box-shadow: 0 6px 16px rgba(55, 42, 28, 0.08);
}

.message-row.agent .message-avatar {
  background: var(--agent-soft);
  color: #9a6a22;
}

.message-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.message-row.mine .message-main {
  justify-items: end;
}

.message-meta {
  display: flex;
  gap: 8px;
}

.message-bubble {
  max-width: min(640px, 68vw);
  padding: 11px 14px;
  border: 1px solid rgba(225, 215, 200, 0.68);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(55, 42, 28, 0.052);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.62;
  font-size: 14px;
}

.message-row.mine .message-bubble {
  border-color: rgba(137, 174, 212, 0.22);
  background: linear-gradient(180deg, #eef6ff, var(--user-soft));
  border-bottom-right-radius: 8px;
}

.message-row:not(.mine) .message-bubble {
  border-bottom-left-radius: 8px;
}

.room-event-message {
  justify-self: center;
  display: grid;
  gap: 6px;
  width: min(620px, 100%);
  padding: 10px 14px;
  border: 1px solid rgba(118, 145, 126, 0.24);
  border-radius: 8px;
  background: rgba(239, 247, 241, 0.86);
  color: #31563d;
  box-shadow: 0 8px 22px rgba(41, 72, 50, 0.055);
}

.room-event-label,
.room-event-time {
  color: rgba(49, 86, 61, 0.72);
  font-size: 11px;
  font-weight: 760;
}

.room-event-content {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.58;
  font-size: 13px;
}

.voice-card {
  display: grid;
  gap: 8px;
  width: min(360px, 68vw);
  padding: 9px 10px;
  border: 1px solid rgba(225, 215, 200, 0.68);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 22px rgba(18, 31, 54, 0.04);
}

.message-row.mine .voice-card {
  background: rgba(220, 234, 255, 0.8);
}

.voice-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.voice-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 22px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  line-height: 1;
}

.voice-player {
  width: 100%;
  min-width: 0;
  height: 34px;
}

.voice-caption {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer {
  position: relative;
  display: grid;
  gap: 9px;
  padding: 12px 26px 16px;
  border-top: 1px solid rgba(225, 215, 200, 0.74);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 -18px 44px rgba(18, 31, 54, 0.05);
}

.composer-actions {
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.file-input {
  display: none;
}

.composer-hint {
  color: var(--muted);
  font-size: 13px;
}

.composer textarea {
  background: #fffdf9;
}

.emoji-panel {
  position: absolute;
  left: 26px;
  bottom: 58px;
  display: flex;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(225, 215, 200, 0.84);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-soft);
}

.emoji-panel button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: 17px;
}

.emoji-panel button:hover {
  background: var(--brand-soft);
}

.attachment-preview {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  padding: 7px 9px 7px 12px;
  border: 1px solid rgba(225, 215, 200, 0.86);
  border-radius: 999px;
  background: #fffdf9;
  color: var(--muted);
  font-size: 12px;
}

.attachment-preview span {
  overflow: hidden;
  max-width: 360px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview button {
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(225, 215, 200, 0.88);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 860px) {
  body {
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .room-shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .room-sidebar {
    min-height: 100dvh;
    padding: 18px;
    border-right: 0;
    border-bottom: 0;
  }

  .brand {
    justify-content: center;
    margin-top: 4px;
  }

  .auth-panel {
    align-self: start;
    width: min(100%, 420px);
    margin: 12px auto 0;
  }

  .invite-panel,
  .user-panel,
  .rooms-panel,
  .chat-stage {
    display: none;
  }

  body.is-logged-in .room-shell {
    display: block;
  }

  body.is-logged-in .room-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 30;
    width: min(84vw, 340px);
    height: 100dvh;
    overflow: auto;
    border-right: 1px solid rgba(225, 215, 200, 0.82);
    box-shadow: 18px 0 42px rgba(55, 42, 28, 0.14);
    transform: translateX(-104%);
    transition: transform 0.2s ease;
  }

  body.is-logged-in.mobile-menu-open .room-sidebar {
    transform: translateX(0);
  }

  body.is-logged-in .brand,
  body.is-logged-in .auth-panel {
    display: none;
  }

  body.is-logged-in .chat-stage,
  body.is-logged-in .invite-panel,
  body.is-logged-in .user-panel,
  body.is-logged-in .rooms-panel {
    display: grid;
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(38, 37, 34, 0.24);
  }

  .mobile-menu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 42px;
    color: var(--text);
    font-size: 15px;
  }

  .mobile-menu-button {
    display: inline-flex;
  }

  .chat-stage {
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
  }

  .chat-header {
    gap: 10px;
    justify-content: flex-start;
    padding: 10px 12px;
  }

  .chat-header > div {
    min-width: 0;
  }

  .chat-header h2 {
    overflow: hidden;
    font-size: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-header p {
    display: none;
  }

  .chat-header .status {
    overflow: hidden;
    margin-top: 2px;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #refreshButton {
    display: none;
  }

  .agent-strip {
    display: none;
  }

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

  .message-row {
    max-width: 100%;
  }

  .message-avatar {
    width: 34px;
    height: 34px;
  }

  .message-bubble {
    max-width: calc(100vw - 86px);
    padding: 10px 12px;
  }

  .voice-card {
    width: calc(100vw - 86px);
  }

  .composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "input emoji trailing"
      "attach attach attach";
    align-items: center;
    gap: 8px;
    padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
    background: #f6f6f6;
    box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.06);
  }

  .composer textarea {
    grid-area: input;
    min-height: 40px;
    max-height: 86px;
    padding: 9px 11px;
    border: 0;
    border-radius: 4px;
    background: #fff;
    line-height: 1.35;
    resize: none;
  }

  .composer-actions {
    display: contents;
  }

  .composer-tools {
    display: contents;
  }

  #emojiButton {
    grid-area: emoji;
  }

  #attachmentButton {
    grid-area: trailing;
  }

  #emojiButton,
  #attachmentButton {
    width: 34px;
    height: 34px;
    border-color: transparent;
    background: transparent;
    color: #1f1d1a;
  }

  #sendButton {
    grid-area: trailing;
    min-height: 38px;
    padding: 0 13px;
    border-radius: 8px;
    background: #09c060;
    border-color: #09c060;
    box-shadow: none;
    font-size: 15px;
    font-weight: 600;
  }

  body:not(.composer-has-content) #sendButton {
    display: none;
  }

  body.composer-has-content #attachmentButton {
    display: none;
  }

  .composer-hint {
    display: none;
  }

  .attachment-preview {
    grid-area: attach;
    max-width: 100%;
  }

  .emoji-panel {
    left: 10px;
    right: 10px;
    bottom: 56px;
    flex-wrap: wrap;
  }

  textarea {
    min-height: 40px;
    max-height: 86px;
  }

  .attachment-preview span {
    max-width: calc(100vw - 120px);
  }
}
