:root {
  color-scheme: light;
  --bg: #ededed;
  --panel: #f7f7f7;
  --panel-soft: #ffffff;
  --line: #d8d8d8;
  --text: #111111;
  --muted: #7a7a7a;
  --primary: #07c160;
  --primary-strong: #06ad56;
  --accent: #b7791f;
  --danger: #b42318;
  --blue: #3478f6;
  --bubble-mine: #95ec69;
  --bubble-other: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100dvh;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  background: var(--panel);
  color: var(--text);
  border-right: 1px solid var(--line);
}

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

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 12px;
  height: 12px;
  margin-top: 8px;
  border-radius: 50%;
  background: #8a94a6;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
}

.status-dot.online {
  background: #28a745;
}

.status-dot.offline {
  background: #d64545;
}

.profile-panel,
.create-panel,
.room-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-panel label,
.section-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 46px;
  max-height: 130px;
  resize: none;
  padding: 12px;
}

input:focus,
textarea:focus {
  border-color: #4c8f84;
  box-shadow: 0 0 0 3px rgba(37, 111, 99, 0.15);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #e6e6e6;
}

.segmented button {
  height: 36px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: var(--text);
  background: #ffffff;
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  white-space: nowrap;
}

.primary {
  color: #ffffff;
  background: var(--primary);
}

.primary:hover {
  background: var(--primary-strong);
}

.secondary {
  color: var(--text);
  background: #e8edf1;
}

.secondary:hover {
  background: #dce5ea;
}

.ghost {
  color: var(--text);
  background: #e9e9e9;
}

.ghost:hover {
  background: #dedede;
}

.danger {
  color: #ffffff;
  background: var(--danger);
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.room-panel {
  min-height: 0;
  flex: 1;
}

.room-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.room-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 14px 12px;
  border: 0;
  border-bottom: 1px solid #e4e4e4;
  border-radius: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.room-card:hover {
  background: #ececec;
}

.room-card.active {
  background: #e1f3e8;
}

.room-card strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.room-lock {
  padding: 3px 8px;
  border-radius: 999px;
  color: #17202b;
  background: #f2c94c;
  font-size: 12px;
}

.room-open {
  padding: 3px 8px;
  border-radius: 999px;
  color: #0c3d35;
  background: #a7f3d0;
  font-size: 12px;
}

.chat-area {
  display: grid;
  grid-template-areas:
    "header"
    "call"
    "messages"
    "composer";
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100dvh;
  background: var(--bg);
}

.room-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.room-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
}

.room-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.room-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.room-controls .ghost {
  color: var(--muted);
  background: #eef2f5;
}

.room-controls .ghost:hover {
  color: var(--text);
  background: #e0e7ed;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #0c3d35;
  background: #d8f5e8;
  font-size: 13px;
  font-weight: 700;
}

.badge.encrypted {
  color: #643b0b;
  background: #ffe8b2;
}

.privacy-password {
  width: 160px;
}

.call-invite {
  grid-area: call;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 22px 0;
  padding: 10px 12px;
  border: 1px solid #cdebd9;
  border-radius: 8px;
  background: #f2fff7;
}

.call-invite strong,
.call-invite span {
  display: block;
}

.call-invite span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.call-invite-actions {
  display: flex;
  gap: 8px;
}

.call-panel {
  grid-area: call;
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0;
  background: #101010;
  color: #f8fafc;
  border: 0;
}

.call-toolbar {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 44px;
  margin-bottom: 0;
}

.call-status {
  color: #f8fafc;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.call-icon-button {
  position: absolute;
  left: 0;
  top: 2px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
  font-size: 18px;
}

.call-actions {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 4;
  transform: translateX(-50%);
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
}

.call-actions .secondary,
.call-actions .danger {
  width: 86px;
  min-height: 58px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
}

.call-actions .danger {
  width: 92px;
  background: #f04438;
}

.video-grid {
  position: relative;
  display: grid;
  flex: 1;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2px;
  align-items: stretch;
  min-height: 0;
  margin: 76px 0 142px;
  overflow: hidden;
}

.media-tile {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #182331;
  cursor: pointer;
}

.media-tile video,
.media-tile audio {
  width: 100%;
  height: 100%;
}

.media-tile video {
  display: block;
  object-fit: contain;
  background: #101010;
}

.local-tile video {
  transform: scaleX(-1);
}

.media-tile span {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: calc(100% - 16px);
  overflow: hidden;
  padding: 4px 8px;
  border-radius: 999px;
  color: #f8fafc;
  background: rgba(0, 0, 0, 0.45);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-grid.duo {
  display: block;
}

.video-grid.duo .media-tile {
  position: absolute;
  inset: 0;
}

.video-grid.duo .thumb-tile {
  inset: 18px 18px auto auto;
  z-index: 2;
  width: min(210px, 30vw);
  height: min(150px, 24vh);
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.video-grid.group {
  grid-auto-rows: minmax(180px, 1fr);
}

.video-grid.group .featured-tile {
  grid-column: span 2;
  grid-row: span 2;
}

.call-panel.minimized {
  inset: 74px auto auto 360px;
  width: 220px;
  height: 136px;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

.call-panel.minimized .call-toolbar {
  top: 0;
  left: 0;
  right: 0;
  min-height: 30px;
  padding: 4px 8px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
}

.call-panel.minimized .call-status {
  font-size: 12px;
}

.call-panel.minimized .call-icon-button {
  display: none;
}

.call-panel.minimized .call-actions {
  display: none;
}

.call-panel.minimized .video-grid {
  display: block;
  height: 100%;
  margin: 0;
}

.call-panel.minimized .media-tile {
  display: none;
}

.call-panel.minimized .main-tile,
.call-panel.minimized .media-tile:first-child {
  display: block;
  position: absolute;
  inset: 0;
}

.media-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #cad5df;
  background: #182331;
  font-size: 14px;
  font-weight: 700;
}

.message-pane {
  grid-area: messages;
  min-height: 0;
  padding: 18px 22px;
  overflow: hidden;
  background: var(--bg);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: #b8b8b8 transparent;
}

.message-list::-webkit-scrollbar {
  width: 10px;
}

.message-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #b8b8b8;
  background-clip: content-box;
}

.message-list::-webkit-scrollbar-track {
  background: transparent;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  font-size: 16px;
}

.message {
  position: relative;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  max-width: min(620px, 78%);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.message.mine {
  align-self: flex-end;
  grid-template-columns: minmax(0, 1fr) 38px;
}

.message-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.message-bubble {
  min-width: 0;
  padding: 9px 11px;
  border-radius: 5px;
  background: var(--bubble-other);
  box-shadow: var(--shadow);
}

.message.mine .message-avatar {
  grid-column: 2;
  grid-row: 1;
}

.message.mine .message-bubble {
  grid-column: 1;
  grid-row: 1;
  background: var(--bubble-mine);
}

.message.system {
  display: block;
  align-self: center;
  max-width: 78%;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.05);
  border: 0;
  border-radius: 999px;
  box-shadow: none;
  text-align: center;
  font-size: 12px;
  padding: 5px 10px;
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

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

.attachment {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment img,
.attachment video {
  max-width: min(520px, 100%);
  max-height: 360px;
  border-radius: 8px;
  background: #111827;
  object-fit: contain;
}

.attachment-image {
  cursor: zoom-in;
}

.attachment audio {
  width: min(420px, 100%);
}

.file-link {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--blue);
  text-decoration: none;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  color: var(--muted);
  font-size: 12px;
}

.composer {
  grid-area: composer;
  padding: 10px 22px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.upload-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid #dce6df;
  border-radius: 8px;
  background: #ffffff;
}

.upload-info {
  min-width: 0;
}

.upload-info strong,
.upload-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-info span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.upload-progress {
  grid-column: 1 / -1;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e5e5;
}

.upload-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.15s ease;
}

.upload-error {
  border-color: #f0b4ae;
  background: #fff5f4;
}

.upload-error .upload-progress span {
  background: var(--danger);
}

.recording-banner {
  display: grid;
  grid-template-columns: auto auto auto 72px;
  gap: 8px;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  color: #ffffff;
  background: #d92d20;
  box-shadow: 0 8px 20px rgba(217, 45, 32, 0.22);
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  animation: recording-pulse 1s infinite ease-in-out;
}

.recording-banner .danger {
  min-height: 30px;
  color: #d92d20;
  background: #ffffff;
}

.recording {
  color: #ffffff;
  background: #d92d20;
}

@keyframes recording-pulse {
  0%, 100% {
    opacity: 0.45;
    transform: scale(0.78);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.message-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.notice {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.notice.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(0, 0, 0, 0.88);
}

.image-viewer-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px;
}

.viewer-button {
  min-width: 42px;
  min-height: 38px;
  border-radius: 8px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 700;
}

.viewer-button:hover {
  background: rgba(255, 255, 255, 0.24);
}

.image-viewer-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

.image-viewer-stage img {
  width: min(92vw, 1600px);
  max-height: 82vh;
  height: auto;
  object-fit: contain;
  transition: width 0.12s ease, max-height 0.12s ease;
  user-select: none;
}

@media (min-width: 881px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    min-height: 0;
    overflow: hidden;
  }

  .room-list {
    flex: 1;
  }

  .chat-area {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
  }

  .chat-area {
    min-height: 72vh;
  }

  .room-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .room-controls {
    justify-content: flex-start;
  }

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

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

  .app-shell {
    display: block;
    min-height: 100dvh;
  }

  .app-shell:not(.in-room) .chat-area {
    display: none;
  }

  .app-shell.in-room .sidebar {
    display: none;
  }

  .sidebar {
    min-height: 100dvh;
    padding: 14px;
    overflow: auto;
  }

  .brand {
    min-height: 44px;
    align-items: center;
  }

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

  .profile-panel,
  .create-panel,
  .room-panel {
    padding: 12px;
    border-radius: 8px;
    background: #ffffff;
  }

  .room-list {
    margin-left: -12px;
    margin-right: -12px;
  }

  .room-card {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .room-header {
    min-height: 52px;
    padding: 8px 12px;
    gap: 8px;
  }

  .room-name {
    font-size: 17px;
  }

  .room-meta {
    margin-top: 2px;
    font-size: 12px;
  }

  .room-controls {
    width: 100%;
    gap: 6px;
  }

  .privacy-password {
    flex: 1;
    min-width: 120px;
  }

  .call-panel {
    padding: 0;
  }

  .call-invite {
    margin: 8px 12px 0;
  }

  .call-panel:not(.minimized) .video-grid {
    margin: 64px 0 126px;
  }

  .call-panel:not(.minimized) .call-toolbar {
    top: 10px;
    left: 12px;
    right: 12px;
  }

  .call-actions {
    bottom: 24px;
    gap: 14px;
  }

  .call-actions .secondary,
  .call-actions .danger {
    width: 76px;
    min-height: 52px;
    padding: 0 8px;
    font-size: 12px;
  }

  .video-grid.group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(150px, 1fr);
  }

  .video-grid.duo .thumb-tile {
    width: 112px;
    height: 150px;
  }

  .call-panel.minimized {
    inset: 62px auto auto 12px;
    width: 156px;
    height: 104px;
  }

  .message-pane {
    padding: 12px;
  }

  .message-list {
    gap: 8px;
    padding-right: 0;
  }

  .message {
    max-width: 82%;
    font-size: 15px;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 7px;
  }

  .message.mine {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    font-size: 18px;
  }

  .message-head {
    margin-bottom: 4px;
    font-size: 11px;
  }

  .composer {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .upload-item {
    grid-template-columns: minmax(0, 1fr) 58px;
    padding: 7px;
  }

  .upload-item .small {
    padding: 0 6px;
  }

  .recording-banner {
    width: 100%;
    grid-template-columns: auto auto 1fr 64px;
    border-radius: 8px;
  }

  .composer-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .composer-actions button {
    min-width: 0;
    padding: 0 6px;
    font-size: 13px;
  }

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

  textarea {
    min-height: 40px;
    max-height: 96px;
    padding: 9px 11px;
    border-radius: 6px;
  }

  .message-compose .primary {
    width: 64px;
    min-height: 40px;
    padding: 0;
  }

  .notice {
    min-height: 18px;
    margin-top: 5px;
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .room-header,
  .message-pane,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .message {
    max-width: 84%;
  }

  .message-compose {
    grid-template-columns: minmax(0, 1fr) 64px;
  }

  .message-compose .primary {
    width: 64px;
  }
}
