/* ==========================================================================
   iEngage Design System — Nexus palette, Inter font, webapp scale
   Matches iEngage Unified Asset Library visual language
   ========================================================================== */

/* --------------------------------------------------------------------------
   Font
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* --------------------------------------------------------------------------
   Design Tokens
   -------------------------------------------------------------------------- */
:root, [data-theme="light"] {
  /* Surfaces */
  --color-bg:               #f4f2ed;
  --color-surface:          #f9f8f5;
  --color-surface-2:        #ffffff;
  --color-surface-offset:   #f0ede8;
  --color-surface-offset-2: #eae7e1;
  --color-surface-dynamic:  #e3e0da;
  --color-divider:          #e3e0da;
  --color-border:           #dbd8d2;

  /* Text */
  --color-text:             #25221c;
  --color-text-muted:       #8a8882;
  --color-text-faint:       #b5b3ae;
  --color-text-inverse:     #f9f8f5;

  /* Primary — Hydra Teal */
  --color-primary:          #01696f;
  --color-primary-hover:    #0c4e54;
  --color-primary-active:   #0f3638;
  --color-primary-soft:     #e3f1f0;
  --color-primary-highlight:#cedcd8;

  /* AI accent */
  --color-ai-bg:            #edf6f7;
  --color-ai-border:        #c3dde0;
  --color-ai-text:          #0a5157;

  /* Status */
  --color-success:          #277c54;
  --color-success-bg:       #e0f4ea;
  --color-warning:          #8c6a1b;
  --color-warning-bg:       #fdf5dc;
  --color-error:            #a12c7b;
  --color-error-bg:         #ffe5f1;
  --color-info:             #2550a4;
  --color-info-bg:          #eef4ff;

  /* Type scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radius */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(15,12,8,0.06);
  --shadow-md:  0 6px 20px rgba(15,12,8,0.07);
  --shadow-lg:  0 12px 36px rgba(15,12,8,0.10);
  --shadow-ai:  0 8px 26px rgba(10,81,86,0.14);

  /* Transitions */
  --transition: 150ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Layout */
  --header-h:   52px;
  --panel-gap:  10px;
}

[data-theme="dark"] {
  --color-bg:               #171614;
  --color-surface:          #1c1b19;
  --color-surface-2:        #201f1d;
  --color-surface-offset:   #1d1c1a;
  --color-surface-offset-2: #222120;
  --color-surface-dynamic:  #2d2c2a;
  --color-divider:          #262523;
  --color-border:           #393836;
  --color-text:             #cdccca;
  --color-text-muted:       #797876;
  --color-text-faint:       #5a5957;
  --color-text-inverse:     #2b2a28;
  --color-primary:          #4f98a3;
  --color-primary-hover:    #227f8b;
  --color-primary-active:   #1a626b;
  --color-primary-soft:     #1e3335;
  --color-primary-highlight:#313b3b;
  --color-ai-bg:            #1a2e30;
  --color-ai-border:        #2a4a4e;
  --color-ai-text:          #7bbcc4;
  --color-success:          #6daa45;
  --color-success-bg:       #1e3320;
  --color-warning:          #e8af34;
  --color-warning-bg:       #2e2510;
  --color-error:            #d163a7;
  --color-error-bg:         #2e1525;
  --color-info:             #5591c7;
  --color-info-bg:          #1a2535;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.2);
  --shadow-md:  0 6px 20px rgba(0,0,0,0.3);
  --shadow-lg:  0 12px 36px rgba(0,0,0,0.4);
  --shadow-ai:  0 8px 26px rgba(0,0,0,0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:               #171614;
    --color-surface:          #1c1b19;
    --color-surface-2:        #201f1d;
    --color-surface-offset:   #1d1c1a;
    --color-surface-offset-2: #222120;
    --color-surface-dynamic:  #2d2c2a;
    --color-divider:          #262523;
    --color-border:           #393836;
    --color-text:             #cdccca;
    --color-text-muted:       #797876;
    --color-text-faint:       #5a5957;
    --color-text-inverse:     #2b2a28;
    --color-primary:          #4f98a3;
    --color-primary-hover:    #227f8b;
    --color-primary-active:   #1a626b;
    --color-primary-soft:     #1e3335;
    --color-primary-highlight:#313b3b;
    --color-ai-bg:            #1a2e30;
    --color-ai-border:        #2a4a4e;
    --color-ai-text:          #7bbcc4;
    --color-success:          #6daa45;
    --color-success-bg:       #1e3320;
    --color-warning:          #e8af34;
    --color-warning-bg:       #2e2510;
    --color-error:            #d163a7;
    --color-error-bg:         #2e1525;
    --color-info:             #5591c7;
    --color-info-bg:          #1a2535;
  }
}

/* --------------------------------------------------------------------------
   Base Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  font-size: 13px;
}

body {
  min-height: 100dvh;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  overflow: hidden;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }
ul, ol { list-style: none; }

::selection {
  background: color-mix(in oklch, var(--color-primary) 20%, transparent);
  color: var(--color-text);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   App Shell
   -------------------------------------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: 10px;
  gap: var(--panel-gap);
  overflow: hidden;
}

/* View switching */
#view-workspace,
#view-library,
#view-profiles,
#view-knowledge {
  display: none;
}
.view-is-workspace #view-workspace {
  display: grid;
}
.view-is-library #view-library {
  display: grid;
}
.view-is-profiles #view-profiles {
  display: grid;
}
.view-is-knowledge #view-knowledge {
  display: grid;
}


/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: radial-gradient(circle at 25% 25%, #52bac6 0%, #01696f 45%, #003c40 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(1,105,111,0.36);
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.logo-sub {
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 1px;
}

/* Nav tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.nav-tab:hover:not(.active):not(.disabled) {
  background: var(--color-divider);
  color: var(--color-text);
}

.nav-tab.active {
  background: var(--color-surface-2);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.nav-tab.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-tab .tab-badge {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--color-surface-dynamic);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Header right */
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  font-size: 11px;
  color: var(--color-text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
}

.status-dot.connecting {
  background: var(--color-warning);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.error {
  background: var(--color-error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Theme toggle */
.theme-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}
.theme-toggle:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Main 2-panel layout
   -------------------------------------------------------------------------- */
.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: var(--panel-gap);
  min-height: 0;
}

/* --------------------------------------------------------------------------
   Panel base
   -------------------------------------------------------------------------- */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-offset);
  flex-shrink: 0;
}

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-title svg {
  color: var(--color-primary);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --------------------------------------------------------------------------
   Left Panel — Chat
   -------------------------------------------------------------------------- */
.chat-panel {
  grid-column: 1;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-thumb {
  background: var(--color-divider);
  border-radius: var(--radius-full);
}

/* Message bubbles */
.msg {
  display: flex;
  gap: var(--space-2);
  animation: msgIn 200ms cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg.agent .msg-avatar {
  background: radial-gradient(circle at 25% 25%, #52bac6 0%, #01696f 45%, #003c40 100%);
  color: #fff;
  box-shadow: 0 3px 10px rgba(1,105,111,0.28);
}

.msg.user .msg-avatar {
  background: var(--color-surface-offset-2);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.msg-bubble {
  max-width: calc(100% - 44px);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.55;
}

.msg.agent .msg-bubble {
  background: var(--color-ai-bg);
  border: 1px solid var(--color-ai-border);
  border-top-left-radius: var(--radius-sm);
  color: var(--color-text);
}

.msg.user .msg-bubble {
  background: var(--color-primary);
  color: #fff;
  border-top-right-radius: var(--radius-sm);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-3) var(--space-4);
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--color-ai-text);
  border-radius: 50%;
  animation: typingDot 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* Progress chips inside chat */
.intake-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: var(--space-2) 0;
}

.progress-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

.progress-chip.done {
  background: var(--color-success-bg);
  border-color: color-mix(in oklch, var(--color-success) 30%, transparent);
  color: var(--color-success);
}

.progress-chip.active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-highlight);
  color: var(--color-primary);
  animation: chipPulse 2s ease-in-out infinite;
}

@keyframes chipPulse {
  0%, 100% { box-shadow: none; }
  50%       { box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary) 15%, transparent); }
}

/* Chat input */
.chat-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-row:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary) 12%, transparent);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  min-height: 20px;
  max-height: 120px;
  color: var(--color-text);
  padding: 2px 0;
}

.chat-input::placeholder { color: var(--color-text-faint); }

.send-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  border: none;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.send-btn:hover { background: var(--color-primary-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled {
  background: var(--color-surface-dynamic);
  color: var(--color-text-faint);
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Right Panel — Canvas
   -------------------------------------------------------------------------- */
.canvas-panel {
  grid-column: 2;
  display: flex;
  flex-direction: column;
}

.canvas-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
}

.canvas-body::-webkit-scrollbar { width: 4px; }
.canvas-body::-webkit-scrollbar-thumb {
  background: var(--color-divider);
  border-radius: var(--radius-full);
}

/* Empty state */
.canvas-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--color-text-faint);
  text-align: center;
  padding: var(--space-8);
}

.canvas-empty-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-lg);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
}

.canvas-empty h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.canvas-empty p {
  font-size: 12px;
  color: var(--color-text-faint);
  max-width: 28ch;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Pipeline tracker (Step 4 placeholder styles)
   -------------------------------------------------------------------------- */
.pipeline-tracker {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  flex-shrink: 0;
}

.pipeline-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-faint);
  margin-bottom: var(--space-3);
}

.pipeline-stages {
  display: flex;
  align-items: center;
  gap: 0;
}

.pipeline-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  position: relative;
}

.pipeline-stage:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 13px;
  left: calc(50% + 14px);
  right: calc(-50% + 14px);
  height: 2px;
  background: var(--color-divider);
  z-index: 0;
}

.pipeline-stage:not(:last-child).done::after,
.pipeline-stage:not(:last-child).running::after {
  background: color-mix(in oklch, var(--color-primary) 40%, var(--color-divider));
}

.stage-node {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-faint);
  font-size: 11px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  transition: all var(--transition);
}

.pipeline-stage.pending .stage-node {
  border-color: var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-faint);
}

.pipeline-stage.running .stage-node {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  animation: stageRun 1.5s ease-in-out infinite;
}

@keyframes stageRun {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklch, var(--color-primary) 30%, transparent); }
  50%       { box-shadow: 0 0 0 5px transparent; }
}

.pipeline-stage.done .stage-node {
  border-color: var(--color-success);
  background: var(--color-success-bg);
  color: var(--color-success);
}

.pipeline-stage.blocked .stage-node {
  border-color: var(--color-error);
  background: var(--color-error-bg);
  color: var(--color-error);
}

.stage-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.pipeline-stage.running .stage-label { color: var(--color-primary); font-weight: 600; }
.pipeline-stage.done .stage-label    { color: var(--color-success); }
.pipeline-stage.blocked .stage-label { color: var(--color-error); }

/* --------------------------------------------------------------------------
   Output cards (Step 5 placeholder styles)
   -------------------------------------------------------------------------- */
.output-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: visible;
  animation: cardIn 250ms cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-offset);
  border-top-left-radius: calc(var(--radius-lg) - 1px);
  border-top-right-radius: calc(var(--radius-lg) - 1px);
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-body {
  padding: var(--space-4);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 4px 14px rgba(1,105,111,0.28);
  transition: background var(--transition), box-shadow var(--transition);
  cursor: pointer;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 6px 18px rgba(1,105,111,0.36);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-ghost:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
  border-color: var(--color-text-faint);
}

.btn-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Pills / badges
   -------------------------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
}
.pill-primary { background: var(--color-primary-soft); color: var(--color-primary); }
.pill-success { background: var(--color-success-bg);   color: var(--color-success); }
.pill-warning { background: var(--color-warning-bg);   color: var(--color-warning); }
.pill-error   { background: var(--color-error-bg);     color: var(--color-error);   }
.pill-info    { background: var(--color-info-bg);      color: var(--color-info);    }
.pill-neutral { background: var(--color-surface-offset-2); color: var(--color-text-muted); }

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

.numfont { font-feature-settings: 'tnum' 1, 'lnum' 1; }

.divider {
  height: 1px;
  background: var(--color-divider);
  margin: var(--space-2) 0;
}

/* --------------------------------------------------------------------------
   Scrollbar — global
   -------------------------------------------------------------------------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-divider);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-border); }

/* ==========================================================================
   Step 3 additions — pipeline tracker, output cards, intake progress
   ========================================================================== */

/* Missing semantic color tokens */
:root, [data-theme="light"] {
  --color-success-bg:  color-mix(in oklch, var(--color-success) 10%, var(--color-surface));
  --color-warning-bg:  color-mix(in oklch, var(--color-warning) 10%, var(--color-surface));
  --color-ai-bg:       color-mix(in oklch, var(--color-primary) 8%, var(--color-surface));
  --color-ai-border:   color-mix(in oklch, var(--color-primary) 20%, transparent);
  --color-ai-text:     var(--color-primary);
}

[data-theme="dark"] {
  --color-success-bg:  color-mix(in oklch, var(--color-success) 12%, var(--color-surface));
  --color-warning-bg:  color-mix(in oklch, var(--color-warning) 12%, var(--color-surface));
  --color-ai-bg:       color-mix(in oklch, var(--color-primary) 10%, var(--color-surface));
  --color-ai-border:   color-mix(in oklch, var(--color-primary) 25%, transparent);
  --color-ai-text:     var(--color-primary);
}

/* Pipeline tracker */
.pipeline-tracker {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4);
}

.pipeline-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--color-text-faint);
  margin-bottom: var(--space-3);
}

.pipeline-stages {
  display: flex;
  align-items: center;
  gap: 0;
}

.pipeline-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  gap: var(--space-2);
  position: relative;
}

/* connector line between stages */
.pipeline-stage:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  left: calc(50% + 14px);
  right: calc(-50% + 14px);
  height: 2px;
  background: var(--color-divider);
  z-index: 0;
  transition: background 400ms ease;
}

.pipeline-stage.completed:not(:last-child)::after {
  background: var(--color-primary);
}

.stage-node {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border: 2px solid var(--color-divider);
  background: var(--color-surface-offset);
  color: var(--color-text-faint);
  position: relative;
  z-index: 1;
  transition: all 300ms cubic-bezier(0.16,1,0.3,1);
}

.pipeline-stage.running .stage-node {
  border-color: var(--color-primary);
  background: var(--color-ai-bg);
  color: var(--color-primary);
  animation: stagePulse 1.2s ease-in-out infinite;
}

.pipeline-stage.completed .stage-node {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: #fff;
}

.pipeline-stage.error .stage-node {
  border-color: var(--color-error);
  background: var(--color-error);
  color: #fff;
}

@keyframes stagePulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklch, var(--color-primary) 40%, transparent); }
  50%       { box-shadow: 0 0 0 6px color-mix(in oklch, var(--color-primary) 0%, transparent); }
}

.stage-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text-faint);
  text-align: center;
  transition: color 300ms ease;
}

.pipeline-stage.running .stage-label,
.pipeline-stage.completed .stage-label {
  color: var(--color-text-muted);
}

/* Output cards in canvas */
.output-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  overflow: visible;
  margin-bottom: var(--space-4);
  animation: cardIn 300ms cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-2);
  border-top-left-radius: calc(var(--radius-xl) - 1px);
  border-top-right-radius: calc(var(--radius-xl) - 1px);
}

.card-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
}

.card-body {
  padding: var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--color-text);
}

.card-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.pill-primary {
  background: color-mix(in oklch, var(--color-primary) 12%, var(--color-surface));
  color: var(--color-primary);
  border: 1px solid color-mix(in oklch, var(--color-primary) 25%, transparent);
}

.pill-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid color-mix(in oklch, var(--color-warning) 25%, transparent);
}

.pill-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid color-mix(in oklch, var(--color-success) 25%, transparent);
}

/* Step 4 — Button styles for export bar */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: all var(--transition-interactive);
  white-space: nowrap;
}
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-2); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-surface-offset); }

/* Card body collapsed/expanded */
.card-body { padding: var(--space-4); font-size: var(--text-sm); line-height: 1.7; color: var(--color-text); position: relative; }
.card-body.expanded { max-height: none !important; }

/* ==========================================================================
   PHASE 2: SESSION HISTORY SIDEBAR
   ========================================================================== */
.chat-panel {
  position: relative; /* Required to contain absolute sidebar */
  overflow: hidden;
}

.session-sidebar-backdrop {
  position: absolute;
  inset: 0;
  background: oklch(0 0 0 / 0.25);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.session-sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.session-sidebar {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 280px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  z-index: 11;
  transform: translateX(-100%);
  transition: transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}
.session-sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.sidebar-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

.session-item {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.session-item:hover {
  background: var(--color-surface-dynamic);
}
.session-item.active {
  background: var(--color-primary-soft);
  border-left-color: var(--color-primary);
}

.session-name {
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: var(--space-1);
  color: var(--color-text);
}

.session-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.session-channels {
  display: flex;
  gap: 4px;
}
.pill-channel {
  font-size: 9px;
  padding: 1px 6px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.sidebar-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.sidebar-empty svg {
  margin-bottom: var(--space-3);
}

.skeleton-list div {
  height: 52px;
  margin: var(--space-2) var(--space-4);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  animation: shimmer 1.5s infinite linear;
}

/* ==========================================================================
   PHASE 2: ASSET LIBRARY VIEW
   ========================================================================== */
.library-main {
  /* Reusing the workspace grid ratio */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
}

.lib-list-panel, .lib-detail-panel {
  display: flex;
  flex-direction: column;
}

/* Tab Bar */
.lib-tab-bar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.lib-tab {
  background: transparent;
  color: var(--color-text-muted);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}
.lib-tab:hover {
  background: var(--color-surface-dynamic);
}
.lib-tab.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 600;
}

/* Detail-panel tabs (inside right panel) */
.lib-detail-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
}
.lib-detail-tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.lib-detail-tab:hover {
  color: var(--color-text);
}
.lib-detail-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}
.lib-detail-tab-pane {
  /* shown by default; hidden via [hidden] attribute */
}
.lib-detail-usage {
  padding: 0 var(--space-6) var(--space-4);
}

/* Search and Filter Toolbar */
.lib-toolbar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  align-items: center;
}

.search-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--color-text-muted);
}

.search-input {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4) var(--space-2) 36px;
  background: var(--color-surface-2);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: border-color var(--transition);
}
.search-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* List Body */
.lib-list-body {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

/* Asset Library: flex child can shrink so list + folder do not clip table columns */
#view-library .lib-content-area {
  min-width: 0;
}

#view-library .lib-list-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Single scroll viewport: H bar stays at bottom of visible list; V scroll inside same box */
#view-library .lib-list-body > * {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-x: auto;
  /* Always reserve vertical scrollbar width (overlay scrollbars otherwise change table width tab-to-tab). */
  overflow-y: scroll;
  overscroll-behavior-x: contain;
}

/* Detail Panel Empty State */
.lib-detail-panel {
  padding: var(--space-6);
  overflow-y: auto;
}

.lib-empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 36ch;
  margin: 0 auto;
}

/* Shimmer animation if not already defined globally */
@keyframes shimmer {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.5; }
}

.lib-empty-state-list {
  padding: var(--space-8);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.lib-empty-state-list svg {
  margin-bottom: var(--space-3);
  color: var(--color-text-faint);
}
.lib-empty-state-list p {
  max-width: 25ch;
  margin-bottom: var(--space-4);
}

.lib-list-error {
  padding: var(--space-8);
  text-align: center;
  color: var(--color-error);
  font-size: var(--text-sm);
}

/* Library Table */
.lib-table {
  width: 100%;
  border-collapse: collapse;
}

.lib-table thead tr {
  border-bottom: 1px solid var(--color-divider);
}

.lib-table th {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  text-align: left;
  font-weight: 600;
}

.lib-table tbody tr {
  border-bottom: 1px solid var(--color-divider);
  transition: background var(--transition);
  cursor: pointer;
}

.lib-table tbody tr:hover {
  background: var(--color-surface-dynamic);
}

.lib-table tbody tr.selected {
  background: var(--color-primary-soft);
  box-shadow: inset 3px 0 0 var(--color-primary);
}

/* Library: use left border on checkbox cell for selection accent (row inset is easy to lose with opaque cell paints) */
#view-library .lib-table tbody tr.selected {
  box-shadow: none;
}

.lib-table td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  vertical-align: middle;
}

/* Asset Library: fixed layout; separate borders so <col> widths are honored (collapse mode ignores them). */
#view-library .lib-table-scroll .lib-table {
  width: 100%;
  table-layout: fixed;
  min-width: max(100%, 720px);
  border-collapse: separate;
  border-spacing: 0;
}

/* Checkbox column: fixed width (do NOT use position:sticky on table cells — Chromium mis-associates cells with columns, so checkboxes can drift under Preview, etc.) */
#view-library .lib-table col.lib-col-cb {
  width: 48px;
}

#view-library .lib-table th.lib-col-select,
#view-library .lib-table td.lib-col-select {
  box-sizing: border-box;
  width: 48px;
  min-width: 48px;
  max-width: 48px;
  padding: var(--space-3) 0;
  text-align: center;
  vertical-align: middle;
}

#view-library .lib-table thead th.lib-col-select {
  text-align: center;
  background: var(--color-surface-offset);
  border-left: 3px solid transparent;
}

#view-library .lib-table tbody td.lib-col-select {
  background: var(--color-surface);
  border-left: 3px solid transparent;
}

#view-library .lib-table tbody tr:hover td.lib-col-select {
  background: var(--color-surface-dynamic);
}

#view-library .lib-table tbody tr.selected td.lib-col-select {
  background: var(--color-primary-soft);
  border-left-color: var(--color-primary);
}

#view-library .lib-table .lib-col-select input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
  vertical-align: middle;
}

/* Asset Library list: CSS grid (checkbox column is always grid track 1 = 40px) */
#view-library .lib-grid {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: min(100%, 100%);
}

#view-library .lib-grid-head,
#view-library .lib-grid-row {
  display: grid;
  grid-template-columns: var(--lib-grid-cols);
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

#view-library .lib-grid-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-surface-offset);
  border-bottom: 1px solid var(--color-divider);
}

#view-library .lib-grid-head .lib-grid-head-cell {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  font-weight: 600;
  text-align: left;
  min-width: 0;
  position: relative;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -2px;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 10;
}
.col-resizer::before {
  content: '';
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: 2px;
  width: 1px;
  background-color: var(--color-border);
  transition: opacity 0.2s;
}
.col-resizer:hover::before, .is-resizing .col-resizer::before {
  opacity: 0;
}
.col-resizer:hover, .is-resizing .col-resizer {
  background: var(--color-primary);
  opacity: 0.5;
}
.is-resizing * {
  user-select: none !important;
  cursor: col-resize !important;
}

#view-library .lib-grid-cell--cb {
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
}

#view-library .lib-grid-head .lib-grid-cell--cb {
  background: var(--color-surface-offset);
  position: relative;
}
#view-library .lib-grid-head .lib-grid-cell--cb::after {
  content: '';
  position: absolute;
  top: 25%;
  bottom: 25%;
  right: 0;
  width: 1px;
  background-color: var(--color-border);
}

#view-library .lib-grid-row {
  border-bottom: 1px solid var(--color-divider);
  cursor: pointer;
  transition: background var(--transition);
  background: var(--color-surface);
}

#view-library .lib-grid-row:hover {
  background: var(--color-surface-dynamic);
}

#view-library .lib-grid-row.selected {
  background: var(--color-primary-soft);
  box-shadow: inset 3px 0 0 var(--color-primary);
}

#view-library .lib-grid-row .lib-grid-cell:not(.lib-grid-cell--cb) {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#view-library .lib-grid--media .lib-grid-cell--preview {
  overflow: visible;
  white-space: normal;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

/* Preview column header: fit "PREVIEW" without overlapping Name */
#view-library .lib-grid--media .lib-grid-head .lib-grid-head-cell:nth-child(2) {
  padding-left: var(--space-2);
  padding-right: var(--space-2);
  white-space: nowrap;
}

#view-library .lib-grid-cell--cb input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
}

/* Library Detail Panel */
.lib-detail-panel {
  padding: 0;
}
.lib-detail-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.lib-detail-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-2);
}
.lib-detail-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  display: flex;
  gap: var(--space-4);
}
.lib-detail-meta strong {
  color: var(--color-text);
  font-weight: 500;
}
.lib-detail-actions {
  display: flex;
  gap: var(--space-2);
}

/* ==========================================================================
   PHASE 2: SAVE TO TEMPLATE POPOVER
   ========================================================================== */
.save-template-wrapper {
  position: relative;
}

.popover {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  right: 0;
  width: 280px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  animation: popoverIn 150ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.popover[hidden] {
  display: none;
}

@keyframes popoverIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.popover-header {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}

.popover-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.popover-body label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: -8px; /* pull closer to input */
}

.popover-body input[type="text"] {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: var(--text-sm);
}
.popover-body input[type="text"]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary) 12%, transparent);
}

.popover-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-divider);
}

.filter-popover {
  top: calc(100% + var(--space-2));
  bottom: auto;
  right: 0;
  left: auto;
  width: 260px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.filter-chip {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-chip.active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-highlight);
  color: var(--color-primary);
}

/* ==========================================================================
   PHASE 2: CANVAS TOAST
   ========================================================================== */
.canvas-toast {
  position: absolute;
  top: 60px; /* Just below the panel header */
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
  animation: toastIn 300ms cubic-bezier(0.16,1,0.3,1) both, toastOut 300ms cubic-bezier(0.16,1,0.3,1) 2.7s both;
  pointer-events: none;
}

@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toastOut { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -10px); } }

.popover-radios {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-1);
}

.popover-radios div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.popover-radios label {
  font-size: var(--text-sm) !important;
  font-weight: 400 !important;
  color: var(--color-text) !important;
  margin-bottom: 0 !important;
  cursor: pointer;
}

/* ==========================================================================
   PHASE 7: PROFILES VIEW
   ========================================================================== */
.profiles-main {
  grid-template-columns: minmax(0, 32%) minmax(0, 68%);
  min-height: 0;
}

.prof-list-panel {
  position: relative;
}

.prof-list-panel,
.prof-detail-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.prof-toolbar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  align-items: center;
  flex-shrink: 0;
}

.prof-filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  align-items: flex-end;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-offset);
  flex-shrink: 0;
}

.prof-filter-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
}

.prof-filter-select {
  min-width: 120px;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: var(--text-sm);
  color: var(--color-text);
}

.prof-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.prof-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft);
  border: 1px solid var(--color-border);
  font-size: var(--text-xs);
  font-weight: 500;
}

.prof-chip-remove {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  color: var(--color-text-muted);
}

.prof-chip-clear {
  margin-left: auto;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
}

.prof-toolbar .search-input-wrapper {
  flex: 1;
}

.prof-meta {
  margin: 0;
  padding: var(--space-2) var(--space-4) 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.prof-list-scroll-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.prof-list-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  min-height: 0;
}

.prof-table thead th button.prof-sort-active {
  color: var(--color-primary);
  font-weight: 700;
}

.prof-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.prof-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.prof-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface-offset);
  text-align: left;
  padding: var(--space-2) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
}

.prof-table thead th button {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
}

.prof-table thead th button:hover {
  color: var(--color-text);
}

.prof-sort-active {
  color: var(--color-primary);
}

.prof-table tbody td {
  padding: 0 var(--space-2);
  vertical-align: middle;
  border-bottom: 1px solid var(--color-divider);
  height: 56px;
}

.prof-table tbody tr.prof-data-row {
  cursor: pointer;
}

.prof-table tbody tr.prof-data-row:hover {
  background: var(--color-surface-dynamic);
}

.prof-table tbody tr.prof-data-row.selected {
  background: var(--color-primary-soft);
  box-shadow: inset 4px 0 0 var(--color-primary);
}

.prof-table .prof-col-cb {
  width: 36px;
  text-align: center;
}

.prof-row-name-cell {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prof-aud-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 160px;
}

.prof-aud-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prof-aud-more {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-muted);
}

.prof-sup-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-error) 12%, transparent);
  color: var(--color-error);
  border: 1px solid color-mix(in srgb, var(--color-error) 35%, transparent);
}

.prof-last-act {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.prof-score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 2px 8px;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 700;
  border: 1px solid transparent;
}

.prof-score-pill.high {
  color: var(--color-success, #15803d);
  background: color-mix(in srgb, var(--color-success, #22c55e) 14%, transparent);
  border-color: color-mix(in srgb, var(--color-success, #22c55e) 35%, transparent);
}

.prof-score-pill.med {
  color: #b45309;
  background: color-mix(in srgb, #f59e0b 18%, transparent);
  border-color: color-mix(in srgb, #f59e0b 40%, transparent);
}

.prof-score-pill.low {
  color: var(--color-error);
  background: color-mix(in srgb, var(--color-error) 12%, transparent);
  border-color: color-mix(in srgb, var(--color-error) 35%, transparent);
}

.prof-score-pill.empty {
  color: var(--color-text-muted);
  background: var(--color-surface-offset, #f1f5f9);
  border-color: var(--color-border, #e2e8f0);
  font-weight: 500;
  min-width: 28px;
}

.prof-ch-ico {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  vertical-align: middle;
}

.prof-list-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.prof-pagination {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.prof-bulk-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-text);
  color: var(--color-surface);
  font-size: var(--text-sm);
}

.prof-bulk-bar .btn {
  font-size: var(--text-xs);
}

.prof-bulk-bar .btn:disabled {
  opacity: 0.45;
}

.prof-empty-state {
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}

.prof-empty-title {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.prof-detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}

.prof-detail-empty h3 {
  margin: var(--space-3) 0 var(--space-2);
  color: var(--color-text);
  font-size: var(--text-lg);
}

.prof-detail-empty-icon {
  margin-bottom: var(--space-2);
}

.prof-detail-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.prof-suppress-banner {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--color-error) 10%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--color-error) 25%, transparent);
  font-size: var(--text-sm);
  color: var(--color-text);
}

.prof-detail-header-mount {
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-divider);
}

.prof-detail-header-inner {
  padding: var(--space-4);
}

.prof-detail-top {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  flex-wrap: wrap;
}

.prof-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  color: #fff;
  flex-shrink: 0;
}

.prof-av-blue { background: #2563eb; }
.prof-av-green { background: #16a34a; }
.prof-av-purple { background: #9333ea; }
.prof-av-amber { background: #d97706; }
.prof-av-pink { background: #db2777; }
.prof-av-indigo { background: #4f46e5; }

.prof-detail-identity {
  flex: 1;
  min-width: 0;
}

.prof-detail-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
}

.prof-detail-name {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
}

.prof-consent-pill {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
}

.prof-idrive-label {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.prof-contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.prof-contact-row span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.prof-contact-row a {
  color: inherit;
  text-decoration: none;
}

.prof-score-block {
  text-align: right;
  flex-shrink: 0;
}

.prof-score-block-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 0 0 4px;
}

.prof-seg-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-3);
}

.prof-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.prof-actions-row .btn {
  font-size: var(--text-xs);
  font-weight: 700;
}

.prof-detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-offset);
  flex-shrink: 0;
}

.prof-detail-tab {
  padding: var(--space-2) var(--space-3);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.prof-detail-tab:hover {
  color: var(--color-text);
  border-bottom-color: var(--color-border);
}

.prof-detail-tab.active {
  color: var(--color-primary);
  font-weight: 700;
  border-bottom-color: var(--color-primary);
}

.prof-tab-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary);
}

.prof-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  min-height: 0;
}

.prof-overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 55%) minmax(0, 45%);
  gap: var(--space-4);
  align-items: start;
}

@media (max-width: 900px) {
  .prof-overview-grid {
    grid-template-columns: 1fr;
  }
  .profiles-main {
    grid-template-columns: 1fr;
  }
}

.prof-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.04));
  margin-bottom: var(--space-4);
  overflow: hidden;
}

.prof-section > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prof-section > summary::-webkit-details-marker {
  display: none;
}

.prof-section-body {
  padding: 0 var(--space-4) var(--space-4);
}

.prof-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4) var(--space-6);
}

.prof-field {
  min-width: 0;
}

.prof-field-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.prof-field-value {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  word-break: break-word;
}

.prof-field input {
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font: inherit;
}

.prof-field-colspan {
  grid-column: 1 / -1;
}

.prof-widget {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.04));
}

.prof-widget-title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
}

.prof-completeness-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.prof-completeness-row:hover {
  background: var(--color-surface-dynamic);
}

.prof-timeline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  align-items: center;
}

.prof-timeline-dd-wrap {
  position: relative;
}

.prof-timeline-pills {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-1);
  flex: 1;
  min-width: 0;
}

.prof-tl-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 700;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.prof-tl-pill.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.prof-timeline-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.prof-tl-card {
  display: flex;
  gap: var(--space-3);
}

.prof-tl-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.prof-ebix-split {
  display: grid;
  grid-template-columns: minmax(0, 40%) minmax(0, 60%);
  gap: 0;
  min-height: 280px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
}

.prof-ebix-tree {
  border-right: 1px solid var(--color-divider);
  overflow-y: auto;
  max-height: 420px;
}

.prof-ebix-detail {
  padding: var(--space-6);
  overflow-y: auto;
  max-height: 420px;
}

.prof-ebix-div-h {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border: none;
  background: var(--color-surface-offset);
  font: inherit;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  text-align: left;
}

.prof-ebix-prod {
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-4);
  border: none;
  border-left: 4px solid transparent;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.prof-ebix-prod:hover {
  background: var(--color-surface-dynamic);
}

.prof-ebix-prod.selected {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  border-left-color: var(--color-primary);
}

.prof-camp-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.prof-camp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.prof-camp-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface-offset);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  padding: var(--space-2);
  text-align: left;
  border-bottom: 1px solid var(--color-divider);
}

.prof-camp-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: middle;
}

.prof-aud-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  background: var(--color-surface);
}

.prof-aud-add {
  width: 100%;
  padding: var(--space-4);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: transparent;
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text-muted);
  cursor: pointer;
}

.prof-aud-add:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 6%, transparent);
}

.prof-kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.prof-kv-table th,
.prof-kv-table td {
  text-align: left;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: top;
}

.prof-kv-table th {
  width: 38%;
  color: var(--color-text-muted);
  font-weight: 500;
}

.prof-tab-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-offset);
}

.prof-seg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.prof-seg-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.prof-seg-name {
  font-weight: 500;
  font-size: var(--text-sm);
  word-break: break-all;
}

.prof-seg-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ==========================================================================
   PHASE 9: KNOWLEDGE CENTER
   ========================================================================== */
.knowledge-main {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  min-height: 0;
}

.kc-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  flex: 1;
}

.kc-page-header {
  display: none !important;
}

.kc-page-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.kc-tree-mobile-btn {
  display: none;
}

.kc-page-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.kc-add-wrap {
  position: relative;
}

.kc-add-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 4px);
  top: auto;
  min-width: 180px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 20;
  padding: var(--space-1);
}

.kc-add-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.kc-add-menu-item:hover {
  background: var(--color-surface-dynamic);
}

.kc-body {
  display: grid;
  grid-template-columns: minmax(260px, 30%) minmax(0, 1fr);
  gap: var(--panel-gap);
  flex: 1;
  min-height: 0;
}

.kc-tree-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.kc-tree-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--space-2);
}

.kc-tree-loading {
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.kc-tree-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3);
  border-top: 1px solid var(--color-divider);
  flex-shrink: 0;
}

.kc-footer-link {
  background: none;
  border: none;
  padding: 4px 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  cursor: pointer;
  text-align: left;
}

.kc-footer-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.kc-tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 2px 6px 2px 0;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  width: 100%;
  text-align: left;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  position: relative;
}

.kc-tree-row:hover {
  background: var(--color-surface-dynamic);
}

.kc-tree-row.selected {
  background: var(--color-primary-soft);
  border-color: var(--color-border);
}

.kc-tree-row.kc-tree-row--firm {
  min-height: 40px;
  font-weight: 600;
}

.kc-tree-chevron {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.kc-tree-chevron:hover {
  background: var(--color-divider);
}

.kc-tree-chevron:disabled {
  visibility: hidden;
  pointer-events: none;
}

.kc-tree-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.kc-tree-label {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kc-tree-menu-btn {
  opacity: 0;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.kc-tree-row:hover .kc-tree-menu-btn,
.kc-tree-row:focus-within .kc-tree-menu-btn {
  opacity: 1;
}

.kc-tree-menu-btn:hover {
  background: var(--color-divider);
  color: var(--color-text);
}

.kc-tree-submenu {
  position: absolute;
  right: 4px;
  top: 100%;
  margin-top: 2px;
  min-width: 160px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 30;
  padding: var(--space-1);
}

.kc-tree-submenu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--color-text);
}

.kc-tree-submenu button:hover {
  background: var(--color-surface-dynamic);
}

.kc-first-division {
  display: block;
  margin: var(--space-2) 0 var(--space-2) 28px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.kc-first-division:hover {
  color: var(--color-primary);
}

.kc-detail-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.kc-detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8);
  color: var(--color-text-muted);
}

.kc-detail-empty h3 {
  margin: var(--space-3) 0 var(--space-2);
  color: var(--color-text);
  font-size: var(--text-base);
}

.kc-detail-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.kc-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.kc-detail-title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  min-width: 0;
}

.kc-detail-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
}

.kc-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
}

.kc-badge--firm {
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
}

.kc-badge--division {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
  border-color: rgba(37, 99, 235, 0.25);
}

[data-theme="dark"] .kc-badge--division {
  color: #93c5fd;
}

.kc-badge--unit {
  background: rgba(124, 58, 237, 0.12);
  color: #6d28d9;
  border-color: rgba(124, 58, 237, 0.25);
}

[data-theme="dark"] .kc-badge--unit {
  color: #c4b5fd;
}

.kc-badge--product {
  background: rgba(13, 148, 136, 0.14);
  color: #0f766e;
  border-color: rgba(13, 148, 136, 0.3);
}

[data-theme="dark"] .kc-badge--product {
  color: #5eead4;
}

.kc-breadcrumb {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.4;
}

.kc-detail-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.kc-detail-tabs {
  display: flex;
  gap: 2px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.kc-detail-tab {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.kc-detail-tab:hover {
  color: var(--color-text);
  background: var(--color-surface-dynamic);
}

.kc-detail-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.kc-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  min-height: 0;
}

.kc-view-hint {
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  line-height: 1.45;
}

.kc-detail-body input[readonly],
.kc-detail-body textarea[readonly] {
  cursor: default;
  opacity: 0.92;
}

.kc-field {
  margin-bottom: var(--space-4);
}

.kc-field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.kc-field .kc-ai-wrap {
  position: relative;
}

.kc-field input.search-input,
.kc-field select.search-input,
.kc-field textarea.search-input {
  width: 100%;
  border-radius: var(--radius-md);
  padding-left: var(--space-3);
}

.kc-field textarea.search-input {
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}

.kc-field-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: 4px;
}

.kc-field-hint.kc-warn {
  color: #b45309;
}

.kc-inherit-banner {
  padding: var(--space-3);
  background: var(--color-primary-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  margin-bottom: var(--space-4);
}

.kc-ai-suggested {
  outline: 2px solid rgba(1, 105, 111, 0.25);
  background: rgba(1, 105, 111, 0.06);
  border-radius: var(--radius-sm);
}

.kc-ai-badge {
  display: inline-block;
  margin-left: var(--space-2);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
  vertical-align: middle;
}

.kc-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.kc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  font-size: var(--text-xs);
}

.kc-chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0 2px;
  color: var(--color-text-muted);
  line-height: 1;
}

.kc-lib-drop {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  background: var(--color-surface-offset);
  cursor: pointer;
  margin-bottom: var(--space-4);
}

.kc-lib-drop.kc-lib-drop--drag {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.kc-lib-drop p {
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.kc-lib-error {
  color: var(--color-error);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}

.kc-lib-table-wrap {
  overflow-x: auto;
}

.kc-lib-toggle-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.kc-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.kc-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.kc-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #d1d5db; /* Gray background when off */
  border-radius: 24px;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
}

.kc-toggle-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.kc-toggle input:checked + .kc-toggle-slider {
  background-color: var(--color-primary); /* Teal background when on */
}

.kc-toggle input:checked + .kc-toggle-slider::before {
  transform: translateX(20px);
}

.kc-inherited-collapsed summary {
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-2) 0;
}

.kc-inherited-list {
  margin-top: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.kc-saved-toast {
  font-size: var(--text-xs);
  color: var(--color-primary);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
}

.kc-saved-toast.visible {
  opacity: 1;
}

/* Tablet: narrow rail + overlay tree */
@media (max-width: 1023px) and (min-width: 768px) {
  .kc-body {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .kc-tree-rail-btn {
    display: flex !important;
    align-self: center;
    justify-self: center;
    margin: var(--space-2) auto;
  }

  .kc-tree-panel {
    position: relative;
    align-items: center;
    padding: var(--space-1) 0;
  }

  .kc-tree-panel:not(.kc-tree-panel--open) .kc-tree-scroll,
  .kc-tree-panel:not(.kc-tree-panel--open) .kc-tree-footer {
    display: none;
  }

  .kc-tree-panel.kc-tree-panel--open {
    position: fixed;
    left: 10px;
    top: calc(var(--header-h) + 24px);
    bottom: 10px;
    width: min(320px, 86vw);
    z-index: 50;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
  }

  .kc-tree-panel.kc-tree-panel--open .kc-tree-scroll,
  .kc-tree-panel.kc-tree-panel--open .kc-tree-footer {
    display: flex;
  }

  .kc-tree-panel.kc-tree-panel--open .kc-tree-rail-btn {
    display: none !important;
  }

  .kc-tree-backdrop.visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 40;
  }
}

.kc-tree-rail-btn {
  display: none;
}

/* Mobile */
@media (max-width: 767px) {
  .kc-tree-mobile-btn {
    display: inline-flex;
  }

  .kc-body {
    grid-template-columns: 1fr;
  }

  .kc-tree-rail-btn {
    display: none !important;
  }

  .kc-tree-panel {
    display: none;
  }

  .kc-tree-panel.kc-tree-panel--sheet {
    display: flex;
  }

  .kc-tree-panel.kc-tree-panel--sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 15vh;
    z-index: 60;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: kc-sheet-in 0.2s ease-out;
  }

  @keyframes kc-sheet-in {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .kc-tree-backdrop.visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 55;
  }
}

/* ==========================================================================
   PHASE 3: TEMPLATE BUILDER
   ========================================================================== */
.view-is-builder #view-builder {
  display: flex;
}
#view-builder {
  display: none;
  flex-direction: column;
  height: 100%;
  gap: var(--space-3);
}

.builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.builder-header-left, .builder-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.builder-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all var(--transition);
}
.builder-title:hover, .builder-title:focus {
  border-color: var(--color-border);
  background: var(--color-surface-2);
  outline: none;
}

.builder-body {
  flex: 1;
  display: flex;
  gap: var(--panel-gap);
  min-height: 0;
}

.builder-panel {
  width: 280px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.builder-canvas-wrapper {
  flex: 1;
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.02);
  display: flex;
  flex-direction: column;
  justify-content: stretch;
  padding: 0;
  overflow: hidden;
  min-height: 0;
}

.builder-canvas {
  width: 100%;
  max-width: 100%;
  background: var(--color-surface-2);
  min-height: 800px;
  box-shadow: var(--shadow-md);
  margin: 0 auto;
  padding: var(--space-6);
  box-sizing: border-box;
}

/* Palette accordion basics */
.palette-section-title {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-offset);
}
.palette-items {
  padding: var(--space-3);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.palette-item {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  text-align: center;
  font-size: var(--text-xs);
  cursor: grab;
  user-select: none;
  transition: all var(--transition);
}
.palette-item:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Builder Drag & Drop States */
.builder-row {
  position: relative;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
  transition: all var(--transition);
}
.builder-row:hover {
  border-color: var(--color-border);
}
.builder-row.active {
  border-color: var(--color-primary) !important;
  background: color-mix(in oklch, var(--color-primary) 4%, transparent);
}
.builder-col {
  transition: background var(--transition), border-color var(--transition);
}
.builder-col.dragover {
  background: var(--color-primary-soft) !important;
  border-color: var(--color-primary) !important;
}
.canvas-empty-dropzone {
  transition: all var(--transition);
}
.canvas-empty-dropzone.dragover {
  background: var(--color-primary-soft) !important;
  border-color: var(--color-primary) !important;
  color: var(--color-primary) !important;
}
body.is-dragging .builder-el-preview,
body.is-dragging .canvas-empty-dropzone * {
  pointer-events: none !important;
}
.builder-element {
  border-radius: var(--radius-sm);
  cursor: default;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.builder-el-drag-handle {
  position: absolute;
  left: 2px;
  top: 2px;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: grab;
  pointer-events: auto;
  flex-shrink: 0;
}
.builder-el-drag-handle:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.builder-el-drag-handle:active {
  cursor: grabbing;
}
.builder-element:hover {
  border-color: var(--color-primary) !important;
  box-shadow: var(--shadow-sm);
}
.builder-element.active {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--color-primary) 15%, transparent);
}

/* Builder Inspector Inputs */
.insp-label {
  font-size: 11px; font-weight: 600; color: var(--color-text-muted); display: block; margin-bottom: 4px;
}
.insp-input {
  width: 100%; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: 12px; background: var(--color-surface);
  transition: border-color var(--transition);
}
.insp-input:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--color-primary) 12%, transparent);
}
.insp-content-rich {
  min-height: 140px;
}

/* Phase 6.1 Inspector Accordions */
details.insp-group summary::-webkit-details-marker { display: none; }
details.insp-group summary { list-style: none; }
details.insp-group[open] .insp-chevron { transform: rotate(180deg); }

/* ==========================================================================
   PHASE 2: MODALS & UPLOADS
   ========================================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: oklch(0 0 0 / 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay[hidden] {
  display: none;
}
.modal-box {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); padding: var(--space-6) var(--space-8);
  max-width: 480px; width: 90%; box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-4); }
.drop-zone {
  border: 2px dashed var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-4); text-align: center; cursor: pointer;
  transition: all var(--transition); background: var(--color-surface-2);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--color-primary); background: var(--color-primary-soft);
}

/* Demo / simulated data callouts (must stay obvious in light + dark theme) */
.iengage-demo-data-banner__title {
  color: #9a3412;
}
.iengage-demo-data-banner__body {
  color: #292524;
}
[data-theme="dark"] .iengage-demo-data-banner {
  border-color: #fb923c !important;
  background: linear-gradient(165deg, #431407 0%, #1c1917 95%) !important;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45) !important;
}
[data-theme="dark"] .iengage-demo-data-banner__title {
  color: #fdba74 !important;
}
[data-theme="dark"] .iengage-demo-data-banner__body {
  color: #e7e5e4 !important;
}
[data-theme="dark"] .iengage-demo-data-banner__body strong {
  color: #fafaf9;
}

/* Knowledge Center Read-Only Forms */
input[readonly], textarea[readonly], select[disabled] {
  background-color: var(--color-bg-subtle) !important;
  border-color: transparent !important;
  cursor: default !important;
  color: var(--color-text) !important;
  box-shadow: none !important;
  font-weight: 600 !important;
}

/* Extraction Diff Styles */
.diff-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); margin-top: var(--space-4); }
.diff-table th, .diff-table td { border: 1px solid var(--color-divider); padding: 8px; text-align: left; vertical-align: top; }
.diff-table th { background: var(--color-surface-offset); font-weight: 600; }
.diff-table td.diff-old { background: rgba(239, 68, 68, 0.1); color: #c62828; text-decoration: line-through; }
[data-theme="dark"] .diff-table td.diff-old { color: #fca5a5; }
.diff-table td.diff-new { background: rgba(34, 197, 94, 0.1); color: #166534; }
[data-theme="dark"] .diff-table td.diff-new { color: #86efac; }

/* --------------------------------------------------------------------------
   Chat Tabs
   -------------------------------------------------------------------------- */
.chat-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  width: fit-content;
}

.chat-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.chat-tab:hover:not(.active) {
  background: var(--color-divider);
  color: var(--color-text);
}

.chat-tab.active {
  background: var(--color-surface-2);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}



/* Restore list bullets in builder */
.builder-el-text ul, .insp-content-rich ul, .builder-canvas ul { list-style-type: disc; padding-left: 1.5rem; margin-bottom: 0.5rem; }
.builder-el-text ol, .insp-content-rich ol, .builder-canvas ol { list-style-type: decimal; padding-left: 1.5rem; margin-bottom: 0.5rem; }
