.chat-widget{
  position:fixed;
  right:20px;
  bottom:96px;
  z-index:1000;
  width:min(390px,calc(100vw - 24px));
  height:min(610px,calc(100vh - 125px));
  display:flex;
  flex-direction:column;
  overflow:hidden;
  border:1px solid rgba(75,139,255,.34);
  border-radius:16px;
  background:rgba(4,14,31,.98);
  box-shadow:0 24px 70px rgba(0,0,0,.58);
  backdrop-filter:blur(18px);
  transition:opacity .22s ease,transform .22s ease,visibility .22s ease;
}

.chat-widget.closed{
  opacity:0;
  visibility:hidden;
  pointer-events:none;
  transform:translateY(16px) scale(.97);
}

.chat-head{
  flex:0 0 auto;
  min-height:68px;
  padding:14px 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  border-bottom:1px solid rgba(75,139,255,.18);
}

.chat-messages{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  overscroll-behavior:contain;
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:12px;
  scrollbar-width:thin;
  scrollbar-color:#2f75d8 transparent;
}

.chat-message{
  max-width:88%;
  padding:12px 14px;
  border-radius:13px;
  font-size:14px;
  line-height:1.55;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
}

.chat-message.assistant{
  align-self:flex-start;
  color:#e7efff;
  background:#0a1b38;
  border:1px solid rgba(75,139,255,.22);
}

.chat-message.user{
  align-self:flex-end;
  color:#fff;
  background:linear-gradient(135deg,#197dff,#0757ec);
}

.chat-message.typing{
  color:#8fa2c1;
}

.chat-message.error{
  color:#c9d5e9;
}

.chat-quick{
  flex:0 0 auto;
  padding:0 14px 12px;
  display:flex;
  flex-wrap:wrap;
  gap:8px;
}

.chat-quick button{
  min-height:34px;
  padding:0 12px;
  border:1px solid rgba(75,139,255,.30);
  border-radius:18px;
  background:#07162e;
  color:#4ea0ff;
  font-size:11px;
}

.chat-input{
  flex:0 0 auto;
  display:flex;
  gap:8px;
  padding:12px;
  border-top:1px solid rgba(75,139,255,.18);
  background:#061126;
}

.chat-input input{
  flex:1;
  min-width:0;
  height:46px;
  padding:0 15px;
  border:1px solid rgba(75,139,255,.32);
  border-radius:24px;
  background:#07162e;
  color:#fff;
  font-size:14px;
  outline:none;
}

.chat-input input:focus{
  border-color:#2d91ff;
  box-shadow:0 0 0 3px rgba(45,145,255,.14);
}

.chat-input button{
  width:46px;
  height:46px;
  flex:0 0 46px;
  border:0;
  border-radius:50%;
  background:#147cff;
  color:#fff;
  font-size:18px;
}

.chat-error-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:11px;
}

.chat-error-actions button,
.chat-error-actions a{
  min-height:34px;
  padding:0 12px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border:1px solid rgba(75,139,255,.36);
  border-radius:18px;
  background:#0b2553;
  color:#fff;
  text-decoration:none;
  font-size:11px;
  font-weight:650;
}

.chat-fab{
  position:fixed;
  right:20px;
  bottom:20px;
  z-index:999;
  width:64px;
  height:64px;
  border:0;
  border-radius:50%;
  background:#1269ff;
  color:#fff;
  font-size:26px;
  box-shadow:0 0 30px rgba(0,88,255,.55);
}

@media(max-width:720px){
  .chat-widget{
    left:12px;
    right:12px;
    bottom:88px;
    width:auto;
    height:min(600px,calc(100dvh - 112px));
  }

  .chat-fab{
    right:14px;
    bottom:14px;
  }
}




/* ===== Stable mobile chat overlay ===== */
.chat-widget,
.chat-widget * {
  box-sizing: border-box;
}

.chat-input,
.chat-input input {
  min-width: 0;
}

@media (max-width: 720px) {
  .chat-widget {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    top: var(--chat-vv-top, 8px) !important;
    bottom: auto !important;
    width: auto !important;
    max-width: none !important;
    height: calc(var(--chat-vv-height, 100dvh) - 16px) !important;
    max-height: calc(var(--chat-vv-height, 100dvh) - 16px) !important;
    min-height: 300px;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    border-radius: 14px;
    transform: none !important;
  }

  .chat-widget.closed {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: translateY(12px) scale(.98) !important;
  }

  .chat-widget:not(.closed) {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .chat-head {
    flex: 0 0 60px;
    min-height: 60px;
    padding: 10px 12px;
  }

  .chat-messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    gap: 10px;
  }

  .chat-message {
    max-width: 92%;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.48;
  }

  .chat-quick {
    flex: 0 0 auto;
    max-height: 88px;
    overflow-y: auto;
    padding: 8px 10px 10px;
    gap: 7px;
    background: #061126;
  }

  .chat-quick button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 10px;
  }

  .chat-input {
    flex: 0 0 auto !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 46px !important;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(75,139,255,.18);
    background: #061126;
  }

  .chat-input input {
    width: 100% !important;
    min-width: 0 !important;
    height: 46px !important;
    padding: 0 14px !important;
    font-size: 16px !important;
    line-height: normal !important;
  }

  .chat-input button {
    width: 46px !important;
    height: 46px !important;
    min-width: 46px !important;
    max-width: 46px !important;
    padding: 0 !important;
    justify-self: end;
  }

  .chat-fab {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  body.chat-open-mobile {
    position: fixed !important;
    left: 0;
    right: 0;
    width: 100%;
    overflow: hidden !important;
  }
}
