/* Chat colours come from the app palette in base.css. Only the two
   chat-specific accents live here: the bubble tint for your own messages
   and the read-receipt ticks. */
:root {
  --bubble-mine: #d7e9ff;
  --tick: #6ba4e0;
  --tick-read: #007aff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bubble-mine: #2b4a6b;
    --tick: #7fa8d0;
    --tick-read: #6fc0ff;
  }
}

.is-chat .app__content { padding: 0; }
.is-chat .app__main { padding-bottom: 0; }

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

.chat__top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 9px) 16px 9px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--separator);
  z-index: 3;
}

.chat__back {
  position: static;
  transform: none;
  flex-shrink: 0;
  width: 32px;
  height: 40px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  color: var(--accent);
  background: none;
  box-shadow: none;
}

.chat__back svg { width: 26px; height: 26px; }

.chat__open {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.chat__title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  margin: 0 auto;
  padding: 0 8px;
  border-radius: 0;
  background: none;
  box-shadow: none;
  max-width: 62%;
}

.chat__name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}

.chat__mark { width: 18px; height: 18px; border-radius: 5px; flex-shrink: 0; }
.chat__presence { font-size: 13px; color: var(--text-dim); }
.chat__presence.is-online { color: var(--accent); }

.chat__avatar {
  position: static;
  transform: none;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(150deg, #56b0ff, #1d6ff2);
  background-size: cover;
  background-position: center;
  border: none;
  box-shadow: none;
}

.chsearchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--separator);
}

.chsearchbar__field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--field-bg);
  border-radius: var(--field-radius);
  padding: 8px 12px;
}
.chsearchbar__field svg { width: 18px; height: 18px; color: var(--text-dim); flex-shrink: 0; }
.chsearchbar__input { flex: 1; min-width: 0; border: none; background: none; outline: none; font-family: inherit; font-size: 17px; color: var(--text); }
.chsearchbar__count { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

.chsearchbar__nav {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.13s ease;
}
.chsearchbar__nav:active { opacity: 0.5; }
.chsearchbar__nav svg { width: 22px; height: 22px; }
.chsearchbar__cancel { border: none; background: none; color: var(--accent); font-size: 17px; cursor: pointer; white-space: nowrap; transition: opacity 0.13s ease; }
.chsearchbar__cancel:active { opacity: 0.5; }

mark.srch { background: rgba(255, 204, 0, 0.5); color: inherit; border-radius: 3px; padding: 0 1px; }
mark.srch.is-cur { background: #ffb300; color: #000; }

.chat__pin {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 16px 0;
  padding: 10px 14px;
  border-radius: var(--card-radius);
  background: var(--surface);
  border-left: 3px solid var(--accent);
}

.chat__pin.is-empty { display: none; }
.chat__pinbody { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.chat__pinlabel { font-size: 13px; font-weight: 600; color: var(--accent); }
.chat__pintext { font-size: 15px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat__pinclose {
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.13s ease;
}
.chat__pinclose:active { opacity: 0.5; }
.chat__pinclose svg { width: 18px; height: 18px; }

.chat__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
}

.chat__feed { display: flex; flex-direction: column; gap: 2px; padding-top: 4px; flex-shrink: 0; }

.daysep {
  align-self: center;
  margin: 16px 0 8px;
  position: sticky;
  top: 4px;
  z-index: 2;
  pointer-events: none;
}

.daysep span {
  display: inline-block;
  padding: 5px 13px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface);
}

.chat__feed > .daysep:first-child { margin-top: 4px; }

.msg { display: flex; max-width: 78%; position: relative; }
.msg--mine { align-self: flex-end; }
.msg:not(.msg--mine) { align-self: flex-start; }
.msg:not(.grouped) { margin-top: 10px; }
.chat__feed > .msg:first-child { margin-top: 0; }
.daysep + .msg { margin-top: 0; }

.bubble {
  position: relative;
  padding: 8px 13px;
  border-radius: var(--card-radius);
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  line-height: 1.38;
  word-break: break-word;
}

.msg--mine .bubble { background: var(--bubble-mine); }

.bubble__text { white-space: pre-wrap; }
.bubble__text code {
  font-family: var(--font-mono); font-size: 14px;
  padding: 1px 5px; border-radius: 5px;
  background: var(--field-bg-strong);
}
.bubble__text pre {
  font-family: var(--font-mono); font-size: 13.5px;
  margin: 6px 0 2px; padding: 10px 12px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.06); overflow-x: auto;
}
@media (prefers-color-scheme: dark) {
  .bubble__text pre { background: rgba(255, 255, 255, 0.06); }
}

.bubble__meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 6px 0 -2px 8px;
  line-height: 1;
  user-select: none;
}

.bubble__time { font-size: 11px; color: var(--text-dim); }

.bubble__ticks { display: inline-flex; color: var(--tick); }
.bubble__ticks svg { width: 17px; height: 11px; display: block; }
.bubble__ticks .tick2 { opacity: 0; }
.bubble__ticks.is-read { color: var(--tick-read); }
.bubble__ticks.is-read .tick2 { opacity: 1; }

.bubble--media, .bubble--circle { padding: 4px; }
.bubble__img, .bubble__square { display: block; max-width: 220px; max-height: 260px; width: auto; object-fit: cover; border-radius: 16px; cursor: pointer; }
.bubble__circle { width: 170px; height: 170px; border-radius: 50%; object-fit: cover; }

.bubble__meta--over {
  position: absolute;
  right: 8px;
  bottom: 8px;
  float: none;
  margin: 0;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
}
.bubble__meta--over .bubble__time { color: #fff; }
.bubble__meta--over .bubble__ticks { color: #fff; }
.bubble__meta--over .bubble__ticks.is-read { color: #eafff2; }

.bubble--voice { display: flex; align-items: center; gap: 8px; }

.voice { display: flex; align-items: center; gap: 10px; padding: 2px 0; min-width: 190px; }

.voice__play {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  padding: 0;
}

.voice__play:active { opacity: 0.72; }
.voice__ico { width: 20px; height: 20px; display: block; }
.voice__ico--play { margin-left: 2px; }

.voice__body { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }

.voice__track {
  height: 4px;
  border-radius: 2px;
  background: rgba(125, 145, 170, 0.32);
  cursor: pointer;
  position: relative;
}

.voice__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
}

.voice__time { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.bubble--file .filecard { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.filecard__icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--accent);
  flex-shrink: 0;
}
.filecard__icon svg { width: 21px; height: 21px; }
.filecard__meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.filecard__name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.filecard__size { font-size: 13px; color: var(--text-dim); }

.chatblank {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 60%;
  padding: 24px;
}

.chatblank[hidden] { display: none; }

.chatblank__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  max-width: 300px;
  padding: 26px 22px;
  border-radius: var(--card-radius);
  background: var(--surface);
}

.chatblank__avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 25px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(150deg, #56b0ff, #1d6ff2);
  background-size: cover;
  background-position: center;
}

.chatblank__title { margin: 4px 0 0; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.chatblank__text { margin: 0; font-size: 15px; line-height: 1.45; color: var(--text-dim); }

.scrolldown {
  position: absolute;
  right: 16px;
  bottom: 78px;
  z-index: 4;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  padding: 0;
  transition: opacity 0.13s ease;
}

.scrolldown[hidden] { display: none; }
.scrolldown:active { opacity: 0.5; }
.scrolldown svg { width: 22px; height: 22px; }

.scrolldown__badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 19px;
  color: #fff;
  background: var(--accent);
}

.scrolldown__badge[hidden] { display: none; }

.msgmenu {
  position: fixed;
  z-index: 60;
  min-width: 180px;
  padding: 6px;
  border-radius: var(--field-radius);
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
}

.msgmenu__item {
  border: none;
  background: none;
  font-family: inherit;
  text-align: left;
  padding: 11px 12px;
  border-radius: 9px;
  font-size: 17px;
  color: var(--text);
  cursor: pointer;
}

.msgmenu__item:active { background: rgba(60, 60, 67, 0.09); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
  padding: 9px 16px calc(9px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 0.5px solid var(--separator);
}

.composer--blocked {
  justify-content: center;
  align-items: center;
  padding-top: 15px;
  padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
}

.composer__notice {
  text-align: center;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text-dim);
}

.composer__input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: none;
  outline: none;
  background: var(--field-bg);
  border-radius: var(--card-radius);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.3;
  color: var(--text);
  max-height: 120px;
}

.composer__btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: none;
  background: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: opacity 0.13s ease;
}

.composer__btn:active { opacity: 0.5; }
.composer__btn svg { width: 24px; height: 24px; }
.composer__send { color: var(--accent); }

.recorder {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 20px -8px rgba(0, 0, 0, 0.3);
  z-index: 5;
}

.recorder__preview { display: flex; justify-content: center; margin-bottom: 12px; }
.recorder__vid { width: 200px; height: 200px; object-fit: cover; border-radius: 14px; background: #000; }
.recorder__vid--circle { border-radius: 50%; }
.recorder__wave { padding: 24px; color: var(--text-dim); }

.recorder__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.recorder__cancel { border: none; background: none; color: var(--danger); font-size: 16px; cursor: pointer; }
.recorder__time { font-size: 16px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.recorder__mode {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--separator);
  background: var(--field-bg); font-size: 20px; color: var(--text); cursor: pointer;
}
.recorder__stop { border: none; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; padding: 9px 18px; border-radius: 20px; cursor: pointer; }

.results { display: flex; flex-direction: column; }
.result { display: flex; align-items: center; gap: 12px; padding: 9px 6px; text-decoration: none; color: var(--text); border-radius: 12px; }
.result:active { background: var(--field-bg); }
.result__avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: #fff;
  background: linear-gradient(150deg, #56b0ff, #1d6ff2);
  background-size: cover; background-position: center;
}
.result__meta { display: flex; flex-direction: column; min-width: 0; }
.result__name { font-size: 16px; font-weight: 500; }
.result__handle { font-size: 13px; color: var(--text-dim); }
.results__empty { padding: 20px; text-align: center; color: var(--text-dim); }

@media (min-width: 821px) {
  .chat { border-radius: 0; }
}

.chats { flex: 1; width: 100%; min-width: 0; display: flex; flex-direction: column; }

.chsearch { display: flex; align-items: center; gap: 10px; padding: 2px 0 12px; }

.searchbar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--field-bg);
  border-radius: 12px;
  padding: 9px 12px;
}

.searchbar__icon { width: 20px; height: 20px; color: var(--text-dim); flex-shrink: 0; }
.searchbar__input { flex: 1; min-width: 0; border: none; background: none; outline: none; font-family: inherit; font-size: 17px; color: var(--text); }
.searchbar__input::placeholder { color: var(--text-dim); }

.chsearch__cancel { border: none; background: none; color: var(--accent); font-size: 16px; cursor: pointer; white-space: nowrap; }

.chatlist { display: flex; flex-direction: column; }

.chatrow { display: flex; align-items: center; gap: 12px; padding: 8px 6px 0; text-decoration: none; color: var(--text); }
.chatrow:active { background: var(--field-bg); border-radius: 12px; }

.chatrow__avatar {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(150deg, #56b0ff, #1d6ff2);
  background-size: cover;
  background-position: center;
}

.chatrow__avatar.is-online::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #34c759;
  border: 2.5px solid var(--bg);
}

.chatrow__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-bottom: 9px;
  border-bottom: 0.5px solid var(--separator);
}

.chatrow:last-child .chatrow__body { border-bottom: none; }

.chatrow__line { display: flex; align-items: center; gap: 8px; }
.chatrow__name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 5px; }
.chatrow__nametext { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16.5px; font-weight: 600; }
.chatrow__mark { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; }
.chatrow__time { font-size: 13px; color: var(--text-dim); flex-shrink: 0; }
.chatrow__preview { flex: 1; min-width: 0; font-size: 15px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatrow__you { color: var(--text-dim); }

.chatrow__unread {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatsempty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 56px 24px; }
.chatsempty__icon {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(150deg, #56b0ff, #1d6ff2);
  box-shadow: 0 10px 24px -10px rgba(29, 111, 242, 0.6);
}
.chatsempty__icon svg { width: 36px; height: 36px; }
.chatsempty__title { margin: 0; font-size: 19px; font-weight: 700; }
.chatsempty__text { margin: 0; font-size: 14px; color: var(--text-dim); max-width: 280px; line-height: 1.4; }

.searchpanel { display: flex; flex-direction: column; }

.circles {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 2px 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.circles::-webkit-scrollbar { display: none; }

.circle { flex-shrink: 0; width: 66px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; color: var(--text); }
.circle__img {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 23px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(150deg, #56b0ff, #1d6ff2);
  background-size: cover;
  background-position: center;
}
.circle__name { font-size: 12px; max-width: 66px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.searchpanel__group { margin: 4px 2px 8px; font-size: 13px; color: var(--text-dim); }

@media (max-width: 820px) {
  .is-chat .app { min-height: 0; height: 100%; }
  .is-chat .app__nav { display: none; }
  .is-chat .app__main { padding-bottom: 0; overflow: hidden; }
  .is-chat .app__content { min-height: 0; }
}

@media (min-width: 821px) {
  body.is-chat { height: 100vh; overflow: hidden; }
  .is-chat .app { min-height: 0; height: 100vh; }
  .is-chat .app__main { min-height: 0; height: 100vh; }
  .is-chat .app__content { min-height: 0; overflow: hidden; }
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.lb__stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 64px 12px;
}

.lb__media { max-width: 100%; max-height: 100%; border-radius: 8px; object-fit: contain; }

.lb__close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 16px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.lb__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb__prev { left: 12px; }
.lb__next { right: 12px; }

.lb__strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  width: 100%;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  justify-content: center;
  scrollbar-width: none;
}
.lb__strip::-webkit-scrollbar { display: none; }

.lb__thumb {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border: 2px solid transparent;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  background-color: #333;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  opacity: 0.55;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.lb__thumb video { width: 100%; height: 100%; object-fit: cover; }
.lb__thumb.is-active { opacity: 1; border-color: #fff; }

body.lb-open { overflow: hidden; }

@media (max-width: 820px) {
  .lb__stage { padding: 48px 12px 8px; }
  .lb__nav { width: 40px; height: 40px; font-size: 26px; }
}
