@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF;
}
:root {
  --blue: #1e6fea;
  --blue-deep: #1558c4;
  --thread: #d31c28;
  --thread-dark: #a8141e;
  --cup: #ffffff;
  --ink: #10203a;
  --muted: #5b6d86;
  --line: #d7e4f5;
  --tg: #229ed9;
  --max: #7b5cff;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
  --kb: 0px;
}
html.android-app {
  --safe-t: max(env(safe-area-inset-top, 0px), 36px);
}
html.android-app body {
  font-family: Roboto, "Noto Sans", "Droid Sans", Arial, sans-serif;
}
html.niti-native-chrome {
  --safe-t: 0px;
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  max-height: var(--vvh, 100%);
}
body {
  font-family: Inter, "Segoe UI", Roboto, Arial, "Noto Sans", sans-serif;
  font-synthesis: none;
  background-color: var(--blue);
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0,30,90,.08) 0 1px, transparent 1px 3px);
  color: var(--ink);
}
button, input, textarea, select { font: inherit; }
#app { height: 100%; max-height: var(--vvh, 100%); min-height: 0; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255,255,255,.18), transparent 42%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0,30,90,.08) 0 1px, transparent 1px 3px),
    var(--blue);
}
.login-card {
  width: min(440px, 100%);
  background: var(--cup);
  border-radius: 24px;
  padding: 28px 26px 32px;
  box-shadow: 0 22px 50px rgba(10, 40, 90, .28);
}
.hero {
  display: block;
  width: min(220px, 70%);
  margin: 0 auto 12px;
  border-radius: 18px;
}
.wordmark {
  text-align: center;
  font-size: 28px;
  letter-spacing: .32em;
  color: var(--thread);
  font-weight: 800;
  margin: 0 0 6px;
  text-shadow: 0 1px 0 #8e1018, 0 2px 0 rgba(0,0,0,.12);
}
.login-card .lead, .login-card .slogan {
  color: var(--muted); text-align: center; margin: 0 0 18px;
  letter-spacing: 0; line-height: 1.45; font-kerning: none;
}
.login-card label {
  display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px;
  letter-spacing: 0; line-height: 1.4;
}
.login-card form { margin: 0; }
.login-card input, .login-card select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px;
}
.primary {
  background: var(--thread); color: #fff; border: 0; border-radius: 12px;
  padding: 12px 16px; cursor: pointer; font-weight: 700; width: 100%;
  letter-spacing: 0; line-height: 1.3; font-synthesis: none;
}
.primary:hover { background: var(--thread-dark); }
.primary:disabled { opacity: .6; }
.error { color: var(--thread); font-size: 14px; min-height: 1.2em; margin: 0 0 10px; text-align: center; }
.candidates { display: flex; flex-direction: column; gap: 8px; margin: 0 0 14px; }
.candidate {
  text-align: left; border: 1px solid var(--line); background: #f7fbff; border-radius: 12px;
  padding: 10px 12px; cursor: pointer;
}
.candidate:hover, .candidate.active { border-color: var(--thread); background: #fff5f5; }
.candidate b { display: block; }
.candidate span { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }

.shell { display: flex; height: 100%; max-height: 100%; min-height: 0; background: #eef5ff; }
.sidebar {
  width: 240px; background: var(--blue); color: #eef6ff;
  padding: calc(16px + var(--safe-t)) 12px 16px; display: flex; flex-direction: column; gap: 6px;
}
.sidebar .brand-row { display: flex; align-items: center; gap: 10px; padding: 8px 8px 0; flex-wrap: wrap; }
.sidebar .brand-row img { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; }
.sidebar .brand-row h1 { margin: 0; font-size: 16px; letter-spacing: .18em; color: #fff; }
.nav-btn {
  background: transparent; color: inherit; border: 0; text-align: left;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
}
.nav-btn.active { background: var(--blue-deep); color: #fff; }
.sidebar .grow { flex: 1; }
.sidebar .who { font-size: 12px; color: #d7ecff; padding: 10px 12px; line-height: 1.4; white-space: pre-line; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  background: var(--cup); border-bottom: 1px solid var(--line);
  padding: calc(12px + var(--safe-t)) 20px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h2 { margin: 0; font-size: 18px; min-width: 0; flex: 1; }
.kpis { display: flex; gap: 16px; color: var(--muted); font-size: 13px; margin-left: auto; }
.workspace { flex: 1; display: flex; min-height: 0; }

.chat-list {
  width: min(340px, 38%); border-right: 1px solid var(--line); background: var(--cup);
  display: flex; flex-direction: column;
}
.search { margin: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.rows { overflow: auto; }
.row {
  width: 100%; background: transparent; border: 0; border-bottom: 1px solid var(--line);
  text-align: left; cursor: pointer; display: flex; gap: 10px; align-items: center;
}
.row .open {
  flex: 1; min-width: 0; background: transparent; border: 0; padding: 12px 16px; text-align: left; cursor: pointer;
}
.row-actions { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px 8px 0; }
.row-actions button {
  background: #f3f7ff; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; cursor: pointer;
}
.add-contact { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.add-contact input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.add-contact .primary { width: auto; padding: 8px 12px; }
.tools { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 22px; }
.tools h3 { margin: 0 0 8px; }
.tools .primary { width: auto; }
.tools p { margin: 0 0 10px; color: var(--muted); }
.tools input, .tools select, .tools textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; width: 100%;
}
.tool-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.tool-item {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  background: var(--cup); border-radius: 12px; padding: 10px 12px;
}
.tool-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tool-btns { display: flex; gap: 6px; }
.tool-item button, .tool-btns button {
  background: #f3f7ff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.tool-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tool-form.col { flex-direction: column; align-items: stretch; }
.tool-form .primary, .tool-form select, .tool-form input { width: auto; flex: 1; min-width: 140px; }
.help-block { background: var(--cup); border-radius: 12px; padding: 8px 12px; }
.help-block summary { cursor: pointer; font-weight: 650; }
.help-block pre { white-space: pre-wrap; margin: 8px 0 0; font-family: inherit; }
.faq-list { display: flex; flex-direction: column; gap: 8px; }
.pay-links { margin-top: 8px; }
.pay-links a { color: var(--red, #c43b3b); }
.link-out { white-space: pre-wrap; background: var(--cup); padding: 12px; border-radius: 12px; min-height: 3em; }
.mass-text, .bcast-text { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; }
.mass-row { display: block; padding: 4px 0; }
.chat-list.hidden { display: none !important; }
.row.active { background: #fff1f1; }
.row .meta { min-width: 0; flex: 1; }
.row .name { font-weight: 650; display: flex; gap: 6px; align-items: center; }
.row .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 999px; color: #fff; }
.badge.tg { background: var(--tg); }
.badge.max { background: var(--max); }
.badge.unread {
  background: #ff2d3a;
  color: #fff;
  min-width: 20px;
  text-align: center;
  margin-left: auto;
  font-weight: 800;
  box-shadow: 0 0 0 2px rgba(255,45,58,.28);
}
.row.has-unread .preview { color: #10203a; font-weight: 650; }
.tool-btns { flex-wrap: wrap; }

.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #e7f1ff; }
.thread-head {
  flex: none;
  background: var(--cup); padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.thread-head .sub.activity {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0;
  line-height: 1.35;
}
.msgs { flex: 1; overflow: auto; min-height: 0; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 78%; padding: 10px 12px; border-radius: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word;
}
.bubble.in { background: var(--cup); align-self: flex-start; }
.bubble.out { background: #ffd6d9; align-self: flex-end; }
.bubble .ch { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bubble .att {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 6px; padding: 8px 10px;
  border-radius: 10px; background: rgba(16,32,58,.06);
  font-size: 13px; font-weight: 650;
}
.bubble img.att-img,
.bubble video.att-video {
  display: block; max-width: min(100%, 320px); max-height: 280px;
  border-radius: 10px; margin: 0 0 6px; object-fit: contain; background: rgba(16,32,58,.06);
}
.bubble .att-gallery { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.bubble .att-gallery img.att-img,
.bubble .att-gallery video.att-video { margin: 0; max-width: min(48%, 160px); max-height: 160px; }
.bubble audio.att-audio { display: block; width: min(100%, 280px); margin: 0 0 6px; }
.bubble .att-dl { margin-left: auto; font-weight: 650; color: var(--blue, #1e6fea); text-decoration: none; }
.bubble.failed { opacity: .85; }
.thread-menu { display: none; }
.composer {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 12px calc(12px + var(--safe-b) + var(--kb));
  background: var(--cup); border-top: 1px solid var(--line); align-items: flex-end;
  flex: none; min-width: 0;
}
.composer select, .composer textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
.composer textarea { flex: 1 1 12rem; min-width: 10rem; min-height: 72px; max-height: 220px; resize: vertical; }
.composer button { width: auto; padding: 12px 18px; }
.composer .attach {
  flex: 0 0 auto; width: 44px; height: 44px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: #f3f7ff;
  font-size: 18px;
}
.composer .attach input { display: none; }
.composer .file-name {
  flex: 1 0 100%; max-width: none; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.composer .file-name:empty { display: none; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 32px; }

.tabbar {
  display: none;
  flex: none;
  background: var(--blue); padding: 8px 8px calc(8px + var(--safe-b));
  justify-content: space-around;
}
.tabbar button { background: transparent; color: #d6ebff; border: 0; padding: 8px; cursor: pointer; }
.tabbar button.active { color: #fff; font-weight: 700; }

@media (max-width: 800px) {
  .sidebar { display: none; }
  .chat-list { width: 100%; border: 0; }
  .thread { display: none; }
  .shell.chat-open .chat-list { display: none; }
  .shell.chat-open .thread { display: flex; }
  .shell.tools-open .chat-list { display: none; }
  .shell.tools-open .thread { display: flex; }
  .tabbar { display: flex; }
  .kpis { display: none; }
  .thread-menu { display: inline-flex; min-width: auto; padding: 8px 12px; }
  .composer {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
  }
  .composer .file-name { grid-column: 1 / -1; max-width: none; }
  .composer select { grid-column: 1 / -1; width: 100%; }
  .composer textarea { min-width: 0; min-height: 48px; max-height: 120px; }
}
@media (max-height: 640px) {
  .composer { padding-top: 8px; padding-bottom: calc(8px + var(--safe-b) + var(--kb)); }
  .composer textarea { min-height: 40px; max-height: 72px; }
}
