/* CAS Mini App — design ported from the CAS Blueprint mockups (indigo accent, 16-20px radii,
   IBM Plex Sans) and reconciled with Telegram's theme so it looks native in BOTH light and dark:
   surfaces come from themeParams (--tg-theme-*) with our palette as the fallback. */
:root {
  --accent: #4F5BD5;
  --accent-2: #7C5CFF;
  --ok: #22A06B;
  --warn: #C9861A;
  --danger: #D5453F;

  --bg: var(--tg-theme-secondary-bg-color, #F4F6FB);
  --card: var(--tg-theme-bg-color, #FFFFFF);
  --text: var(--tg-theme-text-color, #1A2233);
  --muted: var(--tg-theme-hint-color, #8189A0);
  --line: rgba(128, 138, 160, .18);
  --link: var(--tg-theme-link-color, var(--accent));

  --r-lg: 20px; --r-md: 16px; --r-sm: 10px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overscroll-behavior-y: none;
}
.app { padding: 12px 12px calc(78px + var(--safe-b)); max-width: 720px; margin: 0 auto; }

/* ── boot ─────────────────────────────────────────────────────────────────────────────────── */
.boot { display: grid; place-items: center; gap: 8px; min-height: 60vh; }
.boot-logo { font-weight: 700; font-size: 30px; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.boot-hint { color: var(--muted); font-size: 14px; }

/* ── building blocks ──────────────────────────────────────────────────────────────────────── */
.card { background: var(--card); border-radius: var(--r-lg); padding: var(--pad); margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .04); }
.card.tight { padding: 12px; }
.h { font-weight: 600; font-size: 17px; margin: 0 0 2px; }
.sub { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.mt { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }

.title { font-size: 22px; font-weight: 700; margin: 6px 2px 12px; }
.section-t { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; margin: 18px 4px 8px; }

/* status hero */
.hero { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: var(--r-lg); padding: 18px; margin-bottom: 12px; }
.hero.off { background: linear-gradient(135deg, #6B7385, #3B4256); }
.hero.none { background: linear-gradient(135deg, #98A0B3, #6B7385); }
.hero h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.hero p { margin: 0; opacity: .92; font-size: 14px; }
.hero .stats { display: flex; gap: 18px; margin-top: 14px; }
.hero .stat b { display: block; font-size: 20px; line-height: 1.1; }
.hero .stat span { font-size: 12px; opacity: .85; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; cursor: pointer; width: 100%; }
.btn:active { transform: translateY(1px); }
.btn.sec { background: rgba(128, 138, 160, .14); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--link); }
.btn.sm { padding: 8px 12px; font-size: 14px; width: auto; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-row { display: flex; gap: 8px; }

/* chips / filters */
/* A single row that scrolls sideways is right for a short, fixed filter set. It is WRONG for a picker
   whose options are the steps of a scenario: those are many, their names are long, and a cut-off
   "Приве…" tells the user nothing. Those wrap instead. */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow-x: visible; row-gap: 8px; }
.chips.wrap .chip { flex: 0 1 auto; max-width: 100%; white-space: normal; text-align: left; }
.chip { flex: 0 0 auto; padding: 7px 13px; border-radius: 999px; background: rgba(128, 138, 160, .14);
  color: var(--text); font-size: 13px; font-weight: 500; border: 0; cursor: pointer; line-height: 1.25; }
.chip.on { background: var(--accent); color: #fff; }

/* list items */
.item { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: var(--r-md);
  background: var(--card); margin-bottom: 8px; cursor: pointer; }
.item .av { width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto; display: grid;
  place-items: center; font-weight: 700; color: #fff; background: var(--accent); }
.item .body { min-width: 0; flex: 1; }
.item .body .t { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.item .body .p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.item .meta { color: var(--muted); font-size: 12px; text-align: right; flex: 0 0 auto; }

/* badges */
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: rgba(128, 138, 160, .16); color: var(--muted); }
.badge.hot { background: rgba(213, 69, 63, .14); color: var(--danger); }
.badge.warm { background: rgba(201, 134, 26, .16); color: var(--warn); }
.badge.objection { background: rgba(124, 92, 255, .16); color: var(--accent-2); }
.badge.human { background: rgba(79, 91, 213, .16); color: var(--accent); }
.badge.ok { background: rgba(34, 160, 107, .16); color: var(--ok); }
.badge.bad { background: rgba(213, 69, 63, .14); color: var(--danger); }

/* chat */
.thread { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 16px; font-size: 15px; white-space: pre-wrap;
  word-break: break-word; }
.msg.in { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg .at { display: block; font-size: 10px; opacity: .6; margin-top: 3px; }
/* Not-yet-delivered manager messages. Queued is dimmed (it is not a fact yet); failed is marked in the
   danger colour and carries its reason plus a retry, because silence about a failure is the worst case. */
.msg.queued { opacity: .62; }
.msg.failed { background: var(--danger); }
.msg.failed .at { opacity: .95; }
.msg.failed .btn { margin-top: 6px; background: rgba(255, 255, 255, .22); color: #fff; }
.composer { position: sticky; bottom: calc(70px + var(--safe-b)); display: flex; gap: 8px;
  background: var(--bg); padding: 8px 0; }
.composer input { flex: 1; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 11px 14px; font: inherit; outline: none; }

/* forms */
label.f { display: block; font-size: 13px; color: var(--muted); margin: 10px 2px 6px; }
textarea, input.t { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
  font: inherit; background: var(--card); color: var(--text); outline: none; resize: vertical; }
textarea:focus, input:focus { border-color: var(--accent); }

/* stat grid + bars */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: var(--card); border-radius: var(--r-md); padding: 14px; }
.tile b { display: block; font-size: 22px; line-height: 1.15; }
.tile span { color: var(--muted); font-size: 12px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; height: 100%; }
.bars .b i { display: block; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b i.alt { background: rgba(124, 92, 255, .45); }
.bars .b em { font-style: normal; font-size: 10px; color: var(--muted); text-align: center; }

/* bottom tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 8px 4px calc(8px + var(--safe-b));
  z-index: 20; }
.tabbar button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 10px; cursor: pointer; }
.tabbar button.on { color: var(--accent); }
.tabbar .ic { font-size: 19px; line-height: 1; }
.tabbar .dot { position: absolute; transform: translate(14px, -4px); width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger); }

.toast { position: fixed; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%);
  background: #1A2233; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  z-index: 50; opacity: 0; transition: opacity .18s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: .96; }

/* Who said it. Without this an outgoing line from the bot and one typed by a manager are identical,
   so nobody can tell whether a human has already answered — the core question in a shared inbox. */
.msg .who { display: block; font-size: 11px; font-weight: 600; opacity: .75; margin-bottom: 2px; }
.msg.in .who { color: var(--accent); }

/* Who leads this conversation. A two-state control rather than a button, because the question the
   user has when scanning a list is "who is on this one" — not "what happens if I press". */
.item .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: 0 0 auto; }
.sw { display: inline-flex; border-radius: 999px; background: rgba(128, 138, 160, .14); padding: 2px;
  font-size: 11px; font-weight: 600; cursor: pointer; user-select: none; }
.sw span { padding: 4px 9px; border-radius: 999px; color: var(--muted); white-space: nowrap; }
.sw span.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.sw span:first-child.on { color: var(--accent); }
.sw.busy { opacity: .5; pointer-events: none; }
/* A conversation that was not started with us cannot be switched from a list — handing it to the bot
   means choosing where it resumes, which lives in the chat behind a preview. */
.sw.locked { background: transparent; color: var(--muted); font-weight: 500; padding: 4px 0; cursor: default; }
