/* ─── CHATBOT WIDGET ────────────────────────────────────────────────────────
 * Floating AI consultation assistant — abdialamir.com
 * Crimson / red premium palette  ·  dark glass panel  ·  crimson accents
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── Container ───────────────────────────────────────────────────────────── */
#chatbot-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 16px;
}

/* ── Floating toggle — cinematic HUD command panel ───────────────────────── */
#chatbot-toggle {
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 72px;
  padding: 0;
  border: none;
  cursor: pointer;
  font-family: inherit;
  position: relative;
  overflow: hidden;
  white-space: nowrap;

  /* Large-chamfer angular frame — hex geometry */
  clip-path: polygon(
    18px 0%, calc(100% - 18px) 0%,
    100% 18px, 100% calc(100% - 18px),
    calc(100% - 18px) 100%, 18px 100%,
    0% calc(100% - 18px), 0% 18px
  );

  /* Dark glass + neon accent lines fading from corners toward center */
  background:
    linear-gradient(90deg,
      rgba(220, 38, 38, 0.82) 0%,
      rgba(220, 38, 38, 0.30) 18%,
      transparent              44%,
      rgba(220, 38, 38, 0.30) 82%,
      rgba(220, 38, 38, 0.82) 100%
    ) top    / 100% 1.5px no-repeat,
    linear-gradient(90deg,
      rgba(220, 38, 38, 0.82) 0%,
      rgba(220, 38, 38, 0.30) 18%,
      transparent              44%,
      rgba(220, 38, 38, 0.30) 82%,
      rgba(220, 38, 38, 0.82) 100%
    ) bottom / 100% 1.5px no-repeat,
    rgba(4, 2, 8, 0.97);

  /* Primary inset neon border + interior ambient */
  box-shadow:
    inset 0 0 0 1.5px rgba(220, 38, 38, 0.72),
    inset 0 0 32px   rgba(220, 38, 38, 0.06);

  /* Outer glow + floor reflection beneath the panel */
  filter:
    drop-shadow(0 0  8px rgba(220, 38, 38, 0.72))
    drop-shadow(0 0 22px rgba(220, 38, 38, 0.40))
    drop-shadow(0 0 52px rgba(220, 38, 38, 0.14))
    drop-shadow(0 10px 28px rgba(220, 38, 38, 0.26));

  transition: filter 0.30s ease, transform 0.22s ease;
}

/* Diagonal light sweep shimmer */
#chatbot-toggle::before {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 55%; height: 100%;
  background: linear-gradient(
    106deg,
    transparent              18%,
    rgba(220, 70, 70, 0.09) 50%,
    transparent              82%
  );
  animation: cs-shimmer 6s linear infinite;
  pointer-events: none;
  z-index: 1;
}

/* Secondary inner rectangular border — layered HUD depth */
#chatbot-toggle::after {
  content: '';
  position: absolute;
  inset: 3px;
  box-shadow: inset 0 0 0 0.5px rgba(220, 38, 38, 0.20);
  pointer-events: none;
  z-index: 1;
}

@keyframes cs-shimmer {
  0%   { left: -100%; }
  100% { left: 160%;  }
}

#chatbot-toggle:hover {
  transform: translateY(-1px);
  filter:
    drop-shadow(0 0 14px rgba(220, 38, 38, 0.95))
    drop-shadow(0 0 36px rgba(220, 38, 38, 0.56))
    drop-shadow(0 0 76px rgba(220, 38, 38, 0.22))
    drop-shadow(0 14px 36px rgba(220, 38, 38, 0.38));
}

/* Slow glow pulse when panel is closed */
@keyframes chatbot-glow-pulse {
  0%, 100% {
    filter:
      drop-shadow(0 0  8px rgba(220, 38, 38, 0.72))
      drop-shadow(0 0 22px rgba(220, 38, 38, 0.40))
      drop-shadow(0 0 52px rgba(220, 38, 38, 0.14))
      drop-shadow(0 10px 28px rgba(220, 38, 38, 0.26));
  }
  50% {
    filter:
      drop-shadow(0 0 15px rgba(220, 38, 38, 1.00))
      drop-shadow(0 0 40px rgba(220, 38, 38, 0.64))
      drop-shadow(0 0 82px rgba(220, 38, 38, 0.26))
      drop-shadow(0 14px 38px rgba(220, 38, 38, 0.44));
  }
}

#chatbot-toggle[aria-expanded="false"] {
  animation: chatbot-glow-pulse 3.4s ease-in-out infinite;
}
#chatbot-toggle[aria-expanded="true"] {
  animation: none;
}

/* ── Left HUD compartment — targeting reticle + diagonal separator ────────── */
.chatbot-hud-left {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  flex-shrink: 0;
  position: relative;
  border-right: 1px solid rgba(220, 38, 38, 0.40);
  background: linear-gradient(
    145deg,
    rgba(220, 38, 38, 0.20) 0%,
    rgba(220, 38, 38, 0.06) 55%,
    transparent 100%
  );
  z-index: 2;
}

/* Diagonal accent streak bleeding into the text area */
.chatbot-hud-left::after {
  content: '';
  position: absolute;
  top: 0;
  right: -24px;
  width: 48px;
  height: 100%;
  background: linear-gradient(
    148deg,
    transparent             40%,
    rgba(220, 38, 38, 0.24) 48%,
    rgba(220, 38, 38, 0.08) 54%,
    transparent             64%
  );
  pointer-events: none;
  z-index: 0;
}

/* ── Targeting reticle icon ──────────────────────────────────────────────── */
.chatbot-hud-target {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(220, 38, 38, 0.75);
  box-shadow: 0 0 10px rgba(220, 38, 38, 0.38);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: 1;
}

/* Outer dim targeting ring */
.chatbot-hud-target::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 0.5px solid rgba(220, 38, 38, 0.20);
  pointer-events: none;
}

/* Horizontal crosshair line */
.chatbot-hud-target::after {
  content: '';
  position: absolute;
  left: -8px; right: -8px;
  top: 50%; transform: translateY(-50%);
  height: 0.5px;
  background: rgba(220, 38, 38, 0.28);
  pointer-events: none;
}

/* Center dot */
.chatbot-hud-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.95);
  box-shadow: 0 0 6px rgba(220, 38, 38, 0.65);
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

/* ── Two-line center label ───────────────────────────────────────────────── */
.chatbot-toggle-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
  padding: 0 16px;
  position: relative;
  z-index: 2;
  min-width: 0;
}

.chatbot-toggle-line1 {
  font-size: 0.60rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(220, 38, 38, 0.90);
  line-height: 1;
  white-space: nowrap;
}

.chatbot-toggle-line2 {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(248, 250, 252, 0.96);
  line-height: 1;
  white-space: nowrap;
}

/* ── Right HUD compartment — diagonal accent + arrow in bracket frame ────── */
.chatbot-hud-right {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  flex-shrink: 0;
  position: relative;
  border-left: 1px solid rgba(220, 38, 38, 0.40);
  /* Corner bracket marks: top-left and bottom-right L-marks */
  background-image:
    linear-gradient(rgba(220, 38, 38, 0.62), rgba(220, 38, 38, 0.62)),
    linear-gradient(rgba(220, 38, 38, 0.62), rgba(220, 38, 38, 0.62)),
    linear-gradient(rgba(220, 38, 38, 0.62), rgba(220, 38, 38, 0.62)),
    linear-gradient(rgba(220, 38, 38, 0.62), rgba(220, 38, 38, 0.62));
  background-size:    11px 1.5px, 1.5px 11px, 11px 1.5px, 1.5px 11px;
  background-position:
    top    9px left  7px,
    top    9px left  7px,
    bottom 9px right 7px,
    bottom 9px right 7px;
  background-repeat: no-repeat;
  z-index: 2;
}

/* Diagonal dark accent stripe — angled shadow panel effect */
.chatbot-hud-right::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    148deg,
    rgba(0, 0, 0, 0.30) 0%,
    rgba(0, 0, 0, 0.30) 38%,
    transparent 58%
  );
  pointer-events: none;
  z-index: 0;
}

.chatbot-toggle-arrow {
  font-size: 1.05rem;
  color: rgba(220, 38, 38, 0.92);
  position: relative;
  z-index: 1;
  text-shadow: 0 0 8px rgba(220, 38, 38, 0.55);
  transition: color 0.20s ease, transform 0.20s ease;
}

#chatbot-toggle:hover .chatbot-toggle-arrow {
  color: rgba(252, 165, 165, 0.98);
  transform: translateX(3px);
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */
#chatbot-panel {
  position: absolute;
  bottom: calc(100% + 16px);
  right: 0;
  width: 390px;
  display: flex;
  flex-direction: column;
  background: rgba(7, 7, 13, 0.96);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 20px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.035),
    0 14px 52px rgba(0,   0,   0,   0.72),
    0  0  76px rgba(220, 38, 38, 0.07);
  overflow: hidden;

  /* Closed state */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition:
    opacity   0.28s ease,
    transform 0.28s var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

#chatbot-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(220, 38, 38, 0.16);
  background: linear-gradient(
    180deg,
    rgba(220, 38, 38, 0.10) 0%,
    transparent 100%
  );
  flex-shrink: 0;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatbot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.72);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

.chatbot-header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chatbot-title {
  font-size: 0.925rem;
  font-weight: 680;
  color: #f8fafc;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.chatbot-subtitle {
  font-size: 0.70rem;
  color: rgba(148, 163, 184, 0.68);
  line-height: 1.2;
}

#chatbot-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(148, 163, 184, 0.65);
  padding: 0;
  border-radius: 6px;
  transition: color 0.16s ease, background 0.16s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

#chatbot-close:hover {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.08);
}

/* ── Messages area ───────────────────────────────────────────────────────── */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  max-height: 290px;
  scroll-behavior: smooth;
}

#chatbot-messages::-webkit-scrollbar { width: 4px; }
#chatbot-messages::-webkit-scrollbar-track  { background: transparent; }
#chatbot-messages::-webkit-scrollbar-thumb  {
  background: rgba(220, 38, 38, 0.28);
  border-radius: 4px;
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.chat-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.865rem;
  line-height: 1.52;
  animation: chat-msg-in 0.22s ease both;
}

@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

.chat-msg--assistant {
  background: rgba(22, 22, 36, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.07);
  color: rgba(226, 232, 240, 0.92);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg--user {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 14px rgba(220, 38, 38, 0.30);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.chat-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 14px;
  background: rgba(22, 22, 36, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 62px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(220, 38, 38, 0.78);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.20s; }
.chat-typing span:nth-child(3) { animation-delay: 0.40s; }

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.82); }
  30%            { opacity: 1;   transform: scale(1.15); }
}

/* ── Quick prompt chips ──────────────────────────────────────────────────── */
.chatbot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 10px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.chatbot-chip {
  background: transparent;
  border: 1px solid rgba(220, 38, 38, 0.32);
  border-radius: 20px;
  color: rgba(248, 113, 113, 0.88);
  font-family: inherit;
  font-size: 0.71rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background   0.16s ease,
    border-color 0.16s ease,
    color        0.16s ease;
}

.chatbot-chip:hover {
  background: rgba(220, 38, 38, 0.14);
  border-color: rgba(220, 38, 38, 0.60);
  color: #fca5a5;
}

/* ── Input row ───────────────────────────────────────────────────────────── */
.chatbot-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.065);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.22);
}

#chatbot-input {
  flex: 1;
  background: rgba(16, 16, 28, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 10px;
  color: #f1f5f9;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  min-width: 0;
}

#chatbot-input::placeholder { color: rgba(148, 163, 184, 0.38); }

#chatbot-input:focus {
  border-color: rgba(220, 38, 38, 0.44);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.09);
}

#chatbot-send {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.18s ease;
  box-shadow: 0 2px 14px rgba(220, 38, 38, 0.36);
}

#chatbot-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 22px rgba(220, 38, 38, 0.60);
}

#chatbot-send svg { pointer-events: none; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chatbot-widget {
    bottom: 20px;
    right: 16px;
  }

  #chatbot-panel {
    width: calc(100vw - 32px);
    max-height: 70vh;
  }

  /* HUD command panel — compact on narrow mobile */
  #chatbot-toggle { height: 60px; }
  .chatbot-hud-left  { width: 50px; }
  .chatbot-hud-right { width: 46px; }
  .chatbot-hud-target { width: 22px; height: 22px; }
  .chatbot-toggle-label { padding: 0 12px; gap: 4px; }
  .chatbot-toggle-line1 { font-size: 0.52rem; letter-spacing: 0.10em; }
  .chatbot-toggle-line2 { font-size: 0.68rem; letter-spacing: 0.08em; }
}

/* ── Input lock state (during API call) ──────────────────────────────────── */
#chatbot-input:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

#chatbot-send:disabled {
  opacity: 0.40;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ── Streaming text reveal — block cursor blink ──────────────────────────── */
.chat-msg--streaming::after {
  content: '▋';
  font-size: 0.72em;
  color: rgba(220, 38, 38, 0.65);
  animation: cursor-blink 0.60s step-end infinite;
  margin-left: 1px;
  vertical-align: middle;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Error bubble ────────────────────────────────────────────────────────── */
.chat-msg--error {
  background: rgba(28, 8, 8, 0.92);
  border: 1px solid rgba(220, 38, 38, 0.28);
  color: rgba(252, 165, 165, 0.85);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-retry-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid rgba(220, 38, 38, 0.38);
  border-radius: 6px;
  color: rgba(248, 113, 113, 0.80);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.70rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 11px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.chat-retry-btn:hover {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.60);
  color: rgba(252, 165, 165, 0.95);
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #chatbot-toggle[aria-expanded="false"] { animation: none; }
  #chatbot-toggle::before               { animation: none; }
  #chatbot-panel  { transition: opacity 0.01s; }
  .chat-msg       { animation: none; }
  .chat-msg--streaming::after { animation: none; }
  .chat-typing span { animation: none; opacity: 0.6; }
  .chatbot-dot    { animation: none; }
  .chatbot-toggle-arrow { transition: none; }
  .chatbot-hud-target   { box-shadow: none; }
  .chatbot-hud-dot      { box-shadow: none; }
  .chatbot-toggle-arrow { text-shadow: none; }
}
