/* ---------- Nile AI agent: floating assistant ---------- */
.agent { position: fixed; bottom: 22px; inset-inline-end: 22px; z-index: var(--z-agent); display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.agent-fab {
  display: inline-flex; align-items: center; gap: 7px; height: 42px; padding: 0 14px; border-radius: 999px; color: var(--on-solid); font-weight: 600; font-size: var(--fs-xs);
  background: var(--ai); box-shadow: var(--shadow);
  transition: transform var(--t-base) var(--ease-spring), box-shadow var(--t-base), filter var(--t-fast);
  cursor: grab; touch-action: none; user-select: none;
}
.agent-fab:active { cursor: grabbing; }
.agent.dragging { transition: none; } .agent.dragging .agent-fab { box-shadow: var(--shadow-lg); }
.agent-fab svg { width: 18px; height: 18px; }
.agent-fab:hover { filter: brightness(1.08); }
/* the pulsing ring was permanent visual noise — removed */
.agent-fab { position: relative; }
.agent.open .agent-fab { transform: scale(.9); opacity: .55; }
.agent.open .agent-fab::after { display: none; }
@media (max-width: 900px) { .agent-fab-label { display: none; } .agent-fab { width: 42px; padding: 0; justify-content: center; } }

/* The panel is anchored to the VIEWPORT, never to the button. The button can be dragged anywhere; if the
   panel followed it, dragging the button to an edge opened the panel off-screen with its close button out of
   reach — which is exactly what happened. */
.agent-panel {
  position: fixed; bottom: 84px; inset-inline-end: 22px;
  display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg); animation: modal-in var(--t-slow) var(--ease-spring) both;
  width: 400px; height: min(620px, calc(100vh - 130px)); max-height: calc(100vh - 110px); max-width: calc(100vw - 32px);
  transition: width var(--t-base) var(--ease), height var(--t-base) var(--ease);
}
.agent-panel.size-large { width: min(760px, calc(100vw - 44px)); height: min(820px, calc(100vh - 120px)); }
.agent-panel.size-full { inset: 16px; z-index: var(--z-agent); width: auto; height: auto; max-width: none; max-height: none; border-radius: var(--r-xl);  }
@media (max-width: 620px) { .agent-panel, .agent-panel.size-large { width: calc(100vw - 24px); inset-inline: 12px; height: min(70vh, 560px); } }

/* text size control — three steps up for readability */
.agent-panel.font-0 { --agent-fs: 14px; } .agent-panel.font-1 { --agent-fs: 16px; }
.agent-panel.font-2 { --agent-fs: 18.5px; } .agent-panel.font-3 { --agent-fs: 21px; }
.agent-panel { --agent-fs: 14px; }

.agent-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.agent-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.agent-brand > svg { width: 28px; height: 28px; padding: 5px; border-radius: var(--r-xs); background: var(--ai); color: var(--on-solid); flex: none; }
.agent-brand b { display: block; font-size: var(--fs-md); line-height: 1.2; }
.agent-brand span { color: var(--text-3); display: block; }
.agent-actions { display: flex; align-items: center; gap: 2px; }
.agent-actions .icon-btn.sm { width: 30px; height: 30px; border-radius: var(--r-xs); } .agent-actions .icon-btn.sm svg { width: 16px; height: 16px; }
.agent-font-badge { font-size: 12px; font-weight: 800; color: var(--text-3); width: 16px; text-align: center; }

.agent-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; font-size: var(--agent-fs); }
.agent-msg { display: flex; gap: 9px; animation: rise-in var(--t-base) var(--ease-out) both; }
.agent-msg.user { justify-content: flex-end; }
.agent-msg .bubble { max-width: 88%; padding: 10px 14px; border-radius: var(--r-lg); line-height: 1.65; word-break: break-word; }
.agent-msg.user .bubble { background: var(--brand); color: var(--on-solid); border-start-end-radius: 5px; white-space: pre-wrap; }
.agent-msg.bot .bubble { background: var(--surface-2); border: 1px solid var(--border); border-start-start-radius: 5px; max-width: 100%; }
.agent-av { width: 30px; height: 30px; border-radius: var(--r-sm); display: grid; place-items: center; flex: none; background: var(--ai-soft); color: var(--ai-strong); }
.agent-av svg { width: 17px; height: 17px; }
.agent-msg.bot .bubble p { margin: 0 0 7px; } .agent-msg.bot .bubble p:last-child { margin: 0; }
.agent-msg.bot .bubble ul { margin: 6px 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 4px; }
.agent-msg.bot .bubble h4 { margin: 8px 0 4px; color: var(--brand-ink); }
.agent-msg.bot .bubble code { font-family: var(--font-mono); font-size: .88em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
.agent-table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: .93em; }
.agent-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); } .agent-table tr:first-child td { font-weight: 700; color: var(--text-2); background: var(--surface-3); }
.bubble.typing { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.bubble.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ai); animation: float-y 1s var(--ease) infinite; }
.bubble.typing i:nth-child(2) { animation-delay: .15s; } .bubble.typing i:nth-child(3) { animation-delay: .3s; }

.agent-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.agent-sources .src { display: inline-flex; align-items: center; gap: 5px; max-width: 220px; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-ink); font-size: .82em; font-weight: 600; border: 1px solid transparent; transition: all var(--t-fast); }
.agent-sources .src:hover { border-color: var(--brand); transform: translateY(-1px); }
.agent-sources .src svg { width: 13px; height: 13px; flex: none; }
.agent-sources .src.done { background: var(--success-soft); color: var(--success); }
[data-theme="dark"] .agent-sources .src.done { color: var(--success); }
.agent-meta { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-size: .78em; color: var(--text-4); flex-wrap: wrap; }
.agent-meta .tools { display: inline-flex; align-items: center; gap: 4px; cursor: help; } .agent-meta svg { width: 13px; height: 13px; }
.agent-meta .lnk { display: inline-flex; align-items: center; gap: 4px; color: var(--text-4); } .agent-meta .lnk:hover { color: var(--brand); }
.agent-meta .badge { height: 19px; font-size: 10px; padding: 0 7px; }

.agent-welcome { text-align: center; padding: 26px 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.agent-hero { width: 56px; height: 56px; border-radius: var(--r-lg); display: grid; place-items: center; color: var(--on-solid); background: var(--ai); }
.agent-hero svg { width: 32px; height: 32px; }
.agent-welcome h3 { font-size: 1.15em; } .agent-welcome p { color: var(--text-3); line-height: 1.6; max-width: 46ch; }
.agent-caps { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; }

.agent-composer { border-top: 1px solid var(--border); padding: 10px 12px 12px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.agent-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-chips .chip { font-size: .86em; height: auto; padding: 6px 12px; text-align: start; white-space: normal; line-height: 1.4; }
.agent-input { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border); border-radius: var(--r-lg); padding: 6px 6px 6px 12px; background: var(--surface-2); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.agent-input:focus-within { border-color: var(--ai); box-shadow: 0 0 0 3px var(--ai-soft); }
.agent-input textarea { flex: 1; border: 0; background: transparent; outline: none; resize: none; font-size: var(--agent-fs); line-height: 1.5; padding: 6px 0; max-height: 160px; font-family: inherit; }
.agent-input .btn { flex: none; }
.agent-hint { font-size: 10.5px; color: var(--text-4); text-align: center; }

.agent-history { flex: 1; overflow-y: auto; font-size: var(--agent-fs); }
.agent-thread { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--t-fast); }
.agent-thread:hover { background: var(--surface-hover); } .agent-thread.active { background: var(--brand-soft); }
.agent-thread b { font-size: .95em; display: block; } .agent-thread .xs { font-size: .78em; }
.agent-thread .icon-btn { opacity: 0; } .agent-thread:hover .icon-btn { opacity: 1; }

@media print { .agent { display: none; } }

/* The floating "Ask Nile" button sits bottom-end — exactly where the Inbox and Chat composers put their
   Send button. Give those rows clearance so the FAB never covers a button someone needs to click. */
.composer > .row.between, .composer .row:last-child { padding-inline-end: 132px; }
@media (max-width: 620px) { .composer > .row.between, .composer .row:last-child { padding-inline-end: 64px; } }
