#chat-widget{
  position:fixed;
  bottom:1.5rem;
  right:1.5rem;
  z-index:1000;
  font-family:inherit;
}

#chat-toggle{
  width:56px;
  height:56px;
  border-radius:50%;
  background:var(--navy);
  border:none;
  cursor:pointer;
  font-size:1.4rem;
  box-shadow:0 10px 28px rgba(10,31,68,0.28);
  transition:transform 0.15s ease, background 0.15s ease;
}
#chat-toggle:hover{transform:scale(1.06); background:var(--navy-2);}

#chat-panel{
  position:absolute;
  bottom:70px;
  right:0;
  width:340px;
  max-width:calc(100vw - 2.5rem);
  height:460px;
  max-height:70vh;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:16px;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  box-shadow:0 20px 50px rgba(10,31,68,0.18);
}

/* The [hidden] attribute is how JS opens/closes the panel. Without this
   override, the unconditional display:flex above (an ID selector) beats
   the browser's built-in [hidden]{display:none} rule on specificity, so
   panel.hidden = true would silently do nothing visually. */
#chat-panel[hidden]{
  display:none;
}

.chat-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:0.9rem 1.1rem;
  background:var(--navy);
  color:var(--white);
  font-weight:700;
  font-size:0.95rem;
  cursor:default;
}
.chat-header-actions{
  display:flex;
  align-items:center;
  gap:0.35rem;
}
.chat-header-actions button{
  background:none;
  border:none;
  color:rgba(255,255,255,0.75);
  cursor:pointer;
  line-height:1;
  border-radius:5px;
  padding:0.2rem 0.4rem;
  font-size:0.95rem;
}
.chat-header-actions button:hover{color:var(--white); background:rgba(255,255,255,0.12);}
#chat-pin.active{
  background:#ffd166;
  color:var(--navy);
  box-shadow:none;
}
#chat-pin.active:hover{
  background:#ffcb47;
  color:var(--navy);
}
#chat-close{font-size:1.3rem;}

/* Minimized: header stays visible, body collapses away */
#chat-panel.minimized{height:auto;}
#chat-panel.minimized .chat-messages,
#chat-panel.minimized .chat-form{display:none;}

.chat-messages{
  flex:1;
  overflow-y:auto;
  padding:1rem;
  display:flex;
  flex-direction:column;
  gap:0.65rem;
  background:var(--surface);
}

.chat-msg{
  padding:0.6rem 0.85rem;
  border-radius:10px;
  font-size:0.9rem;
  line-height:1.45;
  max-width:85%;
  white-space:pre-wrap;
  word-break:break-word;
}
.chat-msg-bot{
  background:var(--white);
  border:1px solid var(--line);
  color:var(--ink);
  align-self:flex-start;
}
.chat-msg-user{
  background:var(--blue);
  color:var(--white);
  align-self:flex-end;
}
.chat-msg-error{
  background:#fdecea;
  border:1px solid #f3c4bd;
  color:#b3261e;
  align-self:flex-start;
  font-size:0.82rem;
}
.chat-msg-typing{
  color:var(--muted);
  font-size:0.82rem;
  align-self:flex-start;
}

.chat-form{
  display:flex;
  border-top:1px solid var(--line);
  padding:0.6rem;
  gap:0.5rem;
  background:var(--white);
}
.chat-form input{
  flex:1;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:8px;
  padding:0.55rem 0.75rem;
  color:var(--ink);
  font-size:0.9rem;
  font-family:inherit;
}
.chat-form input:focus{outline:none; border-color:var(--blue);}
.chat-form button{
  background:var(--navy);
  border:none;
  border-radius:8px;
  width:38px;
  cursor:pointer;
  font-size:1rem;
  color:var(--white);
  font-weight:700;
}
.chat-form button:hover{background:var(--navy-2);}
.chat-form button:disabled{opacity:0.5; cursor:not-allowed;}

@media (max-width: 480px){
  #chat-widget{right:1rem; bottom:1rem;}
  #chat-panel{width:calc(100vw - 2rem); right:-0.5rem;}
}
