/* ============================================================
   RUSSELLM chat widget: on every page, so it lives in its own file.
   The portfolio pages get their colours from css/style.css; /agents
   has its own tokens and a dock and side panel to stay clear of (see
   the end of this file).
   ============================================================ */

/* One blue for the chat, matching /agents in each theme. */
:root { --rl-blue: #2860f0; --rl-on-blue: #fff; }
html[data-theme="dark"] { --rl-blue: #6b97ff; --rl-on-blue: #0b1530; }

/* The launcher: a round button fixed bottom-right with a red unread
   badge, and a one-line preview card above it. The chat itself opens as
   a panel above the launcher, or full screen on a phone. */
.russellm-toggle {
  position: fixed;
  right: var(--rl-right, 22px);
  bottom: var(--rl-bottom, 22px);
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--rl-blue);
  color: var(--rl-on-blue);
  box-shadow: 0 8px 24px rgba(40, 96, 240, 0.35), 0 2px 6px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  z-index: 110;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.russellm-toggle:hover { transform: scale(1.05); }
.russellm-toggle svg { grid-area: 1 / 1; transition: opacity 160ms ease, transform 160ms ease; }
.russellm-icon-close { opacity: 0; transform: rotate(-30deg); }
.russellm-toggle[aria-expanded="true"] .russellm-icon-chat { opacity: 0; transform: rotate(30deg); }
.russellm-toggle[aria-expanded="true"] .russellm-icon-close { opacity: 1; transform: none; }

.russellm-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #e5262a;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}
.russellm-badge[hidden] { display: none; }

.russellm-preview {
  position: fixed;
  right: var(--rl-right, 22px);
  bottom: calc(var(--rl-bottom, 22px) + 68px);
  width: 340px;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.14), 0 2px 6px rgba(0, 0, 0, 0.06);
  text-align: left;
  cursor: pointer;
  z-index: 110;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.russellm-preview.show { opacity: 1; transform: none; pointer-events: auto; }
.russellm-preview img { flex: none; width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.russellm-preview-text { flex: 1; min-width: 0; }
.russellm-preview-text strong,
.russellm-preview-text small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.russellm-preview-text strong { font-size: 14.5px; font-weight: 400; line-height: 1.35; }
.russellm-preview-text small { margin-top: 2px; font-size: 12.5px; color: var(--text-secondary); }
.russellm-preview-close {
  position: absolute;
  top: -9px;
  right: -7px;
  width: 24px;
  height: 24px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

/* Only used under the phone breakpoint's full-screen panel, so it stays off. */
.russellm-overlay { display: none; }

.russellm-drawer {
  position: fixed;
  right: var(--rl-right, 22px);
  bottom: calc(var(--rl-bottom, 22px) + 68px);
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 620px;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22), 0 2px 8px rgba(0, 0, 0, 0.08);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
  z-index: 130;
}
.russellm-drawer.open { opacity: 1; visibility: visible; transform: none; }

.russellm-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.russellm-drawer-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.russellm-drawer-who img { flex: none; width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.russellm-drawer-title { display: block; font-size: 14.5px; font-weight: 600; color: var(--text-primary); }
.russellm-drawer-who small { display: block; font-size: 12.5px; color: var(--text-secondary); }
.russellm-close {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.russellm-close:hover { background: var(--bg); }

.russellm-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.russellm-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
}
.russellm-msg.user {
  align-self: flex-end;
  background: var(--rl-blue);
  color: var(--rl-on-blue);
}
.russellm-msg.ai {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.russellm-msg.loading { color: var(--text-tertiary); }
.russellm-msg.error { border-color: var(--badge-border); color: var(--text-secondary); }

.russellm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.russellm-chip {
  font-size: 13px;
  color: var(--text-primary);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 6px 12px;
  border-radius: 100px;
  cursor: pointer;
}
.russellm-chip:hover { border-color: var(--rl-blue); }

.russellm-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.russellm-input-row input {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
}
.russellm-input-row input:disabled { opacity: 0.6; }
.russellm-send {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--rl-on-blue);
  border: 0;
  background: var(--rl-blue);
  border-radius: 50%;
  cursor: pointer;
}
.russellm-send:hover { filter: brightness(1.08); }
.russellm-send:disabled { opacity: 0.6; cursor: default; }

@media (max-width: 600px) {
  .russellm-toggle, .russellm-preview { --rl-right: 16px; }
  .russellm-preview { width: calc(100vw - 32px); }
  .russellm-toggle { bottom: var(--rl-bottom, 16px); }
  .russellm-preview { bottom: calc(var(--rl-bottom, 16px) + 68px); }
  /* Full screen, sized to the visible area by syncRussellmViewport. */
  .russellm-drawer {
    top: 0;
    right: 0;
    bottom: auto;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }
}
/* iOS Safari zooms into any field under 16px when it's focused. */
@media (pointer: coarse) {
  .russellm-input-row input { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .russellm-drawer, .russellm-preview, .russellm-toggle, .russellm-toggle svg { transition: none; }
}

/* ---------------- On /agents ---------------- */
.agents-app {
  --bg: var(--ag-bg);
  --bg-elevated: var(--ag-surface);
  --border: var(--ag-border-strong);
  --badge-border: var(--ag-accent-ring);
  --text-primary: var(--ag-text);
  --text-secondary: var(--ag-text-2);
  --text-tertiary: var(--ag-text-2);
}
/* .agents-app button sets color: inherit, which would beat these. */
.agents-app .russellm-toggle,
.agents-app .russellm-send { color: #fff; }
/* An agent's run on the canvas isn't the moment for a preview card. */
.agents-app.is-workspace .russellm-preview { display: none; }
/* Beside the side panel, so it never covers the chat agents' Send button. */
.agents-app.is-workspace:has(.ag-panel:not([hidden]):not(.is-sheet)) { --rl-right: calc(var(--ag-panel-w, 400px) + 28px); }
@media (max-width: 699px) {
  /* Above the bottom dock, and above the canvas's Open chat button. */
  .agents-app { --rl-bottom: calc(var(--ag-dock-space) + 6px); }
  .agents-app.is-workspace { --rl-bottom: calc(var(--ag-dock-space) + 62px); }
  /* The bottom sheet has its own composer to keep clear. */
  .agents-app:has(.ag-panel.is-sheet:not([hidden])) .russellm-toggle { display: none; }
}
