/* Lumo Mini App — мобильный чат. Тема берётся из Telegram, есть тёмный фолбэк. */

:root {
  --bg: var(--tg-theme-bg-color, #0b0d10);
  --bg-soft: var(--tg-theme-secondary-bg-color, #12151a);
  --text: var(--tg-theme-text-color, #e9ecf1);
  --muted: var(--tg-theme-hint-color, #818899);
  --link: var(--tg-theme-link-color, #6ea8fe);
  --accent: var(--tg-theme-button-color, #2f6df6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --bubble-user: var(--tg-theme-button-color, #2f6df6);
  --bubble-user-text: var(--tg-theme-button-text-color, #ffffff);
  --bubble-bot: var(--tg-theme-secondary-bg-color, #171b21);
  --line: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --bg-soft: var(--tg-theme-secondary-bg-color, #f3f4f6);
    --text: var(--tg-theme-text-color, #14161a);
    --muted: var(--tg-theme-hint-color, #6b7280);
    --bubble-bot: var(--tg-theme-secondary-bg-color, #f1f3f6);
    --line: rgba(0, 0, 0, 0.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { overflow: hidden; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; }

.brand-name { font-weight: 650; letter-spacing: -0.01em; font-size: 16px; }

.mark {
  width: 9px; height: 9px; border-radius: 50%;
  background: #6ee7a8;
  box-shadow: 0 0 0 4px color-mix(in srgb, #6ee7a8 18%, transparent);
}

.model { position: relative; display: inline-flex; align-items: center; }

.model select {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 7px 26px 7px 11px;
  border-radius: 11px;
  max-width: 42vw;
  text-overflow: ellipsis;
}

.model select:focus-visible, .icon-btn:focus-visible, .send:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.chev {
  position: absolute; right: 9px; width: 12px; height: 12px;
  color: var(--muted); pointer-events: none;
}

.icon-btn {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-soft);
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, transform .12s;
}

.icon-btn:hover { color: var(--text); border-color: color-mix(in srgb, var(--text) 25%, transparent); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 18px; height: 18px; }

/* ----------------------------------------------------------------- thread */

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

.empty { margin: auto 0; text-align: center; padding: 12px 4px 24px; }
.empty h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; margin: 0 0 6px; }
.empty p { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.chips { display: flex; flex-direction: column; gap: 8px; }

.chip {
  font: inherit; font-size: 14px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .12s;
}

.chip:hover { border-color: color-mix(in srgb, var(--text) 22%, transparent); }
.chip:active { transform: scale(.99); }

.msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: pop .18s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  border-bottom-left-radius: 6px;
}

.msg.bot.error { border: 1px solid color-mix(in srgb, #f87171 45%, transparent); color: #fca5a5; }

.msg .caret {
  display: inline-block;
  width: 6px; height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: currentColor;
  opacity: .5;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* форматирование внутри пузырей */
.msg strong { font-weight: 650; }
.msg em { font-style: italic; }

.msg code {
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: color-mix(in srgb, currentColor 12%, transparent);
  border-radius: 6px;
  padding: 1px 5px;
}

.msg pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, currentColor 10%, transparent);
  overflow-x: auto;
}

.msg pre code { background: none; padding: 0; white-space: pre; }

.msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* --------------------------------------------------------------- composer */

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 11px 14px;
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  overflow-y: hidden;
  scrollbar-width: none;
  transition: border-color .15s;
}

.composer textarea::-webkit-scrollbar { display: none; }

.composer textarea:focus { border-color: color-mix(in srgb, var(--link) 55%, transparent); }
.composer textarea::placeholder { color: var(--muted); }

.send {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: opacity .15s, transform .12s;
}

.send svg { width: 20px; height: 20px; }
.send:disabled { opacity: .4; cursor: default; }
.send:not(:disabled):active { transform: scale(.94); }

/* ------------------------------------------------------------ gate / toast */

.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 20;
}

.gate[hidden] { display: none; }

.gate-card { max-width: 340px; text-align: center; }
.gate-card h2 { font-size: 18px; margin: 0 0 8px; font-weight: 650; }
.gate-card p { color: var(--muted); margin: 0; font-size: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  border-radius: 12px;
  background: #2a1d1f;
  color: #ffd7d7;
  border: 1px solid rgba(248, 113, 113, .35);
  font-size: 13px;
  z-index: 30;
  animation: pop .18s ease-out;
}
