/* Страница операторов «Впринципе». Светлая, спокойная, акцент — кобальт. */
:root {
  --page: #f3f5fa;
  --surface: #ffffff;
  --rail: #fbfcfe;
  --line: #e6e9f1;
  --line-soft: #eef1f6;
  --ink: #161a26;
  --muted: #687089;
  --faint: #9aa1b4;
  --accent: #2b59ff;
  --accent-ink: #ffffff;
  --accent-soft: #eaf0ff;
  --bot: #f1edff;
  --bot-ink: #4b3fb0;
  --wait: #d98a00;
  --late: #e5484d;
  --ok: #18a058;
  --radius-l: 18px;
  --radius-m: 12px;
  --radius-s: 8px;
  --shadow-float: 0 8px 28px rgba(22, 26, 38, .08), 0 1px 3px rgba(22, 26, 38, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14.5px/1.45 "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, textarea:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
svg.i { width: 18px; height: 18px; flex: none; }

/* --- вход --- */
.login-page { display: grid; place-items: center; min-height: 100%; }
.login-box { background: var(--surface); border-radius: 24px; padding: 36px 40px; text-align: center; max-width: 380px; margin: 16px; box-shadow: var(--shadow-float); }
.login-box h1 { font-size: 22px; letter-spacing: -.01em; margin: 0 0 6px; }
.login-box p { margin: 0 0 22px; }
.login-error { color: var(--late); }

/* --- раскладка: список | чат | клиент --- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.list { width: 340px; flex: none; display: flex; flex-direction: column; background: var(--rail); border-right: 1px solid var(--line); }
.chat { flex: 1; display: flex; min-width: 0; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--page); }
.empty { flex: 1; display: grid; place-items: center; color: var(--faint); padding: 24px; text-align: center; }

/* аватарки */
.avatar { position: relative; flex: none; border-radius: 50%; display: grid; place-items: center; overflow: hidden; color: #fff; font-weight: 600; letter-spacing: .01em; user-select: none; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar svg { width: 58%; height: 58%; opacity: .92; }
.av-40 { width: 40px; height: 40px; font-size: 15px; }
.av-36 { width: 36px; height: 36px; font-size: 13.5px; }
.av-72 { width: 72px; height: 72px; font-size: 26px; }
.av-28 { width: 28px; height: 28px; font-size: 11px; }

/* шапка списка */
.list-head { padding: 16px 16px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: 0; }
.live { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.live.on::before { background: var(--ok); box-shadow: 0 0 0 3px rgba(24, 160, 88, .15); }

.tabs { margin: 0 16px 10px; padding: 3px; background: #eceff6; border-radius: 11px; display: flex; gap: 3px; }
.tabs button { flex: 1; border: 0; background: none; padding: 7px 0; border-radius: 9px; color: var(--muted); font-weight: 500; font-size: 13.5px; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(22, 26, 38, .08); }
.tabs .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11.5px; line-height: 18px; }

.rows { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.row { display: flex; gap: 12px; padding: 10px 10px; border-radius: var(--radius-m); cursor: pointer; align-items: center; }
.row:hover { background: #f1f3f9; }
.row.sel { background: var(--accent-soft); }
.row .body { flex: 1; min-width: 0; }
.row .n { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row .n b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .n .t { color: var(--faint); font-size: 12px; white-space: nowrap; }
.row .s { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row .w { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 1px 7px; font-size: 11.5px; font-weight: 500; }
.chip.wait { background: #fff4dc; color: #8a5a00; }
.chip.late { background: #ffe9ea; color: #b4232a; }
.chip.bot { background: var(--bot); color: var(--bot-ink); }
.chip.done { background: #e9f7ef; color: #11703f; }
.chip.op { background: var(--accent-soft); color: #1d3fb8; }
.more { margin: 10px auto; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 7px 14px; font-size: 13px; }
.list-foot { padding: 10px 16px; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* шапка чата */
.head { padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex: none; }
.who { min-width: 0; display: flex; align-items: center; gap: 12px; }
.who .txt { min-width: 0; }
.who b { display: block; font-weight: 600; font-size: 15.5px; }
.who small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; background: none; border: 0; color: var(--accent); padding: 4px 6px 4px 0; }
.act { display: flex; gap: 8px; flex: none; position: relative; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 12px; font-size: 13.5px; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover:not(:disabled) { background: #f5f7fc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #2149e6; }
.act .closed-note { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; }
.pop { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-float); padding: 6px; z-index: 10; display: flex; flex-direction: column; min-width: 240px; border: 1px solid var(--line-soft); }
.pop .q { padding: 8px 10px 6px; color: var(--muted); font-size: 13px; }
.pop button { border: 0; text-align: left; padding: 9px 10px; border-radius: 9px; background: none; }
.pop button:hover { background: #f3f5fa; }
.pop button.primary { color: var(--accent); font-weight: 600; }

/* лента */
.msgs { flex: 1; overflow-y: auto; padding: 20px 24px 8px; display: flex; flex-direction: column; gap: 6px; }
.msgs > * { max-width: 760px; }
.b { max-width: min(72%, 560px); padding: 9px 13px 7px; border-radius: var(--radius-l); line-height: 1.45; overflow-wrap: anywhere; }
.b .meta { display: block; font-size: 11.5px; margin-top: 3px; color: var(--faint); }
.b.client { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 6px; box-shadow: 0 1px 1px rgba(22, 26, 38, .05); }
.b.assistant { background: var(--bot); align-self: flex-end; border-bottom-right-radius: 6px; }
.b.assistant .meta { color: #8277c9; }
.b.operator { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 6px; }
.b.operator .meta { color: rgba(255, 255, 255, .72); }
.b.operator a { color: #fff; text-decoration: underline; }
.b + .b.client, .b.client + .b { margin-top: 6px; }
.b blockquote { margin: 4px 0; padding-left: 9px; border-left: 3px solid rgba(0, 0, 0, .15); }
.b pre, .b code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.b img.att { display: block; max-width: 280px; max-height: 280px; border-radius: 12px; margin: 2px 0 6px; cursor: zoom-in; }
.b a.file { display: inline-flex; align-items: center; gap: 8px; margin: 2px 0 4px; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, .05); color: inherit; }
.b.operator a.file { background: rgba(255, 255, 255, .16); }
.sys { align-self: center; color: var(--faint); font-size: 12px; padding: 6px 0; text-align: center; max-width: 80%; }
.sys.handover { color: var(--wait); }
.earlier { align-self: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 5px 12px; font-size: 12.5px; }

/* поле ответа */
.composer { padding: 8px 20px 18px; flex: none; }
.inp { display: flex; gap: 6px; align-items: flex-end; background: var(--surface); border-radius: 22px; padding: 6px 6px 6px 8px; box-shadow: var(--shadow-float); max-width: 760px; }
.inp textarea { flex: 1; border: 0; padding: 9px 6px; resize: none; font: inherit; max-height: 180px; min-height: 40px; background: none; outline: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; background: none; color: var(--muted); flex: none; }
.icon-btn:hover:not(:disabled) { background: #f1f3f9; color: var(--ink); }
.icon-btn.send { background: var(--accent); color: #fff; }
.icon-btn.send:hover:not(:disabled) { background: #2149e6; color: #fff; }
.attach-note { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); display: inline-flex; gap: 8px; align-items: center; background: var(--surface); border-radius: 10px; padding: 5px 10px; }
.attach-note button { background: none; border: 0; color: var(--late); padding: 0; }
.status-line { margin: 0 0 8px; font-size: 13px; color: var(--late); display: flex; gap: 10px; align-items: center; }
.status-line.info { color: var(--muted); padding: 14px 20px; margin: 0; justify-content: center; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13.5px; z-index: 20; max-width: 90vw; box-shadow: var(--shadow-float); }

/* карточка клиента справа */
.cardside { width: 320px; flex: none; border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; font-size: 13.5px; }
.cardside .hero { padding: 24px 20px 16px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; border-bottom: 1px solid var(--line-soft); }
.cardside .hero b { font-size: 16px; margin-top: 8px; }
.cardside .hero .muted { font-size: 13px; }
.cardside .facts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.cardside .card-body { padding: 16px 20px 24px; white-space: pre-wrap; line-height: 1.55; overflow-wrap: anywhere; }
.card-arrow { display: none; color: var(--muted); font-weight: 400; }

@media (max-width: 1180px) {
  .cardside { display: none; }
  .who { cursor: pointer; }
  .card-arrow { display: inline; }
  .chat { position: relative; }
  .cardside.open { display: block; position: absolute; top: 65px; right: 0; bottom: 0; width: min(340px, 100%); box-shadow: -8px 0 28px rgba(22, 26, 38, .12); z-index: 5; }
}

/* узкий экран и Mini App */
@media (max-width: 720px) {
  .list { width: 100%; border-right: 0; }
  .app.show-chat .list { display: none; }
  .app:not(.show-chat) .chat { display: none; }
  .back { display: inline-flex; }
  .head { padding: 10px 12px; }
  .act .wide { display: none; }
  .menu-btn { display: inline-flex; }
  .msgs { padding: 14px 12px 6px; }
  .b { max-width: 86%; }
  .b img.att { max-width: 220px; }
  .composer { padding: 6px 10px 10px; }
}

@media (prefers-reduced-motion: no-preference) {
  .pop, .toast { animation: pop-in .14s ease-out; }
  @keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  .toast { animation-name: toast-in; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
}
