/* ─── Chat Widget ─ Bottom Bar ──────────────────────────────────── */
#chat-widget {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  pointer-events: none;
  padding: 0 1rem 2.5rem;
  transition: padding .5s cubic-bezier(.4,0,.2,1),
              opacity .35s ease,
              transform .35s ease;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

#chat-bar {
  pointer-events: auto;
  position: relative;
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: rgba(27,37,44,.95);
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 8px 40px rgba(0,0,0,.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: box-shadow .3s ease,
              transform .5s cubic-bezier(.4,0,.2,1),
              max-width .5s cubic-bezier(.4,0,.2,1);
}
#chat-bar.chat-expanded {
  box-shadow: 0 12px 56px rgba(0,0,0,.6);
}

/* Notification badge */
#chat-badge {
  position: absolute;
  top: -12px;
  right: 16px;
  background: var(--deep-sand, #8c654d);
  color: #ffffff;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  padding: .25rem .7rem;
  border-radius: 99px;
  box-shadow: 0 2px 12px rgba(140,101,77,.4);
  animation: badge-in .4s cubic-bezier(.34,1.56,.64,1) both;
  cursor: pointer;
  z-index: 2;
  transition: opacity .25s ease, transform .25s ease;
}
#chat-badge.chat-badge-hidden {
  opacity: 0;
  transform: scale(0.8) translateY(4px);
  pointer-events: none;
  animation: none;
}
@keyframes badge-in {
  from { opacity: 0; transform: scale(0.5) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Messages area */
#chat-messages {
  max-height: 340px;
  overflow-y: auto;
  padding: 1rem 1rem .5rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  transition: max-height .3s ease, padding .3s ease, opacity .25s ease;
}
#chat-messages.chat-collapsed {
  max-height: 0;
  padding: 0 1rem;
  opacity: 0;
  overflow: hidden;
}

.chat-msg {
  max-width: 85%;
  border-radius: 10px;
  padding: .5rem .85rem;
  font-size: .85rem;
  line-height: 1.6;
}
.chat-msg p { margin: 0; }
.chat-msg.user {
  align-self: flex-end;
  background: #8c654d;
  color: #ffffff;
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,.06);
  color: #c8d6e5;
  border: 1px solid rgba(255,255,255,.06);
  border-bottom-left-radius: 3px;
}
.chat-msg a {
  color: var(--sandy-peach, #f4d7b1);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.chat-msg a:hover { opacity: .8; }
.chat-msg strong { color: var(--parchment, #faf7f2); font-weight: 600; }
.chat-msg ul {
  margin: .35rem 0;
  padding-left: 1.1rem;
  list-style: disc;
}
.chat-msg li {
  margin-bottom: .15rem;
}
.chat-msg p { margin: 0; }
.chat-msg p + p { margin-top: .4rem; }

/* Typing indicator */
.typing-dots span {
  display: inline-block;
  animation: typing-bounce .9s infinite;
  font-weight: 700;
  font-size: 1.1em;
  color: var(--cornflower-blue, #9fb8d9);
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Scrollbar */
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.1);
  border-radius: 4px;
}

/* Input row */
#chat-form {
  display: flex;
  align-items: center;
  padding: .6rem .6rem .6rem .75rem;
  gap: .4rem;
  position: relative;
}
#chat-input-row {
  display: flex;
  flex: 1;
  gap: .4rem;
  align-items: center;
}
#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: .55rem .25rem;
  font-size: .88rem;
  color: #faf7f2;
  font-family: inherit;
  outline: none;
}
#chat-input::placeholder {
  color: #5a7a96;
}
#chat-send {
  background: #8c654d;
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
}
#chat-send:hover { background: #a87d63; }
#chat-send:disabled { opacity: .5; cursor: not-allowed; }

#chat-collapse {
  background: none;
  border: none;
  color: #5a7a96;
  cursor: pointer;
  padding: .25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s;
  flex-shrink: 0;
}
#chat-collapse:hover { color: #faf7f2; }
#chat-collapse.chat-hidden { display: none; }

/* ─── Hidden when AI section visible ───────────────────────────── */
#chat-widget.chat-hidden-for-section {
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
}

/* Mobile */
@media (max-width: 640px) {
  #chat-widget { padding: 0 .5rem .75rem; }
  #chat-bar { max-width: 100%; }
  #chat-messages { max-height: 55vh; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #chat-bar,
  #chat-messages {
    transition: none;
  }
}
