/* ── Layout ── */
.chat-layout {
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle, rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(160deg, rgba(60,80,220,0.14) 0%, transparent 50%, rgba(199,64,64,0.13) 100%),
    #04040f;
  background-size: 28px 28px, auto, auto;
  overflow: hidden;
  position: relative;
}

/* scanline overlay */
.chat-layout::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.07) 2px,
    rgba(0,0,0,0.07) 4px
  );
  pointer-events: none;
  z-index: 0;
}

.chat-layout > * { position: relative; z-index: 1; }

/* ── Header bar ── */
.chat-top {
  flex-shrink: 0;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, transparent 0%, rgba(33,50,180,0.55) 30%, transparent 55%, rgba(199,64,64,0.5) 80%, transparent 100%) 1;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: rgba(4,4,15,0.6);
  backdrop-filter: blur(8px);
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgb(60,80,220) 0%, rgb(140,45,155) 55%, rgb(199,64,64) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: 0 0 14px rgba(60,80,220,0.45), 0 0 10px rgba(199,64,64,0.25), inset 0 1px 0 rgba(255,255,255,0.12);
  border: 1px solid rgba(199,64,64,0.3);
}

.chat-top-info h2 {
  font-size: 0.9rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  letter-spacing: 0.5px;
  position: relative;
  padding-bottom: 4px;
}

.chat-top-info h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, rgb(60,80,220), rgb(199,64,64));
  border-radius: 1px;
  opacity: 0.7;
}

.chat-top-info h2 span {
  color: rgb(199,64,64);
  text-shadow: 0 0 10px rgba(199,64,64,0.55);
}

.chat-top-info p {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.28);
  margin-top: 3px;
  letter-spacing: 0.3px;
}

.chat-top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.68rem;
  color: rgba(255,255,255,0.25);
  letter-spacing: 0.5px;
}

.chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgb(80,200,120);
  box-shadow: 0 0 6px rgba(80,200,120,0.8);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* TTS toggle button */
.tts-toggle {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-size: 0.85rem;
}

.tts-toggle:hover  { border-color: rgba(60,80,220,0.4); color: rgba(255,255,255,0.7); }
.tts-toggle.active { border-color: rgba(60,80,220,0.6); background: rgba(60,80,220,0.15); color: rgb(120,140,255); }

/* ── Messages area ── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar { width: 3px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(to bottom, rgba(60,80,220,0.35), rgba(199,64,64,0.2));
  border-radius: 2px;
}

/* ── Message bubbles ── */
.msg {
  display: flex;
  gap: 0.55rem;
  max-width: 80%;
  animation: msg-in 0.18s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg--bot  { align-self: flex-start; }
.msg--user { align-self: flex-end; flex-direction: row-reverse; }

.msg-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  margin-top: 3px;
  overflow: hidden;
}

.msg--bot .msg-icon {
  background: linear-gradient(135deg, rgb(60,80,220) 0%, rgb(140,45,155) 55%, rgb(199,64,64) 100%);
  border: 1px solid rgba(199,64,64,0.3);
  box-shadow: 0 0 10px rgba(60,80,220,0.35), 0 0 6px rgba(199,64,64,0.2);
}

.msg-icon svg {
  width: 80%;
  height: 80%;
}

.msg--user .msg-icon {
  background: rgba(199,64,64,0.12);
  border: 1px solid rgba(199,64,64,0.22);
  font-size: 0.75rem;
}

.msg-bubble {
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  font-size: 0.875rem;
  line-height: 1.6;
  word-break: break-word;
}

.msg--bot .msg-bubble {
  background:
    linear-gradient(rgba(8,8,8,0.82), rgba(8,8,8,0.82)) padding-box,
    linear-gradient(135deg, rgb(60,80,220), transparent 55%, rgba(199,64,64,0.7)) border-box;
  border: 1px solid transparent;
  border-radius: 4px 12px 12px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.35), 0 0 12px rgba(60,80,220,0.08);
  color: rgba(255,255,255,0.85);
}

.msg--user .msg-bubble {
  background:
    linear-gradient(rgba(8,8,8,0.82), rgba(8,8,8,0.82)) padding-box,
    linear-gradient(225deg, rgb(199,64,64), transparent 55%, rgba(60,80,220,0.4)) border-box;
  border: 1px solid transparent;
  border-radius: 12px 4px 12px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.35), 0 0 12px rgba(199,64,64,0.08);
  color: rgba(255,255,255,0.92);
}

/* speak button on bot messages */
.msg-speak {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.2);
  font-size: 0.75rem;
  padding: 0 0 0 0.4rem;
  align-self: flex-end;
  margin-bottom: 2px;
  transition: color 0.15s;
  flex-shrink: 0;
}
.msg-speak:hover   { color: rgba(60,80,220,0.8); }
.msg-speak.playing { color: rgb(100,140,255); animation: speak-pulse 1s ease-in-out infinite; }

@keyframes speak-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Typing indicator */
.msg--typing .msg-bubble { padding: 0.65rem 0.9rem; }

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 1rem;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgb(60,80,220), rgb(199,64,64));
  animation: dot-bounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
  40%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Suggestion chips ── */
#suggestion-wrap {
  flex-shrink: 0;
  padding: 0 1.5rem 0.65rem;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

#suggestion-wrap.hidden { display: none; }

.chip {
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid rgba(60,80,220,0.2);
  background: rgba(60,80,220,0.06);
  color: rgba(255,255,255,0.38);
  font-size: 0.74rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.chip:hover {
  border-color: rgba(199,64,64,0.4);
  background: rgba(199,64,64,0.08);
  color: rgba(255,255,255,0.85);
  box-shadow: 0 0 8px rgba(199,64,64,0.15), 0 0 4px rgba(60,80,220,0.1);
}

/* ── Input bar ── */
.chat-input-bar {
  flex-shrink: 0;
  padding: 0.7rem 1.5rem 1rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  border-top: 1px solid transparent;
  border-image: linear-gradient(90deg, transparent, rgba(60,80,220,0.35) 35%, rgba(199,64,64,0.3) 70%, transparent) 1;
  background: rgba(4,4,15,0.5);
}

#chat-input {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 10px 13px;
  color: #fff;
  font-size: 0.875rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 1.5;
  transition: border-color 0.2s;
  overflow-y: auto;
}

#chat-input:focus {
  border-color: rgba(60,80,220,0.4);
  background: rgba(60,80,220,0.04);
}

#chat-input::placeholder { color: rgba(255,255,255,0.18); }

/* shared icon button style */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.icon-btn svg { width: 17px; height: 17px; }

/* mic button */
#mic-btn:hover     { border-color: rgba(199,64,64,0.4); color: rgba(199,64,64,0.7); }
#mic-btn.recording {
  border-color: rgb(199,64,64);
  background: rgba(199,64,64,0.12);
  color: rgb(220,80,80);
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(199,64,64,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(199,64,64,0); }
}

/* send button */
#send-btn {
  background: linear-gradient(135deg, rgb(60,80,220) 0%, rgb(199,64,64) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 10px rgba(60,80,220,0.3), 0 0 6px rgba(199,64,64,0.15);
}
#send-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, rgb(75,95,235) 0%, rgb(220,75,75) 100%);
  box-shadow: 0 0 16px rgba(60,80,220,0.4), 0 0 10px rgba(199,64,64,0.3);
}
#send-btn:active:not(:disabled) { transform: scale(0.93); }
#send-btn:disabled               { opacity: 0.35; cursor: default; }

/* ── Error banner ── */
.chat-error {
  margin: 0 1.5rem;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  background: rgba(199,64,64,0.08);
  border: 1px solid rgba(199,64,64,0.22);
  border-left: 3px solid rgba(199,64,64,0.6);
  color: rgba(220,100,100,0.9);
  font-size: 0.78rem;
  display: none;
}
.chat-error.show { display: block; }

/* ── Mobile ── */
@media (max-width: 650px) {
  #chat-messages   { padding: 0.9rem 1rem; }
  .chat-input-bar  { padding: 0.6rem 1rem 0.85rem; }
  #suggestion-wrap { padding: 0 1rem 0.5rem; }
  .chat-top        { padding: 0.75rem 1rem; }
  .msg             { max-width: 92%; }
}

/* ── Voice mode overlay ── */
#voice-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(4,4,15,0.97);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
  overflow: hidden;
}
#voice-overlay.active { display: flex; }

/* scanline on overlay */
#voice-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.1) 2px, rgba(0,0,0,0.1) 4px);
  pointer-events: none;
}

/* ── Mainframe circle ── */
.voice-mf-wrap {
  position: relative;
  width: min(72vw, 60vh);
  height: min(72vw, 60vh);
  max-width: 440px;
  max-height: 440px;
}

.voice-mf-wrap svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.vmf-ring, .vmf-scan {
  transform-box: view-box;
  transform-origin: center;
}
.vmf-ring--1 { animation: mfSpinCW  30s linear infinite; }
.vmf-ring--2 { animation: mfSpinCCW 20s linear infinite; }
.vmf-ring--3 { animation: mfSpinCW  14s linear infinite; }
.vmf-ring--4 { animation: mfSpinCCW 38s linear infinite; }
.vmf-scan    { animation: mfSpinCW   6s linear infinite; }
.vmf-pulse   { animation: mfPulse   3s ease-in-out infinite alternate; }

/* state: listening */
#voice-overlay.state-listening .vmf-scan  { animation-duration: 2s; }
#voice-overlay.state-listening .vmf-pulse { animation-duration: 1.4s; }

/* state: thinking */
#voice-overlay.state-thinking .vmf-ring--3 { animation-duration: 4s; }
#voice-overlay.state-thinking .vmf-scan    { animation-duration: 0.9s; }

/* state: speaking */
#voice-overlay.state-speaking .vmf-scan  { animation-duration: 1.2s; }
#voice-overlay.state-speaking .vmf-pulse { animation-duration: 0.7s; }

/* SVG colour overrides per state */
#voice-overlay.state-thinking .vmf-accent       { stroke: rgba(210,160,40,0.8)  !important; }
#voice-overlay.state-thinking .vmf-dot-a        { fill:   rgb(210,160,40)       !important; }
#voice-overlay.state-thinking .vmf-scan-line    { stroke: rgba(210,160,40,0.7)  !important; }
#voice-overlay.state-thinking .vmf-scan-dot     { fill:   rgb(210,160,40)       !important; }
#voice-overlay.state-thinking .vmf-center-fill  { fill:   url(#vmf-glow-gold)   !important; }

#voice-overlay.state-speaking .vmf-accent       { stroke: rgba(60,200,120,0.8)  !important; }
#voice-overlay.state-speaking .vmf-dot-a        { fill:   rgb(60,200,120)       !important; }
#voice-overlay.state-speaking .vmf-scan-line    { stroke: rgba(60,200,120,0.7)  !important; }
#voice-overlay.state-speaking .vmf-scan-dot     { fill:   rgb(60,200,120)       !important; }
#voice-overlay.state-speaking .vmf-center-fill  { fill:   url(#vmf-glow-green)  !important; }

/* ── HUD text elements ── */
.voice-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-line {
  position: absolute;
  font-size: 0.62rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(60,80,220,0.45);
  font-family: 'Stack Sans Text', monospace;
  white-space: nowrap;
}

.hud-line.top-left  { top: 18%; left: 4%; }
.hud-line.top-right { top: 18%; right: 4%; text-align: right; }
.hud-line.bot-left  { bottom: 18%; left: 4%; }
.hud-line.bot-right { bottom: 18%; right: 4%; text-align: right; }

.hud-line span { display: block; line-height: 1.8; }
.hud-val { color: rgba(255,255,255,0.25); }

/* ── Status bar below circle ── */
.voice-status-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
}

.voice-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgb(60,80,220);
  box-shadow: 0 0 8px rgba(60,80,220,0.9);
}
#voice-overlay.state-thinking .voice-status-dot { background: rgb(210,160,40); box-shadow: 0 0 8px rgba(210,160,40,0.9); }
#voice-overlay.state-speaking .voice-status-dot { background: rgb(60,200,120); box-shadow: 0 0 8px rgba(60,200,120,0.9); }

.voice-state-label {
  font-size: 0.72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
}

.voice-transcript {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.65);
  max-width: 380px;
  text-align: center;
  min-height: 1.4rem;
  line-height: 1.55;
  padding: 0 1rem;
}

.voice-hint {
  font-size: 0.66rem;
  color: rgba(255,255,255,0.15);
  letter-spacing: 0.5px;
}

.voice-close {
  position: absolute;
  top: calc(var(--header-height) + 1.2rem);
  right: 1.5rem;
  background: none;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: rgba(255,255,255,0.3);
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.voice-close:hover { color: #fff; border-color: rgba(255,255,255,0.3); }

@media (max-width: 650px) {
  .hud-line      { display: none; }
  .voice-mf-wrap { width: 80vw; height: 80vw; }
}
