:root{
  --bg: #f5f1ee;
  --ink: #1f2430;
  --muted: #666c78;
  --navy: #16284c;
  --line:#d7d0ca;
  --surface:#ffffff;
  --surface-2:#f8f5f2;
  --user:#2f4f9a;
  --shadow: 0 18px 40px rgba(22,40,76,.18), 0 4px 12px rgba(22,40,76,.08);
}

html,body{
  margin:0;
  font-family: Inter, Arial, sans-serif;
  background: transparent;
  max-width: 100%;
  overflow-x: hidden;
}

.chat-fab,
.chat-widget,
.chat-widget *{
  box-sizing: border-box;
}

.chat-fab,
.chat-widget button,
.chat-widget textarea{
  font-family: inherit;
}

.chat-fab{
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  min-width: 122px;
  height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #355cc0 0%, #2e4f9d 100%);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.chat-fab:hover{ transform: translateY(-1px); }
.chat-fab.hidden{ opacity:0; pointer-events:none; }

.chat-widget{
  position: fixed;
  right: 24px;
  bottom: 86px;
  width: min(410px, calc(100vw - 32px));
  height: min(650px, calc(100vh - 112px));
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 112px);
  background: rgba(248,245,242,.95);
  backdrop-filter: blur(12px);
  color: var(--ink);
  border: 1px solid rgba(22,40,76,.10);
  border-radius: 24px;
  overflow: hidden;
  z-index: 10000;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transform: translateY(18px) scale(.96);
  opacity: 0;
  transition: transform .18s ease, opacity .18s ease;
}
.chat-widget.open{
  transform: translateY(0) scale(1);
  opacity: 1;
}
.hidden{ display:none !important; }

.chat-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  padding:16px 16px 14px 16px;
  background: linear-gradient(180deg, rgba(22,40,76,.97) 0%, rgba(22,40,76,.94) 100%);
  color:#fff;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.brand-wrap{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
}
.brand-mark{
  width:12px;
  height:12px;
  border-radius:4px;
  background:#6d89d8;
  box-shadow: 16px 0 0 #6d89d8, 0 16px 0 #6d89d8, 16px 16px 0 #6d89d8;
  transform: scale(.55);
  transform-origin: left top;
}
.chat-title{
  font-size:15px;
  font-weight:800;
  letter-spacing:.01em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-actions{
  display:flex;
  gap:8px;
  flex: 0 0 auto;
}
.icon-btn{
  width:34px;
  height:34px;
  border:0;
  border-radius:12px;
  background: rgba(255,255,255,.10);
  color:#fff;
  cursor:pointer;
  font-size:14px;
}

.messages{
  flex:1;
  overflow-y:auto;
  overflow-x:hidden;
  padding:16px;
  min-width:0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.18) 0%, rgba(255,255,255,0) 100%),
    var(--surface-2);
}
.message{
  max-width: 88%;
  min-width:0;
  box-sizing:border-box;
  margin-bottom: 12px;
  padding: 13px 15px;
  border-radius: 18px;
  line-height: 1.48;
  font-size: 14px;
  box-shadow: 0 6px 18px rgba(22,40,76,.05);
  overflow-wrap:anywhere;
  word-break:break-word;
}
.message.user{
  margin-left:auto;
  background: linear-gradient(180deg, #3560d4 0%, #3056b8 100%);
  color:#fff;
  border-bottom-right-radius: 8px;
  white-space: pre-wrap;
}
.message.assistant{
  background: #fff;
  color: var(--ink);
  border:1px solid rgba(22,40,76,.08);
  border-bottom-left-radius:8px;
  max-width: min(92%, 100%);
  overflow:hidden;
}
.label{ font-weight: 800; margin-bottom: 4px; color: var(--navy); }
.section{
  color: var(--ink);
  min-width:0;
  max-width:100%;
}
.spacer{ height: 8px; }
.inline-code{
  display:inline-block;
  max-width:100%;
  padding:1px 5px;
  border-radius:6px;
  background:#f0f3f8;
  color:#16284c;
  font-family: Consolas, "Liberation Mono", Menlo, monospace;
  font-size:.92em;
  vertical-align:baseline;
  overflow-wrap:anywhere;
}
.code-block{
  max-width:100%;
  max-height:360px;
  box-sizing:border-box;
  margin:10px 0;
  padding:12px;
  border:1px solid rgba(22,40,76,.12);
  border-radius:12px;
  background:#101828;
  color:#edf2ff;
  overflow:auto;
  white-space:pre;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
}
.code-block code{
  display:block;
  min-width:max-content;
  font-family: Consolas, "Liberation Mono", Menlo, monospace;
  font-size:12.5px;
  line-height:1.5;
  white-space:pre;
  overflow-wrap:normal;
  word-break:normal;
}

.typing{
  display:flex;
  gap:6px;
  padding: 0 18px 10px 18px;
  align-items:center;
}
.typing span{
  width:8px;
  height:8px;
  border-radius:50%;
  background:#7b8391;
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2){ animation-delay:.2s; }
.typing span:nth-child(3){ animation-delay:.4s; }
@keyframes blink{
  0%,80%,100%{ opacity:.25; transform:scale(.9);}
  40%{ opacity:1; transform:scale(1);}
}

.composer{
  display:grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap:10px;
  padding:14px;
  border-top:1px solid rgba(22,40,76,.08);
  background: rgba(255,255,255,.68);
  min-width:0;
}
textarea{
  width:100%;
  min-width:0;
  box-sizing:border-box;
  border-radius:16px;
  border:1px solid rgba(22,40,76,.14);
  background:#fff;
  color:var(--ink);
  padding:12px 14px;
  font:inherit;
  resize:none;
  outline:none;
}
textarea::placeholder{ color:#7b8391; }
.send-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  border:0;
  border-radius:16px;
  background: linear-gradient(180deg, #355cc0 0%, #2e4f9d 100%);
  color:#fff;
  cursor:pointer;
  font-size:16px;
  box-shadow: 0 8px 18px rgba(47,79,154,.28);
}

@media (max-width: 520px), (max-height: 760px){
  .chat-fab{
    right: 16px;
    bottom: 16px;
  }
  .chat-widget{
    right: 12px;
    bottom: 76px;
    width: calc(100vw - 24px);
    height: min(610px, calc(100vh - 92px));
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 92px);
    border-radius: 20px;
  }
  .messages{
    padding: 12px;
  }
  .message{
    max-width: 94%;
    font-size: 13.5px;
  }
  .composer{
    padding: 12px;
    grid-template-columns: minmax(0, 1fr) 46px;
  }
}
