/* ====================================================================
   VCM AI Assistant — floating glass chat widget.
   Loads after glass.css; uses all existing design tokens.
   Works in dark + light mode via var() + [data-mode="light"] overrides.
   ==================================================================== */

/* ---- Launcher button (bottom-right FAB) --------------------------- */
#vcm-chat-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 200;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255,255,255,.18);
  background:
    linear-gradient(155deg, rgba(255,255,255,.28), rgba(255,255,255,.06) 50%),
    linear-gradient(140deg, var(--accent), var(--accent-press));
  color: var(--accent-fg);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.50),
    0 8px 24px color-mix(in srgb, var(--accent) 42%, transparent),
    0 2px 6px rgba(0,0,0,.30);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  overflow: hidden;
  isolation: isolate;
}
#vcm-chat-launcher::after {
  content: "";
  position: absolute;
  left: -25%; top: -60%;
  width: 150%; height: 120%;
  background: radial-gradient(58% 46% at 32% 22%, rgba(255,255,255,.55), transparent 62%);
  opacity: .55;
  pointer-events: none;
  z-index: -1;
}
#vcm-chat-launcher:hover { transform: translateY(-2px); box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 12px 32px color-mix(in srgb, var(--accent) 54%, transparent), 0 3px 8px rgba(0,0,0,.35); }
#vcm-chat-launcher:active { transform: scale(.95); }
#vcm-chat-launcher[aria-expanded="true"] { background: linear-gradient(155deg, rgba(255,255,255,.16), rgba(255,255,255,.04) 50%), var(--surface-3); color: var(--fg-muted); box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 4px 14px rgba(0,0,0,.30); }

/* ---- Chat panel --------------------------------------------------- */
#vcm-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 28px;
  z-index: 199;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  border-radius: var(--radius-xl);
  border: 1px solid var(--lg-edge, rgba(255,255,255,.16));
  background:
    linear-gradient(176deg, var(--lg-sheenA, rgba(255,255,255,.22)), var(--lg-sheenB, rgba(255,255,255,.04)) 34%, transparent 60%),
    var(--glass-3);
  backdrop-filter: blur(28px) saturate(185%);
  -webkit-backdrop-filter: blur(28px) saturate(185%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.45),
    inset 0 -16px 28px rgba(0,0,0,.18),
    0 20px 56px rgba(0,0,0,.50);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* animate in/out */
  transform-origin: bottom right;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
  transform: scale(.88) translateY(12px);
  opacity: 0;
  pointer-events: none;
}
#vcm-chat-panel.open {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

/* ---- Panel header ------------------------------------------------- */
.vcm-chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.vcm-chat-header .vcm-chat-av {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(155deg, rgba(255,255,255,.28), rgba(255,255,255,.06) 50%),
    var(--accent-ghost);
  border: 1px solid rgba(255,255,255,.20);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.50), 0 4px 10px rgba(0,0,0,.25);
  color: var(--accent);
}
.vcm-chat-header .vcm-chat-av::after {
  content: "";
  position: absolute;
  left: -25%; top: -70%;
  width: 150%; height: 130%;
  background: radial-gradient(58% 46% at 32% 22%, rgba(255,255,255,.55), transparent 62%);
  opacity: .55;
  pointer-events: none;
  z-index: -1;
}
.vcm-chat-hinfo { flex: 1; min-width: 0; }
.vcm-chat-hinfo strong { font-size: var(--text-sm); font-weight: var(--w-bold); display: block; }
.vcm-chat-hinfo small { font-size: var(--text-2xs); color: var(--fg-subtle); }
.vcm-chat-close {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--fg-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 13px;
  flex-shrink: 0;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.vcm-chat-close:hover { background: var(--surface-3); color: var(--fg); }

/* ---- Message list ------------------------------------------------- */
.vcm-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}
.vcm-chat-messages::-webkit-scrollbar { width: 6px; }
.vcm-chat-messages::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 999px; }
.vcm-chat-messages::-webkit-scrollbar-track { background: transparent; }

/* ---- Suggested prompts (first-open chips) ------------------------ */
.vcm-chat-suggestions {
  padding: 0 var(--space-4) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex-shrink: 0;
}
.vcm-chat-suggestions .vcm-sug-label {
  font-size: var(--text-2xs);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  font-weight: var(--w-medium);
  margin-bottom: var(--space-1);
}
.vcm-chat-sug-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.vcm-sug-chip {
  font-size: var(--text-xs);
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
  background: var(--accent-ghost);
  color: var(--accent);
  cursor: pointer;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
  text-align: left;
  font-family: inherit;
}
.vcm-sug-chip:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); transform: translateY(-1px); }
.vcm-sug-chip:active { transform: scale(.97); }

/* ---- Message bubbles --------------------------------------------- */
.vcm-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
  animation: vcm-msg-in var(--dur-slow) var(--ease);
}
@keyframes vcm-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.vcm-msg.user { align-self: flex-end; align-items: flex-end; }
.vcm-msg.assistant { align-self: flex-start; align-items: flex-start; }

.vcm-msg-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: var(--text-sm);
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.vcm-msg.user .vcm-msg-bubble {
  background: linear-gradient(140deg, var(--accent), var(--accent-press));
  color: var(--accent-fg);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 36%, transparent);
}
.vcm-msg.assistant .vcm-msg-bubble {
  background:
    linear-gradient(176deg, rgba(255,255,255,.14), rgba(255,255,255,.04) 50%),
    var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.vcm-msg.error .vcm-msg-bubble {
  background: var(--danger-ghost);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
  border-bottom-left-radius: 4px;
}

/* ---- Action chips below assistant reply --------------------------- */
.vcm-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.vcm-action-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-2xs);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
  background: var(--ok-ghost);
  color: var(--ok);
  font-weight: var(--w-medium);
}
.vcm-action-chip.warn {
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
  background: var(--warn-ghost);
  color: var(--warn);
}

/* ---- Typing / loading indicator ---------------------------------- */
.vcm-typing {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  background:
    linear-gradient(176deg, rgba(255,255,255,.14), rgba(255,255,255,.04) 50%),
    var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  align-self: flex-start;
  animation: vcm-msg-in var(--dur-slow) var(--ease);
}
.vcm-typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--fg-subtle);
  animation: vcm-bounce 1.2s ease infinite;
}
.vcm-typing span:nth-child(2) { animation-delay: .2s; }
.vcm-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes vcm-bounce {
  0%, 60%, 100% { transform: none; opacity: .5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- Input row ---------------------------------------------------- */
.vcm-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#vcm-chat-input {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg);
  font-size: var(--text-sm);
  font-family: inherit;
  line-height: 1.45;
  resize: none;
  transition: border-color var(--dur) var(--ease);
  overflow-y: auto;
}
#vcm-chat-input:focus { border-color: var(--accent); outline: none; }
#vcm-chat-input:focus-visible { outline: var(--ring-w) solid var(--ring); outline-offset: 2px; }
#vcm-chat-input::placeholder { color: var(--fg-subtle); }
#vcm-chat-input:disabled { opacity: .55; cursor: not-allowed; }

#vcm-chat-send {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,.14);
  background:
    linear-gradient(176deg, rgba(255,255,255,.26), rgba(255,255,255,.04) 52%),
    var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 4px 12px color-mix(in srgb, var(--accent) 36%, transparent);
  transition: all var(--dur) var(--ease);
}
#vcm-chat-send:hover { background: linear-gradient(176deg, rgba(255,255,255,.26), rgba(255,255,255,.04) 52%), var(--accent-hover); }
#vcm-chat-send:active { transform: scale(.95); }
#vcm-chat-send:disabled { background: var(--surface-2); color: var(--fg-disabled); box-shadow: none; border-color: var(--border); cursor: not-allowed; }

/* ---- Light mode overrides ---------------------------------------- */
[data-mode="light"] #vcm-chat-panel {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.90),
    0 12px 40px rgba(15,23,42,.18);
}
[data-mode="light"] .vcm-msg.assistant .vcm-msg-bubble,
[data-mode="light"] .vcm-typing {
  background: linear-gradient(176deg, rgba(255,255,255,.82), rgba(255,255,255,.55) 60%), var(--surface-1);
}
[data-mode="light"] #vcm-chat-input { background: var(--surface-1); }

/* ---- Reduced motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  #vcm-chat-panel { transition: none !important; }
  .vcm-typing span { animation: none !important; opacity: .6; }
  .vcm-msg { animation: none !important; }
}

/* ---- Mobile: panel fills more of the screen when narrow ---------- */
@media (max-width: 480px) {
  #vcm-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 88px;
  }
  #vcm-chat-launcher { right: 16px; bottom: 20px; }
}
