:root {
  --bg: #ffffff;
  --ink: #000000;
  --ink-soft: #555555;
  --line: #e6e6e6;
  --bubble-in: #f1f1f1;     /* входящие (оператор) */
  --bubble-out: #000000;    /* исходящие (юзер) — чёрные */
  --bubble-out-ink: #ffffff;
  --accent: #000000;
  --radius: 18px;

  /* Безопасные отступы. По умолчанию из CSS env(), в Telegram переопределяются из JS. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --app-height: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: var(--app-height, 100dvh);
}

/* ---------- Шапка ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar__title { font-weight: 700; font-size: 17px; color: var(--ink); }
.topbar__status { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.topbar__status.online { color: #1a8917; }

/* ---------- Лента сообщений ---------- */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.day-empty {
  margin: auto;
  color: var(--ink-soft);
  font-size: 14px;
  text-align: center;
}

.msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: var(--radius);
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
  animation: pop .12s ease-out;
}
@keyframes pop { from { transform: translateY(4px); opacity: .5; } to { transform: none; opacity: 1; } }

.msg--in {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--ink);
  border-bottom-left-radius: 5px;
}
.msg--out {
  align-self: flex-end;
  background: var(--bubble-out);
  color: var(--bubble-out-ink);
  border-bottom-right-radius: 5px;
}
.msg__time {
  display: block;
  font-size: 10.5px;
  margin-top: 3px;
  opacity: .6;
  text-align: right;
}
.msg--in .msg__time { color: var(--ink-soft); }

/* группировка подряд идущих */
.msg + .msg.same { margin-top: -2px; }

/* ---------- Поле ввода ---------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-bottom));
  padding-left: calc(10px + var(--safe-left));
  padding-right: calc(10px + var(--safe-right));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer__input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 14px;
  font: inherit;
  color: var(--ink);
  background: #fafafa;
  max-height: 120px;
  outline: none;
}
.composer__input:focus { border-color: var(--ink); background: #fff; }

.composer__send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .08s, opacity .15s;
}
.composer__send:active { transform: scale(.92); }
.composer__send:disabled { opacity: .35; cursor: default; }

/* системная плашка (ошибки/инфо) */
.toast {
  position: fixed;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 50;
}
.toast.show { opacity: .92; }
