/* Оформление мини-приложения «Чаты HH» (с 26.11.2026): цвета берутся из темы Telegram (переменные --tg-theme-*),
   без них — светлая или тёмная тема устройства. Оранжевый — чаты, где нужны вы; закреплены сверху. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #14161a);
  --hint: var(--tg-theme-hint-color, #7b8089);
  --link: var(--tg-theme-link-color, #2a7de1);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: var(--tg-theme-section-separator-color, rgba(120, 128, 140, 0.18));
  --orange: #e8710a;
  --orange-soft: rgba(232, 113, 10, 0.1);
  --green: #1f9d55;
  --red: #d64545;
  --amber: #b7791f;
  --radius: 14px;
  --font: -apple-system, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17191d);
    --bg-2: var(--tg-theme-secondary-bg-color, #0f1013);
    --text: var(--tg-theme-text-color, #eceef2);
    --hint: var(--tg-theme-hint-color, #8b919b);
    --link: var(--tg-theme-link-color, #6aa9ff);
    --accent: var(--tg-theme-button-color, #3b8cf0);
    --orange: #ff9233;
    --orange-soft: rgba(255, 146, 51, 0.13);
    --green: #3ccf7f;
    --red: #ff6b6b;
    --amber: #f0b44c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* Шапка */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 0;
}
.top-row { display: flex; align-items: center; justify-content: space-between; }
.brand {
  display: flex; align-items: center; gap: 8px;
  margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.02em;
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 3px; background: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-soft);
}
.icon-button {
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--bg-2); font-size: 18px; line-height: 36px;
}
.icon-button.is-busy { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 10px -16px 0; padding: 0 16px 10px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--bg);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap;
}
.tab b { font-weight: 700; font-variant-numeric: tabular-nums; }
.tab b:empty { display: none; }
.tab.is-active { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab-orange b { color: var(--orange); }
.tab-orange.is-active { background: var(--orange); border-color: var(--orange); color: #fff; }
.tab-orange.is-active b { color: #fff; }
.top.is-hidden-tabs .tabs { display: none; }

.screen { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Список чатов */
.group-title {
  margin: 14px 16px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--hint);
}
.group-title.is-orange { color: var(--orange); }
.list { background: var(--section); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.row {
  position: relative; display: grid; grid-template-columns: 44px 1fr; gap: 12px;
  width: 100%; padding: 10px 16px; border: 0; background: transparent; text-align: left;
  animation: rise 0.32s ease both;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 72px; right: 0; border-top: 1px solid var(--line);
}
.row:active { background: var(--bg-2); }
.row.is-orange { background: var(--orange-soft); }
.row.is-orange::after {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--orange);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.row:nth-child(2) { animation-delay: 0.03s; } .row:nth-child(3) { animation-delay: 0.06s; }
.row:nth-child(4) { animation-delay: 0.09s; } .row:nth-child(5) { animation-delay: 0.12s; }
.row:nth-child(n+6) { animation-delay: 0.15s; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: #fff; position: relative;
}
.c0 { background: #e0675a; } .c1 { background: #d98a2b; } .c2 { background: #4b9b5f; } .c3 { background: #3e8fb0; }
.c4 { background: #5b74c9; } .c5 { background: #9363c4; } .c6 { background: #c45b8f; } .c7 { background: #5f8a8b; }
.avatar-mark {
  position: absolute; right: -3px; bottom: -3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--section); display: grid; place-items: center; font-size: 11px;
  box-shadow: 0 0 0 2px var(--section);
}

.row-body { min-width: 0; }
.row-head { display: flex; align-items: baseline; gap: 8px; }
.row-title {
  flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-time { flex: none; font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.row-company { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-last {
  font-size: 14px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-last.is-mine::before { content: "Вы: "; color: var(--text); }
.row-label { margin-top: 3px; font-size: 13px; font-weight: 600; }
.tone-orange { color: var(--orange); }
.tone-ok { color: var(--green); }
.tone-quiet { color: var(--hint); font-weight: 500; }

.empty { margin: 48px 24px; text-align: center; color: var(--hint); }
.empty b { display: block; margin-bottom: 6px; color: var(--text); font-size: 17px; }

/* Экран чата */
.chat-head {
  background: var(--section); padding: 12px 16px 14px; border-bottom: 1px solid var(--line);
}
.chat-title { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.chat-company { margin-top: 2px; color: var(--hint); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--bg-2); }
.badge.ok { color: var(--green); }
.badge.bad { color: var(--red); }
.badge.warn { color: var(--amber); }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.button {
  flex: 1; min-height: 40px; border: 0; border-radius: 10px; padding: 8px 12px;
  background: var(--bg-2); font-weight: 600; font-size: 14px;
}
.button.primary { background: var(--accent); color: var(--accent-text); }
.button.is-on { color: var(--red); }
.button:active { opacity: 0.75; }

.banner {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: var(--radius);
  background: var(--orange-soft); border-left: 4px solid var(--orange);
}
.banner p { margin: 0 0 10px; font-weight: 600; color: var(--orange); }
.banner .button { background: var(--orange); color: #fff; width: 100%; }

.thread { padding: 8px 12px 4px; display: flex; flex-direction: column; gap: 6px; }
.marker {
  align-self: center; margin: 8px 0; padding: 3px 10px; border-radius: 999px;
  background: var(--section); color: var(--hint); font-size: 12px;
}
.bubble {
  max-width: 86%; padding: 8px 12px; border-radius: 16px; background: var(--section);
  white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 0 var(--line);
}
.bubble.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 5px; }
.bubble.theirs { align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble-label { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 700; color: var(--link); }
.bubble.bot .bubble-label { color: var(--amber); }
.bubble-link {
  display: block; margin-top: 6px; padding: 0; border: 0; background: none;
  color: var(--link); text-decoration: underline; text-align: left; overflow-wrap: anywhere;
}
.bubble.mine .bubble-link { color: inherit; }
.note { margin: 12px 16px; color: var(--hint); font-size: 14px; }

.section-title { margin: 18px 16px 8px; font-size: 13px; font-weight: 700; color: var(--hint); text-transform: uppercase; letter-spacing: 0.06em; }
.card {
  margin: 0 12px 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--section);
  border: 1px solid var(--line); animation: rise 0.3s ease both;
}
.card-head { display: flex; align-items: baseline; gap: 8px; }
.card-label { flex: 1; font-weight: 600; }
.card-when { font-size: 12px; color: var(--hint); }
.card-text { margin-top: 6px; font-size: 14px; color: var(--hint); white-space: pre-wrap; overflow-wrap: anywhere; }
.draft {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg-2);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px;
}
.card .button { margin-top: 10px; width: 100%; }
.card-title { font-weight: 700; }
.card-sub { margin-top: 2px; font-size: 14px; color: var(--hint); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { padding: 3px 9px; border-radius: 999px; background: var(--bg-2); font-size: 12px; font-weight: 600; }
.chip.orange { color: var(--orange); background: var(--orange-soft); }
.card .actions .button { margin-top: 0; }
.letter-toggle { margin-top: 10px; padding: 0; border: 0; background: none; color: var(--link); font-weight: 600; }

.copy-area { position: fixed; left: -9999px; top: 0; opacity: 0; }
[hidden] { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 10;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 14px; transition: opacity 0.2s, transform 0.2s;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
