/* ============================================
   TechBot chat widget (ported from the TechTips widget v3)
============================================ */

@keyframes tw-glitch-1 { 0%,85%,100% { transform: translate(0); } 87% { transform: translate(-3px,1px); } 89% { transform: translate(3px,-1px); } 91% { transform: translate(0); } }
@keyframes tw-glitch-2 { 0%,85%,100% { transform: translate(0); } 87% { transform: translate(3px,1px); } 89% { transform: translate(-3px,-1px); } 91% { transform: translate(0); } }
@keyframes tw-fadein  { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes tw-fadeout { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes tw-blink   { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes tw-msg-in  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes tw-dots    { 0%,80%,100% { opacity: 0.2; transform: scaleY(0.6); } 40% { opacity: 1; transform: scaleY(1); } }

#tw-chat-fab {
  position: fixed; bottom: 24px; right: 24px; z-index: 9998;
  width: 48px; height: 48px; border-radius: 12px;
  background: #0a0c10; border: 1px solid #00e5ff;
  box-shadow: 0 0 12px rgba(0,229,255,0.2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: box-shadow 0.25s;
}
#tw-chat-fab:hover, #tw-chat-fab:focus-visible { box-shadow: 0 0 22px rgba(0,229,255,0.38); outline: none; }
#tw-chat-fab .tw-icon-wrap { position: relative; width: 20px; height: 20px; }
#tw-chat-fab .tw-icon-wrap > div { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#tw-chat-fab .tw-icon-g1 { clip-path: polygon(0 0,100% 0,100% 45%,0 45%); animation: tw-glitch-1 3.5s infinite; }
#tw-chat-fab .tw-icon-g2 { clip-path: polygon(0 55%,100% 55%,100% 100%,0 100%); animation: tw-glitch-2 3.5s infinite; }

#tw-chat-window {
  position: fixed; bottom: 84px; right: 24px; z-index: 9999;
  width: 370px; max-width: calc(100vw - 32px);
  height: 520px; max-height: calc(100vh - 120px);
  background: #0a0c10; border: 1px solid #1f2733; border-radius: 16px;
  box-shadow: 0 0 40px rgba(0,0,0,0.7), 0 0 0 1px rgba(0,229,255,0.06);
  display: flex; flex-direction: column; overflow: hidden;
  font-family: 'Exo 2', sans-serif; color: #c8d6e5;
}
#tw-chat-window[hidden] { display: none; }
#tw-chat-window.tw-open  { animation: tw-fadein 0.22s ease both; }
#tw-chat-window.tw-close { animation: tw-fadeout 0.18s ease both; }

.tw-header { display: flex; align-items: center; gap: 0.6rem; padding: 0.85rem 1rem; border-bottom: 1px solid #1f2733; background: #111318; flex-shrink: 0; }
.tw-header-dot { width: 8px; height: 8px; border-radius: 50%; background: #00e5ff; box-shadow: 0 0 6px #00e5ff; animation: tw-blink 2s step-end infinite; flex-shrink: 0; }
.tw-header-text { flex: 1; }
.tw-header-title { font-family: 'Share Tech Mono', monospace; font-size: 0.78rem; color: #00e5ff; letter-spacing: 0.08em; }
.tw-header-sub { font-size: 0.68rem; color: #5a6a7e; font-family: 'Share Tech Mono', monospace; letter-spacing: 0.05em; }
.tw-header-btn { background: none; border: none; cursor: pointer; color: #5a6a7e; font-family: 'Share Tech Mono', monospace; font-size: 0.68rem; letter-spacing: 0.06em; line-height: 1; padding: 4px 6px; border-radius: 4px; transition: color 0.2s; }
.tw-header-btn.tw-x { font-size: 1.1rem; }
.tw-header-btn:hover, .tw-header-btn:focus-visible { color: #c8d6e5; outline: none; }

.tw-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; scroll-behavior: smooth; }
.tw-messages::-webkit-scrollbar { width: 4px; }
.tw-messages::-webkit-scrollbar-thumb { background: #1f2733; border-radius: 2px; }

.tw-msg { display: flex; flex-direction: column; max-width: 88%; animation: tw-msg-in 0.2s ease both; }
.tw-msg.tw-user { align-self: flex-end; align-items: flex-end; }
.tw-msg.tw-bot  { align-self: flex-start; align-items: flex-start; }
.tw-label { font-family: 'Share Tech Mono', monospace; font-size: 0.62rem; color: #5a6a7e; letter-spacing: 0.08em; margin-bottom: 0.25rem; }
.tw-bubble { padding: 0.6rem 0.85rem; border-radius: 12px; font-size: 0.875rem; line-height: 1.65; font-weight: 300; white-space: pre-wrap; overflow-wrap: anywhere; }
.tw-msg.tw-user .tw-bubble { background: rgba(0,229,255,0.1); border: 1px solid rgba(0,229,255,0.2); border-bottom-right-radius: 4px; }
.tw-msg.tw-bot  .tw-bubble { background: #181c24; border: 1px solid #1f2733; border-bottom-left-radius: 4px; }
.tw-msg.tw-error .tw-bubble { border-color: rgba(244,81,79,0.4); }
.tw-bubble a { color: #00e5ff; text-decoration: underline; text-underline-offset: 2px; }
.tw-bubble strong { font-weight: 600; color: #e4edf6; }

.tw-typing { display: flex; gap: 4px; align-items: center; padding: 0.2rem 0; }
.tw-typing span { display: inline-block; width: 5px; height: 14px; background: #5a6a7e; border-radius: 2px; animation: tw-dots 1.2s ease-in-out infinite; }
.tw-typing span:nth-child(2) { animation-delay: 0.2s; }
.tw-typing span:nth-child(3) { animation-delay: 0.4s; }

.tw-input-row { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid #1f2733; background: #111318; flex-shrink: 0; }
.tw-input { flex: 1; background: #181c24; border: 1px solid #1f2733; border-radius: 8px; color: #c8d6e5; font-family: 'Exo 2', sans-serif; font-size: 16px; font-weight: 300; padding: 0.55rem 0.75rem; outline: none; resize: none; line-height: 1.5; max-height: 100px; transition: border-color 0.2s, box-shadow 0.2s; }
.tw-input::placeholder { color: #5a6a7e; }
.tw-input:focus { border-color: rgba(0,229,255,0.4); box-shadow: 0 0 0 3px rgba(0,229,255,0.08); }
.tw-send-btn { background: rgba(0,229,255,0.1); border: 1px solid rgba(0,229,255,0.25); border-radius: 8px; cursor: pointer; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; align-self: flex-end; transition: background 0.2s, border-color 0.2s; }
.tw-send-btn:hover:not(:disabled) { background: rgba(0,229,255,0.18); border-color: rgba(0,229,255,0.5); }
.tw-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.tw-disclaimer { padding: 0.35rem 1rem; font-family: 'Share Tech Mono', monospace; font-size: 0.58rem; color: #5a6a7e; letter-spacing: 0.05em; text-align: center; flex-shrink: 0; border-top: 1px solid #1f2733; background: #111318; }

@media (max-width: 480px) {
  #tw-chat-window { right: 8px; left: 8px; width: auto; max-width: none; bottom: 80px; height: calc(100vh - 100px); }
  #tw-chat-fab { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #tw-chat-fab .tw-icon-g1, #tw-chat-fab .tw-icon-g2, .tw-header-dot { animation: none !important; }
}
