/* ==========================================================================
   The assistant — floating button, panel (float / dock / full), chat list.
   ========================================================================== */

/* --- floating action button ---------------------------------------------- */
/* Position is set in JS (draggable, snaps to an edge) — see makeFabDraggable. */
.fab {
  position: fixed; z-index: 120;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--blue) 0%, var(--purple) 125%);
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.38), 0 2px 6px rgba(0, 0, 0, 0.2);
  touch-action: none;
  cursor: grab;
  animation: fabIn var(--t-slow) var(--ease-spring) both;
}
.fab:hover { transform: scale(1.08) rotate(-6deg); box-shadow: 0 10px 30px rgba(0,122,255,0.45); }
.fab:active { transform: scale(0.94); }
.fab.is-dragging {
  cursor: grabbing;
  transform: scale(1.12);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35), 0 0 0 6px color-mix(in srgb, var(--blue) 18%, transparent);
}
.fab.is-dragging .fab__pulse { display: none; }
.fab.is-hidden { opacity: 0; pointer-events: none; transform: scale(0.6); }

@keyframes fabIn {
  from { opacity: 0; transform: scale(0.4) translateY(18px); }
  to   { opacity: 1; transform: none; }
}

.fab__pulse {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--blue);
  animation: fabPulse 2.6s var(--ease-out, ease) infinite;
  pointer-events: none;
}
@keyframes fabPulse {
  0%   { opacity: 0.5; transform: scale(1); }
  70%  { opacity: 0;   transform: scale(1.5); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* --- panel --------------------------------------------------------------- */
.agent {
  position: fixed; z-index: 130;
  display: flex; flex-direction: column;
  background: var(--material-thick);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: var(--hairline) solid var(--separator-firm);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transition: opacity var(--t) var(--ease);
}

/* float — a card in the corner, on whichever side the button was left. */
.agent--float {
  right: 20px; bottom: 20px;
  width: min(440px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 110px));
  border-radius: var(--r-2xl);
  animation: agentFloatIn var(--t-slow) var(--ease-spring) both;
  transform-origin: bottom right;
}
body.fab-left .agent--float {
  left: 20px; right: auto;
  transform-origin: bottom left;
}
@keyframes agentFloatIn {
  from { opacity: 0; transform: translateY(24px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

/* dock — glued to the right edge, full height; the app shifts to make room */
.agent--dock {
  top: 0; right: 0; bottom: 0;
  width: min(460px, 100vw);
  border-radius: 0;
  border-top: 0; border-right: 0; border-bottom: 0;
  animation: agentDockIn var(--t-slow) var(--ease) both;
}
@keyframes agentDockIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: none; }
}

/* full — everything */
.agent--full {
  inset: 0; width: 100vw; height: 100vh;
  border-radius: 0; border: 0;
  background: var(--bg);
  animation: agentFullIn var(--t-slow) var(--ease) both;
}
@keyframes agentFullIn {
  from { opacity: 0; transform: scale(0.985); }
  to   { opacity: 1; transform: none; }
}
/* Full screen earns a permanent chat list and a comfortable reading column. */
.agent--full .agent__main { max-width: 780px; margin: 0 auto; width: 100%; padding-top: var(--sp-6); }
.agent--full .agent__composer-inner { max-width: 780px; margin: 0 auto; }
.agent--full .agent__side { display: flex; }
.agent--full .agent__composer { padding: var(--sp-3) var(--sp-5) var(--sp-4); }

/* --- body layout: optional chat list + the conversation column ----------- */
.agent__body { flex: 1 1 auto; min-height: 0; display: flex; }
.agent__col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.agent__side {
  display: none;                     /* only full screen has room for it */
  flex-direction: column;
  width: 264px; flex: 0 0 auto;
  min-height: 0;
  border-right: var(--hairline) solid var(--separator);
  background: var(--surface-2);
}
.agent__side-head {
  display: flex; align-items: center; gap: 6px;
  padding: var(--sp-3) var(--sp-3) var(--sp-2) var(--sp-4);
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: var(--tracking-wide); color: var(--text-4);
  flex: 0 0 auto;
}
.agent__side-inner { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--sp-2) var(--sp-3); }

.agent.is-closing { animation: agentOut var(--t-fast) var(--ease-in-out) both; }
@keyframes agentOut {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(10px) scale(0.97); }
}

/* the app slides over when docked */
.app { transition: padding-right var(--t-slow) var(--ease); }
.app.is-docked { padding-right: min(460px, 100vw); }
@media (max-width: 860px) { .app.is-docked { padding-right: 0; } }

/* --- header -------------------------------------------------------------- */
.agent__head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  flex: 0 0 auto;
  border-bottom: var(--hairline) solid var(--separator);
}
.agent__mark {
  width: 26px; height: 26px; border-radius: 8px; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, var(--blue), var(--purple) 130%);
  box-shadow: var(--shadow-accent);
}
.agent__title {
  font-size: var(--fs-base); font-weight: 620; letter-spacing: -0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent__sub { font-size: var(--fs-xs); color: var(--text-4); }

/* --- chat list drawer ---------------------------------------------------- */
.agent__drawer {
  flex: 0 0 auto;
  max-height: 0; overflow: hidden;
  border-bottom: var(--hairline) solid transparent;
  transition: max-height var(--t-slow) var(--ease), border-color var(--t) var(--ease);
}
.agent__drawer.is-open { max-height: 260px; border-bottom-color: var(--separator); }
.agent__drawer-inner { max-height: 260px; overflow-y: auto; padding: var(--sp-2); }

.chatrow {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  border-radius: var(--r-sm);
  text-align: left;
  transition: background var(--t-fast) var(--ease);
}
.chatrow:hover { background: var(--surface-hover); }
.chatrow.is-active { background: var(--accent-soft); color: var(--accent); }
.chatrow__title {
  flex: 1 1 auto; min-width: 0;
  font-size: var(--fs-sm); font-weight: 540;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chatrow__time { font-size: var(--fs-xs); color: var(--text-4); flex: 0 0 auto; }
.chatrow__del {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: var(--r-xs);
  display: grid; place-items: center; color: var(--text-4);
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.chatrow:hover .chatrow__del { opacity: 1; }
.chatrow__del:hover { background: var(--red-soft); color: var(--red); }

/* --- messages ------------------------------------------------------------ */
.agent__main {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
  display: flex; flex-direction: column; gap: var(--sp-3);
}

.amsg { display: flex; flex-direction: column; animation: riseIn var(--t) var(--ease) both; }
.amsg--user { align-items: flex-end; }
.amsg--user .amsg__body {
  max-width: 86%;
  background: linear-gradient(160deg, var(--blue), var(--blue-600));
  color: #fff;
  padding: 9px 13px; border-radius: 16px 16px 5px 16px;
  font-size: var(--fs-base); line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 2px 8px rgba(0,122,255,0.24);
}
.amsg--assistant .amsg__body {
  font-size: var(--fs-base); line-height: var(--lh-loose);
  color: var(--text); max-width: 100%;
}
.amsg__body p { margin: 0 0 8px; }
.amsg__body p:last-child { margin-bottom: 0; }
.amsg__body ul, .amsg__body ol { margin: 6px 0 8px; padding-left: 20px; }
.amsg__body ul { list-style: disc; }
.amsg__body ol { list-style: decimal; }
.amsg__body li { margin: 3px 0; }
.amsg__body strong { font-weight: 640; }
.amsg__body code {
  font-family: var(--font-mono); font-size: 0.9em;
  background: var(--surface-3); padding: 1px 5px; border-radius: 5px;
}
.amsg__body a { text-decoration: underline; }

/* --- tool chips ---------------------------------------------------------- */
.tools { display: flex; flex-direction: column; gap: 4px; }
.toolchip {
  display: inline-flex; align-items: center; gap: 7px;
  align-self: flex-start;
  max-width: 100%;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: var(--hairline) solid transparent;
  font-size: var(--fs-xs); font-weight: 540; color: var(--text-3);
  animation: popIn var(--t) var(--ease-spring) both;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  cursor: default;
}
.toolchip .icon { flex: 0 0 auto; }
.toolchip__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolchip--write { background: var(--purple-50); color: var(--purple); }
.toolchip--send  { background: var(--green-soft); color: var(--green); }
.toolchip--error { background: var(--red-soft); color: var(--red); }

.agent__thinking {
  display: inline-flex; gap: 5px; align-items: center; align-self: flex-start;
  padding: 8px 12px; border-radius: var(--r-pill);
  background: var(--surface-3);
  font-size: var(--fs-xs); color: var(--text-3);
}
.agent__thinking i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-4);
  animation: blink 1.3s var(--ease-in-out) infinite;
}
.agent__thinking i:nth-child(2) { animation-delay: 0.18s; }
.agent__thinking i:nth-child(3) { animation-delay: 0.36s; }

/* --- empty state --------------------------------------------------------- */
.agent__hello { margin: auto 0; padding: var(--sp-4) var(--sp-2); text-align: center; }
.agent__hello-mark {
  width: 46px; height: 46px; border-radius: 14px; margin: 0 auto var(--sp-3);
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(145deg, var(--blue), var(--purple) 130%);
  box-shadow: var(--shadow-accent);
}
.agent__hello-title { font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.02em; }
.agent__hello-text {
  font-size: var(--fs-sm); color: var(--text-3); margin-top: 5px;
  line-height: var(--lh-loose); max-width: 320px; margin-inline: auto;
}
.agent__prompts { display: flex; flex-direction: column; gap: 6px; margin-top: var(--sp-4); }
.agent__prompt {
  padding: 9px 12px; border-radius: var(--r-md);
  background: var(--surface); border: var(--hairline) solid var(--separator);
  font-size: var(--fs-sm); text-align: left; color: var(--text-2);
  transition: border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease);
}
.agent__prompt:hover { border-color: var(--accent); background: var(--surface-2); transform: translateY(-1px); }
.agent__prompt:active { transform: scale(0.985); }

/* --- composer ------------------------------------------------------------ */
.agent__composer {
  flex: 0 0 auto;
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
  border-top: var(--hairline) solid var(--separator);
}
.agent__composer-box {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 6px 6px 6px 13px;
  border-radius: var(--r-xl);
  background: var(--surface);
  border: var(--hairline) solid var(--separator-firm);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.agent__composer-box:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.agent__input {
  flex: 1 1 auto; border: 0; background: none; resize: none;
  max-height: 160px; min-height: 24px; padding: 4px 0;
  font-size: var(--fs-base); line-height: 1.45;
}
.agent__input:focus { outline: none; }
.agent__send {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  transition: transform var(--t-fast) var(--ease-spring), opacity var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease);
}
.agent__send:hover { background: var(--accent-hover); transform: scale(1.08); }
.agent__send:active { transform: scale(0.9); }
.agent__send:disabled { opacity: 0.3; pointer-events: none; }
.agent__hint {
  margin-top: 6px; text-align: center;
  font-size: 10.5px; color: var(--text-4);
}

/* --- markdown inside assistant messages ---------------------------------- */
.amsg__body h3,
.amsg__body h4 {
  font-size: var(--fs-md);
  font-weight: 660;
  letter-spacing: -0.02em;
  margin: var(--sp-4) 0 var(--sp-2);
}
.amsg__body h4 { font-size: var(--fs-base); color: var(--text-2); }
.amsg__body > :first-child { margin-top: 0; }
.amsg__body > :last-child { margin-bottom: 0; }

.amsg__body pre {
  margin: var(--sp-3) 0;
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  border: var(--hairline) solid var(--separator);
  overflow-x: auto;                 /* long lines scroll, never widen the panel */
}
.amsg__body pre code {
  background: none; padding: 0; border-radius: 0;
  font-size: var(--fs-sm); line-height: 1.5; white-space: pre;
}

.amsg__body blockquote {
  margin: var(--sp-3) 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--separator-firm);
  color: var(--text-3);
}
.amsg__body hr {
  margin: var(--sp-4) 0;
  border: 0; height: var(--hairline); background: var(--separator);
}
.amsg__body del { opacity: 0.6; }

/* Tables scroll inside their own box rather than stretching the conversation. */
.amsg__body table {
  display: block;
  width: max-content; max-width: 100%;
  overflow-x: auto;
  margin: var(--sp-3) 0;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.amsg__body th,
.amsg__body td {
  padding: 6px 11px;
  text-align: left;
  border-bottom: var(--hairline) solid var(--separator);
  white-space: nowrap;
}
.amsg__body th {
  font-weight: 640; color: var(--text-3);
  font-size: var(--fs-xs); text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.amsg__body tbody tr:last-child td { border-bottom: 0; }
