/* ════════════════════════════════════════════════════════════════════════════
   Synetic Portal — Base Components (#523)

   Built on tokens.css. New vocabulary for patterns that the audit found
   scattered as inline styles. Existing classes (.btn, .card, .m-input)
   are left alone in this PR — their migration to tokens lives in a
   follow-up. This file ONLY adds:

     - Truly new components (.pill, .status-dot, .empty-state, etc.)
     - New modifiers on existing classes that don't conflict (.btn-ghost,
       .card-info / .card-warning / .card-danger left-accent variants)

   Loaded AFTER portal.css so it can layer modifiers cleanly. Loading
   order in index.html:
     tokens.css  (foundation)
     portal.css  (existing styles, gradually migrating)
     components.css  (new component vocabulary — this file)

   Naming convention matches existing portal.css: kebab-case with dash
   modifiers (.pill-success, not .pill--success).

   See docs/UI-DESIGN.md for usage guidance.
   ════════════════════════════════════════════════════════════════════════════ */


/* ────────────────────────────────────────────────────────────────────────────
   Status pill — used for connection / activity / state labels.
   Differs from .badge: .pill is full-radius with a colored dot prefix,
   .badge is rectangular with rounded corners.
   ──────────────────────────────────────────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  font-family: var(--font-sans);
  border-radius: var(--radius-full);
  border: var(--border-width-default) solid transparent;
  white-space: nowrap;
  line-height: var(--leading-snug);
}

.pill::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  opacity: 0.85;
}

.pill-neutral {
  background: var(--bg-surface-2);
  color: var(--text-muted);
  border-color: var(--border-default);
}

.pill-success {
  background: var(--success-bg);
  color: var(--success-fg);
  border-color: rgba(34, 197, 94, 0.25);
}

.pill-warning {
  background: var(--warning-bg);
  color: var(--warning-fg);
  border-color: rgba(245, 158, 11, 0.25);
}

.pill-danger {
  background: var(--danger-bg);
  color: var(--danger-fg);
  border-color: rgba(239, 68, 68, 0.25);
}

.pill-info {
  background: var(--brand-soft-bg);
  color: var(--brand-soft-fg);
  border-color: rgba(99, 102, 241, 0.25);
}

/* Pill without the leading dot (for counts, plain labels) */
.pill-plain::before { display: none; }

/* Animated pill for indeterminate states (e.g. "Indexing…") */
.pill-pulsing::before {
  animation: pill-pulse 1.4s ease-in-out infinite;
}
@keyframes pill-pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1);    }
}


/* ────────────────────────────────────────────────────────────────────────────
   Status dot — bare 8px dot for compact connection indicators.
   Standardizes the scattered inline `<span style="width:8px;height:8px;">`
   patterns the audit identified.
   ──────────────────────────────────────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot-success { background: var(--success-solid); box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }
.status-dot-warning { background: var(--warning-solid); box-shadow: 0 0 6px rgba(245, 158, 11, 0.5); }
.status-dot-danger  { background: var(--danger-solid);  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5); }
.status-dot-muted   { background: var(--text-muted); }
.status-dot-info    { background: var(--brand); box-shadow: 0 0 6px rgba(99, 102, 241, 0.5); }

/* Pulsing animation for activity indicators (chat-active, indexing, etc.) */
.status-dot-pulsing {
  animation: status-dot-pulse 1.4s ease-in-out infinite;
}
@keyframes status-dot-pulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1;   }
}


/* ────────────────────────────────────────────────────────────────────────────
   Empty state — single template for "no data yet" surfaces.
   The audit found inconsistent empty states across the portal:
   My Agents has icon+title+CTA; Knowledge Sources has plain text;
   Team has "Loading..." that becomes empty if data fails. This unifies.
   ──────────────────────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  gap: var(--space-3);
  background: var(--bg-surface);
  border: var(--border-width-default) solid var(--border-default);
  border-radius: var(--radius-lg);
}

.empty-state-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-2);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.empty-state-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

.empty-state-body {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
  max-width: 420px;
  margin: 0;
}

.empty-state-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  flex-wrap: wrap;
  justify-content: center;
}

/* Compact variant for inline empty states (inside a card with other content) */
.empty-state-sm {
  padding: var(--space-6) var(--space-4);
  gap: var(--space-2);
}

.empty-state-sm .empty-state-icon {
  width: 36px;
  height: 36px;
}

.empty-state-sm .empty-state-title {
  font-size: var(--text-base);
}

.empty-state-sm .empty-state-body {
  font-size: var(--text-md);
}


/* ────────────────────────────────────────────────────────────────────────────
   Tab strip — horizontal tabs for in-page navigation.
   The audit found Expertise uses a bespoke #expertise-tabs implementation;
   this generalizes so other pages can adopt the same vocabulary.
   ──────────────────────────────────────────────────────────────────────────── */

.tab-strip {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-base);
  border: var(--border-width-default) solid var(--border-default);
  border-radius: var(--radius-lg);
}

.tab-strip-item {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--motion-fast) var(--easing-out),
              color var(--motion-fast) var(--easing-out);
  position: relative;
}

.tab-strip-item:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.tab-strip-item-active,
.tab-strip-item[aria-selected="true"] {
  background: var(--brand);
  color: var(--brand-fg);
}

.tab-strip-item-active:hover,
.tab-strip-item[aria-selected="true"]:hover {
  background: var(--brand);
  color: var(--brand-fg);
}

/* Step indicator bullet (between tabs) — used in workflow-style strips */
.tab-strip-step {
  color: var(--text-muted);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

/* Pulse dot inside an inactive tab — signals "next recommended step" */
.tab-strip-pulse {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 6px;
  height: 6px;
  background: var(--brand);
  border-radius: var(--radius-full);
  animation: tab-strip-pulse 1.6s ease-in-out infinite;
}
@keyframes tab-strip-pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1.1);  }
}

/* Vertical variant — same items, stacked */
.tab-strip-vertical {
  flex-direction: column;
  align-items: stretch;
}

.tab-strip-vertical .tab-strip-item {
  justify-content: flex-start;
}


/* ────────────────────────────────────────────────────────────────────────────
   Form primitives — field group, label, helper text.
   The audit found 2 input class names (.form-input vs .m-input) and
   inline-styled form rows everywhere. This adds the wrapper / label /
   helper components so future forms have a single shape. The input,
   select, textarea elements themselves still use existing .m-input etc.
   classes (refactor lives in next PR).
   ──────────────────────────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  line-height: var(--leading-snug);
}

.label-required::after {
  content: '*';
  color: var(--danger-fg);
  margin-left: 2px;
}

.field-help {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: var(--leading-normal);
  margin-top: var(--space-1);
}

.field-error {
  font-size: var(--text-xs);
  color: var(--danger-fg);
  line-height: var(--leading-normal);
  margin-top: var(--space-1);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Input group: input + suffix or prefix (e.g., email username + @domain) */
.input-group {
  display: flex;
  align-items: stretch;
}

.input-group > * {
  border-radius: 0;
}

.input-group > *:first-child {
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}

.input-group > *:last-child {
  border-top-right-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

.input-group > *:not(:first-child) {
  border-left: 0;
}


/* ────────────────────────────────────────────────────────────────────────────
   Section heading — small heading inside a card or panel.
   Replaces the inline `<div style="font-size:13px;font-weight:700;">` pattern.
   ──────────────────────────────────────────────────────────────────────────── */

.section-heading {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.section-heading-eyebrow {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}


/* ────────────────────────────────────────────────────────────────────────────
   Icon button — square button containing only an icon.
   Standardizes the inline `<button style="padding:4px;...">` patterns
   used for delete / edit / close in lists.
   ──────────────────────────────────────────────────────────────────────────── */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: var(--border-width-default) solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--motion-fast) var(--easing-out),
              color var(--motion-fast) var(--easing-out);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.icon-btn-sm { width: 22px; height: 22px; }
.icon-btn-lg { width: 36px; height: 36px; }

.icon-btn-danger:hover {
  background: var(--danger-bg);
  color: var(--danger-fg);
}


/* ────────────────────────────────────────────────────────────────────────────
   Card accent variants — left-border colored cards.
   The audit found 20+ inline `border-left:3px solid #...` patterns.
   These modifiers extract that into a reusable system. Apply alongside
   the existing .card or .m-card classes.
   ──────────────────────────────────────────────────────────────────────────── */

.card-info,
.m-card-info {
  border-left: var(--border-width-accent) solid var(--brand);
}

.card-success,
.m-card-success {
  border-left: var(--border-width-accent) solid var(--success-solid);
}

.card-warning,
.m-card-warning {
  border-left: var(--border-width-accent) solid var(--warning-solid);
}

.card-danger,
.m-card-danger {
  border-left: var(--border-width-accent) solid var(--danger-solid);
}

.card-brand2,
.m-card-brand2 {
  border-left: var(--border-width-accent) solid var(--brand2-500);
}


/* ────────────────────────────────────────────────────────────────────────────
   Button modifiers — adds .btn-ghost (was missing despite being referenced
   in HTML at index.html:844). Existing .btn / .btn-primary / .btn-secondary /
   .btn-danger / .btn-sm in portal.css are unchanged in this PR.
   ──────────────────────────────────────────────────────────────────────────── */

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: var(--border-width-default) solid transparent;
}

.btn-ghost:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.btn-lg {
  padding: 12px 24px;
  font-size: var(--text-base);
}

/* Icon prefix / suffix slot inside a button — keeps icon and text aligned */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}


/* ────────────────────────────────────────────────────────────────────────────
   Divider — horizontal rule with consistent spacing.
   ──────────────────────────────────────────────────────────────────────────── */

.divider {
  border: 0;
  border-top: var(--border-width-default) solid var(--border-default);
  margin: var(--space-4) 0;
}

.divider-tight { margin: var(--space-2) 0; }
.divider-loose { margin: var(--space-6) 0; }


/* ────────────────────────────────────────────────────────────────────────────
   Kbd — keyboard key display for shortcut hints.
   ──────────────────────────────────────────────────────────────────────────── */

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-1);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  background: var(--bg-surface-2);
  border: var(--border-width-default) solid var(--border-default);
  border-radius: var(--radius-sm);
  line-height: 1;
}


/* ────────────────────────────────────────────────────────────────────────────
   Skeleton — animated placeholder for loading states.
   Standardizes loading affordance. Used as a child of .skeleton-stack
   for vertical lists or inline as a single block.
   ──────────────────────────────────────────────────────────────────────────── */

.skeleton {
  display: block;
  background: linear-gradient(
    90deg,
    var(--bg-surface-2) 0%,
    var(--bg-surface) 50%,
    var(--bg-surface-2) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  height: 14px;
  width: 100%;
}

.skeleton-line   { height: 14px; }
.skeleton-title  { height: 22px; }
.skeleton-avatar { height: 36px; width: 36px; border-radius: var(--radius-full); }

.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ────────────────────────────────────────────────────────────────────────────
   Slide-over — right-side panel for primary editing (#523 sub-issue 8).
   Replaces modal-based edit flows so the user can reference the underlying
   page. Use .slide-over for the overlay backdrop, .slide-over-panel for
   the actual content panel. Toggle .open class to show.
   ──────────────────────────────────────────────────────────────────────────── */

.slide-over {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  justify-content: flex-end;
  z-index: var(--z-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-base) var(--easing-out);
}

.slide-over.open {
  opacity: 1;
  pointer-events: auto;
}

.slide-over-panel {
  width: var(--slide-over-w);
  max-width: 100vw;
  height: 100%;
  background: var(--bg-surface);
  border-left: var(--border-width-default) solid var(--border-default);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--motion-base) var(--easing-out);
  z-index: var(--z-modal);
}

.slide-over.open .slide-over-panel {
  transform: translateX(0);
}

.slide-over-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: var(--border-width-default) solid var(--border-default);
  flex-shrink: 0;
}

.slide-over-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

.slide-over-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.slide-over-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: var(--border-width-default) solid var(--border-default);
  background: var(--bg-base);
  flex-shrink: 0;
}

/* Wider slide-over for content-heavy edits */
.slide-over-lg .slide-over-panel { width: 640px; }
.slide-over-xl .slide-over-panel { width: 800px; }


/* ────────────────────────────────────────────────────────────────────────────
   Save state stamp — "Saved · 2s ago" indicator (#523 sub-issue 3).
   Companion to the auto-save model agreed in #523. Place inside a card
   header to indicate save state without an explicit button.
   ──────────────────────────────────────────────────────────────────────────── */

.save-stamp {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-sans);
}

.save-stamp-dirty   { color: var(--warning-fg); }
.save-stamp-saving  { color: var(--text-muted); }
.save-stamp-saved   { color: var(--success-fg); }
.save-stamp-error   { color: var(--danger-fg); }


/* ────────────────────────────────────────────────────────────────────────────
   Focus ring utility — apply to any element that needs a visible focus state.
   Avoids re-defining the focus shadow per component.
   ──────────────────────────────────────────────────────────────────────────── */

.focusable:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}


/* ────────────────────────────────────────────────────────────────────────────
   Visually-hidden — content for screen readers only.
   Use on labels that aren't visible but should be announced.
   ──────────────────────────────────────────────────────────────────────────── */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ────────────────────────────────────────────────────────────────────────────
   Accessibility baseline (#523 sub-issue 13)
   ──────────────────────────────────────────────────────────────────────────── */

/* Skip-to-content link. Visually hidden until focused. Keyboard users tab to
   it as the very first focusable element on the page and jump past the nav. */
.skip-link {
  position: absolute;
  top: -100px;
  left: 12px;
  z-index: 9999;
  padding: 8px 14px;
  background: var(--surface, #1a1a1a);
  color: var(--text, #fff);
  border: 1px solid var(--border, #333);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus {
  top: 12px;
  outline: none;
  box-shadow: var(--focus-ring);
}

/* Baseline focus ring for any keyboard-focused interactive element that
   doesn't already define its own. Using :focus-visible avoids the
   click-and-leave-an-outline behavior. */
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-md, 8px);
}

/* Reduced motion preference — respect the user's OS-level setting. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ────────────────────────────────────────────────────────────────────────────
   Optional-card marker on Expertise
   Replaces the previous "Show advanced" progressive-disclosure toggle.
   Cards that aren't required to ship (Mental Models, Patterns, Socratic Mode,
   Metacognition, Emotional Awareness, Anticipation) carry data-optional="true"
   from portal.js, which paints a small "Optional" pill at the top-right of
   the card. The pill is informational only — every card is always rendered.
   ──────────────────────────────────────────────────────────────────────────── */

#page-manage-llm [data-optional="true"] {
  position: relative;
}
#page-manage-llm [data-optional="true"]::before {
  content: 'Optional';
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 1;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #7a7888);
  background: var(--bg-surface-2, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border-default, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-full, 9999px);
  pointer-events: none;
}


/* ────────────────────────────────────────────────────────────────────────────
   Org inheritance banner (#523 sub-issue 12)
   Shown beneath an agent-level field that's enforced at the org level.
   Uses a subtle warning tint plus a clear "Manage at organization level"
   link for users who can edit the org settings.
   ──────────────────────────────────────────────────────────────────────────── */

.org-inherited {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--warning-bg, rgba(245, 158, 11, 0.07));
  border: 1px solid var(--warning-border, rgba(245, 158, 11, 0.22));
  border-radius: var(--radius-md, 8px);
  font-size: 12px;
  color: var(--text-2, var(--text-secondary));
  line-height: 1.5;
}
.org-inh-icon {
  flex-shrink: 0;
  color: var(--warning-fg, #d97706);
}
.org-inh-text { flex: 1; min-width: 0; }
.org-inh-link {
  color: var(--brand, var(--primary));
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.org-inh-link:hover { text-decoration: underline; }

/* Disabled inputs that are locked by org enforcement get a clearer visual
   than plain HTML disabled. Same pattern across <input>, <select>,
   <textarea> so the cue is consistent everywhere. */
[data-org-locked="true"] {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--bg-base, var(--bg)) !important;
}


/* ────────────────────────────────────────────────────────────────────────────
   Card accents — additional hue variants beyond the four semantic ones
   (info/success/warning/danger/brand2). Used by the Expertise page where
   each cognitive layer carries a distinctive accent so owners can tell
   them apart at a glance. Naming describes the hue, not a semantic role —
   these are intentionally non-semantic differentiators.
   ──────────────────────────────────────────────────────────────────────────── */

.card-accent-blue,
.m-card-accent-blue       { border-left: var(--border-width-accent) solid #3b82f6; }
.card-accent-pink,
.m-card-accent-pink       { border-left: var(--border-width-accent) solid #ec4899; }
.card-accent-violet,
.m-card-accent-violet     { border-left: var(--border-width-accent) solid #8b5cf6; }
.card-accent-cyan,
.m-card-accent-cyan       { border-left: var(--border-width-accent) solid #06b6d4; }
.card-accent-lavender,
.m-card-accent-lavender   { border-left: var(--border-width-accent) solid #a78bfa; }
.card-accent-emerald,
.m-card-accent-emerald    { border-left: var(--border-width-accent) solid #10b981; }


/* ────────────────────────────────────────────────────────────────────────────
   Card header row — flex row with title on left, actions on right. The
   most-repeated layout pattern in the portal (28+ occurrences). Three
   spacing variants for tight / default / loose.
   ──────────────────────────────────────────────────────────────────────────── */

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-header-row-tight  { margin-bottom: 6px; }
.card-header-row-loose  { margin-bottom: 14px; }
.card-header-row-md     { margin-bottom: 12px; }


/* ────────────────────────────────────────────────────────────────────────────
   Card help text — the "what is this card about" paragraph that sits below
   the title. Standardized so prose blocks across the portal share line
   height and color.
   ──────────────────────────────────────────────────────────────────────────── */

.card-help {
  font-size: 12px;
  color: var(--text-2, var(--text-secondary));
  line-height: 1.6;
  margin-bottom: 12px;
}


/* ────────────────────────────────────────────────────────────────────────────
   Margin / display utilities — restrained set. We avoid Tailwind-style
   utility spam, but a handful of one-property classes earn their keep
   because they appear hundreds of times across dynamic HTML.
   ──────────────────────────────────────────────────────────────────────────── */

.m-0          { margin: 0; }
.is-hidden    { display: none; }


/* ────────────────────────────────────────────────────────────────────────────
   Pill — extra-small variant. The portal's status badges historically use
   10px font + 8px radius (slightly smaller and less round than the default
   .pill). This modifier preserves that look so existing inline pills can
   migrate to the .pill component without visual change.
   ──────────────────────────────────────────────────────────────────────────── */

.pill-xs {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 8px;
}


/* ────────────────────────────────────────────────────────────────────────────
   AI gradient button — for "AI Generate / AI Draft / AI Suggest" actions
   sprinkled across the portal. Unifies ~20 inline gradient buttons under
   one class, driven by brand tokens so a brand refresh reflows everything.
   ──────────────────────────────────────────────────────────────────────────── */

.btn-ai {
  background: linear-gradient(135deg, var(--brand, var(--primary)), var(--brand2, var(--primary-2))) !important;
  color: var(--brand-fg, #fff) !important;
  border: 0 !important;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-ai:hover {
  filter: brightness(1.05);
}


/* ────────────────────────────────────────────────────────────────────────────
   .btn-quiet — secondary-style action with a filled surface (vs
   .btn-secondary's transparent background). Used for "Configure" / "Manage"
   actions that sit inside a card and need to recede slightly.
   ──────────────────────────────────────────────────────────────────────────── */

.btn-quiet {
  background: var(--bg-surface-2, var(--surface-2)) !important;
  color: var(--text-secondary, var(--text-2)) !important;
  border: 1px solid var(--border-default, var(--border)) !important;
  font-size: 11px;
  padding: 5px 14px;
}
.btn-quiet:hover {
  background: var(--hover-bg) !important;
  color: var(--text-primary, var(--text)) !important;
}


/* ────────────────────────────────────────────────────────────────────────────
   .placeholder-text — for "Loading…" / "No items yet" messages inside
   list cards. Standardizes the muted 13px text + vertical padding pattern.
   ──────────────────────────────────────────────────────────────────────────── */

.placeholder-text {
  color: var(--text-muted, var(--muted));
  font-size: 13px;
  padding: 20px 0;
}


/* ────────────────────────────────────────────────────────────────────────────
   Inline meta text — small muted helper text. The portal had 17+ inline
   sites with this exact styling; now there's one class.
   ──────────────────────────────────────────────────────────────────────────── */

.text-meta { font-size: 12px; color: var(--text-muted, var(--muted)); }


/* ────────────────────────────────────────────────────────────────────────────
   AI button — disabled state when no LLM provider is configured
   (#458). Adds a visual cue alongside the disabled attribute.
   ──────────────────────────────────────────────────────────────────────────── */

.btn-ai[data-no-llm="true"],
.btn-ai:disabled {
  opacity: 0.45 !important;
  cursor: not-allowed !important;
  filter: grayscale(0.5);
  pointer-events: auto !important; /* allow tooltip on hover */
}
.btn-ai[data-no-llm="true"]:hover {
  filter: grayscale(0.5); /* don't brighten when disabled */
}


/* ────────────────────────────────────────────────────────────────────────────
   Legacy modal overlay — for static modals (terms, deactivate, duplicate,
   cancel, etc.) and dynamically-created confirmation overlays. Show /
   close via inline style.display = 'flex' / 'none' (existing handlers).
   Normalizes the 14+ inline overlay declarations across portal.js +
   index.html into one class.
   ──────────────────────────────────────────────────────────────────────────── */

.modal-overlay-legacy {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay, rgba(0, 0, 0, 0.7));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 20px;
}
.modal-overlay-legacy.is-open { display: flex; }


/* ════════════════════════════════════════════════════════════════════════════
   Responsive — phone & small tablet (#523 — mobile pass)

   Strategy: progressive enhancement. The portal is desktop-first. These
   rules only narrow grids, ease padding, and full-width overlays at
   sub-tablet sizes. Existing desktop behavior is unchanged at >768px.
   ════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Manage pages: tighter horizontal padding so content doesn't crowd */
  .manage-page {
    padding: 24px 16px !important;
  }

  /* Page header: smaller title, tighter margins */
  .page-header { margin-bottom: 16px; }
  .page-title { font-size: 22px !important; }
  .page-subtitle { font-size: 13px !important; }

  /* Slide-overs: full-width on phone */
  .slide-over-panel,
  .slide-over-lg .slide-over-panel,
  .slide-over-xl .slide-over-panel {
    width: 100vw !important;
    max-width: 100vw !important;
  }

  /* Modal overlays: reduce padding so the dialog has more room */
  .modal-overlay,
  .modal-overlay-legacy {
    padding: 12px !important;
  }
  .modal {
    max-width: 100% !important;
    padding: 24px 20px !important;
  }

  /* Form rows: stack two-column form fields to single column */
  .m-row {
    grid-template-columns: 1fr !important;
  }

  /* Card padding: a bit tighter */
  .m-card,
  .card {
    padding: 18px 16px !important;
  }

  /* Stat grid: smaller min-width so two cells fit on a phone */
  .m-stats-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 10px !important;
  }

  /* Feature flag grid: smaller min-width */
  #features-grid-wrap {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
  }

  /* Card-header-row: allow wrapping when title + actions overflow */
  .card-header-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Expertise tab strip: hide the decorative arrows on phone, allow scroll */
  #expertise-tabs {
    overflow-x: auto;
    flex-wrap: nowrap !important;
  }
  #expertise-tabs > span { display: none; }
  #expertise-tabs button { font-size: 10px !important; padding: 6px 8px !important; }

  /* Manage breadcrumb: tighter padding, allow wrap */
  .manage-breadcrumb {
    padding: 12px 16px 0 !important;
    flex-wrap: wrap;
  }

  /* Topbar: ensure it shows on mobile and the sidebar toggle works */
  #topbar {
    padding: 12px 16px;
  }

  /* Toast container: don't overflow off screen */
  #toast-container {
    bottom: 12px !important;
    right: 12px !important;
    left: 12px !important;
    max-width: calc(100vw - 24px);
  }

  /* Hide large secondary content that's not essential on phone */
  .hide-on-mobile { display: none !important; }
}

/* Phone-specific (< 480px) */
@media (max-width: 480px) {
  .manage-page { padding: 16px 12px !important; }
  .m-card, .card { padding: 14px 12px !important; }
  .page-title { font-size: 20px !important; }

  /* Confirm dialog and small modals fully fit */
  .modal { padding: 20px 16px !important; }

  /* Drop the breadcrumb middle pieces, just show "Agents / [page]" */
  .manage-breadcrumb .crumb:nth-child(3),
  .manage-breadcrumb .crumb-sep:nth-child(4) {
    display: none;
  }
}


/* ════════════════════════════════════════════════════════════════════════════
   Light-mode polish (#523 — sub-issue 3 long tail)

   Targeted fixes for places where dark-mode assumptions leaked through:
   shadows recoloured, button gradients re-tinted, card borders firmed up.
   The token system mostly handles this; these are spot fixes for elements
   that bypassed tokens.
   ════════════════════════════════════════════════════════════════════════════ */

[data-theme="light"] {
  /* Slightly stronger card border so cards stay visible against the
     near-white background. Without this, cards on light bg almost
     disappear. */
  --border-default: rgba(0, 0, 0, 0.10);
  --border-strong:  rgba(0, 0, 0, 0.16);
}

/* Help FAB gradient — tones down on light bg */
[data-theme="light"] #help-fab {
  box-shadow: var(--shadow-md, 0 4px 12px rgba(15, 23, 42, 0.12));
}

/* Toasts on light: soften the dark backdrop visible behind them */
[data-theme="light"] .toast {
  border-color: rgba(0, 0, 0, 0.08);
}

/* Slide-over panel border — needs more contrast on light bg */
[data-theme="light"] .slide-over-panel {
  border-left-color: rgba(0, 0, 0, 0.10);
}

/* AI button — slightly softer gradient in light mode so it doesn't
   clash with the lighter surrounding palette */
[data-theme="light"] .btn-ai {
  filter: saturate(0.92) brightness(0.96);
}

/* Pills on light mode get a touch more border presence */
[data-theme="light"] .pill {
  border-color: rgba(0, 0, 0, 0.08);
}
