/* ==========================================================
   HGP Floating Chat + Ghost Chat Cleanup
   Frontend-only. Does not touch data/server/business logic.
   ========================================================== */

/* Hide old broken/ghost chat text or panels after JS tags them */
[data-hgp-chat-ghost="true"],
.hgp-chat-ghost-hidden{
  display:none !important;
  visibility:hidden !important;
  opacity:0 !important;
  pointer-events:none !important;
}

/* Also suppress obvious old chat shells if they exist */
body > .chat,
body > #chat,
body > .chat-box,
body > .chat-panel,
body > .chat-shell,
body > .chat-banner,
body > .command-chat,
body > .command-chat-panel,
body > .hgp-chat-overlay:not(.hgp-chat-bubble-root){
  display:none !important;
}

/* Floating bubble root */
.hgp-chat-bubble-root{
  position:fixed;
  right:22px;
  bottom:22px;
  z-index:999999;
  font-family:Orbitron, "Share Tech Mono", Consolas, monospace;
  color:#ecfdff;
}

/* Floating button */
.hgp-chat-bubble-button{
  width:68px;
  height:68px;
  border-radius:50%;
  border:1px solid rgba(80,235,255,.75);
  background:
    radial-gradient(circle at 35% 28%, rgba(255,255,255,.28), transparent 22%),
    linear-gradient(145deg, rgba(0,190,255,.92), rgba(12,48,88,.96) 54%, rgba(8,12,28,.98));
  box-shadow:
    0 0 18px rgba(61,233,255,.55),
    0 0 38px rgba(61,233,255,.22),
    inset 0 0 22px rgba(255,255,255,.12);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  user-select:none;
  transition:transform .18s ease, box-shadow .18s ease, filter .18s ease;
}

.hgp-chat-bubble-button:hover{
  transform:translateY(-2px) scale(1.04);
  filter:brightness(1.1);
  box-shadow:
    0 0 24px rgba(61,233,255,.68),
    0 0 52px rgba(61,233,255,.30),
    inset 0 0 24px rgba(255,255,255,.16);
}

.hgp-chat-bubble-icon{
  font-size:30px;
  line-height:1;
  text-shadow:0 0 12px rgba(255,255,255,.55);
}

.hgp-chat-bubble-pulse{
  position:absolute;
  right:2px;
  top:2px;
  width:15px;
  height:15px;
  border-radius:50%;
  background:#52ffb2;
  box-shadow:0 0 12px rgba(82,255,178,.95);
}

/* Panel */
.hgp-chat-panel{
  position:absolute;
  right:0;
  bottom:82px;
  width:min(420px, calc(100vw - 36px));
  max-height:min(620px, calc(100vh - 120px));
  display:none;
  flex-direction:column;
  overflow:hidden;
  border-radius:18px;
  border:1px solid rgba(80,235,255,.58);
  background:
    linear-gradient(180deg, rgba(5,21,38,.96), rgba(3,8,18,.96)),
    radial-gradient(circle at 80% 0%, rgba(0,220,255,.14), transparent 30%);
  box-shadow:
    0 0 30px rgba(61,233,255,.25),
    0 0 80px rgba(0,0,0,.45),
    inset 0 0 28px rgba(61,233,255,.08);
  backdrop-filter:blur(14px) saturate(1.25);
  -webkit-backdrop-filter:blur(14px) saturate(1.25);
}

.hgp-chat-bubble-root.is-open .hgp-chat-panel{
  display:flex;
}

.hgp-chat-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 15px;
  border-bottom:1px solid rgba(80,235,255,.25);
  background:rgba(0,0,0,.22);
}

.hgp-chat-title{
  display:flex;
  flex-direction:column;
  gap:3px;
}

.hgp-chat-title strong{
  font-size:14px;
  letter-spacing:.08em;
  color:#ffffff;
}

.hgp-chat-title span{
  font-size:11px;
  letter-spacing:.04em;
  color:rgba(196,239,255,.78);
}

.hgp-chat-close{
  width:34px;
  height:34px;
  border-radius:10px;
  border:1px solid rgba(80,235,255,.35);
  background:rgba(255,255,255,.06);
  color:#ecfdff;
  cursor:pointer;
  font-size:20px;
  line-height:1;
}

.hgp-chat-status{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
  padding:12px 14px;
  border-bottom:1px solid rgba(80,235,255,.16);
}

.hgp-chat-status-card{
  border:1px solid rgba(80,235,255,.25);
  background:rgba(0,0,0,.18);
  border-radius:12px;
  padding:9px;
}

.hgp-chat-status-card .k{
  font-size:10px;
  color:#89f3ff;
  letter-spacing:.08em;
  text-transform:uppercase;
}

.hgp-chat-status-card .v{
  margin-top:4px;
  font-size:13px;
  color:#55ffb3;
}

.hgp-chat-messages{
  padding:14px;
  overflow:auto;
  max-height:310px;
  min-height:180px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.hgp-chat-msg{
  border:1px solid rgba(80,235,255,.18);
  background:rgba(0,0,0,.24);
  border-radius:14px;
  padding:10px 11px;
  font-size:13px;
  line-height:1.45;
  color:#eafdff;
}

.hgp-chat-msg.user{
  margin-left:28px;
  border-color:rgba(82,255,178,.28);
  background:rgba(0,85,58,.20);
}

.hgp-chat-msg.system{
  margin-right:28px;
}

.hgp-chat-msg.error{
  border-color:rgba(255,86,141,.35);
  color:#ffdce8;
  background:rgba(130,0,50,.16);
}

.hgp-chat-input-wrap{
  padding:12px 14px 14px;
  border-top:1px solid rgba(80,235,255,.16);
  display:grid;
  gap:9px;
}

.hgp-chat-input{
  width:100%;
  min-height:88px;
  resize:vertical;
  border-radius:12px;
  border:1px solid rgba(80,235,255,.35);
  background:rgba(0,0,0,.26);
  color:#ecfdff;
  padding:10px;
  font-size:14px;
  line-height:1.45;
  font-family:"Share Tech Mono", Consolas, monospace;
}

.hgp-chat-actions{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:9px;
}

.hgp-chat-send,
.hgp-chat-telegram{
  min-height:40px;
  border-radius:12px;
  border:1px solid rgba(80,235,255,.45);
  background:linear-gradient(180deg, rgba(0,190,255,.24), rgba(6,25,46,.90));
  color:#f2fdff;
  cursor:pointer;
  font-size:12px;
  letter-spacing:.06em;
  font-weight:700;
  text-transform:uppercase;
}

.hgp-chat-telegram{
  border-color:rgba(82,255,178,.38);
  background:linear-gradient(180deg, rgba(82,255,178,.18), rgba(6,34,36,.92));
}

.hgp-chat-footnote{
  font-size:11px;
  line-height:1.35;
  color:rgba(208,237,247,.68);
}

@media(max-width:760px){
  .hgp-chat-bubble-root{
    right:14px;
    bottom:14px;
  }

  .hgp-chat-bubble-button{
    width:58px;
    height:58px;
  }

  .hgp-chat-panel{
    bottom:72px;
  }
}