@font-face {
  font-family: "Circe";
  src: url("/fonts/Circe-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Circe";
  src: url("/fonts/Circe-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --main-bg: #F7F7F7;
  --panel: #FFFFFF;
  --ink: #000000;
  --muted: #8E8E8E;
  --quiet: #C6C6C6;
  --line: #D8D8D8;
  --line-soft: #EDEDED;
  --main-blue: #1863BC;
  --main-blue-soft: #DAEBFF;
  --incoming: #F5F5F5;
  --outgoing: #E6F4E8;
  --outgoing-line: #CEE7D2;
  --danger: #E50000;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: var(--main-bg);
  font-family: "Circe", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
}

button,
input {
  color: inherit;
  font: inherit;
}

button {
  border: 0;
}

[hidden] {
  display: none !important;
}

#app {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--main-bg);
}

#chats {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.inbox-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.search-toggle,
.search-close {
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.search-toggle:hover,
.search-close:hover {
  background: var(--line-soft);
}

.search-toggle svg,
.search-close svg,
.search-form svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.search-panel {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
}

.search-head {
  display: flex;
  min-height: 82px;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}

.search-form {
  display: flex;
  min-width: 0;
  height: 48px;
  flex: 1;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.search-form:focus-within {
  color: var(--ink);
  border-color: var(--main-blue);
  box-shadow: 0 0 0 3px rgba(24, 99, 188, 0.1);
}

.search-form input {
  min-width: 0;
  flex: 1;
  outline: none;
  background: transparent;
  border: 0;
}

.search-form input::placeholder {
  color: var(--quiet);
}

.search-results {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.search-section h2 {
  padding: 18px 18px 9px;
  font-size: 15px;
  font-weight: 700;
}

.search-result {
  display: flex;
  width: 100%;
  min-height: 70px;
  align-items: center;
  gap: 11px;
  padding: 11px 14px 11px 18px;
  overflow: hidden;
  text-align: left;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}

.search-result:hover {
  background: var(--main-bg);
}

.search-result .avatar {
  display: flex;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #575757;
  background: #E9EDF2;
  font-size: 13px;
  font-weight: 700;
}

.search-result-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}

.search-result-copy strong,
.search-result-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-copy strong {
  font-size: 16px;
}

.search-result-copy span,
.search-result time {
  color: var(--muted);
  font-size: 13px;
}

.search-result time {
  flex: 0 0 auto;
  align-self: flex-start;
  padding-top: 2px;
  white-space: nowrap;
}

.search-message {
  align-items: flex-start;
}

.search-hint {
  padding: 42px 24px;
  color: var(--muted);
  text-align: center;
}

.inbox-brand {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line-soft);
}

.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inbox-brand h1 {
  font-size: 24px;
  font-weight: 400;
  line-height: 1.08;
}

.channel-mark,
.thread-channel {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.telegram-dot,
.telegram-mark {
  display: inline-flex;
  width: 23px;
  height: 23px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #FFFFFF;
  background: var(--main-blue);
  font-size: 15px;
  font-weight: 700;
}

#chat-list {
  min-height: calc(100% - 82px);
}

.chat {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 76px;
  align-items: center;
  gap: 13px;
  padding: 13px 18px 13px 20px;
  overflow: hidden;
  text-align: left;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background-color 140ms ease;
}

.chat:hover {
  background: var(--main-bg);
}

.chat.active {
  background: var(--line-soft);
}

.chat.active::before {
  position: absolute;
  top: 13px;
  bottom: 13px;
  left: 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--main-blue);
  content: "";
}

.chat .avatar {
  display: flex;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #575757;
  background: #E9EDF2;
  font-size: 14px;
  font-weight: 700;
}

.chat.group .avatar {
  color: #53715A;
  background: #E5F0E7;
}

.chat .meta {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 3px;
}

.chat .name,
.chat .last {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat .name {
  font-size: 17px;
  font-weight: 700;
}

.chat .last {
  color: var(--muted);
  font-size: 14px;
}

.chat .badge {
  display: inline-flex;
  min-width: 24px;
  height: 24px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  border-radius: 12px;
  color: #FFFFFF;
  background: var(--main-blue);
  font-size: 12px;
  font-weight: 700;
}

#thread {
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
}

.thread-head {
  display: flex;
  min-height: 82px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.thread-placeholder {
  color: var(--muted);
  font-size: 20px;
}

.thread-menu {
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.thread-menu:hover {
  background: var(--line-soft);
}

.thread-menu svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.thread-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
}

.thread-identity div {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.thread-identity strong {
  overflow: hidden;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-identity span:not(.telegram-mark) {
  color: var(--muted);
  font-size: 13px;
}

#messages {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 9px;
  padding: 24px 32px;
  overflow-y: auto;
  background: var(--panel);
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.thread-empty {
  display: flex;
  max-width: 320px;
  flex: 1;
  align-self: center;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  text-align: center;
}

.thread-empty.compact {
  margin: auto;
}

.thread-empty strong {
  color: #575757;
  font-size: 19px;
  font-weight: 400;
}

.thread-empty span:not(.thread-empty-mark) {
  font-size: 14px;
}

.thread-empty-mark {
  display: inline-flex;
  width: 50px;
  height: 50px;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  border-radius: 50%;
  color: var(--main-blue);
  background: var(--main-blue-soft);
  font-size: 28px;
}

.thread-loading,
.empty {
  margin: auto;
  padding: 40px 24px;
  color: var(--muted);
  text-align: center;
}

.date-divider {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 14px;
  margin: 9px 0 5px;
  color: var(--muted);
  font-size: 13px;
}

.date-divider::before,
.date-divider::after {
  height: 1px;
  flex: 1;
  background: var(--line-soft);
  content: "";
}

.date-divider span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 2px 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel);
}

.msg {
  width: fit-content;
  max-width: min(68%, 720px);
  padding: 9px 12px 7px;
  overflow-wrap: anywhere;
  border-radius: 10px;
  animation: message-in 150ms ease-out;
}

.msg.in {
  align-self: flex-start;
  background: var(--incoming);
}

.msg.out {
  align-self: flex-end;
  background: var(--outgoing);
  box-shadow: inset 0 0 0 1px var(--outgoing-line);
}

.msg .body {
  min-width: 28px;
  font-size: 16px;
  white-space: pre-wrap;
}

.msg img {
  display: block;
  max-width: min(320px, 100%);
  margin-bottom: 7px;
  border-radius: 8px;
}

.msg .doc {
  display: inline-flex;
  color: var(--main-blue);
  font-weight: 700;
  text-decoration: none;
}

.msg .time {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-height: 14px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.msg .edited,
.msg .sending {
  font-style: normal;
}

.msg.pending {
  opacity: 0.58;
}

.msg.search-focus {
  outline: 3px solid rgba(24, 99, 188, 0.36);
  outline-offset: 3px;
}

.composer {
  display: flex;
  min-height: 82px;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  padding: 15px 20px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.composer .attach,
.composer button {
  display: inline-flex;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  cursor: pointer;
}

.composer .attach {
  color: var(--muted);
  background: var(--main-bg);
}

.composer .attach:hover {
  color: var(--ink);
  background: var(--line-soft);
}

.composer svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.composer input[type="text"] {
  min-width: 0;
  height: 48px;
  flex: 1;
  padding: 0 16px;
  outline: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
}

.composer input[type="text"]::placeholder {
  color: var(--quiet);
}

.composer input[type="text"]:focus {
  border-color: var(--main-blue);
  box-shadow: 0 0 0 3px rgba(24, 99, 188, 0.1);
}

.composer button {
  color: #FFFFFF;
  background: var(--main-blue);
}

.composer button:hover {
  background: #14549F;
}

.chat:focus-visible,
.thread-menu:focus-visible,
.search-toggle:focus-visible,
.search-close:focus-visible,
.search-result:focus-visible,
.attach:focus-visible,
.composer button:focus-visible,
.composer input:focus-visible,
.doc:focus-visible {
  outline: 3px solid rgba(24, 99, 188, 0.34);
  outline-offset: 2px;
}

:root.card-mode #chats {
  display: none;
}

:root.card-mode #app {
  display: block;
  background: var(--panel);
}

:root.card-mode #thread {
  width: 100%;
  height: 100%;
  border-radius: 22px;
}

:root.card-mode .thread-head {
  min-height: 72px;
  padding: 13px 20px;
}

:root.card-mode .thread-identity strong {
  font-size: 18px;
}

:root.card-mode .thread-channel {
  display: none;
}

:root.card-mode #messages {
  padding: 18px 20px;
}

:root.card-mode .msg {
  max-width: 84%;
}

:root.card-mode .composer {
  min-height: 78px;
  padding: 13px 16px;
}

:root.header-embed #app {
  position: relative;
  display: block;
  background: var(--panel);
}

:root.header-embed #chats,
:root.header-embed #thread {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

:root.header-embed #chats {
  border-right: 0;
}

:root.header-embed #thread {
  display: none;
}

:root.header-embed.thread-open #chats {
  display: none;
}

:root.header-embed.thread-open #thread {
  display: flex;
}

:root.header-embed .inbox-brand {
  min-height: 74px;
  padding: 12px 16px;
}

:root.header-embed .inbox-actions {
  gap: 4px;
}

:root.header-embed .channel-mark {
  font-size: 0;
}

:root.header-embed .channel-mark .telegram-dot {
  font-size: 15px;
}

:root.header-embed .search-head {
  min-height: 74px;
  padding: 12px 10px;
}

:root.header-embed .inbox-brand h1 {
  font-size: 22px;
}

:root.header-embed .thread-head {
  min-height: 74px;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 14px;
}

:root.header-embed .thread-identity {
  min-width: 0;
  flex: 1;
  gap: 9px;
}

:root.header-embed .thread-identity strong {
  font-size: 18px;
}

:root.header-embed .thread-channel {
  display: none;
}

:root.header-embed #messages {
  padding: 18px 16px;
}

:root.header-embed .msg {
  max-width: 88%;
}

:root.header-embed .composer {
  min-height: 76px;
  gap: 7px;
  padding: 12px 10px;
}

:root.header-embed .composer .attach,
:root.header-embed .composer button {
  width: 42px;
  height: 44px;
}

:root.header-embed .composer input[type="text"] {
  height: 44px;
  padding: 0 12px;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
}

@media (max-width: 760px) {
  #app {
    grid-template-columns: 42% minmax(0, 1fr);
  }

  .inbox-brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .chat {
    padding-right: 12px;
    padding-left: 14px;
  }

  .chat .avatar {
    width: 38px;
    height: 38px;
  }

  .thread-head,
  #messages {
    padding-right: 18px;
    padding-left: 18px;
  }

  .msg {
    max-width: 84%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
