* {
  box-sizing: border-box;
}

:root {
  --tg-blue: #3390ec;
  --tg-blue-active: #4ea4f6;
  --tg-text: #111827;
  --tg-muted: #707579;
  --tg-border: #dadce0;
  --tg-panel: #ffffff;
  --tg-hover: #f4f4f5;
  --tg-in: #ffffff;
  --tg-out: #d9fdd3;
  --tg-chat-fallback: #e7d9bd;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: #ffffff;
  color: var(--tg-text);
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  user-select: none;
}

.hidden {
  display: none !important;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  min-width: 860px;
  background: #fff;
  overflow: hidden;
}

/* LEFT PANEL */

.sidebar {
  background: var(--tg-panel);
  border-right: 1px solid #dfe3e8;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar-toolbar {
  height: 48px;
  min-height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  position: relative;
}

.round-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #707579;
  cursor: pointer;
  font-size: 22px;
  display: grid;
  place-items: center;
  line-height: 1;
  flex: 0 0 auto;
}

.round-btn:hover {
  background: #f1f3f4;
}

.add-btn {
  color: var(--tg-blue);
  font-size: 24px;
}

.search-box {
  height: 36px;
  flex: 1;
  position: relative;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: #9aa0a6;
  font-size: 20px;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 36px;
  border: 0;
  outline: 0;
  border-radius: 18px;
  padding: 0 14px 0 39px;
  background: #f1f3f4;
  color: #202124;
}

.search-box input:focus {
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--tg-blue);
}

.search-box input::placeholder {
  color: #8b949e;
}

.contacts {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 6px 10px;
}

.contacts-empty {
  color: var(--tg-muted);
  text-align: center;
  padding: 28px 12px;
  font-size: 14px;
}

.contact {
  width: 100%;
  height: 72px;
  border: 0;
  background: transparent;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.contact:hover {
  background: var(--tg-hover);
}

.contact.active {
  background: var(--tg-blue-active);
  color: #fff;
}

.avatar,
.chat-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 0;
  background: linear-gradient(135deg, #6ec6ff, #3f8cff);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}

.contact-body {
  min-width: 0;
  flex: 1;
}

.contact-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.contact-name {
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.provider {
  color: #8b949e;
  font-size: 12px;
  flex: 0 0 auto;
}

.contact.active .provider {
  color: rgba(255, 255, 255, 0.82);
}

.last-message {
  margin-top: 5px;
  color: var(--tg-muted);
  font-size: 14px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact.active .last-message {
  color: rgba(255, 255, 255, 0.9);
}

/* DROPDOWNS */

.menu-wrap,
.header-actions {
  position: relative;
  flex: 0 0 auto;
  z-index: 30;
}

.dropdown {
  position: absolute;
  z-index: 20;
  top: 42px;
  left: 0;
  min-width: 190px;
  padding: 6px 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.contact-dropdown {
  left: auto;
  right: 0;
  top: 42px;
}

.dropdown.hidden {
  display: none;
}

.dropdown-item {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 16px;
  text-align: left;
  cursor: pointer;
  color: #202124;
  font-size: 14px;
}

.dropdown-item:hover {
  background: #f4f4f5;
}

.dropdown-item.danger {
  color: #d93025;
}

/* CHAT */

.chat {
  display: grid;
  grid-template-rows: 56px auto minmax(0, 1fr) auto;
  grid-template-areas:
    "header"
    "topics"
    "messages"
    "composer";
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: #f4efe9;
}

.chat-header {
  grid-area: header;
  height: 56px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid #dfe3e8;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  z-index: 5;
  overflow: visible;
}

.chat-peer {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1 1 auto;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  flex-basis: 40px;
  font-size: 15px;
}

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

.chat-title {
  font-weight: 600;
  font-size: 16px;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  color: var(--tg-muted);
  font-size: 13px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #707579;
  cursor: pointer;
  font-size: 25px;
  display: grid;
  place-items: center;
  line-height: 1;
}

.header-btn:hover:not(:disabled) {
  background: #f1f3f4;
}

.header-btn:disabled {
  cursor: default;
  opacity: 0.35;
}

.messages {
  grid-area: messages;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: var(--tg-chat-fallback);
  background-image:
    linear-gradient(rgba(229, 221, 213, 0.72), rgba(229, 221, 213, 0.72)),
    url("/static/bg.png");
  background-repeat: repeat, repeat;
  background-size: auto, auto;
  background-position: left top, left top;
}

.empty-state {
  margin: auto;
  color: #fff;
  background: rgba(84, 112, 96, 0.72);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 14px;
}

.message {
  position: relative;
  max-width: min(620px, 72%);
  padding: 6px 8px 5px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.13);
  color: #111827;
  font-size: 14px;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.message.in {
  align-self: flex-start;
  background: var(--tg-in);
  border-bottom-left-radius: 3px;
}

.message.out {
  align-self: flex-end;
  background: var(--tg-out);
  border-bottom-right-radius: 3px;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: #2f80ed;
  margin-bottom: 2px;
}

.message.out .message-sender {
  color: #168246;
}

.message-text {
  white-space: pre-wrap;
  padding-right: 46px;
}

.message-time {
  float: right;
  margin-top: -2px;
  margin-left: 8px;
  font-size: 11px;
  line-height: 15px;
  color: #7a8a79;
}

.composer {
  grid-area: composer;
  min-height: 58px;
  max-height: 156px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(244, 239, 233, 0.92);
  border-top: 1px solid rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 42px;
  max-height: 140px;
  resize: none;
  border: 0;
  outline: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: #fff;
  color: #202124;
  font-family: inherit;
  font-size: 15px;
  line-height: 20px;
  overflow-y: auto;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.composer textarea::placeholder {
  color: #8b949e;
}

.composer-icon,
.send-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #707579;
  cursor: pointer;
  font-size: 22px;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.composer-icon:hover,
.send-btn:hover {
  color: var(--tg-blue);
}

.send-btn {
  color: #fff;
  background: var(--tg-blue);
  font-size: 18px;
  padding-left: 3px;
}

.send-btn:hover {
  color: #fff;
  background: #2584df;
}

/* DIALOGS */

dialog {
  border: 0;
  border-radius: 14px;
  background: #fff;
  color: #202124;
  width: 430px;
  padding: 0;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

.settings-dialog {
  width: min(560px, calc(100vw - 40px));
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 20px;
}

.dialog-form h3 {
  margin: 0 0 4px;
  font-size: 20px;
}

.dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #4b5563;
  font-size: 13px;
  font-weight: 500;
}

.field-hint {
  color: #707579;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 400;
}

.dialog-form input,
.dialog-form select {
  width: 100%;
  border: 1px solid #dfe3e8;
  outline: 0;
  border-radius: 9px;
  padding: 10px 11px;
  background: #fff;
  color: #202124;
}

.dialog-form input:focus,
.dialog-form select:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.14);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.dialog-actions button {
  border: 0;
  border-radius: 9px;
  padding: 10px 14px;
  cursor: pointer;
  color: #202124;
  background: #f1f3f4;
}

.dialog-actions button:last-child {
  background: var(--tg-blue);
  color: white;
}

.dialog-actions button:disabled {
  opacity: 0.65;
  cursor: default;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  max-height: min(68vh, 640px);
  overflow-y: auto;
  padding-right: 4px;
}

.settings-grid fieldset {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-grid legend {
  color: #111827;
  font-weight: 700;
  padding: 0 5px;
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.settings-status {
  min-height: 18px;
  color: var(--tg-muted);
  font-size: 13px;
}

/* SCROLLBARS */

.contacts::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.settings-grid::-webkit-scrollbar {
  width: 8px;
}

.contacts::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.settings-grid::-webkit-scrollbar-thumb {
  background: rgba(112, 117, 121, 0.35);
  border-radius: 999px;
}

.contacts::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.settings-grid::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 900px) {
.layout {
    grid-template-columns: 330px 1fr;
    min-width: 760px;
  }

  .message {
    max-width: 82%;
  }
}

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

.layout {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .sidebar {
    display: none;
  }

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


/* TELEGRAM TOPICS MENU */

.dropdown-section {
  padding: 0;
}

.dropdown-separator {
  height: 1px;
  margin: 6px 0;
  background: #eceff1;
}

.dropdown-title {
  padding: 7px 16px 5px;
  color: #707579;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dropdown-item.nested {
  padding-left: 28px;
}

.dropdown-item:disabled {
  cursor: default;
  color: #b0b6bc;
  background: transparent;
}

.dropdown-item.danger:disabled {
  color: #d8a4a0;
}

.chat.no-dialog .composer {
  display: none !important;
}

.chat.no-dialog .topic-tabs {
  display: none !important;
}

.chat.no-dialog .messages {
  padding: 20px 24px;
}

/* TOPICS AS TABS INSIDE TELEGRAM GROUP */

.topic-tabs {
  grid-area: topics;
  height: 38px;
  min-height: 38px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 6px;
  padding: 0 8px 0 12px;
  background: #fff;
  border-bottom: 1px solid #dfe3e8;
  overflow: visible;
  z-index: 4;
}

.topic-tabs.hidden {
  display: none !important;
}

.topic-tabs-list {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
}

.topic-menu-wrap {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  z-index: 25;
}

.topic-menu-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #707579;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.topic-menu-btn:hover {
  background: #f1f3f4;
}

.topic-dropdown {
  left: auto;
  right: 0;
  top: 36px;
  min-width: 210px;
}

.topic-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: #707579;
  padding: 0 10px;
  min-width: max-content;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.topic-tab:hover {
  background: #f4f4f5;
  color: #202124;
}

.topic-tab.active {
  color: var(--tg-blue);
}

.topic-tab.active::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--tg-blue);
}

.topic-tabs-list::-webkit-scrollbar {
  height: 0;
}

.message-topic {
  display: inline-block;
  color: #707579;
  background: rgba(51, 144, 236, 0.12);
  border-radius: 6px;
  padding: 2px 6px;
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 600;
}

.composer textarea:disabled {
  color: #9aa0a6;
  background: #f4f4f5;
  cursor: not-allowed;
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ATTACHMENTS */

.composer {
  flex-wrap: wrap;
  max-height: 220px;
}

.selected-files-preview {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 0 2px 50px;
}

.selected-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(51, 144, 236, 0.12);
  color: #202124;
  font-size: 12px;
}

.selected-file-chip span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.selected-file-chip button {
  border: 0;
  background: transparent;
  color: #707579;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.selected-file-chip button:hover {
  color: #d93025;
}

.message-attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 2px 0 5px;
}

.attachment-image-link {
  display: block;
  line-height: 0;
}

.message-image {
  display: block;
  max-width: min(420px, 100%);
  max-height: 380px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.04);
}

.attachment-file,
.attachment-card {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(51, 144, 236, 0.10);
  color: #1f5f99;
  text-decoration: none;
}

.attachment-file:hover,
.attachment-card a:hover {
  text-decoration: underline;
}

.attachment-file-icon {
  font-size: 19px;
  flex: 0 0 auto;
}

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

.message-video {
  width: min(420px, 100%);
  max-height: 320px;
  border-radius: 8px;
  background: #000;
}

.message-audio {
  width: min(360px, 100%);
}

.composer-icon:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ATTACHMENTS AND DRAG-DROP UPDATE */

.chat {
  position: relative;
}

.drop-overlay {
  position: absolute;
  inset: 56px 0 58px 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(51, 144, 236, 0.15);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.drop-overlay-card {
  min-width: 320px;
  padding: 24px 28px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.22);
  text-align: center;
  color: #202124;
  border: 2px dashed rgba(51, 144, 236, 0.65);
}

.drop-overlay-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: #56c568;
  font-size: 28px;
  font-weight: 800;
}

.drop-overlay-title {
  font-weight: 700;
  font-size: 18px;
}

.drop-overlay-subtitle {
  margin-top: 4px;
  color: #707579;
  font-size: 14px;
}

.selected-files-preview {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 0 2px 50px;
}

.selected-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 300px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(51, 144, 236, 0.12);
  color: #202124;
  font-size: 12px;
}

.selected-file-chip::before {
  content: "▣";
  color: #56c568;
  font-weight: 900;
}

.selected-file-chip span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.message.attachments-only {
  min-width: min(360px, 72%);
}

.message-attachments {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 2px 0 3px;
}

.attachment-file,
.attachment-card .attachment-file {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: min(430px, 100%);
  max-width: 430px;
  min-height: 50px;
  padding: 6px 8px;
  border-radius: 12px;
  background: transparent;
  color: #111827;
  text-decoration: none;
}

.message.in .attachment-file,
.message.in .attachment-card .attachment-file {
  background: rgba(51, 144, 236, 0.07);
}

.message.out .attachment-file,
.message.out .attachment-card .attachment-file {
  background: rgba(82, 185, 97, 0.12);
}

.attachment-file:hover .attachment-file-name {
  text-decoration: underline;
}

.attachment-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #56c568;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.attachment-file-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.attachment-file-name {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 600;
  color: #111827;
}

.attachment-file-size {
  color: #4cae52;
  font-size: 12px;
  line-height: 1.2;
  min-height: 14px;
}

.attachment-card.media-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  max-width: 430px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-decoration: none;
}

.attachment-card.media-card .attachment-file.compact {
  width: 100%;
  max-width: 100%;
}

.message-image {
  display: block;
  max-width: min(430px, 100%);
  max-height: 380px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.04);
}

.message-video {
  width: min(430px, 100%);
  max-height: 320px;
  border-radius: 8px;
  background: #000;
}

.message-audio {
  width: min(360px, 100%);
}

.composer.drag-ready {
  box-shadow: inset 0 0 0 2px rgba(51, 144, 236, 0.35);
}

/* UNREAD COUNTERS */
.contact-side {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 0;
}

.contact-unread-badge,
.topic-unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: #b8bec4;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  white-space: nowrap;
}

.contact.active .contact-unread-badge {
  background: rgba(255, 255, 255, 0.33);
  color: #fff;
}

.topic-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topic-tab .topic-unread-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 18px;
  background: #c4c9ce;
}

.topic-tab.active .topic-unread-badge {
  background: var(--tg-blue);
}


/* PINNED CONTACTS AND PROVIDER AVATARS */

.provider-avatar {
  background-color: transparent;
  background-image: none;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
  font-size: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
}

.provider-avatar-telegram {
  background-image: url("/static/telegram.png");
}

.provider-avatar-max {
  background-image: url("/static/max.png");
}

.provider-avatar-mailru {
  background-image: url("/static/mailru.png");
}

.chat-avatar.provider-avatar {
  width: 40px;
  height: 40px;
  flex-basis: 40px;
}

.pinned-separator {
  height: 1px;
  margin: 5px 12px;
  background: #dfe3e8;
}

.contact-pin {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  color: #8b949e;
  font-size: 12px;
  line-height: 1;
  opacity: 0.75;
  transform: rotate(-12deg);
}

.contact.active .contact-pin {
  color: rgba(255, 255, 255, 0.9);
  opacity: 0.95;
}

/* FILE TYPE ICONS, VOICE PLAYER AND REPLY QUOTES */

.message {
  overflow: visible;
}

.message-reply-btn {
  position: absolute;
  top: 4px;
  right: 6px;
  z-index: 3;
  border: 0;
  border-radius: 999px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--tg-blue);
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.message:hover .message-reply-btn {
  opacity: 1;
  transform: translateY(0);
}

.message.out .message-reply-btn {
  right: auto;
  left: 6px;
}

.message-reply-quote {
  margin: 2px 0 6px;
  padding: 5px 8px 5px 9px;
  border-left: 3px solid var(--tg-blue);
  border-radius: 6px;
  background: rgba(51, 144, 236, 0.10);
  max-width: 100%;
}

.message.out .message-reply-quote {
  border-left-color: #4fae54;
  background: rgba(79, 174, 84, 0.12);
}

.message-reply-quote-sender {
  color: var(--tg-blue);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message.out .message-reply-quote-sender {
  color: #168246;
}

.message-reply-quote-text {
  margin-top: 1px;
  color: #707579;
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview {
  width: 100%;
  min-height: 46px;
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 9px;
  padding: 7px 8px 7px 54px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.reply-preview-marker {
  width: 4px;
  align-self: stretch;
  border-radius: 999px;
  background: var(--tg-blue);
}

.reply-preview-body {
  min-width: 0;
}

.reply-preview-title {
  color: var(--tg-blue);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-text {
  margin-top: 2px;
  color: #707579;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #707579;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.reply-preview-close:hover {
  background: #f1f3f4;
  color: #d93025;
}

.attachment-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 0;
  display: grid;
  place-items: center;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.attachment-file-icon-img,
.voice-file-icon {
  width: 38px;
  height: 38px;
  object-fit: contain;
  display: block;
}

.selected-file-chip::before {
  content: "";
  width: 16px;
  height: 16px;
  background: url("/static/fileicons/_page.png") center / contain no-repeat;
  flex: 0 0 16px;
}

.voice-player {
  width: min(430px, 100%);
  min-height: 58px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 12px;
  background: rgba(51, 144, 236, 0.07);
}

.message.out .voice-player {
  background: rgba(82, 185, 97, 0.12);
}

.voice-play-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding-left: 2px;
  color: #fff;
  background: #3fa7e8;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}

.voice-player.playing .voice-play-btn {
  padding-left: 0;
}

.voice-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.voice-wave {
  position: relative;
  height: 26px;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow: hidden;
  cursor: pointer;
}

.voice-wave span {
  width: 3px;
  min-width: 3px;
  border-radius: 999px;
  background: #c6d9e8;
}

.message.out .voice-wave span {
  background: #a8d8a7;
}

.voice-progress {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(63, 167, 232, 0.20), rgba(63, 167, 232, 0.03));
  border-radius: 8px;
}

.message.out .voice-progress {
  background: linear-gradient(90deg, rgba(72, 166, 78, 0.20), rgba(72, 166, 78, 0.03));
}

.voice-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: #7a8a79;
  font-size: 12px;
  line-height: 1;
}

.voice-download {
  width: 30px;
  height: 42px;
  display: grid;
  place-items: center;
  opacity: 0.85;
}

.voice-download:hover {
  opacity: 1;
}

/* AUTH, NOTIFICATIONS AND MUTED CONTACTS */
.auth-hidden {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background:
    linear-gradient(rgba(229, 221, 213, 0.82), rgba(229, 221, 213, 0.82)),
    url("/static/bg.png");
  background-repeat: repeat, repeat;
}

.login-card {
  width: min(380px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 28px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.login-logo {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: var(--tg-blue);
  font-weight: 800;
  font-size: 24px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-card p {
  margin: -6px 0 4px;
  color: var(--tg-muted);
  font-size: 14px;
  line-height: 1.35;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #4b5563;
  font-size: 13px;
  font-weight: 600;
}

.login-card input {
  border: 1px solid #dfe3e8;
  outline: 0;
  border-radius: 10px;
  padding: 11px 12px;
  background: #fff;
  color: #202124;
}

.login-card input:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.14);
}

.login-card button {
  height: 42px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--tg-blue);
  cursor: pointer;
  font-weight: 700;
}

.login-card button:hover {
  background: #2584df;
}

.login-error {
  min-height: 18px;
  color: #d93025;
  font-size: 13px;
}

.settings-grid .settings-wide {
  grid-column: 1 / -1;
}

.dialog-form textarea {
  width: 100%;
  min-height: 94px;
  border: 1px solid #dfe3e8;
  outline: 0;
  border-radius: 9px;
  padding: 10px 11px;
  background: #fff;
  color: #202124;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
}

.dialog-form textarea:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.14);
}

.contact-muted {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  color: #8b949e;
  font-size: 13px;
  line-height: 1;
  opacity: 0.82;
}

.contact.active .contact-muted {
  color: rgba(255, 255, 255, 0.92);
}

/* TELEGRAM ADD BOT LINK IN CONTACT DIALOG */

.telegram-add-bot-block {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px;
  border: 1px solid rgba(51, 144, 236, 0.22);
  border-radius: 12px;
  background: rgba(51, 144, 236, 0.07);
}

.telegram-add-bot-title {
  color: #111827;
  font-size: 14px;
  font-weight: 700;
}

.telegram-add-bot-link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.telegram-add-bot-link-row input {
  min-width: 0;
  background: #fff;
}

.telegram-add-bot-link-row button,
.telegram-add-bot-actions button {
  border: 0;
  border-radius: 9px;
  padding: 9px 11px;
  cursor: pointer;
  color: #202124;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.telegram-add-bot-link-row button:hover:not(:disabled),
.telegram-add-bot-actions button:hover:not(:disabled) {
  color: var(--tg-blue);
  background: #f8fafc;
}

.telegram-add-bot-link-row button:disabled,
.telegram-add-bot-actions button:disabled {
  opacity: 0.58;
  cursor: default;
}

.telegram-add-bot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.telegram-add-bot-actions button:first-child {
  background: var(--tg-blue);
  color: #fff;
}

.telegram-add-bot-actions button:first-child:hover:not(:disabled) {
  background: #2584df;
  color: #fff;
}

.telegram-add-bot-status {
  min-height: 16px;
  color: var(--tg-muted);
  font-size: 12px;
  line-height: 1.35;
}

.telegram-add-bot-status-ok {
  color: #168246;
}

.telegram-add-bot-status-error {
  color: #d93025;
}

/* SETTINGS CLEANUP */
.settings-hidden-fields {
  display: none !important;
}

.settings-form .settings-grid {
  grid-template-columns: 1fr;
}

.settings-form .two-cols {
  grid-template-columns: 1fr;
}

.settings-form .settings-wide {
  grid-column: auto;
}

/* TELEGRAM @MENTIONS */
.composer {
  position: relative;
}

.mention-suggestions {
  position: absolute;
  left: 64px;
  bottom: calc(100% - 4px);
  width: min(360px, calc(100% - 96px));
  max-height: 260px;
  overflow-y: auto;
  z-index: 80;
  padding: 6px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.24);
}

.mention-suggestion {
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #202124;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  padding: 7px 8px;
  text-align: left;
  cursor: pointer;
}

.mention-suggestion:hover,
.mention-suggestion.selected {
  background: rgba(51, 144, 236, 0.10);
}

.mention-suggestion-disabled {
  opacity: 0.55;
  cursor: default;
}

.mention-suggestion-disabled:hover,
.mention-suggestion-disabled.selected {
  background: transparent;
}

.mention-suggestion-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--tg-blue);
  font-weight: 700;
  font-size: 14px;
}

.mention-suggestion-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mention-suggestion-name,
.mention-suggestion-username {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mention-suggestion-name {
  color: #111827;
  font-size: 14px;
  font-weight: 600;
}

.mention-suggestion-username {
  color: var(--tg-muted);
  font-size: 12px;
}

/* MENTION POPUP LAYER FIX
   The mention dropdown is positioned above the composer. The composer used
   overflow:hidden for attachments, so the dropdown was clipped or covered by
   the chat background. Keep the composer above the message background and let
   the dropdown overflow upward. */
.composer {
  position: relative;
  z-index: 120;
  overflow: visible !important;
}

.messages {
  position: relative;
  z-index: 1;
}

.mention-suggestions {
  z-index: 250;
}
