:root {
  --bg: #0b141a;
  --bg-elev: #111b21;
  --bg-panel: #202c33;
  --bg-input: #2a3942;
  --line: #2f3b43;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-2: #21c7a8;
  --mine: #005c4b;
  --theirs: #202c33;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 50% -30%, rgba(0, 168, 132, 0.2), transparent 60%),
    var(--bg);
}

.layout {
  width: 100%;
  height: 100dvh;
}

.screen { width: 100%; height: 100%; }
.hidden { display: none !important; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 0;
}

#qrScreen {
  display: grid;
  place-items: center;
  padding: 20px;
  background: transparent;
  border: 0;
}

#qrScreen > h1,
#qrScreen > .muted,
#qrScreen > .qr-box,
#qrScreen > .status,
#qrScreen > .meta,
#qrScreen > .row {
  width: min(300px, 100%);
}

#qrScreen > h1 {
  margin: 0 0 10px;
  font-size: 30px;
  text-align: center;
}

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

#qrScreen > .muted {
  text-align: center;
  line-height: 1.4;
  margin-bottom: 10px;
}

.qr-box {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  outline: 0;
  overflow: hidden;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  padding: 12px;
}

.qr-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #ffffff;
  image-rendering: crisp-edges;
  filter: none;
  mix-blend-mode: normal;
}

.status {
  margin: 12px 0 0;
  text-align: center;
  font-weight: 700;
  min-height: 24px;
}

.meta {
  margin: 6px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.row {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.btn {
  border: 1px solid transparent;
  background: var(--bg-input);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #04130f;
}

#chatScreen {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: 232px 1fr;
  gap: 0;
  border: 0;
  border-radius: 0;
  background: var(--bg-elev);
}

.sidebar {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 0 1px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  background: var(--bg-elev);
}

.sidebar-head {
  height: 60px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-panel);
}

.title { font-weight: 700; }

.rooms {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 0;
}

.rooms-empty { padding: 10px; }

.room {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid rgba(134, 150, 160, 0.11);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 0 1px;
  cursor: pointer;
}

.room:hover { background: rgba(255, 255, 255, 0.03); }
.room.active { background: #24343d; }

.room-row {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 4px;
  min-height: 40px;
}

.room-avatar,
.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #36474f;
  color: #e7eef1;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  overflow: hidden;
  flex-shrink: 0;
}

.room-avatar {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.room-avatar img,
.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.room-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat {
  border: 0;
  border-radius: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 60px 1fr auto auto;
  background: var(--bg);
}

.chat-head {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
}

.messages {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding: 12px;
  align-content: start;
  background:
    linear-gradient(0deg, rgba(11, 20, 26, 0.9), rgba(11, 20, 26, 0.9)),
    radial-gradient(600px 300px at 90% 10%, rgba(0, 168, 132, 0.12), transparent 70%);
}

.msg {
  max-width: min(78%, 760px);
  border-radius: 10px;
  padding: 7px 9px;
  border: 0;
  background: var(--theirs);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
}

.msg.me {
  margin-left: auto;
  background: var(--mine);
}

.msg.system {
  margin: 0 auto;
  max-width: 100%;
  background: #182229;
  font-size: 13px;
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.msg.me .msg-avatar { display: none; }

.msg .meta-row {
  color: var(--muted);
  font-size: 11px;
}

.msg-actions {
  margin-top: 3px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.msg-action {
  border: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 11px;
  padding: 3px 7px;
  cursor: pointer;
}

.msg-action.danger {
  background: rgba(255, 82, 82, 0.2);
}

.reply-chip {
  margin-top: 5px;
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #d6e3ea;
  font-size: 12px;
  border-left: 2px solid var(--accent-2);
}

.msg-text {
  margin-top: 5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.media-preview {
  display: block;
  width: min(340px, 100%);
  max-height: 260px;
  margin-top: 7px;
  border-radius: 10px;
  background: #0f1518;
  cursor: pointer;
}

.media-preview.image {
  object-fit: cover;
}

.media-preview.video {
  object-fit: contain;
  cursor: default;
}

.file-link {
  display: inline-block;
  margin-top: 6px;
  color: #b7e8ff;
  text-decoration: underline;
  word-break: break-all;
}

.reply-bar {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #1f2c35;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reply-info {
  font-size: 13px;
  color: #dbe8ee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel {
  border: 0;
  border-radius: 8px;
  padding: 4px 9px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  cursor: pointer;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 9px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  background: var(--bg-panel);
}

.composer input[type="text"] {
  width: 100%;
  border: 1px solid transparent;
  background: var(--bg-input);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
  outline: none;
}

.composer input[type="text"]:focus {
  border-color: rgba(0, 168, 132, 0.55);
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: var(--bg-input);
  border-radius: 10px;
  padding: 0 12px;
  font-weight: 600;
  cursor: pointer;
}

.file-btn input { display: none; }

.media-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
}

.media-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
}

.media-modal-image,
.media-modal-video {
  max-width: min(92vw, 1200px);
  max-height: 86vh;
  border-radius: 12px;
}

@media (max-width: 980px) {
  #chatScreen {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(160px, 30dvh) 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

.media-audio {
  display: block;
  width: min(320px, 100%);
  margin-top: 7px;
}

.msg-jump {
  outline: 2px solid #6ce5c8;
  box-shadow: 0 0 0 2px rgba(108, 229, 200, 0.25);
  transition: outline-color 0.6s ease, box-shadow 0.6s ease;
}


.voice-player {
  margin-top: 7px;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 8px;
  width: min(340px, 100%);
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
}

.voice-play {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #2e444f;
  color: #e9edef;
  cursor: pointer;
  font-size: 14px;
}

.voice-progress {
  width: 100%;
  accent-color: #21c7a8;
}

.voice-time {
  color: var(--muted);
  font-size: 11px;
  min-width: 68px;
  text-align: right;
}
