/* IEUM AI agent — Spotlight-style floating glass palette. */

.agent-root {
  position: fixed;
  z-index: 80;
  width: min(660px, calc(100vw - 32px));
  transition: width 0.34s cubic-bezier(0.33, 1, 0.68, 1);
}
/* On page load, restore saved state with no transitions (no flash). */
.agent-preload,
.agent-preload .agent-panel,
.agent-preload .agent-sidebar,
.agent-preload .agent-msgs-wrap,
.agent-preload .agent-msgs,
.agent-preload .agent-head { transition: none !important; }
.agent-root.agent-snap {
  transition: left 0.32s cubic-bezier(0.2, 0.7, 0.2, 1),
    top 0.32s cubic-bezier(0.2, 0.7, 0.2, 1),
    bottom 0.32s cubic-bezier(0.2, 0.7, 0.2, 1),
    width 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.agent-root.agent-large { width: min(780px, calc(100vw - 32px)); }
/* Widen to fit the sidebar when it opens (only meaningful when expanded). */
.agent-root.agent-open.agent-sidebar-open { width: min(880px, calc(100vw - 32px)); }
.agent-root.agent-open.agent-large.agent-sidebar-open { width: min(1000px, calc(100vw - 32px)); }
.agent-root[hidden] { display: none; }

.agent-panel {
  display: flex;
  flex-direction: row;
  border-radius: 18px;
  background: rgba(2, 4, 8, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  box-shadow: 0 24px 70px -18px rgba(0, 0, 0, 0.75), 0 0 40px -20px rgba(79, 140, 255, 0.3);
  overflow: hidden;
  transform-origin: bottom center;
  transition: opacity 0.26s ease, transform 0.34s cubic-bezier(0.33, 1, 0.68, 1);
}
.agent-root.agent-dragging .agent-panel { transition: none; }
.agent-root.agent-dragging .agent-panel {
  box-shadow: 0 34px 90px -18px rgba(0, 0, 0, 0.85), 0 0 60px -18px rgba(79, 140, 255, 0.55);
}
/* panel appear / disappear (hide, show, ⌘K) */
.agent-root.agent-dismissing .agent-panel {
  opacity: 0;
  transform: translateY(16px) scale(0.965);
  pointer-events: none;
}
.agent-main {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* sidebar — width animates 0 -> 240 so it slides open next to the chat */
.agent-sidebar {
  position: relative;
  width: 0;
  flex: none;
  overflow: hidden;
  transition: width 0.34s cubic-bezier(0.33, 1, 0.68, 1);
}
.agent-root.agent-open.agent-sidebar-open .agent-sidebar { width: 240px; }
.agent-sidebar-inner {
  /* Absolutely positioned so the recents list can NEVER set the panel's
     height: otherwise collapsing the chat leaves the pill stretched to the
     sidebar's content height — a big empty glass area under the input. */
  position: absolute;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: 240px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.22);
}
.agent-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 12px 12px 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.agent-sidebar-title {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
}
.agent-newchat {
  border: 1px solid rgba(140, 175, 240, 0.28);
  background: rgba(110, 168, 255, 0.1);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s;
}
.agent-newchat:hover { background: rgba(110, 168, 255, 0.2); border-color: rgba(110, 168, 255, 0.5); }
.agent-side-toggle {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: none;
}
.agent-side-toggle:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }
.agent-root.agent-sidebar-open .agent-side-toggle { color: var(--accent); }

/* header bar (only when expanded) */
.agent-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-height: 0;
  padding: 0 14px;
  opacity: 0;
  overflow: hidden;
  border-bottom: 1px solid transparent;
  cursor: grab;
  user-select: none;
  transition: max-height 0.4s cubic-bezier(0.33, 1, 0.68, 1),
    opacity 0.28s ease, padding 0.4s cubic-bezier(0.33, 1, 0.68, 1),
    border-color 0.4s ease;
}
.agent-root.agent-open .agent-head {
  max-height: 52px;
  padding: 10px 14px;
  opacity: 1;
  border-bottom-color: rgba(255, 255, 255, 0.07);
}
.agent-head:active { cursor: grabbing; }
.agent-head .agent-title {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}
.ieum-mark { display: block; width: 1em; height: 1em; }
.agent-head .agent-star {
  color: #fff;
  font-size: 15px;
  filter: drop-shadow(0 0 7px rgba(160, 195, 255, 0.8));
}
.agent-head-btns { margin-left: auto; display: flex; gap: 4px; }
.agent-head-btns button {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.agent-head-btns button:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }

/* messages — grid 0fr→1fr reveal animates to the real content height, so the
   growth is smooth for any amount of content (not a fast pop). */
.agent-msgs-wrap {
  display: grid;
  grid-template-rows: 0fr;
  max-height: 44vh;
  transition: grid-template-rows 0.44s cubic-bezier(0.33, 1, 0.68, 1);
}
.agent-root.agent-open .agent-msgs-wrap { grid-template-rows: 1fr; }
.agent-root.agent-large .agent-msgs-wrap { max-height: 66vh; }
.agent-msgs {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 0;
  padding: 0 var(--sp-4);
  opacity: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  transition: opacity 0.3s ease, padding 0.4s cubic-bezier(0.33, 1, 0.68, 1);
}
.agent-root.agent-open .agent-msgs { opacity: 1; padding: var(--sp-4); }
/* while free-resizing, follow the pointer immediately (no lag) */
.agent-root.agent-resizing .agent-msgs-wrap { transition: none; }
.agent-root.agent-resizing { transition: none; }

.agent-msg { max-width: 86%; font-size: var(--text-sm); line-height: 1.6; white-space: pre-wrap; }
.agent-msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, 0.3);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 14px;
}
.agent-msg.bot { align-self: flex-start; color: var(--ink); }
.agent-msg.bot .muted-note { color: var(--ink-muted); }

.agent-cards { display: flex; flex-direction: column; gap: 6px; align-self: stretch; }
.agent-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  text-align: left;
  width: 100%;
  color: var(--ink);
  font: inherit;
}
.agent-card:hover {
  border-color: rgba(110, 168, 255, 0.45);
  background: rgba(79, 140, 255, 0.08);
  transform: translateY(-1px);
}
.agent-card .ac-star { color: #fff; font-size: 13px; flex: none; opacity: 0.85; }
.agent-card .ac-body { min-width: 0; flex: 1; }
.agent-card .ac-name { font-size: var(--text-sm); font-weight: 600; }
.agent-card .ac-sub {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-card .ac-meta { flex: none; font-size: var(--text-xs); color: var(--ink-faint); }

/* recents list — lives inside the sidebar */
.agent-recents {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
}
.agent-clear-all {
  margin: 6px 4px 2px;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-size: var(--text-xs);
  padding: 7px 8px;
  border-radius: 8px;
  text-align: center;
  transition: color 0.2s, background 0.2s;
}
.agent-clear-all:hover { background: rgba(255, 90, 95, 0.12); color: var(--danger); }
.agent-recents-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--ink-faint);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.agent-recent {
  display: flex;
  align-items: stretch;
  border-radius: 11px;
  overflow: hidden;
  transition: background 0.2s;
}
.agent-recent:hover { background: rgba(255, 255, 255, 0.045); }
.agent-recent.current { background: var(--accent-soft); }
/* new conversation slides + fades in */
.agent-recent.agent-recent-new { animation: agent-row-in 0.34s cubic-bezier(0.33, 1, 0.68, 1); }
@keyframes agent-row-in {
  from { opacity: 0; transform: translateX(-10px); max-height: 0; }
  to { opacity: 1; transform: translateX(0); max-height: 60px; }
}
/* deleted conversation collapses + fades out */
.agent-recent.agent-recent-removing {
  opacity: 0;
  transform: translateX(24px);
  max-height: 0 !important;
  margin: 0;
  transition: opacity 0.22s ease, transform 0.24s ease, max-height 0.24s ease;
  pointer-events: none;
}
.agent-recent-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--ink);
  font: inherit;
}
.agent-recent-open .ar-title {
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-recent-open .ar-time {
  font-size: 11px;
  color: var(--ink-faint);
}
.agent-recent-del {
  flex: none;
  width: 34px;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-size: 12px;
  border-radius: 0 11px 11px 0;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, background 0.2s;
}
.agent-recent:hover .agent-recent-del { opacity: 1; }
.agent-recent-del:hover { color: var(--danger); background: rgba(255, 90, 95, 0.12); }

.agent-typing { display: flex; gap: 4px; padding: 4px 2px; }
.agent-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: agent-blink 1.2s infinite;
}
.agent-typing i:nth-child(2) { animation-delay: 0.2s; }
.agent-typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes agent-blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* input row — always visible; this IS the pill when collapsed */
.agent-form {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 13px 16px;
}
.agent-root.agent-open .agent-form { border-top: 1px solid rgba(255, 255, 255, 0.07); }
.agent-grip {
  color: #fff;
  font-size: 19px;
  cursor: grab;
  filter: drop-shadow(0 0 9px rgba(160, 195, 255, 0.85));
  flex: none;
  padding: 2px;
  user-select: none;
}
.agent-grip:active { cursor: grabbing; }
.agent-form input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: none;
  color: var(--ink);
  font-size: var(--text-base);
}
.agent-form input::placeholder { color: var(--ink-faint); }
.agent-kbd {
  flex: none;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 2px 7px;
}
.agent-send {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #06101f;
  font-size: 16px;
  font-weight: 700;
  display: grid;
  place-items: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.agent-send:hover { transform: translateY(-1px); box-shadow: var(--glow-blue-sm); }
.agent-send:disabled { opacity: 0.45; transform: none; box-shadow: none; }

/* snap ghost — glowing light frame */
.agent-ghost {
  position: fixed;
  z-index: 79;
  border-radius: 18px;
  border: 1.5px solid rgba(150, 190, 255, 0.85);
  background: radial-gradient(120% 120% at 50% 100%, rgba(79, 140, 255, 0.10), transparent 70%);
  box-shadow:
    0 0 22px -2px rgba(110, 168, 255, 0.55),
    0 0 60px -10px rgba(79, 140, 255, 0.45),
    inset 0 0 26px -8px rgba(110, 168, 255, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  animation: agent-ghost-pulse 1.4s ease-in-out infinite;
}
.agent-ghost.show { opacity: 1; }

/* full-viewport shield during drag/resize: blocks background hover + selection */
.agent-shield {
  position: fixed;
  inset: 0;
  z-index: 78;
  display: none;
}
.agent-shield.show { display: block; }
.agent-shield.dragging { cursor: grabbing; }
.agent-shield.resizing { cursor: nwse-resize; }

/* free-resize handles — one per corner, shown when open */
.agent-resize {
  position: absolute;
  width: 18px;
  height: 18px;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.2s;
}
.agent-root.agent-open .agent-resize { opacity: 1; }
.agent-resize.nw { top: 0; left: 0; cursor: nwse-resize; }
.agent-resize.ne { top: 0; right: 0; cursor: nesw-resize; }
.agent-resize.sw { bottom: 0; left: 0; cursor: nesw-resize; }
.agent-resize.se { bottom: 0; right: 0; cursor: nwse-resize; }
.agent-resize::before {
  content: "";
  position: absolute;
  width: 7px;
  height: 7px;
  border-top: 2px solid rgba(180, 205, 255, 0.55);
  border-left: 2px solid rgba(180, 205, 255, 0.55);
}
.agent-resize.nw::before { top: 6px; left: 6px; transform: rotate(0deg); }
.agent-resize.ne::before { top: 6px; right: 6px; transform: rotate(90deg); }
.agent-resize.sw::before { bottom: 6px; left: 6px; transform: rotate(-90deg); }
.agent-resize.se::before { bottom: 6px; right: 6px; transform: rotate(180deg); }
.agent-resize:hover::before { border-color: rgba(180, 205, 255, 0.95); }
/* Interactive controls sit above the corner handles so they stay clickable. */
.agent-head-btns button,
.agent-side-toggle,
.agent-grip,
.agent-send { position: relative; z-index: 5; }

/* empty-state greeting (shown when a fresh chat is expanded) */
.agent-greeting {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 20px 0;
  color: var(--ink-muted);
}
.agent-greeting-mark {
  color: #fff;
  font-size: 26px;
  filter: drop-shadow(0 0 12px rgba(160, 195, 255, 0.7));
  opacity: 0.9;
}
.agent-greeting p { margin: 0; font-size: var(--text-base); color: var(--ink); font-weight: 500; }
.agent-greeting-sub { font-size: var(--text-xs); color: var(--ink-faint); }
@keyframes agent-ghost-pulse {
  0%, 100% { box-shadow: 0 0 22px -2px rgba(110, 168, 255, 0.55), 0 0 60px -10px rgba(79, 140, 255, 0.45), inset 0 0 26px -8px rgba(110, 168, 255, 0.5); }
  50% { box-shadow: 0 0 30px 0 rgba(110, 168, 255, 0.75), 0 0 80px -8px rgba(79, 140, 255, 0.6), inset 0 0 34px -6px rgba(110, 168, 255, 0.65); }
}

@media (max-width: 640px) {
  .agent-kbd { display: none; }
  /* Scope to the open state so the pill still collapses (and animates) on mobile. */
  .agent-root.agent-open .agent-msgs { max-height: 52vh; }
  /* Narrow screens: sidebar overlays the chat instead of squeezing it. */
  .agent-root.agent-open.agent-sidebar-open,
  .agent-root.agent-open.agent-large.agent-sidebar-open { width: min(660px, calc(100vw - 32px)); }
  .agent-panel { position: relative; }
  .agent-root.agent-open.agent-sidebar-open .agent-sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: 78%;
    max-width: 300px;
    z-index: 2;
    background: rgba(6, 9, 16, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
}
