/* Админка — цвета темы Telegram (Mini App задаёт --tg-theme-*), запасные — для обычного браузера. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary: var(--tg-theme-secondary-bg-color, #eef1f5);
  --separator: var(--tg-theme-section-separator-color, #e1e4e8);
  --danger: var(--tg-theme-destructive-text-color, #d93838);
  --out: #dcecfb;
  --height: var(--tg-viewport-stable-height, 100vh);
  color-scheme: light dark;
}

@supports (background: color-mix(in srgb, red 50%, blue)) {
  :root { --out: color-mix(in srgb, var(--button) 16%, var(--bg)); }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--secondary);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: var(--height);
}

/* Телефон: сначала список, потом чат — назад кнопкой Telegram */
@media (max-width: 719px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .view-list .chat { display: none; }
  .view-chat .list { display: none; }
}

/* ——— Список ——— */
.list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--separator);
}

.list-head {
  padding: 10px 10px 6px;
  border-bottom: 1px solid var(--separator);
}

#search {
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--secondary);
  outline-offset: 1px;
}

.tabs { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; }

.tab {
  flex: none;
  padding: 5px 12px;
  border: 0;
  border-radius: 14px;
  background: var(--secondary);
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
}

.tab.active { background: var(--button); color: var(--button-text); }

.chats { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  text-align: left;
}

.chat-item:hover, .chat-item.selected { background: var(--secondary); }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
}

.c0 { background: #e17076; } .c1 { background: #eda86c; } .c2 { background: #a695e7; } .c3 { background: #7bc862; }
.c4 { background: #6ec9cb; } .c5 { background: #65aadd; } .c6 { background: #ee7aae; }

.chat-main { flex: 1; min-width: 0; }
.chat-top, .chat-bottom { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.chat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { flex: none; color: var(--hint); font-size: 12px; }
.chat-preview { color: var(--hint); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badges { flex: none; display: flex; gap: 4px; align-items: center; }
.badge { padding: 0 6px; border-radius: 9px; font-size: 11px; line-height: 18px; }
.badge.waiting { background: var(--button); color: var(--button-text); }
.badge.failed { background: var(--danger); color: #fff; }
.badge.banned { background: var(--hint); color: #fff; }

.more, .older {
  margin: 8px auto;
  padding: 6px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--secondary);
  color: var(--link);
}

.more { display: block; }
.nothing { padding: 24px 16px; color: var(--hint); text-align: center; }

/* ——— Переписка ——— */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.empty { margin: auto; color: var(--hint); }
.conversation { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.chat-head {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}

.head-main { flex: 1; min-width: 0; }
.head-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-meta { color: var(--hint); font-size: 13px; }

.ban {
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--danger);
  border-radius: 14px;
  background: transparent;
  color: var(--danger);
  font-size: 13px;
}

.ban.banned { border-color: var(--hint); color: var(--hint); }

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  overflow-y: auto;
}

.day {
  align-self: center;
  margin: 8px 0 4px;
  padding: 2px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--hint) 22%, transparent);
  color: var(--text);
  font-size: 12px;
}

.bubble {
  max-width: min(78%, 560px);
  padding: 6px 10px 4px;
  border-radius: 14px;
  background: var(--bg);
  overflow-wrap: anywhere;
}

.bubble.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--out); }
.bubble.bot { align-self: flex-end; background: transparent; color: var(--hint); font-size: 13px; padding: 0 4px; }
.bubble.pending { opacity: 0.75; }

.text { white-space: pre-wrap; }
.author { color: var(--link); font-size: 12px; font-weight: 600; }
.label { color: var(--hint); font-size: 13px; }
.state { color: var(--hint); font-size: 12px; }
.state.bad { color: var(--danger); }
.time { color: var(--hint); font-size: 11px; text-align: right; }
.bubble.bot .time { display: inline; margin-left: 6px; }

.link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  text-align: left;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px;
  background: var(--bg);
  border-top: 1px solid var(--separator);
}

#reply {
  flex: 1;
  max-height: 140px;
  padding: 9px 14px;
  border: 0;
  border-radius: 18px;
  background: var(--secondary);
  resize: none;
}

.send {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  font-size: 18px;
}

.send:disabled { opacity: 0.5; }

.banner {
  position: fixed;
  inset: 0 0 auto;
  z-index: 10;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 2px solid var(--danger);
}

.banner button {
  flex: none;
  padding: 6px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  z-index: 10;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(20, 22, 26, 0.88);
  color: #fff;
  font-size: 14px;
}
