/* ============================================================================
   AVATAR — Components layer. Depends on tokens.css.
   Real, build-ready component classes shared by the mockups and the doc.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

/* Honour reduced-motion: stop the looping caret/typing animations and snap transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--surface-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--yellow-soft); color: var(--text); }

/* ---- Icon ---- */
.icon { width: 20px; height: 20px; display: inline-block; flex: none; vertical-align: middle; }
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }
.icon--xl { width: 32px; height: 32px; }

/* ---- Eyebrow / mono caps label ---- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}

/* ---- Headings (editorial serif display) ---- */
.display { font-family: var(--font-display); font-weight: 500; line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight); color: var(--text); }
.display--italic { font-style: italic; }

/* ---- HUD texture (decorative bg): a faint tiled mark, masked so its colour
   follows --grid-line per theme. Fixed, full-viewport, behind everything. ---- */
.hud-grid::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--grid-line);
  -webkit-mask: var(--grid-mark) 0 0 / 44px 44px repeat;
  mask: var(--grid-mark) 0 0 / 44px 44px repeat;
}

/* ============================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-family: var(--font-sans); font-size: var(--text-base); font-weight: 600;
  line-height: 1; letter-spacing: -0.01em;
  padding: 0 var(--space-4); height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out),
              transform var(--dur-fast) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

/* Primary = purple, reserved for submit / key actions ONLY */
.btn--primary { background: var(--purple-strong); color: #fff; border-color: var(--purple-strong); }
.btn--primary:hover { background: var(--purple-hover); border-color: var(--purple-hover); }

/* Blue = key but non-destructive secondary actions / links-as-buttons */
.btn--blue { background: var(--blue-soft); color: var(--blue-ink); border-color: var(--blue-line); }
.btn--blue:hover { background: var(--blue-line); color: var(--text); }

/* Secondary = outline on surface */
.btn--secondary { background: var(--surface-1); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:hover { background: var(--surface-2); border-color: var(--text-faint); }

/* Ghost = quiet */
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.btn--icon { width: 40px; padding: 0; }
.btn--sm { height: 32px; font-size: var(--text-sm); padding: 0 var(--space-3); }
.btn--lg { height: 48px; font-size: var(--text-md); padding: 0 var(--space-6); }

/* Send button (circular, purple) */
.btn-send {
  width: 44px; height: 44px; flex: none; border: none; cursor: pointer;
  border-radius: var(--radius-md); background: var(--purple-strong); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn-send:hover { background: var(--purple-hover); }
.btn-send:active { transform: translateY(1px); }
.btn-send:disabled { background: var(--surface-3); color: var(--text-faint); cursor: not-allowed; }

/* ============================================================================
   FIELDS
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.label { font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); }
.input, .textarea {
  font-family: var(--font-sans); font-size: var(--text-base); color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 10px var(--space-3); width: 100%;
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .textarea:focus { outline: none; border-color: var(--yellow-line); box-shadow: 0 0 0 3px var(--focus-ring); }
.textarea { resize: none; line-height: var(--leading-snug); }
.input--sm { height: 34px; padding: 0 var(--space-3); }

/* Name field (compact, top of chat) */
.name-field {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 0 var(--space-3); height: 36px;
}
.name-field input { border: none; background: none; color: var(--text); font-size: var(--text-sm);
  width: 130px; outline: none; font-family: var(--font-sans); }

/* ============================================================================
   SWITCH (Keep chat)
   ========================================================================== */
.switch { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 38px; height: 22px; border-radius: var(--radius-pill);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  position: relative; transition: background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.switch .thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-muted); transition: transform var(--dur) var(--ease-out), background var(--dur) var(--ease-out);
}
.switch input:checked + .track { background: var(--blue-soft); border-color: var(--blue-line); }
.switch input:checked + .track .thumb { transform: translateX(16px); background: var(--blue-strong); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--focus-ring); }
.switch .switch-label { font-size: var(--text-sm); color: var(--text-muted); font-weight: 500; }

/* ============================================================================
   BADGES / PILLS / CHIPS
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-family: var(--font-mono); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; font-weight: 500;
  padding: 3px 8px; border-radius: var(--radius-pill);
  background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border);
}
.badge--attention { background: var(--yellow-soft); color: var(--yellow-ink); border-color: var(--yellow-line); }
.badge--blue { background: var(--blue-soft); color: var(--blue-ink); border-color: var(--blue-line); }
.badge--unread { background: var(--blue-strong); color: #fff; border-color: transparent; padding: 2px 7px; }
.badge--dot { width: 8px; height: 8px; padding: 0; border-radius: 50%; background: var(--blue-strong); border: none; }
.badge--dot.is-attention { background: var(--yellow-strong); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: 500;
  padding: 5px var(--space-3); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--dur) var(--ease-out);
}
.chip:hover { border-color: var(--blue-line); color: var(--text); }

/* keyboard key */
.kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px;
  padding: 0 6px; font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: var(--radius-sm);
}

/* ============================================================================
   AVATARS
   ========================================================================== */
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; position: relative;
  background-size: cover; background-position: center; overflow: hidden; }
.avatar--sm { width: 30px; height: 30px; }
.avatar--lg { width: 56px; height: 56px; }

/* Visitor = initials token (square-ish, blue) */
.avatar-initials {
  width: 40px; height: 40px; flex: none; border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 600; font-size: var(--text-sm); letter-spacing: 0.02em;
  background: var(--blue-soft); color: var(--blue-ink); border: 1px solid var(--blue-line);
  text-transform: uppercase;
}
.avatar-initials--sm { width: 30px; height: 30px; font-size: var(--text-2xs); }

/* Avatar (twin) image with cyan identity ring */
.avatar-twin { border: 1.5px solid var(--blue-line); box-shadow: 0 0 0 3px rgba(40,168,224,0.08); }

/* Human image with the yellow spark ring — the designed "live human" moment */
.avatar-human { border: 2px solid var(--yellow-strong); box-shadow: 0 0 0 3px var(--yellow-soft); }
.avatar-human .spark-badge {
  position: absolute; right: -3px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--yellow-strong); color: var(--text-on-yellow);
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface-1);
}
.avatar-human .spark-badge .icon { width: 10px; height: 10px; }

/* ============================================================================
   MESSAGE BUBBLES — the three roles
   ========================================================================== */
.msg { display: flex; gap: var(--space-3); max-width: 100%; }
.msg-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.msg-meta { display: flex; align-items: center; gap: var(--space-2); }
.msg-name { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.01em; }
.msg-time { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--text-faint); }
.bubble {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg);
  font-size: var(--text-md); line-height: var(--leading-relaxed); color: var(--text);
  border: 1px solid transparent; max-width: 560px; width: fit-content;
}
.bubble p { margin: 0 0 0.6em; } .bubble p:last-child { margin-bottom: 0; }
.bubble a { color: var(--blue-ink); text-decoration: underline; text-underline-offset: 2px;
  text-decoration-color: var(--blue-line); }
.bubble strong { font-weight: 700; }

/* Visitor — right aligned */
.msg--visitor { flex-direction: row-reverse; margin-left: auto; }
.msg--visitor .msg-body { align-items: flex-end; }
.msg--visitor .bubble {
  background: var(--surface-2); border-color: var(--border);
  border-bottom-right-radius: var(--radius-xs);
}

/* Avatar / twin — left aligned */
.msg--avatar .msg-name { color: var(--role-avatar); }
.msg--avatar .bubble {
  background: var(--surface-1); border-color: var(--border);
  border-bottom-left-radius: var(--radius-xs);
}
[data-theme="dark"] .msg--avatar .bubble { background: var(--surface-2); }

/* Human — the designed moment: photo + yellow ring + tinted bubble + spark mark.
   NO name is ever shown (per spec). NOT a left-border accent. */
.msg--human .bubble {
  background:
    linear-gradient(0deg, var(--yellow-soft), var(--yellow-soft)) padding-box,
    var(--surface-2);
  border-color: var(--yellow-line);
  border-bottom-left-radius: var(--radius-xs);
  box-shadow: var(--glow-yellow);
  position: relative;
}
.msg--human .msg-meta .human-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--yellow-ink); font-weight: 600;
}
.msg--human .human-tag .icon { width: 12px; height: 12px; color: var(--yellow-strong); }

/* Tool-status line (small mono, shows tool use while streaming) */
.tool-status {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-faint);
  padding: 4px 0;
}
.tool-status .icon { width: 14px; height: 14px; color: var(--blue); }
.tool-status .dots::after { content: "…"; }
.tool-status.is-done { color: var(--text-muted); }
.tool-status.is-done .icon { color: var(--positive); }

/* "instant answer" tag for Qn shortcut replies */
.instant-tag {
  font-family: var(--font-mono); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--blue-ink); background: var(--blue-soft);
  border: 1px solid var(--blue-line); border-radius: var(--radius-sm); padding: 1px 6px;
}

/* ============================================================================
   COMPOSER (message input bar)
   ========================================================================== */
.composer {
  display: flex; align-items: flex-end; gap: var(--space-3);
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); padding: var(--space-3);
  box-shadow: var(--shadow-md);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.composer:focus-within { border-color: var(--yellow-line); box-shadow: var(--shadow-md), 0 0 0 3px var(--focus-ring); }
.composer textarea {
  flex: 1; border: none; background: none; resize: none; color: var(--text);
  font-family: var(--font-sans); font-size: var(--text-md); line-height: var(--leading-snug);
  outline: none; max-height: 160px; padding: 8px 4px;
}
.composer textarea::placeholder { color: var(--text-faint); }

/* ============================================================================
   INBOX / CONVERSATION LIST (admin)
   ========================================================================== */
.convo-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); cursor: pointer; position: relative;
  border-bottom: 1px solid var(--hairline);
  transition: background var(--dur-fast) var(--ease-out);
}
.convo-item:hover { background: var(--surface-2); }
.convo-item.is-active { background: var(--surface-3); }
.convo-item.is-active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  background: var(--blue-strong); border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}
.convo-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.convo-top { display: block; min-width: 0; }
.convo-name { font-weight: 700; font-size: var(--text-sm); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-preview { font-size: var(--text-sm); color: var(--text-muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.convo-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.convo-item.is-unread .convo-name { color: var(--text); }
.convo-item.is-unread .convo-preview { color: var(--text); font-weight: 500; }
.convo-item.is-attention { background: var(--yellow-soft); }
.convo-item.is-attention:hover { background: color-mix(in srgb, var(--yellow-soft) 70%, var(--surface-2)); }

/* ---- Surfaces / cards ---- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.hairline { height: 1px; background: var(--hairline); border: 0; margin: 0; }

/* ---- Scrollbar ---- */
.scroll { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px;
  border: 3px solid transparent; background-clip: content-box; }
.scroll::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
