/* ═══════════════════════════════════════════════════════════════
   Nyx Terminal — Chat Panel v3
   Clean. One close button. Expands to near-fullscreen.
   ═══════════════════════════════════════════════════════════════ */

/* ── Trigger ─────────────────────────────────────────────── */
.chat-trigger-wrap {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 920;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  animation: trigger-appear 0.8s ease 1.5s forwards;
  transition: opacity 0.3s, transform 0.3s;
}

/* Hide trigger when panel is expanded */
.chat-trigger-wrap.hidden-by-expand {
  opacity: 0 !important;
  pointer-events: none;
  transform: translateY(8px);
}

@keyframes trigger-appear {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-trigger {
  width: 3rem;
  height: 3rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  position: relative;
  cursor: pointer;
}

.chat-trigger--closed {
  background: rgba(15, 10, 28, 0.35);
  backdrop-filter: blur(12px) saturate(1.4) brightness(1.1);
  -webkit-backdrop-filter: blur(12px) saturate(1.4) brightness(1.1);
  border: none;
  color: hsl(268 55% 72%);
  box-shadow:
    0 2px 12px -2px rgba(0,0,0,0.4),
    inset 0 1px 0 0 rgba(200,170,255,0.14);
  animation: breathe 4s ease-in-out infinite;
}

.chat-trigger--closed::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: linear-gradient(170deg, rgba(180,140,255,0.5) 0%, rgba(140,100,230,0.18) 30%, transparent 70%);
  pointer-events: none;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
}

.chat-trigger--closed:hover {
  transform: translateY(-2px);
  animation: none;
  color: hsl(268 60% 82%);
}

.chat-trigger--open {
  background: rgba(15,10,28,0.38);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: none;
  color: hsl(var(--muted-foreground));
  animation: none;
}
.chat-trigger--open::before { display: none; }
.chat-trigger--open:hover { color: hsl(var(--foreground)); }

.chat-trigger__label {
  font-size: 0.5625rem;
  font-family: var(--font-mono);
  color: hsl(268 40% 55% / 0.5);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  transition: opacity 0.3s;
}
.chat-trigger__label.hidden { opacity: 0; }

@keyframes breathe {
  0%, 100% { box-shadow: 0 2px 12px -2px rgba(0,0,0,0.4), inset 0 1px 0 0 rgba(200,170,255,0.12); }
  50%      { box-shadow: 0 4px 18px -2px rgba(0,0,0,0.45), inset 0 1px 0 0 rgba(210,185,255,0.18); }
}

/* ── Backdrop ────────────────────────────────────────────── */
.chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 909;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.chat-backdrop.active {
  display: block;
  animation: fade-in 0.3s ease forwards;
}

/* ── Panel ───────────────────────────────────────────────── */
.chat-panel {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 915;
  width: 370px;
  max-height: 500px;
  border-radius: 0.875rem;
  background: rgba(10, 8, 18, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow:
    0 4px 24px rgba(0,0,0,0.5),
    0 16px 48px -8px rgba(0,0,0,0.35);
  flex-direction: column;
  overflow: hidden;
}

.chat-panel.open {
  display: flex;
  animation: panel-emerge 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes panel-emerge {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Expanded: full area next to sidebar ──────────────────── */
.chat-panel.open.expanded {
  top: 0;
  left: 62px; /* sidebar width */
  right: 0;
  bottom: 0;
  width: auto;
  max-height: none;
  border-radius: 0;
  border: none;
  border-left: 1px solid rgba(255,255,255,0.04);
  animation: panel-fullscreen 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes panel-fullscreen {
  from {
    top: auto; left: auto;
    bottom: 1.25rem; right: 1.25rem;
    width: 370px; max-height: 500px;
    border-radius: 0.875rem;
  }
  to {
    top: 0;
    left: 62px;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: none;
    border-radius: 0;
  }
}

/* ── Header ──────────────────────────────────────────────── */
.chat-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

.chat-header__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: hsl(var(--primary));
  box-shadow: 0 0 6px hsl(268 70% 58% / 0.3);
  flex-shrink: 0;
}

.chat-header__title {
  font-size: 0.8125rem;
  font-family: var(--font-display);
  font-weight: 600;
  color: hsl(var(--foreground));
  margin: 0;
}

.chat-header__sub {
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: hsl(var(--muted-foreground));
  margin: 0;
}

.chat-header__close {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground) / 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.chat-header__close:hover {
  color: hsl(var(--foreground));
  background: rgba(255,255,255,0.04);
}

/* ── Messages ────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.125rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* In expanded, center content with max-width */
.chat-panel.expanded .chat-messages {
  padding: 1.5rem 2rem;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.chat-msg--system {
  font-size: 0.5625rem;
  font-family: var(--font-mono);
  color: hsl(220 8% 46% / 0.3);
  text-align: center;
  padding: 0.25rem 0;
}

.chat-msg--user {
  align-self: flex-end;
  max-width: 75%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem 0.5rem 0.125rem 0.5rem;
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(255,255,255,0.05);
  font-size: 0.8125rem;
  color: hsl(220 15% 90% / 0.85);
}

.chat-msg--assistant {
  align-self: flex-start;
  max-width: 95%;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: rgba(255,255,255,0.015);
  border: 1px solid rgba(255,255,255,0.025);
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  color: hsl(220 15% 90% / 0.75);
  line-height: 1.75;
}

.chat-msg--assistant .prompt-char {
  color: hsl(220 8% 46% / 0.35);
  font-size: 0.6875rem;
}

.chat-msg--assistant strong { color: hsl(var(--foreground) / 0.9); font-weight: 600; }
.chat-msg--assistant code {
  font-size: 0.75rem;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.03);
}
.chat-msg--assistant h4 {
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  color: hsl(var(--foreground) / 0.85);
  margin: 0.75rem 0 0.25rem;
}
.chat-msg--assistant h4:first-child { margin-top: 0; }
.chat-msg--assistant ul, .chat-msg--assistant ol { margin: 0.25rem 0; padding-left: 1.125rem; }
.chat-msg--assistant li { margin: 0.2rem 0; }
.chat-msg--assistant p { margin: 0 0 0.5rem; }
.chat-msg--assistant p:last-child { margin-bottom: 0; }

/* Typing cursor */
.chat-msg--assistant.typing::after {
  content: '';
  display: inline-block;
  width: 1.5px;
  height: 13px;
  background: hsl(220 15% 90% / 0.35);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: cursor-blink 0.9s step-end infinite;
}

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

.chat-msg--meta {
  font-size: 0.5625rem;
  font-family: var(--font-mono);
  color: hsl(220 8% 46% / 0.25);
  padding: 0 1rem;
}

/* ── Tool Pills ──────────────────────────────────────────── */
.chat-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.25rem 0;
}

.chat-tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.625rem;
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
  color: hsl(220 8% 46% / 0.5);
  animation: fade-in 0.2s ease;
}

.chat-tool-pill--live {
  border-color: hsl(268 50% 50% / 0.12);
  color: hsl(268 50% 70% / 0.6);
}

.chat-tool-pill__icon {
  display: flex;
  opacity: 0.4;
}

.chat-tool-pill__name {
  font-weight: 500;
}

.chat-tool-pill__param {
  opacity: 0.5;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-tool-pill__cost {
  opacity: 0.4;
  margin-left: 0.125rem;
}

/* ── Citations ───────────────────────────────────────────── */
.chat-citations {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  padding: 0.375rem 0 0.125rem;
}

.chat-citations__label {
  font-size: 0.5rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: hsl(220 8% 46% / 0.35);
  padding-right: 0.25rem;
}

.chat-citation-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.45rem;
  border-radius: 0.25rem;
  font-size: 0.5625rem;
  font-family: var(--font-mono);
  background: rgba(124, 58, 237, 0.06);
  border: 1px solid rgba(124, 58, 237, 0.12);
  color: hsl(268 50% 72% / 0.7);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  max-width: 220px;
}

.chat-citation-chip:hover {
  background: rgba(124, 58, 237, 0.12);
  border-color: rgba(124, 58, 237, 0.25);
  color: hsl(268 60% 80% / 0.95);
}

.chat-citation-chip__source {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.5rem;
  letter-spacing: 0.06em;
  flex-shrink: 0;
  opacity: 0.7;
}

.chat-citation-chip__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.85;
}

/* ── Inline links in chat ─────────────────────────────────── */
.chat-msg--assistant .chat-link {
  color: hsl(268 60% 72%);
  text-decoration: underline;
  text-decoration-color: hsl(268 60% 72% / 0.3);
  text-underline-offset: 2px;
}

.chat-msg--assistant .chat-link:hover {
  color: hsl(268 70% 82%);
  text-decoration-color: hsl(268 70% 82% / 0.6);
}

/* ── Suggestions ─────────────────────────────────────────── */
.chat-suggestions {
  padding: 0.5rem 1.125rem;
  border-top: 1px solid rgba(255,255,255,0.03);
  display: flex;
  gap: 0.375rem;
  overflow-x: auto;
  flex-shrink: 0;
}

.chat-suggestions::-webkit-scrollbar { height: 0; }

.chat-suggestion {
  flex-shrink: 0;
  padding: 0.375rem 0.625rem;
  border-radius: 0.3rem;
  font-size: 0.625rem;
  font-weight: 500;
  background: rgba(255,255,255,0.02);
  color: hsl(var(--muted-foreground));
  border: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  transition: all 0.15s;
}

.chat-suggestion:hover {
  border-color: rgba(255,255,255,0.08);
  color: hsl(var(--foreground));
}

/* ── Input ───────────────────────────────────────────────── */
.chat-input {
  padding: 0.625rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.03);
  flex-shrink: 0;
}

.chat-panel.expanded .chat-input {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 2rem 1rem;
}

.chat-input__field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem 0.5rem 0.875rem;
  border-radius: 0.5rem;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
  transition: border-color 0.2s;
}

.chat-input__field:focus-within {
  border-color: rgba(255,255,255,0.08);
}

.chat-input__field input:focus {
  outline: none;
  box-shadow: none;
}

.chat-input__field input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 0.8125rem;
  font-family: var(--font-body);
  color: hsl(var(--foreground));
  min-width: 0;
}

.chat-input__field input::placeholder { color: hsl(220 8% 46% / 0.3); }

.chat-input__send {
  width: 26px; height: 26px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  color: hsl(var(--muted-foreground) / 0.6);
  padding: 0;
}

.chat-input__send:hover {
  background: rgba(255,255,255,0.06);
  color: hsl(var(--foreground));
}

/* ── Cite ────────────────────────────────────────────────── */
.chat-cite {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  margin: 0 1rem 0.25rem;
  border-radius: 0.3rem;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
  font-size: 0.625rem;
  font-family: var(--font-mono);
  color: hsl(220 15% 90% / 0.45);
  flex-shrink: 0;
}
.chat-cite.visible { display: flex; }
.chat-cite__text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-cite__close {
  background: transparent; border: none; color: hsl(var(--muted-foreground) / 0.3);
  cursor: pointer; padding: 0; display: flex; transition: color 0.15s;
}
.chat-cite__close:hover { color: hsl(var(--foreground)); }
.chat-cite__close svg { width: 10px; height: 10px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-panel { width: calc(100vw - 2rem); }
  .chat-panel.open.expanded {
    left: 0; top: 0; right: 0; bottom: 0;
    border-radius: 0;
  }
}
