:root {
  --bg: #0e1525;
  --bg-soft: #141d31;
  --panel: #ffffff;
  --ink: #16203a;
  --ink-soft: #5b6b86;
  --line: #e7ecf4;
  --brand: #2f6bff;
  --brand-deep: #1c4fd6;
  --accent: #14c9a3;
  --bot-bubble: #f1f4fb;
  --user-bubble: linear-gradient(135deg, #2f6bff, #1c4fd6);
  --shadow: 0 20px 50px rgba(16, 31, 70, 0.16);
  --radius: 18px;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 80% 0%, rgba(47,107,255,0.18), transparent 60%),
    linear-gradient(180deg, #0e1525, #0b1120 60%, #0a0f1c);
  min-height: 100vh;
}
/* Сцена — только чат, по центру */
.stage {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Chat card */
.chat-card {
  width: min(560px, 100%);
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; height: 680px; max-height: calc(100vh - 48px); overflow: hidden;
}
.chat-card__head { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.agent { display: flex; align-items: center; gap: 12px; }
.agent-ava {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 18px;
}
.agent-meta { display: flex; flex-direction: column; }
.agent-name { font-weight: 700; font-size: 15px; }
.agent-status { font-size: 12.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.agent-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(20,201,163,0.2); }

.chat-card__body { flex: 1; overflow-y: auto; padding: 20px 18px; display: flex; flex-direction: column; gap: 12px; background: #fbfcfe; }

/* Messages */
.msg { max-width: 80%; padding: 11px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; animation: pop .22s ease; }
.msg.bot { align-self: flex-start; background: var(--bot-bubble); color: var(--ink); border-bottom-left-radius: 5px; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: #fff; border-bottom-right-radius: 5px; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.typing { align-self: flex-start; background: var(--bot-bubble); padding: 13px 16px; border-radius: 16px; border-bottom-left-radius: 5px; display: flex; gap: 5px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #9fb0cd; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .3; transform: translateY(0);} 30% { opacity: 1; transform: translateY(-3px);} }

/* Inputs */
.chat-card__input, .widget-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: #fff; }
.chat-card__input input, .widget-input input {
  flex: 1; border: 1px solid var(--line); background: #f6f8fc; border-radius: 12px;
  padding: 12px 14px; font: inherit; font-size: 14.5px; color: var(--ink); outline: none; transition: border .15s, box-shadow .15s;
}
.chat-card__input input:focus, .widget-input input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,107,255,0.14); background: #fff; }
.chat-card__input button, .widget-input button {
  flex: none; width: 46px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: #fff;
  display: grid; place-items: center; transition: transform .12s, filter .15s;
}
.chat-card__input button:hover, .widget-input button:hover { filter: brightness(1.07); }
.chat-card__input button:active, .widget-input button:active { transform: scale(.94); }
.chat-card__input button:disabled, .widget-input button:disabled { opacity: .5; cursor: default; }

/* Floating widget */
.widget { position: fixed; right: 24px; bottom: 24px; z-index: 50; display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }
.widget-toggle {
  position: relative; width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: #fff;
  display: grid; place-items: center; box-shadow: 0 14px 30px rgba(28,79,214,0.45);
  transition: transform .18s ease, box-shadow .18s ease;
}
.widget-toggle:hover { transform: translateY(-2px) scale(1.04); }
.widget-toggle .ico-close { display: none; }
.widget-toggle.is-open .ico-chat { display: none; }
.widget-toggle.is-open .ico-close { display: block; }

.widget-panel {
  width: min(380px, 90vw); height: min(560px, 72vh); background: var(--panel);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; transform-origin: bottom right; animation: panelIn .2s ease;
}
.widget-panel[hidden] { display: none; }
@keyframes panelIn { from { transform: translateY(12px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.widget-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: #fff; }
.widget-head .agent-ava { background: rgba(255,255,255,0.2); }
.widget-head .agent-name { color: #fff; }
.widget-head .agent-status { color: rgba(255,255,255,0.82); }
.widget-head .agent-status i { background: #b8ffec; box-shadow: 0 0 0 3px rgba(255,255,255,0.18); }
.widget-close { background: rgba(255,255,255,0.16); border: 0; color: #fff; width: 30px; height: 30px; border-radius: 9px; cursor: pointer; display: grid; place-items: center; }
.widget-close:hover { background: rgba(255,255,255,0.28); }
.widget-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #fbfcfe; }
.widget-body .msg { max-width: 86%; font-size: 14px; }

/* Scrollbars */
.chat-card__body::-webkit-scrollbar, .widget-body::-webkit-scrollbar { width: 8px; }
.chat-card__body::-webkit-scrollbar-thumb, .widget-body::-webkit-scrollbar-thumb { background: #d6deec; border-radius: 8px; }

/* Responsive */
@media (max-width: 920px) {
  .main-grid { grid-template-columns: 1fr; gap: 30px; }
  .header-meta { display: none; }
  .chat-card { height: 560px; order: -1; }
}
@media (max-width: 480px) {
  .widget { right: 14px; bottom: 14px; }
  .widget-panel { height: 70vh; }
}
