/**
 * FieldChat Widget CSS v2.3
 * - Mobile-first design
 * - Highly visible send & close buttons
 * - Scrollable chat area
 * - Markdown rendering support
 * - Navigation buttons
 * - Glass morphism design
 */

/* ═══════════════════════════════════════════════════════════════════════
   CSS VARIABLES
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --fc-bg-body: var(--surface-0);
  --fc-bg-surface: var(--surface-3);
  --fc-bg-surface-elevated: var(--bg-surface-elevated);
  
  --fc-text-primary: var(--text-primary);
  --fc-text-secondary: var(--text-secondary);
  --fc-text-muted: var(--text-muted);
  --fc-text-inverse: var(--text-inverse);
  
  --fc-color-primary: var(--color-primary);
  --fc-color-primary-dark: var(--color-primary-dark);
  --fc-color-primary-light: var(--color-primary-light);
  --fc-color-accent: var(--color-accent);
  --fc-color-chlorophyll: var(--color-chlorophyll);
  --fc-color-danger: var(--color-error);
  
  --fc-gradient-primary: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 40%, var(--color-accent) 100%);
  
  --fc-glass-bg: var(--surface-3);
  --fc-glass-bg-strong: var(--surface-3);
  --fc-glass-border: color-mix(in srgb, var(--text-muted) 40%, transparent);
  --fc-glass-blur: blur(20px);
  
  --fc-shadow-sm: 0 2px 8px var(--surface-1);
  --fc-shadow-md: 0 10px 35px color-mix(in srgb, var(--surface-0) 75%, transparent);
  --fc-shadow-lg: 0 20px 60px var(--surface-3);
  --fc-shadow-glow: 0 4px 15px color-mix(in srgb, var(--color-primary) 40%, transparent);
  --fc-shadow-glow-strong: 0 6px 24px color-mix(in srgb, var(--color-primary) 60%, transparent);
  
  --fc-radius-sm: 8px;
  --fc-radius-md: 12px;
  --fc-radius-lg: 16px;
  --fc-radius-xl: 24px;
  --fc-radius-full: 9999px;
  
  --fc-transition-fast: 150ms ease;
  --fc-transition-base: 250ms ease;
  --fc-transition-slow: 400ms ease;
  
  --fc-z-backdrop: 9998;
  --fc-z-container: 9999;
  
  /* Mobile-first touch targets (minimum 44px) */
  --fc-touch-target: 44px;
  --fc-touch-target-lg: 48px;
}

/* ═══════════════════════════════════════════════════════════════════════
   BACKDROP
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-backdrop {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--fc-transition-base), visibility var(--fc-transition-base);
  z-index: var(--fc-z-backdrop);
}

.fieldchat-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* ═══════════════════════════════════════════════════════════════════════
   CONTAINER - Mobile First
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-container {
  position: fixed;
  /*
   * Mobile bottom-sheet layout.
   *
   * WHY top + bottom instead of height: calc(100vh - X):
   *   • 100vh on iOS Safari equals the layout viewport (doesn't shrink when
   *     the URL bar is visible), so calc(100vh - 60px) can be taller than
   *     the actual visible area, pushing the header/close button behind
   *     the browser chrome.
   *   • Using top + bottom: 0 makes the browser determine the height from
   *     real edge positions, which is always correct regardless of URL bar
   *     visibility or virtual keyboard state.
   *
   * --fc-top-offset: pages set this CSS custom property to match their
   *   navigation height. Playground pages set it to ~108px (site nav +
   *   workspace nav). Falls back to 60px for non-playground pages.
   */
  top: var(--fc-top-offset, 60px);
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: auto;      /* height is derived from top + bottom — no 100vh needed */
  max-height: none;

  display: flex;
  flex-direction: column;

  background: var(--fc-glass-bg-strong);
  backdrop-filter: var(--fc-glass-blur);
  -webkit-backdrop-filter: var(--fc-glass-blur);
  border: 1px solid var(--fc-glass-border);
  border-bottom: none;
  border-radius: var(--fc-radius-xl) var(--fc-radius-xl) 0 0;
  box-shadow: var(--fc-shadow-lg);

  opacity: 0;
  visibility: hidden;
  transform: translateY(100%);
  transition:
    opacity var(--fc-transition-base),
    visibility var(--fc-transition-base),
    transform var(--fc-transition-base);

  z-index: var(--fc-z-container);
  overflow: hidden;
}

.fieldchat-container.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ── Desktop / tablet ≥ 768px: anchored floating card (bottom-right) ──────── */
@media (min-width: 768px) {
  .fieldchat-container {
    /*
     * CRITICAL: reset top to auto so that bottom + height drive placement.
     * Without this, the inherited top: var(--fc-top-offset, 60px) from the
     * mobile base fights with bottom: 1.5rem and wins, making the widget
     * appear 60px from the top of the viewport instead of the bottom-right.
     */
    top: auto;
    bottom: 1.5rem;
    right: 1.5rem;
    left: auto;
    width: min(420px, calc(100vw - 3rem));
    /* Responsive height: shrinks gracefully on shorter viewports */
    height: min(600px, calc(100vh - 5rem));
    max-height: calc(100vh - 3rem);
    border-radius: var(--fc-radius-xl);
    border: 1px solid var(--fc-glass-border);
    border-bottom: 1px solid var(--fc-glass-border); /* restore full border */
    transform: translateY(20px) scale(0.95);
  }

  .fieldchat-container.open {
    transform: translateY(0) scale(1);
  }
}

/* Docked mode — side panel, always full height */
.fieldchat-container.docked {
  top: 0;          /* override: docked panel runs full viewport height */
  bottom: 0;
  right: 0;
  left: auto;
  height: auto;    /* top + bottom determine height */
  max-height: none;
  width: 100%;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--fc-glass-border);
}

@media (min-width: 768px) {
  .fieldchat-container.docked {
    width: min(48vw, 1040px);
  }
}

/* Resizer for docked mode */
.fieldchat-resizer {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: ew-resize;
  background: transparent;
  transition: background var(--fc-transition-fast);
  z-index: 10;
}

.fieldchat-container.docked .fieldchat-resizer {
  display: block;
}

.fieldchat-resizer:hover {
  background: var(--fc-color-primary);
}

/* ═══════════════════════════════════════════════════════════════════════
   MOBILE DRAG HANDLE — appears above the header on small screens.
   Signals to mobile users that the bottom sheet can be pulled down to
   dismiss. Hidden on desktop (where the close button is sufficient).
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-container::before {
  content: '';
  display: block;
  width: 40px;
  height: 4px;
  background: color-mix(in srgb, var(--text-muted) 45%, transparent);
  border-radius: var(--fc-radius-full);
  margin: 10px auto 6px;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  /* No drag handle on desktop — the widget is a floating card, not a sheet */
  .fieldchat-container::before { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════════
   HEADER - Always-visible, sticky close button
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: color-mix(in srgb, var(--surface-0) 97%, transparent); /* fully opaque so it reads over any content */
  border-bottom: 1px solid var(--fc-glass-border);
  flex-shrink: 0;     /* never compress — always visible */
  min-height: 56px;
  /*
   * Safety net: even if some browser quirk causes the container to scroll
   * internally, the header stays pinned at the top so the close button is
   * always reachable. z-index keeps it above the thread content.
   */
  position: sticky;
  top: 0;
  z-index: 5;
}

.fieldchat-header-title {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.fieldchat-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--fc-radius-full);
  object-fit: cover;
  border: 2px solid var(--fc-color-primary);
  box-shadow: 0 0 12px color-mix(in srgb, var(--color-primary) 50%, transparent);
}

.fieldchat-title {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--fc-text-primary);
  letter-spacing: -0.01em;
}

.fieldchat-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════════════════
   HEADER BUTTONS - HIGHLY VISIBLE
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Mobile touch target */
  width: var(--fc-touch-target);
  height: var(--fc-touch-target);
  min-width: var(--fc-touch-target);
  min-height: var(--fc-touch-target);
  padding: 0;
  background: var(--glass-border);
  border: 1px solid color-mix(in srgb, var(--text-muted) 30%, transparent);
  border-radius: var(--fc-radius-md);
  color: var(--fc-text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--fc-transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.fieldchat-btn-icon:hover {
  background: var(--glass-border-hover);
  border-color: color-mix(in srgb, var(--text-muted) 50%, transparent);
  color: var(--fc-text-primary);
}

.fieldchat-btn-icon:active {
  transform: scale(0.95);
  background: color-mix(in srgb, var(--text-muted) 35%, transparent);
}

/* ═══════════════════════════════════════════════════════════════════════
   CLOSE BUTTON — always visible, red accent, larger on mobile
   ═══════════════════════════════════════════════════════════════════════ */

#fieldchat-close-btn {
  background: color-mix(in srgb, var(--color-error) 18%, transparent);
  border-color: color-mix(in srgb, var(--color-error) 45%, transparent);
  color: var(--pill-rose-text);
}

#fieldchat-close-btn:hover {
  background: color-mix(in srgb, var(--color-error) 32%, transparent);
  border-color: color-mix(in srgb, var(--color-error) 65%, transparent);
  color: var(--alert-danger-text);
}

#fieldchat-close-btn:active {
  background: var(--fc-color-danger);
  border-color: var(--fc-color-danger);
  color: white;
}

#fieldchat-close-btn i {
  font-size: 1.1rem;
  font-weight: bold;
}

/* On mobile, give the close button a text label so it's unmistakeable */
@media (max-width: 767px) {
  #fieldchat-close-btn {
    /* Wider pill shape to accommodate the label */
    width: auto;
    padding: 0 0.85rem;
    gap: 0.35rem;
    border-radius: var(--fc-radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    /* Stronger background so it reads clearly against any chat content */
    background: color-mix(in srgb, var(--color-error) 22%, transparent);
  }

  /* Inject "Close" label via pseudo-element — no HTML change required */
  #fieldchat-close-btn::after {
    content: 'Close';
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--pill-rose-text);
  }

  #fieldchat-close-btn:hover::after { color: var(--alert-danger-text); }
  #fieldchat-close-btn:active::after { color: white; }
}

/* ═══════════════════════════════════════════════════════════════════════
   BODY - SCROLLABLE CHAT AREA
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.fieldchat-thread {
  height: 100%;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-muted) 40%, transparent) transparent;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.fieldchat-thread::-webkit-scrollbar {
  width: 6px;
}

.fieldchat-thread::-webkit-scrollbar-track {
  background: transparent;
}

.fieldchat-thread::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text-muted) 40%, transparent);
  border-radius: var(--fc-radius-full);
}

.fieldchat-thread::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-muted) 60%, transparent);
}

/* ═══════════════════════════════════════════════════════════════════════
   GREETING
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-greeting {
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: -0.005em;
  /* No surface, no border, no glow — just gradient text. */
  background: transparent;
  border: 0;
  box-shadow: none;
}

/* Gradient is applied to the INNER <p> (markdown wraps content) and to any
   direct text node. Doing it on the outer .fieldchat-greeting alone fails
   because the <p> child sets its own color via inheritance from the chat
   body, which overrides the gradient and renders white-on-white. */
.fieldchat-greeting,
.fieldchat-greeting p,
.fieldchat-greeting strong,
.fieldchat-greeting em {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-info) 100%) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent !important;
  /* Fallback for browsers that don't support background-clip: text */
  -moz-text-fill-color: transparent;
}

.fieldchat-greeting p {
  margin: 0;
}

.fieldchat-greeting strong {
  font-weight: 700;
}

/* ═══════════════════════════════════════════════════════════════════════
   MESSAGES
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-msg {
  display: flex;
  margin-bottom: 1rem;
  animation: fc-fadeIn 0.3s ease;
}

@keyframes fc-fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fieldchat-msg.user {
  justify-content: flex-end;
}

.fieldchat-msg.bot {
  justify-content: flex-start;
}

.fieldchat-msg-content {
  max-width: 85%;
  display: flex;
  flex-direction: column;
}

.fieldchat-msg.user .fieldchat-msg-content {
  align-items: flex-end;
}

.fieldchat-msg.bot .fieldchat-msg-content {
  align-items: flex-start;
}

/* ═══════════════════════════════════════════════════════════════════════
   MESSAGE BUBBLES
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--fc-radius-lg);
  font-size: 0.9rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.fieldchat-msg.user .fieldchat-bubble {
  background: var(--fc-gradient-primary);
  color: var(--fc-text-inverse);
  border-bottom-right-radius: 4px;
  box-shadow: var(--fc-shadow-glow);
}

.fieldchat-msg.bot .fieldchat-bubble {
  background: color-mix(in srgb, var(--surface-0) 90%, transparent);
  color: var(--fc-text-primary);
  border: 1px solid var(--fc-glass-border);
  border-bottom-left-radius: 4px;
}

/* Streaming indicator */
.fieldchat-bubble.streaming::after {
  content: '▋';
  animation: fc-blink 0.8s infinite;
  color: var(--fc-color-primary);
  margin-left: 2px;
}

@keyframes fc-blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════
   MARKDOWN STYLES IN BUBBLES
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-bubble h1,
.fieldchat-bubble h2,
.fieldchat-bubble h3,
.fieldchat-bubble h4,
.fieldchat-bubble h5,
.fieldchat-bubble h6 {
  margin-top: 0.75em;
  margin-bottom: 0.5em;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 600;
  line-height: 1.3;
  color: var(--fc-text-primary);
}

.fieldchat-bubble h1:first-child,
.fieldchat-bubble h2:first-child,
.fieldchat-bubble h3:first-child,
.fieldchat-bubble h4:first-child,
.fieldchat-bubble h5:first-child,
.fieldchat-bubble h6:first-child {
  margin-top: 0;
}

.fieldchat-bubble h1 { font-size: 1.35em; }
.fieldchat-bubble h2 { font-size: 1.2em; }
.fieldchat-bubble h3 { font-size: 1.1em; }
.fieldchat-bubble h4,
.fieldchat-bubble h5,
.fieldchat-bubble h6 { font-size: 1em; }

.fieldchat-bubble p {
  margin-bottom: 0.7em;
  line-height: 1.6;
}

.fieldchat-bubble p:last-child {
  margin-bottom: 0;
}

.fieldchat-bubble ul,
.fieldchat-bubble ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}

.fieldchat-bubble li {
  margin-bottom: 0.3em;
  line-height: 1.5;
}

.fieldchat-bubble li:last-child {
  margin-bottom: 0;
}

.fieldchat-bubble code {
  background: color-mix(in srgb, var(--surface-0) 35%, transparent);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.88em;
  color: var(--fc-color-chlorophyll);
}

.fieldchat-bubble pre {
  background: color-mix(in srgb, var(--surface-0) 45%, transparent);
  border: 1px solid var(--glass-border-hover);
  border-radius: var(--fc-radius-sm);
  padding: 0.7em 0.9em;
  margin: 0.7em 0;
  overflow-x: auto;
  font-size: 0.85em;
}

.fieldchat-bubble pre code {
  background: none;
  padding: 0;
  color: var(--fc-text-primary);
}

.fieldchat-bubble blockquote {
  border-left: 3px solid var(--fc-color-primary);
  margin: 0.7em 0;
  padding: 0.4em 0 0.4em 0.9em;
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  border-radius: 0 var(--fc-radius-sm) var(--fc-radius-sm) 0;
  font-style: italic;
  color: var(--fc-text-secondary);
}

.fieldchat-bubble a {
  color: var(--fc-color-primary-light);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--fc-transition-fast);
}

.fieldchat-bubble a:hover {
  color: var(--fc-color-chlorophyll);
}

.fieldchat-bubble strong,
.fieldchat-bubble b {
  font-weight: 600;
  color: var(--fc-text-primary);
}

.fieldchat-bubble em,
.fieldchat-bubble i {
  font-style: italic;
}

.fieldchat-bubble hr {
  border: none;
  border-top: 1px solid var(--glass-border-hover);
  margin: 0.9em 0;
}

.fieldchat-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.7em 0;
  font-size: 0.88em;
}

.fieldchat-bubble th,
.fieldchat-bubble td {
  border: 1px solid var(--glass-border-hover);
  padding: 0.45em 0.65em;
  text-align: left;
}

.fieldchat-bubble th {
  background: var(--pill-emerald-bg);
  font-weight: 600;
}

.fieldchat-bubble tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface-0) 8%, transparent);
}

/* ═══════════════════════════════════════════════════════════════════════
   NAVIGATION BUTTONS
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-nav-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid color-mix(in srgb, var(--text-muted) 20%, transparent);
}

.fieldchat-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.875rem;
  min-height: var(--fc-touch-target);
  background: var(--pill-emerald-bg);
  border: 1px solid color-mix(in srgb, var(--color-primary) 35%, transparent);
  border-radius: var(--fc-radius-full);
  color: var(--fc-color-primary-light);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--fc-transition-fast);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.fieldchat-nav-btn:hover {
  background: var(--fc-color-primary);
  border-color: var(--fc-color-primary);
  color: var(--fc-text-inverse);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--color-primary) 35%, transparent);
}

.fieldchat-nav-btn:active {
  transform: translateY(0);
}

.fieldchat-nav-btn i {
  font-size: 0.75rem;
}

/* Button variants */
.fieldchat-nav-btn.btn-products {
  background: var(--pill-indigo-bg);
  border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
  color: var(--pill-indigo-text);
}

.fieldchat-nav-btn.btn-products:hover {
  background: var(--fc-color-accent);
  border-color: var(--fc-color-accent);
  color: var(--fc-text-inverse);
}

.fieldchat-nav-btn.btn-research {
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  border-color: color-mix(in srgb, var(--color-warning) 35%, transparent);
  color: var(--pill-amber-text);
}

.fieldchat-nav-btn.btn-research:hover {
  background: var(--color-warning);
  border-color: var(--color-warning);
  color: var(--surface-0);
}

.fieldchat-nav-btn.btn-playground {
  background: color-mix(in srgb, var(--brand-pink) 12%, transparent);
  border-color: color-mix(in srgb, var(--brand-pink) 35%, transparent);
  color: var(--pill-pink-text);
}

.fieldchat-nav-btn.btn-playground:hover {
  background: var(--brand-pink);
  border-color: var(--brand-pink);
  color: var(--fc-text-inverse);
}

.fieldchat-nav-btn.btn-safety {
  background: var(--pill-rose-bg);
  border-color: color-mix(in srgb, var(--color-error) 35%, transparent);
  color: var(--pill-rose-text);
}

.fieldchat-nav-btn.btn-safety:hover {
  background: var(--color-error);
  border-color: var(--color-error);
  color: var(--fc-text-inverse);
}

.fieldchat-nav-btn.btn-solutions {
  background: color-mix(in srgb, var(--color-info) 12%, transparent);
  border-color: color-mix(in srgb, var(--color-info) 35%, transparent);
  color: var(--color-info);
}

.fieldchat-nav-btn.btn-solutions:hover {
  background: var(--color-info);
  border-color: var(--color-info);
  color: var(--surface-0);
}

.fieldchat-nav-btn.btn-contact {
  background: color-mix(in srgb, var(--product-fieldmap-accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--product-fieldmap-accent) 35%, transparent);
  color: var(--product-fieldmap-accent);
}

.fieldchat-nav-btn.btn-contact:hover {
  background: var(--product-fieldmap-accent);
  border-color: var(--product-fieldmap-accent);
  color: var(--fc-text-inverse);
}

.fieldchat-nav-placeholder:empty {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════════════
   MESSAGE META (TIMESTAMP + AUDIO)
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
  padding: 0 0.25rem;
}

.fieldchat-timestamp {
  font-size: 0.7rem;
  color: var(--fc-text-muted);
  font-family: 'IBM Plex Mono', monospace;
}

/* ═══════════════════════════════════════════════════════════════════════
   STAGE-PROGRESS LOADING CARD
   Replaces the old 3-dot typing indicator. Driven by the backend's
   per-stage events on /api/chat/jobs/<id>. Uses existing glass + brand
   tokens so it inherits dark/light theme automatically.
   ═══════════════════════════════════════════════════════════════════════ */

.fc-stagecard {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  background: var(--fc-glass-bg);
  backdrop-filter: var(--fc-glass-blur);
  -webkit-backdrop-filter: var(--fc-glass-blur);
  border: 1px solid var(--fc-glass-border);
  border-radius: var(--fc-radius-lg);
  border-bottom-left-radius: 4px;
  min-width: min(20rem, 100%);
  max-width: 22rem;
  box-shadow: var(--fc-shadow-sm);
}

.fc-stagecard-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.fc-brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: var(--fc-radius-sm);
  object-fit: contain;
  animation: fc-brand-breathe 2.2s ease-in-out infinite;
  will-change: transform, opacity;
}

@keyframes fc-brand-breathe {
  0%, 100% { transform: scale(1);     opacity: 0.85; }
  50%      { transform: scale(1.06);  opacity: 1;    }
}

.fc-stagecard-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
  flex: 1;
}

.fc-stagecard-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fc-text-primary);
  line-height: 1.25;
}

.fc-stagecard-elapsed {
  font-size: 0.75rem;
  color: var(--fc-text-secondary);
  font-variant-numeric: tabular-nums;
}

.fc-stagecard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.fc-stage {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--fc-text-secondary);
  line-height: 1.3;
  transition: color var(--fc-transition-fast);
}

.fc-stage-glyph {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid var(--fc-glass-border);
  background: transparent;
  position: relative;
  transition: border-color var(--fc-transition-fast), background var(--fc-transition-fast);
}

.fc-stage-label { flex: 1; min-width: 0; }

.fc-stage-meta {
  font-size: 0.75rem;
  color: var(--fc-color-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Pending — muted, hollow circle (default state above already covers it). */
.fc-stage.is-pending { opacity: 0.6; }

/* Running — accent ring with an animated inner pulse. */
.fc-stage.is-running {
  color: var(--fc-text-primary);
  opacity: 1;
}
.fc-stage.is-running .fc-stage-glyph {
  border-color: var(--fc-color-accent);
}
.fc-stage.is-running .fc-stage-glyph::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--fc-color-accent);
  animation: fc-stage-pulse 1.2s ease-in-out infinite;
}

@keyframes fc-stage-pulse {
  0%, 100% { transform: scale(0.6); opacity: 0.65; }
  50%      { transform: scale(1);   opacity: 1;    }
}

/* Done — primary green filled with a CSS check mark. */
.fc-stage.is-done { color: var(--fc-text-primary); opacity: 1; }
.fc-stage.is-done .fc-stage-glyph {
  border-color: var(--fc-color-primary);
  background: var(--fc-color-primary);
}
.fc-stage.is-done .fc-stage-glyph::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 1px;
  width: 4px;
  height: 7px;
  border-right: 1.5px solid var(--text-inverse);
  border-bottom: 1.5px solid var(--text-inverse);
  transform: rotate(45deg);
}

/* Failed — danger red, no check. */
.fc-stage.is-failed { color: var(--fc-color-danger); opacity: 1; }
.fc-stage.is-failed .fc-stage-glyph {
  border-color: var(--fc-color-danger);
  background: var(--fc-color-danger);
}

/* Skipped — dashed ring, muted. */
.fc-stage.is-skipped { opacity: 0.45; }
.fc-stage.is-skipped .fc-stage-glyph {
  border-style: dashed;
}

.fc-stagecard-hint {
  font-size: 0.6875rem;
  color: var(--fc-text-muted);
  text-align: center;
  padding-top: 0.125rem;
}

/* ═══════════════════════════════════════════════════════════════════════
   COMPOSER (INPUT AREA) - MOBILE FIRST
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-composer {
  padding: 0.75rem;
  background: var(--surface-3);
  border-top: 1px solid var(--fc-glass-border);
  flex-shrink: 0;
  /* Safe area for iPhone notch/home indicator */
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.fieldchat-composer-form {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.fieldchat-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--surface-0) 80%, transparent);
  border: 1px solid var(--fc-glass-border);
  border-radius: var(--fc-radius-full);
  padding: 0.5rem 0.625rem 0.5rem 1rem;
  min-height: var(--fc-touch-target);
  transition: border-color var(--fc-transition-fast), box-shadow var(--fc-transition-fast);
}

.fieldchat-input-wrapper:focus-within {
  border-color: var(--fc-color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 25%, transparent);
}

.fieldchat-composer-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fc-text-primary);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.25rem 0;
  min-width: 0;
}

.fieldchat-composer-input::placeholder {
  color: var(--fc-text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════
   SEND BUTTON - HIGHLY VISIBLE
   ═══════════════════════════════════════════════════════════════════════ */

.fieldchat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Large touch target */
  width: var(--fc-touch-target-lg);
  height: var(--fc-touch-target-lg);
  min-width: var(--fc-touch-target-lg);
  min-height: var(--fc-touch-target-lg);
  padding: 0;
  background: var(--fc-gradient-primary);
  border: none;
  border-radius: var(--fc-radius-full);
  color: var(--fc-text-inverse);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--fc-shadow-glow-strong);
  transition: all var(--fc-transition-fast);
  -webkit-tap-highlight-color: transparent;
  /* Ensure it's always visible */
  flex-shrink: 0;
}

.fieldchat-send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--color-primary) 60%, transparent);
}

.fieldchat-send-btn:active {
  transform: scale(0.95);
  box-shadow: var(--fc-shadow-glow);
}

.fieldchat-send-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
  box-shadow: none;
}

/* Send button icon */
.fieldchat-send-btn i {
  /* Slight offset to center the paper plane visually */
  margin-left: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE ADJUSTMENTS
   ═══════════════════════════════════════════════════════════════════════ */

/* Small phones */
@media (max-width: 374px) {
  .fieldchat-header {
    padding: 0.625rem 0.75rem;
  }
  
  .fieldchat-title {
    font-size: 0.9rem;
  }
  
  .fieldchat-avatar {
    width: 28px;
    height: 28px;
  }
  
  .fieldchat-thread {
    padding: 0.75rem;
  }
  
  .fieldchat-composer {
    padding: 0.625rem;
  }
  
  .fieldchat-bubble {
    padding: 0.625rem 0.875rem;
    font-size: 0.88rem;
  }
  
  .fieldchat-send-btn {
    width: var(--fc-touch-target);
    height: var(--fc-touch-target);
    min-width: var(--fc-touch-target);
    min-height: var(--fc-touch-target);
  }
}

/* Standard phones */
@media (max-width: 575.98px) {
  .fieldchat-msg-content {
    max-width: 88%;
  }
  
  .fieldchat-nav-buttons {
    flex-direction: column;
  }
  
  .fieldchat-nav-btn {
    width: 100%;
    justify-content: center;
  }
}

/* Tablet and up - can use slightly smaller buttons */
@media (min-width: 768px) {
  .fieldchat-btn-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
  }
  
  .fieldchat-send-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  
  .fieldchat-composer {
    padding: 0.875rem 1rem;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   PRINT - HIDE WIDGET
   ═══════════════════════════════════════════════════════════════════════ */

@media print {
  #fieldchat-root,
  .fieldchat-backdrop,
  .fieldchat-container {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   ACCESSIBILITY - Reduced Motion
   ═══════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .fieldchat-container,
  .fieldchat-backdrop,
  .fieldchat-msg,
  .fieldchat-btn-icon,
  .fieldchat-send-btn,
  .fieldchat-nav-btn,
  .fc-brand-mark,
  .fc-stage.is-running .fc-stage-glyph::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}