/* ═══════════════════════════════════════════════════════════
   PipeCraft — Design System (Dataiku/SaaS data-grade)
   Inter + JetBrains Mono — Blue primary — Light-first
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── DESIGN TOKENS ─── */
:root {
  /* Brand */
  --brand-primary:       #2563eb;
  --brand-primary-dark:  #1d4ed8;
  --brand-primary-light: #dbeafe;

  /* Gray palette */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Semantic colours */
  --success:       #10b981;
  --success-light: #d1fae5;
  --warning:       #f59e0b;
  --warning-light: #fef3c7;
  --danger:        #ef4444;
  --danger-light:  #fee2e2;
  --info:          #3b82f6;
  --info-light:    #dbeafe;

  /* Aliases (light-mode defaults) */
  --bg:            var(--gray-50);
  --surface:       #ffffff;
  --surface-2:     var(--gray-100);
  --surface-3:     var(--gray-200);
  --surface-hover: var(--gray-100);
  /* Alias used by AI-modal / drive / context-menu rules that pass a
     hardcoded light fallback; defining it keeps dark theme correct. */
  --bg-2:          var(--gray-100);
  --text:          var(--gray-900);
  --text-1:        var(--gray-900);
  --text-2:        var(--gray-600);
  /* RGAA/WCAG AA: text-3 darkened from gray-400 (#9ca3af, ~2.8:1 — FAILS)
     to gray-500 (#6b7280, ~4.6:1 — passes AA for normal text). */
  --text-3:        var(--gray-500);
  /* Readable secondary text token (4.6:1) for any future use. */
  --text-muted:    var(--gray-500);
  --border:        var(--gray-200);
  --border-2:      var(--gray-300);
  --accent:        var(--brand-primary);
  --accent-glow:   rgba(37,99,235,0.20);
  --accent-dim:    rgba(37,99,235,0.08);
  --green:         var(--success);
  --green-glow:    rgba(16,185,129,0.20);
  --blue:          var(--brand-primary);
  --blue-dim:      var(--brand-primary-light);
  --purple:        #7c3aed;
  --purple-dim:    rgba(124,58,237,0.10);
  --red:           var(--danger);
  --red-dim:       var(--danger-light);
  --amber:         var(--warning);
  --amber-dim:     var(--warning-light);
  --ok-bg:         var(--success-light);
  --ok-text:       #065f46;
  --ok-border:     #a7f3d0;
  --warn-bg:       var(--warning-light);
  --warn-text:     #92400e;
  --warn-border:   #fcd34d;
  --err-bg:        var(--danger-light);
  --err-text:      #991b1b;
  --err-border:    #fca5a5;

  /* Layout */
  --sidebar-width:  220px;
  --sidebar-collapsed-width: 60px;
  --topbar-height:  56px;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Shadows */
  --shadow:    0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.10), 0 4px 6px rgba(0,0,0,0.05);

  /* Legacy shadow alias */
  --shadow-sm: var(--shadow);

  /* Motion */
  --transition-fast: 150ms ease;
  --transition:      150ms cubic-bezier(0.4,0,0.2,1);

  /* Geometry */
  --border-radius: 8px;
  --radius:        8px;
  --radius-lg:     12px;
  --radius-xl:     16px;

  /* Node canvas */
  --node-w: 220px;
  --lane-w: 240px;

  /* Category colours (workflow canvas) */
  --cat-check:          #2563eb;
  --cat-check-dim:      rgba(37,99,235,0.08);
  --cat-clean:          #10b981;
  --cat-clean-dim:      rgba(16,185,129,0.08);
  --cat-transform:      #7c3aed;
  --cat-transform-dim:  rgba(124,58,237,0.08);
  --cat-compute:        #f59e0b;
  --cat-compute-dim:    rgba(245,158,11,0.08);
  --cat-filter:         #ef4444;
  --cat-filter-dim:     rgba(239,68,68,0.08);
  --cat-normalize:      #9333ea;
  --cat-normalize-dim:  rgba(147,51,234,0.08);
  --cat-extract:        #0d9488;
  --cat-extract-dim:    rgba(13,148,136,0.08);
  --cat-scaler:         #4f46e5;
  --cat-scaler-dim:     rgba(79,70,229,0.08);
}

/* ─── DARK MODE ─── */
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg:          #0f1117;
  --surface:     #171923;
  --surface-2:   #1e2030;
  --surface-3:   #262a3a;
  --surface-hover: #2e3348;
  --bg-2:        #1e2030;
  --text:        #f0f0f5;
  --text-1:      #f0f0f5;
  /* AA on --bg (#0f1117): #a8a8b8 ≈ 7.7:1, #9a9aac ≈ 5.9:1.
     Brightened from #8a8a9a so text-3 also clears 4.5:1 on lighter
     surfaces (surface-2/3) used by badges/inputs. */
  --text-2:      #a8a8b8;
  --text-3:      #9a9aac;
  --text-muted:  #9a9aac;
  --border:      rgba(255,255,255,0.07);
  --border-2:    rgba(255,255,255,0.12);
  --accent:      #60a5fa;
  --accent-glow: rgba(96,165,250,0.20);
  --accent-dim:  rgba(96,165,250,0.10);
  --green:       #34d399;
  --green-glow:  rgba(52,211,153,0.20);
  --blue:        #60a5fa;
  --blue-dim:    rgba(96,165,250,0.12);
  --purple:      #a78bfa;
  --purple-dim:  rgba(167,139,250,0.12);
  --red:         #f87171;
  --red-dim:     rgba(248,113,113,0.12);
  --amber:       #fbbf24;
  --amber-dim:   rgba(251,191,36,0.12);
  --ok-bg:       rgba(52,211,153,0.08);
  --ok-text:     #6ee7b7;
  --ok-border:   rgba(52,211,153,0.25);
  --warn-bg:     rgba(251,191,36,0.08);
  --warn-text:   #fcd34d;
  --warn-border: rgba(251,191,36,0.25);
  --err-bg:      rgba(248,113,113,0.08);
  --err-text:    #fca5a5;
  --err-border:  rgba(248,113,113,0.25);
  --shadow:    0 2px 8px rgba(0,0,0,0.40);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.60);
  --brand-primary:       #60a5fa;
  --brand-primary-dark:  #3b82f6;
  --brand-primary-light: rgba(96,165,250,0.15);
  --cat-check:         #60a5fa;
  --cat-check-dim:     rgba(96,165,250,0.12);
  --cat-clean:         #34d399;
  --cat-clean-dim:     rgba(52,211,153,0.12);
  --cat-transform:     #a78bfa;
  --cat-transform-dim: rgba(167,139,250,0.12);
  --cat-compute:       #fbbf24;
  --cat-compute-dim:   rgba(251,191,36,0.12);
  --cat-filter:        #f87171;
  --cat-filter-dim:    rgba(248,113,113,0.12);
  --cat-normalize:     #c084fc;
  --cat-normalize-dim: rgba(192,132,252,0.12);
  --cat-extract:       #2dd4bf;
  --cat-extract-dim:   rgba(45,212,191,0.12);
  --cat-scaler:        #818cf8;
  --cat-scaler-dim:    rgba(129,140,248,0.12);
}

/* ─── MINIMAL RESET ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body.modal-open { overflow: hidden; }

/* ─── ACCESSIBILITY ─── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--brand-primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  z-index: 9999;
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 8px; }

/* RGAA 10.7 — strong, consistent focus ring on every interactive element.
   Outline + offset so it reads on any background; never removed without
   an equally visible replacement. */
*:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: 2px;
}
:root[data-theme='dark'] *:focus-visible { outline-color: #60a5fa; }

/* Explicit coverage for interactive controls whose own rules set
   outline:none or sit on dark/coloured backgrounds. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.toolbar-btn:focus-visible,
.sidebar-link:focus-visible,
.side-nav a:focus-visible,
.wf-item:focus-visible,
.rule-chip:focus-visible,
.run-btn:focus-visible,
.canvas-col-item:focus-visible,
.prompt-send-btn:focus-visible,
.hamburger:focus-visible,
.sidebar-collapse-btn:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 2px;
}
:root[data-theme='dark'] a:focus-visible,
:root[data-theme='dark'] button:focus-visible,
:root[data-theme='dark'] .btn:focus-visible,
:root[data-theme='dark'] .icon-btn:focus-visible,
:root[data-theme='dark'] .sidebar-link:focus-visible,
:root[data-theme='dark'] .side-nav a:focus-visible,
:root[data-theme='dark'] .wf-item:focus-visible { outline-color: #60a5fa; }

/* On the dark sidebar a blue ring on a dark bg can be low-contrast;
   add a light halo so it stays visible. */
.sidebar-link:focus-visible,
.side-nav a:focus-visible,
.wf-item:focus-visible,
.sidebar-collapse-btn:focus-visible {
  outline-color: #93c5fd;
  outline-offset: -2px;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.4);
}

/* Suppress mouse-click focus rings only where focus-visible is handled. */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
.btn:focus:not(:focus-visible),
.icon-btn:focus:not(:focus-visible),
summary:focus:not(:focus-visible) { outline: none; }

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

/* RGAA / WCAG 2.3.3 — honour reduced-motion: kill animations,
   transitions and smooth scrolling app-wide. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
  /* Disable looping/decorative motion explicitly. */
  .prompt-dock-label::before,
  .ai-thinking__dot,
  .column-runner,
  .canvas-preview-loading::before,
  .skeleton { animation: none !important; }
}

/* ─── TYPOGRAPHY ─── */
h1 { font-size: 1.5rem; margin: 0 0 8px; font-weight: 700; letter-spacing: -0.03em; }
h2 { font-size: 1.1rem; margin: 0 0 8px; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 0.95rem; margin: 0 0 8px; font-weight: 600; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { filter: brightness(1.1); }

/* ─── APP LAYOUT ─── */
.wrap { max-width: none; margin: 0; padding: 0; }

/* Toujours hors du flux grid — l'overlay mobile ne doit jamais occuper une colonne */
.sidebar-overlay { display: none; position: fixed; }

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0,1fr);
  min-height: calc(100vh - var(--topbar-height));
}

/* ─── TOPBAR ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar-inner {
  height: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── BRAND ─── */
.brand {
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 0 16px var(--accent-glow);
  color: #fff;
  font-weight: 800;
}

.brand-sep { width: 1px; height: 18px; background: var(--border-2); flex-shrink: 0; }

/* ─── BREADCRUMB ─── */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); white-space: nowrap; }
.crumb { color: var(--text-3); transition: color var(--transition); }
.crumb:hover { color: var(--text-2); }
.crumb.current { color: var(--text); font-weight: 500; }
.crumb-sep { color: var(--text-3); font-size: 11px; }

/* ─── SIDEBAR ─── */
.sidebar {
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  width: var(--sidebar-width);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  border-right: 1px solid var(--border);
  background: var(--gray-900);
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.12) transparent;
  transition: width 0.25s ease, padding 0.25s ease;
}

:root[data-theme='dark'] .sidebar { background: #0d1117; border-right-color: rgba(255,255,255,0.04); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 12px;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  margin-bottom: 4px;
}

.sidebar-brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
}

.sidebar-brand-name {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.28);
  padding: 8px 8px 4px;
  margin-top: 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  color: rgba(255,255,255,0.55);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.sidebar-link:hover { color: rgba(255,255,255,0.90); background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.06); }

.sidebar-link.active {
  color: #fff;
  background: var(--brand-primary);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(37,99,235,0.35);
}

.sidebar-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-link.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.05);
  margin-top: 8px;
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user-name { font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.65); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Legacy sidebar nav */
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 4px; }

.side-nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  color: rgba(255,255,255,0.55);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
}

.side-nav a:hover { color: rgba(255,255,255,0.90); background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.06); }

.side-nav a.active {
  color: #fff;
  background: var(--brand-primary);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(37,99,235,0.35);
}

.side-nav a .nav-icon {
  width: 16px;
  height: 16px;
  opacity: 0.7;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-nav a.active .nav-icon { opacity: 1; }

.sidebar-card {
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-lg);
  padding: 12px;
}

.sidebar-card h3 { margin: 0 0 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(255,255,255,0.28); }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

/* Workflow items */
.wf-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  transition: all var(--transition);
}

.wf-item:hover { border-color: rgba(255,255,255,0.10); color: rgba(255,255,255,0.90); background: rgba(255,255,255,0.06); text-decoration: none; }

.wf-item .wf-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.25); flex-shrink: 0; }
.wf-item.active .wf-dot { background: var(--success); box-shadow: 0 0 8px var(--green-glow); }

.wf-separator { height: 1px; background: rgba(255,255,255,0.06); margin: 4px 0; }

/* Sidebar collapsed states */
body.sidebar-collapsed .app-layout { grid-template-columns: var(--sidebar-collapsed-width) minmax(0,1fr); }
body.workflow-page.sidebar-collapsed .app-layout { grid-template-columns: 0 minmax(0,1fr); }
body.workflow-page.sidebar-collapsed .sidebar { width: 0; padding: 0; overflow: hidden; border-right: none; }

body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); padding: 12px 6px; align-items: center; }
body.sidebar-collapsed .sidebar-card h3,
body.sidebar-collapsed .sidebar-head .btn-xs,
body.sidebar-collapsed .wf-item,
body.sidebar-collapsed .wf-separator,
body.sidebar-collapsed .sidebar-footer,
body.sidebar-collapsed .sidebar__quotas,
body.sidebar-collapsed .sidebar__user { display: none; }
body.sidebar-collapsed .side-nav a span,
body.sidebar-collapsed .side-nav a .nav-label { display: none; }
body.sidebar-collapsed .side-nav a { justify-content: center; padding: 10px 4px; }
body.sidebar-collapsed .sidebar-collapse-btn .collapse-label { display: none; }
body.sidebar-collapsed .sidebar-collapse-btn { justify-content: center; }

/* Mobile sidebar */
@media (max-width: 1024px) {
  body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
  body.sidebar-collapsed .app-layout { grid-template-columns: 1fr; }
  body.sidebar-collapsed .side-nav a { display: flex; }
}

/* ─── SIDEBAR COLLAPSE BUTTON ─── */
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: rgba(255,255,255,0.40);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  transition: all var(--transition);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-collapse-btn:hover { color: rgba(255,255,255,0.75); background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.12); }
.sidebar-collapse-btn svg { width: 14px; height: 14px; flex-shrink: 0; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.25s ease; }
body.sidebar-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

/* ─── SIDEBAR NAV SEPARATOR ─── */
.sidebar-nav-sep { height: 1px; background: rgba(255,255,255,0.06); margin: 6px 4px; }

/* ─── SIDEBAR QUOTAS ─── */
.sidebar__quotas {
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.quota { display: flex; flex-direction: column; gap: 5px; }

.quota__label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  font-weight: 500;
}

.quota__label span:first-child { color: rgba(255,255,255,0.60); }

.quota__bar {
  height: 5px;
  background: rgba(255,255,255,0.10);
  border-radius: 99px;
  overflow: hidden;
}

.quota__fill {
  height: 100%;
  border-radius: 99px;
  background: var(--success);
  transition: width 0.4s ease;
}

/* Colour thresholds via data attribute set by JS */
.quota__fill[data-level="warn"] { background: var(--warning); }
.quota__fill[data-level="danger"] { background: var(--danger); }

/* ─── SIDEBAR USER ZONE ─── */
.sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  cursor: default;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar__user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar__user-info { min-width: 0; flex: 1; }
.sidebar__user-name { font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.80); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-plan { font-size: 10px; color: rgba(255,255,255,0.35); font-weight: 500; margin-top: 1px; }

/* ─── SIDEBAR TOGGLE ─── */
#sidebar-toggle { position: relative; }
#sidebar-toggle .sidebar-toggle-icon { position: absolute; inset: 0; margin: auto; }
#sidebar-toggle .sidebar-toggle-icon.close { display: none; }
body.sidebar-expanded #sidebar-toggle .sidebar-toggle-icon.open { display: none; }
body.sidebar-expanded #sidebar-toggle .sidebar-toggle-icon.close { display: block; }

/* ─── ICON BUTTON ─── */
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.icon-btn:hover { border-color: var(--border-2); color: var(--text); background: var(--surface-3); }
.icon-btn:active { transform: translateY(0.5px); }

.icon-btn.subtle { width: 30px; height: 30px; background: transparent; border-color: transparent; opacity: 0.7; }
.icon-btn.subtle:hover { opacity: 1; border-color: var(--border); background: var(--surface-2); }

/* WCAG 2.5.5 — guarantee ≥44px tappable targets on touch devices without
   inflating desktop density. Uses a transparent expansion via min-size. */
@media (pointer: coarse) {
  .icon-btn,
  .icon-btn.subtle,
  .hamburger,
  .prompt-send-btn,
  .connector-edit-btn,
  .item button { min-width: 44px; min-height: 44px; }
  .btn,
  .btn-sm,
  .btn-xs,
  .toolbar-btn,
  .run-btn,
  .sidebar-link,
  .side-nav a,
  .wf-item,
  .profile-panel a,
  .menu-panel a { min-height: 44px; }
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg *, .toolbar-btn svg *, .prompt-send-btn svg * { stroke: currentColor; fill: none; }

/* ─── ADMIN ENTRY ─── */
.admin-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-family: var(--font-mono);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* ─── BUTTONS ─── */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 8px 14px;
  font: 500 13px/1 var(--font-sans);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-2);
  transition: all var(--transition);
  text-decoration: none;
}

button:not(.btn):hover, .btn:hover { background: var(--surface-3); color: var(--text); }
button:disabled, .btn:disabled { opacity: 0.40; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
  box-shadow: 0 1px 2px rgba(37,99,235,0.25);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-primary-dark); border-color: var(--brand-primary-dark); box-shadow: 0 2px 6px rgba(37,99,235,0.30); color: #fff; }
.btn-primary:active:not(:disabled) { transform: translateY(0.5px); box-shadow: 0 1px 2px rgba(37,99,235,0.25); }

.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-2); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.btn-secondary:active:not(:disabled) { transform: translateY(0.5px); background: var(--surface-3); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: 0 1px 2px rgba(239,68,68,0.25); }
.btn-danger:hover:not(:disabled) { background: #dc2626; border-color: #dc2626; color: #fff; box-shadow: 0 2px 6px rgba(239,68,68,0.30); }
.btn-danger:active:not(:disabled) { transform: translateY(0.5px); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-ghost:active:not(:disabled) { background: var(--surface-3); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.w-full { width: 100%; justify-content: center; }

/* Legacy compat */
.secondary {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-2);
}
.secondary:hover { background: var(--surface-3); color: var(--text); }

.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-xs { padding: 4px 8px; font-size: 11px; border-radius: 7px; }

/* ─── RUN BUTTON ─── */
.run-btn {
  background: linear-gradient(135deg, var(--success), #059669);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 7px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all var(--transition);
  box-shadow: 0 0 20px var(--green-glow);
}

.run-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 0 30px var(--green-glow), 0 4px 16px rgba(0,0,0,0.20); }
.run-btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.run-btn svg { width: 14px; height: 14px; fill: currentColor; }

/* ─── BADGES ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}

.badge-success { background: var(--success-light); color: #065f46; border-color: #a7f3d0; }
.badge-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.badge-danger  { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.badge-info    { background: var(--info-light);    color: #1e40af; border-color: #bfdbfe; }
.badge-neutral { background: var(--gray-100);      color: var(--gray-600); border-color: var(--gray-200); }

:root[data-theme='dark'] .badge-success { background: rgba(16,185,129,0.15); color: #6ee7b7; border-color: rgba(16,185,129,0.30); }
:root[data-theme='dark'] .badge-warning { background: rgba(245,158,11,0.15);  color: #fcd34d; border-color: rgba(245,158,11,0.30); }
:root[data-theme='dark'] .badge-danger  { background: rgba(239,68,68,0.15);   color: #fca5a5; border-color: rgba(239,68,68,0.30); }
:root[data-theme='dark'] .badge-info    { background: rgba(96,165,250,0.15);  color: #93c5fd; border-color: rgba(96,165,250,0.30); }
:root[data-theme='dark'] .badge-neutral { background: var(--surface-2);       color: var(--text-3); border-color: var(--border); }

/* Role badges */
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: 0.04em; border: 1px solid var(--border); font-family: var(--font-mono); }
.role-badge.super { color: #fde68a; background: rgba(253,230,138,0.1); border-color: rgba(253,230,138,0.25); }
.role-badge.user  { color: var(--text-2); background: var(--surface-3); }

/* ─── FORMS ─── */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label { font-size: 12px; font-weight: 500; color: var(--gray-700); display: block; }
:root[data-theme='dark'] .form-label { color: var(--text-2); }

.form-input, .form-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font: 400 13px/1.4 var(--font-sans);
  transition: all var(--transition);
  outline: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-input::placeholder { color: var(--text-3); }
.form-select { cursor: pointer; }

/* Error state — used by .error class or [aria-invalid] from validation. */
.form-input.error, .form-select.error,
.form-input[aria-invalid="true"], .form-select[aria-invalid="true"],
input.error, select.error, textarea.error,
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.form-input.error:focus, .form-select.error:focus,
.form-input[aria-invalid="true"]:focus,
input.error:focus, select.error:focus, textarea.error:focus,
input[aria-invalid="true"]:focus, textarea[aria-invalid="true"]:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.15);
}

/* Required indicator + help / error text. */
.form-label .req, label .req { color: var(--danger); margin-left: 2px; }
.form-help { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.form-error, .field-error { font-size: 11px; color: var(--err-text); font-weight: 500; margin-top: 2px; }
:root[data-theme='dark'] .form-error,
:root[data-theme='dark'] .field-error { color: #fca5a5; }

input:disabled, select:disabled, textarea:disabled,
.form-input:disabled, .form-select:disabled {
  opacity: 0.55; cursor: not-allowed; background: var(--surface-3);
}

/* Legacy */
form { display: flex; flex-direction: column; gap: 10px; }
label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 4px; }

input, select, textarea {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 11px;
  font: 400 13px var(--font-sans);
  transition: all var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
  outline: none;
}

textarea { min-height: 120px; font-family: var(--font-mono); resize: vertical; }
select { cursor: pointer; }
select option { background: var(--surface-2); }

/* ─── TABLES ─── */
/* Responsive overflow wrapper (referenced by responsive @media too). */
.table-wrapper, .admin-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.table-wrapper > .table, .admin-table-wrapper > .admin-table { border: none; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
/* Optional zebra striping + sticky header helpers. */
.table--zebra tbody tr:nth-child(even) td { background: var(--gray-50); }
:root[data-theme='dark'] .table--zebra tbody tr:nth-child(even) td { background: var(--surface-2); }
.table--sticky th { position: sticky; top: 0; z-index: 1; }

.table th {
  background: var(--gray-50);
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover td { background: var(--gray-50); }

:root[data-theme='dark'] .table th { background: var(--surface-2); color: var(--text-3); }
:root[data-theme='dark'] .table tbody tr:hover td { background: var(--surface-2); }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--border); padding: 10px 8px; text-align: left; vertical-align: middle; font-size: 13px; }
.admin-table th { color: var(--text-3); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; background: var(--gray-50); }
:root[data-theme='dark'] .admin-table th { background: var(--surface-2); }
.inline-actions { display: flex; gap: 6px; }

/* ─── UPLOAD ZONE ─── */
.upload-zone {
  border: 2px dashed var(--border-2);
  border-radius: var(--border-radius);
  padding: 32px 24px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--brand-primary);
  background: var(--brand-primary-light);
}

.upload-progress-bar { width: 100%; height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.upload-progress-bar-fill { height: 100%; background: var(--brand-primary); border-radius: 999px; transition: width 300ms ease; }

/* Legacy dropzone */
.file-dropzone { border: 1px dashed var(--border-2); border-radius: var(--radius); padding: 14px; background: var(--accent-dim); display: flex; flex-direction: column; gap: 8px; }
.file-dropzone span { font-size: 12px; color: var(--text-3); }

/* ─── PIPELINE STEPPER ─── */
.stepper { display: flex; align-items: center; gap: 0; }
.step { display: flex; align-items: center; gap: 8px; flex: 1; }
.step:last-child { flex: 0; }
.step-connector { flex: 1; height: 2px; background: var(--border); margin: 0 8px; transition: background var(--transition); }
.step.completed .step-connector { background: var(--brand-primary); }
.step-circle { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: var(--text-3); flex-shrink: 0; transition: all var(--transition); }
.step.active .step-circle { border-color: var(--brand-primary); background: var(--brand-primary); color: #fff; }
.step.completed .step-circle { border-color: var(--brand-primary); background: var(--brand-primary-light); color: var(--brand-primary); }
.step-label { font-size: 12px; font-weight: 500; color: var(--text-3); white-space: nowrap; }
.step.active .step-label { color: var(--brand-primary); font-weight: 600; }
.step.completed .step-label { color: var(--text-2); }

/* Legacy steps */
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.step.legacy {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--text-3);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 500;
}
.step.legacy.active { color: var(--brand-primary); border-color: var(--brand-primary-light); background: var(--brand-primary-light); font-weight: 700; }

/* ─── TOASTS ─── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

/* Legacy toast-root */
.toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  min-width: 280px;
  max-width: 400px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
  font: 500 13px var(--font-sans);
  animation: toast-in 300ms cubic-bezier(0.34,1.56,0.64,1) both;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  backdrop-filter: blur(12px);
}

.toast::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--text-3); }

.toast.ok { border-color: var(--ok-border); background: var(--ok-bg); color: var(--ok-text); }
.toast.ok::before { background: var(--success); }
.toast.error { border-color: var(--err-border); background: var(--err-bg); color: var(--err-text); }
.toast.error::before { background: var(--danger); }
.toast.warning { border-color: var(--warn-border); background: var(--warn-bg); color: var(--warn-text); }
.toast.warning::before { background: var(--warning); }
.toast.hide { opacity: 0; transform: translateX(16px) scale(0.95); transition: all 200ms ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ─── METRIC CARDS ─── */
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.metric-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-2); transform: translateY(-1px); }

.metric-label { font-size: 12px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-value { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -0.04em; line-height: 1; }
.metric-delta { font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.metric-delta.up { color: var(--success); }
.metric-delta.down { color: var(--danger); }

/* ─── SKELETON ─── */
.skeleton {
  display: block;
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius);
}

:root[data-theme='dark'] .skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
}

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

/* ─── EMPTY STATES ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  border: 1px dashed var(--border-2);
  border-radius: var(--border-radius);
  background: var(--surface-2);
  color: var(--text-3);
}

.empty-state-title { font-size: 15px; font-weight: 600; color: var(--text-2); }
.empty-state-desc { font-size: 13px; color: var(--text-3); max-width: 400px; }

/* ─── UTILITIES ─── */
.text-muted { color: var(--text-2); }
.muted      { color: var(--text-2); }
.font-mono  { font-family: var(--font-mono); }
.flex       { display: flex; }
.hidden     { display: none !important; }
.grid2      { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ─── CARDS (general) ─── */
.card {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  min-width: 0;
  width: 100%;
  animation: fade-in 300ms ease both;
}

body.workflow-page .card { height: calc(100vh - var(--topbar-height)); padding: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }

.box { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow); transition: box-shadow var(--transition), border-color var(--transition); }

/* ─── WORKFLOW CANVAS ─── */
body.workflow-page {
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, var(--accent-dim) 0%, transparent 60%),
    var(--bg);
}

.workflow { display: flex; flex-direction: column; height: 100%; }

.canvas {
  position: relative;
  border: none !important;
  border-radius: 0 !important;
  background:
    radial-gradient(ellipse 60% 40% at 70% 50%, rgba(59,130,246,0.03) 0%, transparent 60%),
    var(--bg);
  padding: 0 !important;
  height: 100%;
  overflow: hidden;
}

body.workflow-page .workflow .canvas {
  min-height: calc(100vh - var(--topbar-height));
  height: calc(100vh - var(--topbar-height));
}

.canvas-head {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 90%, transparent) 0%, transparent 100%);
  pointer-events: none;
}

.canvas-head > * { pointer-events: auto; }
.canvas-head h3 { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; }
.canvas-head .muted { font-size: 11px; color: var(--text-3); }
.btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ─── FLOATING TOOLBAR ─── */
.canvas-toolbar {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 4px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  padding: 6px 8px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
}

.toolbar-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font: 500 12px var(--font-sans);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.toolbar-btn:hover { background: var(--surface-3); color: var(--text); }

.toolbar-btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.toolbar-btn .kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  font-size: 10px;
  border-radius: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-3);
  font-family: var(--font-mono);
}

/* ─── WORKSPACE VIEWPORT ─── */
.workspace-viewport {
  position: absolute;
  inset: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.12) transparent;
  cursor: grab;
}

:root[data-theme='dark'] .workspace-viewport { scrollbar-color: rgba(255,255,255,0.08) transparent; }

.workspace-viewport::-webkit-scrollbar { width: 6px; height: 6px; }
.workspace-viewport::-webkit-scrollbar-track { background: transparent; }
.workspace-viewport::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }
:root[data-theme='dark'] .workspace-viewport::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); }

.workspace-viewport:active { cursor: grabbing; }
.workspace-viewport.panning { cursor: grabbing; user-select: none; }

.workspace-surface {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  width: max-content;
  height: max-content;
  background-image: radial-gradient(circle, var(--gray-300) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0px 0px;
}

:root[data-theme='dark'] .workspace-surface {
  background-image: radial-gradient(circle, rgba(255,255,255,0.13) 1px, transparent 1px);
}

.workspace-lanes { position: relative; width: 100%; height: 100%; }

[data-col].drag-over { outline: 2px dashed var(--accent-glow); outline-offset: 6px; border-radius: var(--radius-xl); }

.workspace-lane-body {
  position: relative;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

/* ─── NODES ─── */
.workflow-node-box { position: relative; z-index: 2; width: 100%; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  width: 268px;
  min-width: 268px;
  max-width: 268px;
  min-height: 74px;
  padding: 12px 12px 12px 10px;
  background: var(--surface);
  cursor: grab;
  transition: border-color 150ms ease, box-shadow 200ms ease, background 150ms ease;
  position: relative;
  box-shadow: var(--shadow);
}

.item:hover { border-color: var(--border-2); box-shadow: var(--shadow-md); }
.item.selected { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--brand-primary-light), var(--shadow-md); }
.item.link-source { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--brand-primary-light), 0 0 20px var(--accent-glow); }
.item.dragging-item { opacity: 0.6; cursor: grabbing; box-shadow: var(--shadow-lg); }

.column-item { border-color: rgba(37,99,235,0.30); }
.column-item:hover { border-color: rgba(37,99,235,0.50); }

.item::before {
  content: '';
  position: absolute;
  left: -1px; top: 10px; bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--text-3);
  transition: background var(--transition);
}

.column-item::before    { background: var(--brand-primary); }
.item.selected::before  { background: var(--brand-primary); }
.node-check::before     { background: var(--cat-check); }
.node-clean::before     { background: var(--cat-clean); }
.node-transform::before { background: var(--cat-transform); }
.node-compute::before   { background: var(--cat-compute); }
.node-filter::before    { background: var(--cat-filter); }
.node-normalize::before { background: var(--cat-normalize); }
.node-extract::before   { background: var(--cat-extract); }
.node-scaler::before    { background: var(--cat-scaler); }

.node-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; background: var(--surface-2); border: 1px solid var(--border); }
.column-item .node-icon { background: var(--brand-primary-light); border-color: rgba(37,99,235,0.25); }

.node-content { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.node-title { font-size: 13px; line-height: 1.3; font-weight: 700; color: var(--text); letter-spacing: -0.01em; white-space: normal; word-break: break-word; }
.node-meta { display: inline-flex; align-self: flex-start; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-3); font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.node-subtitle { font-size: 11px; line-height: 1.4; color: var(--text-3); font-family: var(--font-mono); white-space: normal; overflow-wrap: anywhere; }

.node-port { width: 8px; height: 8px; min-width: 8px; border-radius: 50%; border: 1.5px solid var(--border-2); background: var(--surface-3); cursor: crosshair; transition: all var(--transition); flex-shrink: 0; }
.node-port:hover { border-color: var(--brand-primary); background: var(--brand-primary); box-shadow: 0 0 8px var(--accent-glow); transform: scale(1.4); }

.item-actions { display: flex; align-items: center; gap: 3px; opacity: 0; transition: opacity var(--transition); margin-left: auto; padding-top: 2px; }
.item:hover .item-actions { opacity: 1; }

.item button { width: 22px; height: 22px; border: 1px solid var(--border); background: var(--surface-3); color: var(--text-3); border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 11px; transition: all var(--transition); padding: 0; font-family: var(--font-sans); }
.item button:hover { color: var(--text); border-color: var(--border-2); background: var(--surface-hover); }
.item button.remove:hover { color: var(--danger); border-color: rgba(239,68,68,0.3); }
.item button.duplicate:hover { color: var(--brand-primary); border-color: rgba(37,99,235,0.3); }

/* ─── CONNECTOR LINES ─── */
.lane-links { position: absolute; inset: 0; z-index: 1; pointer-events: auto; }

.lane-link-path {
  fill: none;
  stroke: var(--border-2);
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.92;
  pointer-events: stroke;
  cursor: pointer;
  transition: opacity 150ms ease, stroke 150ms ease, stroke-width 150ms ease;
}

.lane-link-path:hover { opacity: 1; stroke-width: 3; stroke: var(--brand-primary); }
.lane-link-path.selected { stroke: var(--brand-primary); stroke-width: 3.25; opacity: 1; }

/* ─── CANVAS EDGES (canvas_edges.js) ─── */
/* SVG overlay pour les liens style nonote.fr */
.canvas-edges-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
  width: 100%;
  height: 100%;
}
/* Les groupes d'edges reçoivent les events uniquement sur le trait */
.canvas-edges-svg g { pointer-events: stroke; }

.canvas-edge {
  transition: stroke-width 0.15s ease, stroke 0.15s ease;
}
.canvas-edge--preview {
  opacity: 0.7;
  pointer-events: none;
}
.edge-delete-btn {
  transition: opacity 0.15s ease;
}
.edge-delete-btn circle {
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
}

/* ─── Poignées sur les nœuds (data-handle) ─── */
[data-handle] {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--brand-primary, #2563eb);
  cursor: crosshair;
  z-index: 20;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  flex-shrink: 0;
}
[data-handle]:hover {
  transform: scale(1.4);
  box-shadow: 0 0 0 3px var(--brand-primary-light, rgba(37,99,235,0.2));
}
[data-handle].handle--magnetic {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35);
  transform: scale(1.3);
}

/* Positionnement des poignées input (gauche) et output (droite) */
.handle-input {
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2, #f1f5f9);
}
.handle-input:hover {
  transform: translateY(-50%) scale(1.4);
}
.handle-input.handle--magnetic {
  transform: translateY(-50%) scale(1.3);
}

.handle-output {
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--brand-primary, #2563eb);
  border-color: var(--brand-primary, #2563eb);
}
.handle-output:hover {
  transform: translateY(-50%) scale(1.4);
  box-shadow: 0 0 0 3px var(--brand-primary-light, rgba(37,99,235,0.2));
}

/* Les nœuds du canvas doivent avoir overflow visible pour les poignées */
[data-node-id] {
  overflow: visible !important;
}

/* Category node colours */
.node-check .node-meta     { color: var(--cat-check);     border-color: color-mix(in srgb, var(--cat-check) 28%, transparent);     background: color-mix(in srgb, var(--cat-check) 10%, var(--surface-2)); }
.node-clean .node-meta     { color: var(--cat-clean);     border-color: color-mix(in srgb, var(--cat-clean) 28%, transparent);     background: color-mix(in srgb, var(--cat-clean) 10%, var(--surface-2)); }
.node-transform .node-meta { color: var(--cat-transform); border-color: color-mix(in srgb, var(--cat-transform) 28%, transparent); background: color-mix(in srgb, var(--cat-transform) 10%, var(--surface-2)); }
.node-compute .node-meta   { color: var(--cat-compute);   border-color: color-mix(in srgb, var(--cat-compute) 28%, transparent);   background: color-mix(in srgb, var(--cat-compute) 10%, var(--surface-2)); }
.node-filter .node-meta    { color: var(--cat-filter);    border-color: color-mix(in srgb, var(--cat-filter) 28%, transparent);    background: color-mix(in srgb, var(--cat-filter) 10%, var(--surface-2)); }
.node-normalize .node-meta { color: var(--cat-normalize); border-color: color-mix(in srgb, var(--cat-normalize) 28%, transparent); background: color-mix(in srgb, var(--cat-normalize) 10%, var(--surface-2)); }
.node-extract .node-meta   { color: var(--cat-extract);   border-color: color-mix(in srgb, var(--cat-extract) 28%, transparent);   background: color-mix(in srgb, var(--cat-extract) 10%, var(--surface-2)); }
.node-scaler .node-meta    { color: var(--cat-scaler);    border-color: color-mix(in srgb, var(--cat-scaler) 28%, transparent);    background: color-mix(in srgb, var(--cat-scaler) 10%, var(--surface-2)); }

.node-check .node-icon     { background: var(--cat-check-dim);     border-color: var(--cat-check);     color: var(--cat-check); }
.node-clean .node-icon     { background: var(--cat-clean-dim);     border-color: var(--cat-clean);     color: var(--cat-clean); }
.node-transform .node-icon { background: var(--cat-transform-dim); border-color: var(--cat-transform); color: var(--cat-transform); }
.node-compute .node-icon   { background: var(--cat-compute-dim);   border-color: var(--cat-compute);   color: var(--cat-compute); }
.node-filter .node-icon    { background: var(--cat-filter-dim);    border-color: var(--cat-filter);    color: var(--cat-filter); }
.node-normalize .node-icon { background: var(--cat-normalize-dim); border-color: var(--cat-normalize); color: var(--cat-normalize); }
.node-extract .node-icon   { background: var(--cat-extract-dim);   border-color: var(--cat-extract);   color: var(--cat-extract); }
.node-scaler .node-icon    { background: var(--cat-scaler-dim);    border-color: var(--cat-scaler);    color: var(--cat-scaler); }

.node-check .node-title    { color: var(--cat-check); }
.node-clean .node-title    { color: var(--cat-clean); }
.node-transform .node-title{ color: var(--cat-transform); }
.node-compute .node-title  { color: var(--cat-compute); }
.node-filter .node-title   { color: var(--cat-filter); }
.node-normalize .node-title{ color: var(--cat-normalize); }
.node-extract .node-title  { color: var(--cat-extract); }
.node-scaler .node-title   { color: var(--cat-scaler); }

/* ─── MINIMAP ─── */
.workflow-minimap {
  position: fixed;
  right: 72px; bottom: 16px;
  width: 160px; height: 100px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  z-index: 100;
  overflow: hidden;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: opacity var(--transition), box-shadow var(--transition);
}

.workflow-minimap:hover { box-shadow: var(--shadow-lg), 0 0 0 1px var(--brand-primary) inset; }
.workflow-minimap::before { content: 'MAP'; position: absolute; top: 6px; left: 8px; font-size: 8px; font-weight: 700; letter-spacing: 0.1em; color: var(--text-3); z-index: 2; }
.workflow-minimap-content { position: absolute; inset: 0; }
.workflow-minimap-view { position: absolute; border: 1px solid var(--accent-glow); background: var(--accent-dim); border-radius: 4px; transition: all 50ms linear; }
.minimap-node { position: absolute; border-radius: 3px; height: 12px; background: var(--gray-300); }
:root[data-theme='dark'] .minimap-node { background: rgba(255,255,255,0.15); }
.minimap-node.active { background: var(--brand-primary); opacity: 0.6; }

.workflow-zoom-controls { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; z-index: 101; }
.workflow-zoom-controls button { width: 44px; height: 44px; min-width: 44px; padding: 0; border-radius: 12px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-size: 24px; line-height: 1; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: var(--shadow-md); transition: all 140ms ease-in-out; }
.workflow-zoom-controls button:hover { border-color: var(--brand-primary); background: var(--brand-primary-light); transform: translateY(-1px); }

/* ─── PROMPT DOCK ─── */
.workflow-prompt-dock {
  z-index: 150;
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 14px;
  width: min(620px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  padding: 6px 8px;
  backdrop-filter: blur(14px) saturate(1.15);
  box-shadow: var(--shadow-lg);
  transition: all 180ms ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.workflow-prompt-dock:focus-within { background: color-mix(in srgb, var(--surface) 90%, transparent); border-color: var(--brand-primary); box-shadow: var(--shadow-lg), 0 0 0 3px rgba(37,99,235,0.10); }
.workflow-prompt-dock form { display: grid; grid-template-columns: minmax(0, 1fr) 34px; align-items: center; flex: 1; gap: 8px; margin: 0; width: 100%; }

.prompt-suggestions { position: absolute; left: 0; right: 0; bottom: calc(100% + 10px); display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--border-2); border-radius: 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow-lg); backdrop-filter: blur(18px); }
.prompt-suggestions-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.prompt-suggestions-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prompt-suggestion-btn { width: 100%; min-height: 66px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); text-align: left; font-size: 12px; line-height: 1.45; cursor: pointer; transition: all 140ms ease; }
.prompt-suggestion-btn:hover { transform: translateY(-1px); border-color: var(--brand-primary); background: var(--brand-primary-light); color: var(--text); }

.workflow-prompt-dock textarea { width: 100%; min-width: 0; min-height: 34px; max-height: 150px; resize: none; background: transparent; border: none; color: var(--text); font: 400 13px var(--font-sans); padding: 6px 8px; outline: none; line-height: 1.35; overflow: hidden; }
.workflow-prompt-dock textarea::placeholder { color: var(--text-3); font-size: 12px; }

.prompt-send-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: all var(--transition); justify-self: end; }
.workflow-prompt-dock:focus-within .prompt-send-btn { border-color: var(--brand-primary); background: var(--brand-primary-light); color: var(--brand-primary); }
.prompt-send-btn:hover { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); transform: translateY(-1px); }
.prompt-send-btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.prompt-dock-label { font-size: 10px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.prompt-dock-label::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--brand-primary); animation: pulse-dot 2s ease infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.7); }
}

/* ─── VALIDATION STATUS ─── */
#workflow-validation-status { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 999px; display: none; font-family: var(--font-mono); }
#workflow-validation-status.ok { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-border); }
#workflow-validation-status.error { background: var(--err-bg); color: var(--err-text); border: 1px solid var(--err-border); }

/* ─── PALETTE ─── */
.palette-list { display: flex; flex-direction: column; gap: 6px; }
.rule-chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius); padding: 8px 10px; cursor: grab; transition: all var(--transition); }
.rule-chip:hover { border-color: var(--border-2); background: var(--surface-3); transform: translateX(2px); }
.rule-chip strong { display: block; font-size: 12px; font-weight: 600; color: var(--text); }
.rule-chip span { color: var(--text-3); font-size: 11px; }

/* ─── MODALS ─── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.50); display: flex; align-items: center; justify-content: center; z-index: 200; backdrop-filter: blur(4px); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 220ms ease-in-out, visibility 220ms ease-in-out; }
.modal-backdrop.open { opacity: 1; visibility: visible; pointer-events: auto; }

.modal { width: min(520px, calc(100% - 32px)); border: 1px solid var(--border-2); background: var(--surface); border-radius: var(--radius-xl); padding: 24px; box-shadow: var(--shadow-lg); opacity: 0; transform: scale(0.96) translateY(10px); transition: opacity 220ms ease-in-out, transform 240ms ease-in-out; }
.modal-backdrop.open .modal { opacity: 1; transform: scale(1) translateY(0); }
.modal h2 { font-size: 16px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.02em; }
.modal p.muted { font-size: 13px; color: var(--text-2); margin-bottom: 16px; }
.modal-steps { margin: 10px 0 16px; padding-left: 20px; }
.modal-steps li { margin: 8px 0; color: var(--text-3); font-size: 13px; }
.modal-steps li.active { color: var(--brand-primary); font-weight: 600; }

/* ─── NOTICES ─── */
.notice { border: 1px solid; border-radius: var(--radius); padding: 10px 12px; margin: 0 0 14px; font-size: 13px; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.notice.error { background: var(--err-bg); color: var(--err-text); border-color: var(--err-border); }
.notice[data-transient-msg="1"] { display: none; }

/* ─── PLATFORM ALERTS ─── */
.platform-alerts { position: sticky; top: 0; z-index: 150; display: flex; flex-direction: column; gap: 0; }
.alert { padding: 10px 16px; font-size: 13px; border-bottom: 1px solid transparent; }
.alert--info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.alert--warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.alert--error   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert--success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
[data-theme="dark"] .alert--info    { background: rgba(30,64,175,0.18); color: #93c5fd; border-color: rgba(147,197,253,0.2); }
[data-theme="dark"] .alert--warning { background: rgba(146,64,14,0.18);  color: #fcd34d; border-color: rgba(252,211,77,0.2); }
[data-theme="dark"] .alert--error   { background: rgba(153,27,27,0.18);  color: #fca5a5; border-color: rgba(252,165,165,0.2); }
[data-theme="dark"] .alert--success { background: rgba(6,95,70,0.18);    color: #6ee7b7; border-color: rgba(110,231,183,0.2); }

/* ─── SUPPORT TICKETS ─── */
.ticket-card { border: 1px solid var(--border-2); border-radius: var(--radius-lg); padding: 14px 16px; margin-bottom: 10px; display: flex; align-items: flex-start; gap: 12px; }
.ticket-card .ticket-meta { flex: 1; min-width: 0; }
.ticket-card .ticket-subject { font-size: 14px; font-weight: 600; margin: 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-card .ticket-date { font-size: 11px; color: var(--text-3); }
.ticket-status { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; white-space: nowrap; text-transform: uppercase; letter-spacing: 0.04em; }
.ticket-status.open       { background: #dbeafe; color: #1e40af; }
.ticket-status.in_progress{ background: #fef3c7; color: #92400e; }
.ticket-status.resolved   { background: #d1fae5; color: #065f46; }
[data-theme="dark"] .ticket-status.open        { background: rgba(30,64,175,0.25); color: #93c5fd; }
[data-theme="dark"] .ticket-status.in_progress { background: rgba(146,64,14,0.25);  color: #fcd34d; }
[data-theme="dark"] .ticket-status.resolved    { background: rgba(6,95,70,0.25);    color: #6ee7b7; }

/* ─── PROFILE MENU ─── */
.profile-menu, .menu { position: relative; }
.profile-menu summary, .menu summary { list-style: none; }
.profile-menu summary::-webkit-details-marker, .menu summary::-webkit-details-marker { display: none; }
.profile-trigger { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.avatar-chip { width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--border-2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; background: var(--brand-primary); color: #fff; }

.profile-panel, .menu-panel { position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; border: 1px solid var(--border-2); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-lg); padding: 8px; display: flex; flex-direction: column; gap: 2px; z-index: 200; animation: dropdown-in 150ms cubic-bezier(0.4,0,0.2,1) both; }

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.profile-panel a, .menu-panel a, .menu-text { display: block; padding: 8px 10px; border-radius: var(--radius); color: var(--text-2); font-size: 13px; transition: all var(--transition); }
.profile-panel a:hover, .menu-panel a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ─── PIPELINE CARDS ─── */
.pipeline-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.pipeline-create-form { margin: 0 0 8px; gap: 6px; }
.pipeline-create-inline { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.pipeline-switch-btn { width: 100%; text-align: left; }
.pipeline-substeps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.pipeline-substeps a { border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; color: var(--text-2); font-size: 12px; background: var(--surface-3); display: block; }
.pipeline-substeps a:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }

/* ─── FILE GRID ─── */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 10px; }
.file-card { position: relative; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); overflow: hidden; transition: all var(--transition); }
.file-card:hover { border-color: var(--border-2); box-shadow: var(--shadow-md); }
.file-main { display: flex; flex-direction: column; gap: 8px; padding: 14px 14px 40px; color: var(--text); min-height: 140px; }
.file-main:hover { text-decoration: none; background: var(--surface-3); }
.file-main h4 { margin: 0; font-size: 13px; word-break: break-word; }
.file-icon { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 20px; background: var(--surface-3); }
.file-download { position: absolute; right: 10px; bottom: 10px; width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; color: var(--text-2); background: var(--surface-3); transition: all var(--transition); }
.file-download:hover { text-decoration: none; color: var(--text); background: var(--surface-hover); }

/* ─── AI SIDEBAR ─── */
.ai-sidebar-backdrop { position: fixed; inset: var(--topbar-height) 0 0 0; background: rgba(0,0,0,0.38); opacity: 0; pointer-events: none; transition: opacity 220ms ease; z-index: 139; }
.ai-sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
.ai-sidebar { position: fixed; top: var(--topbar-height); right: 0; bottom: 0; width: 360px; background: var(--surface); border-left: 1px solid var(--border-2); display: flex; flex-direction: column; z-index: 140; transform: translateX(100%); transition: transform 250ms ease; box-shadow: var(--shadow-lg); }
.ai-sidebar.open { transform: translateX(0); }
.ai-sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px; }
.ai-sidebar-body { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.ai-sidebar-body .ai-msg { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; line-height: 1.5; max-width: 90%; }
.ai-sidebar-body .ai-msg.user { align-self: flex-end; background: var(--brand-primary-light); border: 1px solid rgba(37,99,235,0.25); }
.ai-sidebar-body .ai-msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.ai-sidebar-form { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.ai-sidebar-form textarea { flex: 1; min-height: 40px; max-height: 100px; resize: vertical; }
.ai-sidebar-form button { flex-shrink: 0; padding: 8px 14px; }

/* ─── Canvas Context Menu ────────────────────────────────────────────────── */
.canvas-ctx-menu {
  position: fixed;
  z-index: 3000;
  background: var(--surface, white);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08);
  min-width: 210px;
  padding: 4px;
  animation: ctx-pop 0.12s ease;
}
.canvas-ctx-menu[hidden] { display: none; }
@keyframes ctx-pop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.canvas-ctx-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px;
  border: none; border-radius: 6px;
  background: none; color: var(--text-1, #1e293b);
  font-size: 13px; font-weight: 500;
  cursor: pointer; text-align: left;
  transition: background 0.1s;
}
.canvas-ctx-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.canvas-ctx-item:hover { background: var(--bg-2, #f1f5f9); }
.canvas-ctx-item--danger { color: #dc2626; }
.canvas-ctx-item--danger:hover { background: #fef2f2; }
.canvas-ctx-item--ai { color: #7c3aed; font-size: 12px; }
.canvas-ctx-item--ai:hover { background: #f5f3ff; }
.canvas-ctx-separator { height: 1px; background: var(--border, #e2e8f0); margin: 4px 0; }
.canvas-ctx-ai-label {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 12px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3, #94a3b8);
}
.canvas-ctx-item kbd { margin-left: auto; font-size: 10px; opacity: 0.5; background: var(--surface-3, #f1f5f9); padding: 1px 5px; border-radius: 3px; }

/* ─── DRIVE PAGE ─── */
.drive-shell { width: 100%; }
.drive-page { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; min-height: 400px; }
.drive-main { min-width: 0; }

/* Header */
.drive-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 20px; flex-wrap: wrap; }
.drive-head-copy { min-width: 0; }
.drive-head-kicker { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 6px; }
.drive-head-copy h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; color: var(--text-1); }
.drive-head-copy p { font-size: 13px; color: var(--text-2); margin: 0; max-width: 60ch; line-height: 1.5; }
.drive-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

/* Breadcrumb */
.drive-breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); margin-bottom: 16px; flex-wrap: wrap; }
.drive-breadcrumb a { color: var(--accent); text-decoration: none; }
.drive-breadcrumb a:hover { text-decoration: underline; }
.drive-breadcrumb a[aria-current="page"] { color: var(--text-2); font-weight: 600; }
.drive-breadcrumb span { color: var(--text-3); }

/* Dropzone panel */
.drive-dropzone-panel {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  background: var(--surface-2);
  margin-bottom: 18px;
  transition: border-color var(--transition), background var(--transition);
}
.drive-dropzone-panel.drag-over { border-color: var(--accent); background: var(--accent-dim); }
.drive-dropzone-title { font-size: 14px; font-weight: 600; color: var(--text-1); margin-bottom: 2px; }
.drive-dropzone-text { font-size: 12px; color: var(--text-3); }
.drive-dropzone-link {
  flex-shrink: 0; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 14px;
  background: var(--surface); transition: border-color var(--transition), background var(--transition);
}
.drive-dropzone-link:hover { border-color: var(--accent); background: var(--accent-dim); }

/* Global drag overlay */
.drive-global-drop-overlay {
  position: fixed; inset: 0; z-index: 180;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(3px);
  pointer-events: none;
}
.drive-global-drop-copy {
  background: var(--surface); border: 2px dashed var(--accent); border-radius: var(--radius-xl);
  padding: 32px 48px; text-align: center; box-shadow: var(--shadow-lg);
}
.drive-global-drop-title { font-size: 18px; font-weight: 700; color: var(--text-1); margin-bottom: 4px; }
.drive-global-drop-text { font-size: 13px; color: var(--text-3); }

/* Upload progress */
.drive-progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-bottom: 16px; }
.drive-progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }

/* Grid toolbar */
.drive-grid-toolbar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.drive-grid-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.drive-grid-meta { font-size: 12px; color: var(--text-3); }

/* Card grid */
.drive-grid-advanced { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

.drive-card {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.drive-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,0.06)); }
.drive-card.dragging { opacity: 0.5; }
.drive-card.folder.drag-over { border-color: var(--accent); background: var(--accent-dim); }

.drive-card-main { display: flex; align-items: center; gap: 12px; padding: 16px; text-decoration: none; color: inherit; min-width: 0; flex: 1; text-align: left; }
.drive-card-icon {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; letter-spacing: 0.02em;
  background: var(--surface-3); color: var(--text-2);
}
.drive-card.folder .drive-card-icon { background: var(--accent-dim); color: var(--accent); }
.drive-card-body { min-width: 0; flex: 1; }
.drive-card-title { font-size: 14px; font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive-card-subtitle { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.drive-card-actions { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.drive-action {
  font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer;
  border: 1px solid transparent; border-radius: 6px; padding: 4px 8px;
  background: transparent; text-decoration: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.drive-action:hover { background: var(--surface-3); color: var(--text-1); border-color: var(--border); }
.drive-action.danger { color: var(--err-text); }
.drive-action.danger:hover { background: var(--err-bg); border-color: var(--err-border); }

/* Back / up card */
.drive-back-card { flex-direction: row; align-items: center; gap: 12px; padding: 16px; cursor: pointer; text-align: left; background: var(--surface-2); }
.drive-back-card .drive-card-icon { background: var(--surface-3); color: var(--text-3); }

/* Empty state */
.drive-empty-state {
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 48px 24px; text-align: center;
  border: 1px dashed var(--border); border-radius: var(--radius-lg); background: var(--surface-2);
}
.drive-empty-title { font-size: 15px; font-weight: 600; color: var(--text-2); }
.drive-empty-text { font-size: 13px; color: var(--text-3); }

/* Sidebar */
.drive-sidebar { display: flex; flex-direction: column; gap: 16px; }
.drive-sidebar-card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 18px; }
.drive-sidebar-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin-bottom: 12px; }
.drive-storage-value { font-size: 22px; font-weight: 700; color: var(--text-1); letter-spacing: -0.02em; }
.drive-storage-subtitle { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.drive-storage-bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 12px 0 8px; }
.drive-storage-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.drive-storage-foot { font-size: 12px; color: var(--text-3); }

/* Tree */
.drive-tree { font-size: 13px; }
.drive-tree-list { display: flex; flex-direction: column; gap: 2px; }
.drive-tree-node {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 10px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-2); cursor: pointer; text-align: left;
  font-size: 13px; transition: background var(--transition), color var(--transition);
}
.drive-tree-node:hover:not(:disabled) { background: var(--surface-2); color: var(--text-1); }
.drive-tree-node:disabled { cursor: default; opacity: 0.6; }
.drive-tree-bullet { width: 6px; height: 6px; border-radius: 999px; background: var(--text-3); flex-shrink: 0; }
.drive-tree-modal { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; }

@media (max-width: 900px) {
  .drive-page { grid-template-columns: 1fr; }
  .drive-sidebar { flex-direction: row; flex-wrap: wrap; }
  .drive-sidebar-card { flex: 1; min-width: 220px; }
}

/* ─── MISC HELPERS ─── */
.floating-zone-wrap { border: 1px dashed var(--border-2); border-radius: var(--radius-lg); padding: 12px; background: var(--surface-2); margin-bottom: 10px; }
.floating-zone-wrap h4 { margin: 0 0 6px; font-size: 12px; color: var(--text-3); }
.floating-zone { min-height: 60px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.floating-item { border: 1px solid var(--border); background: var(--surface-3); color: var(--text-2); border-radius: var(--radius); padding: 6px 10px; font-size: 12px; cursor: grab; display: flex; align-items: center; gap: 8px; }
.floating-item button { border: 1px solid var(--border); background: transparent; color: var(--text-3); border-radius: 6px; padding: 0 6px; font-size: 11px; }

.lanes { display: flex; flex-direction: column; gap: 10px; }
.lane { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); min-height: 120px; padding: 10px; }
.lane.drag-over { border-color: var(--brand-primary); }
.lane h4 { margin: 0 0 8px; font-size: 12px; color: var(--text-3); }
.lane-items { display: flex; flex-direction: column; gap: 10px; position: relative; }
.lane.horizontal .lane-items { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }

.flow-node { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-3); border: 1px dashed var(--border-2); background: var(--surface-3); border-radius: 999px; padding: 4px 10px; }
.preview { min-height: 120px; }
.column-runner { width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--brand-primary); background: var(--brand-primary-light); animation: column-runner-move 1.6s ease-in-out infinite; }

.kbd-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.kbd-list li { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-2); padding: 6px 10px; border-radius: var(--radius); background: var(--surface-2); }
.kbd-list code { border: 1px solid var(--border-2); border-radius: 6px; padding: 2px 7px; background: var(--surface-3); font-size: 11px; font-family: var(--font-mono); color: var(--text); }

.source-box { max-width: 860px; }
.inline-form { margin: 0; }

/* ─── RUN PROGRESS ─── */
.run-progress-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: none; align-items: center; justify-content: center; z-index: 300; backdrop-filter: blur(4px); }
.run-progress-overlay.open { display: flex; }
.run-progress-card { width: min(400px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-xl); padding: 24px; box-shadow: var(--shadow-lg); }
.run-progress-card h3 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.run-progress-bar { margin-top: 12px; width: 100%; height: 6px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.run-progress-bar span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--success), #059669); transition: width 320ms ease; }

/* ─── APP SHELL (spec aliases) ─── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-content {
  flex: 1;
  padding: 24px;
  background: var(--bg);
}

/* Hamburger button (mobile) */
.hamburger {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-2);
  flex-shrink: 0;
  transition: all var(--transition);
}

.hamburger:hover { background: var(--surface-3); color: var(--text); }

.hamburger svg {
  width: 16px; height: 16px;
  stroke: currentColor; stroke-width: 2;
  fill: none; stroke-linecap: round;
}

@media (max-width: 1023px) {
  .hamburger { display: inline-flex; }
  .main-content { margin-left: 0; }
  .app-shell .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 240ms cubic-bezier(0.4,0,0.2,1);
  }
  .app-shell .sidebar.open { transform: translateX(0); }
}

/* ─── ANIMATIONS ─── */
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes column-runner-move { 0% { transform: translateX(-8px); opacity: 0.5; } 50% { transform: translateX(8px); opacity: 1; } 100% { transform: translateX(-8px); opacity: 0.5; } }

/* ─── RESPONSIVE ─── */
@media (max-width: 1200px) {
  .topbar-inner { padding: 0 10px; gap: 8px; }
  .topbar-left { gap: 8px; }
  .topbar-actions { gap: 6px; }
  .run-btn { padding: 7px 10px; font-size: 12px; }
  .workflow-prompt-dock { width: min(560px, calc(100vw - 24px)); }
}

@media (max-width: 1024px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: var(--topbar-height); left: 0; bottom: 0;
    width: 260px; z-index: 90;
    transform: translateX(-100%);
    transition: transform 240ms cubic-bezier(0.4,0,0.2,1);
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-expanded .sidebar { transform: translateX(0); }
  body.sidebar-expanded::before { content: ''; position: fixed; inset: var(--topbar-height) 0 0 0; background: rgba(0,0,0,0.40); z-index: 89; }
  .card { width: 100%; min-width: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .breadcrumb { max-width: 36vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .canvas-toolbar { top: 62px; max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: thin; }
  .workflow-minimap { right: 10px; bottom: 12px; }
  .workflow-zoom-controls { right: 182px; bottom: 12px; }
}

@media (max-width: 900px) {
  .breadcrumb { display: none; }
  .topbar-actions .admin-entry { display: none; }
  .canvas-toolbar { left: 8px; right: 8px; transform: none; justify-content: flex-start; }
  .toolbar-btn { padding: 6px 8px; font-size: 11px; }
  .toolbar-btn .kbd { display: none; }
  .workflow-prompt-dock { width: calc(100vw - 14px); max-width: calc(100vw - 14px); bottom: 8px; }
  .workflow-minimap { width: 132px; height: 84px; right: 8px; bottom: 56px; }
  .workflow-zoom-controls { right: 148px; bottom: 56px; gap: 8px; }
  .workflow-zoom-controls button { width: 36px; height: 36px; min-width: 36px; border-radius: 10px; font-size: 20px; }
  .toast-root { right: 8px; left: 8px; top: 60px; }
  .toast { min-width: 0; max-width: 100%; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (max-width: 700px) {
  :root { --topbar-height: 48px; }
  .app-layout { min-height: calc(100vh - 48px); }
  body.workflow-page .card, body.workflow-page .workflow .canvas { height: calc(100vh - 48px); min-height: calc(100vh - 48px); }
  .brand { font-size: 14px; }
  .brand-logo { width: 24px; height: 24px; font-size: 12px; border-radius: 7px; }
  .run-btn { padding: 6px 8px; font-size: 11px; gap: 4px; }
  .run-btn svg { width: 12px; height: 12px; }
  .icon-btn { width: 30px; height: 30px; }
  .canvas-toolbar { top: 54px; padding: 5px 6px; border-radius: 10px; }
  .toolbar-sep { margin: 0 2px; }
  .item { width: 180px; min-width: 180px; max-width: 180px; }
  .workflow-prompt-dock { padding: 5px 6px; border-radius: 12px; }
  .workflow-prompt-dock form { grid-template-columns: minmax(0, 1fr) 30px; gap: 6px; }
  .prompt-send-btn { width: 30px; height: 30px; }
  .admin-table { display: block; overflow-x: auto; white-space: nowrap; }
  .inline-actions { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .topbar-inner { padding: 0 6px; gap: 6px; }
  .topbar-actions { gap: 4px; }
  .run-btn { padding: 6px 7px; }
  .profile-trigger .role-badge { display: none; }
  .canvas-toolbar { top: 52px; }
  .workflow-minimap { width: 116px; height: 74px; right: 6px; bottom: 58px; }
  .workflow-zoom-controls { right: 128px; bottom: 58px; }
  .workflow-zoom-controls button { width: 32px; height: 32px; min-width: 32px; font-size: 18px; }
  .workflow-prompt-dock textarea { font-size: 12px; }
  .modal { width: calc(100% - 14px); padding: 16px 12px; border-radius: 12px; }
  .file-grid { grid-template-columns: 1fr; }
}

/* ─── AI Bar ─────────────────────────────────────────────────────────────── */
.ai-bar {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
}
.ai-bar__trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  background: #1e293b;
  color: white;
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  transition: all 0.2s;
  white-space: nowrap;
}
.ai-bar__trigger:hover { background: #334155; transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.ai-bar__trigger kbd { background: rgba(255,255,255,0.15); padding: 0.125rem 0.375rem; border-radius: 4px; font-size: 0.75rem; font-family: inherit; }
.ai-bar__trigger svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ─── AI Modal ───────────────────────────────────────────────────────────── */
.ai-modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 24px; }
.ai-modal[hidden] { display: none; }
.ai-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(6px); }
.ai-modal__panel {
  position: relative;
  background: var(--surface, white);
  border-radius: 18px;
  width: 100%;
  max-width: 760px;
  height: min(75vh, 680px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.3), 0 0 0 1px var(--border, rgba(0,0,0,0.08));
  animation: ai-pop-in 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes ai-pop-in { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.ai-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
}
.ai-modal__header h2 { margin: 0; font-size: 1rem; font-weight: 600; color: var(--text-1, #1e293b); }
.ai-modal__close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-3, #94a3b8);
  padding: 0.25rem;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s;
}
.ai-modal__close:hover { color: var(--text-1, #1e293b); }
.ai-modal__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.ai-message { max-width: 80%; padding: 0.75rem 1rem; border-radius: 12px; line-height: 1.5; font-size: 0.875rem; }
.ai-message--user { background: #2563eb; color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.ai-message--assistant { background: var(--bg-2, #f1f5f9); color: var(--text-1, #1e293b); align-self: flex-start; border-bottom-left-radius: 4px; }
.ai-message--loading { opacity: 0.65; font-style: italic; }
.ai-modal__input-area {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
}
.ai-modal__input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  padding: 0.625rem;
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--bg, white);
  color: var(--text-1, #1e293b);
  outline: none;
  transition: border-color 0.15s;
}
.ai-modal__input-area textarea:focus { border-color: #2563eb; }
.ai-modal__send {
  align-self: flex-end;
  width: 40px; height: 40px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  flex-shrink: 0;
}
.ai-modal__send svg { width: 16px; height: 16px; }

/* Header restructuré */
.ai-modal__header { gap: 0.75rem; }
.ai-modal__header-left { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.ai-modal__header-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.ai-modal__icon { width: 18px; height: 18px; color: #2563eb; flex-shrink: 0; }
.ai-modal__title { font-size: 0.9375rem; font-weight: 600; color: var(--text-1, #1e293b); white-space: nowrap; }

/* Badge pipeline connecté */
.ai-pipeline-badge {
  font-size: 0.7rem; font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background: #dcfce7; color: #166534;
  border: 1px solid #bbf7d0;
  white-space: nowrap;
}

/* Bouton nouvelle discussion */
.ai-new-chat-btn {
  display: flex; align-items: center; gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: white;
  color: var(--text-2, #475569);
  font-size: 0.8125rem; font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.ai-new-chat-btn:hover { background: var(--bg-2, #f1f5f9); color: var(--text-1, #1e293b); border-color: #94a3b8; }
.ai-new-chat-btn svg { width: 14px; height: 14px; }

/* Message de bienvenue */
.ai-welcome { padding: 1rem; background: var(--bg-2, #f8fafc); border-radius: 12px; font-size: 0.875rem; line-height: 1.6; color: var(--text-2, #475569); }
.ai-welcome p { margin: 0 0 0.5rem; }
.ai-welcome p:last-child { margin-bottom: 0; }
.ai-welcome strong { color: var(--text-1, #1e293b); }
.ai-welcome__hint { font-size: 0.8rem; color: var(--text-3, #94a3b8); font-style: italic; }

/* Zone de réflexion */
.ai-thinking {
  display: flex; align-items: center; gap: 0.375rem;
  padding: 0.625rem 1.5rem;
  border-top: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
}
.ai-thinking[hidden] { display: none; }
.ai-thinking__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #2563eb;
  animation: ai-pulse 1.2s ease-in-out infinite;
}
.ai-thinking__dot:nth-child(2) { animation-delay: 0.2s; }
.ai-thinking__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-pulse { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
.ai-thinking__label { font-size: 0.8125rem; color: var(--text-3, #94a3b8); font-style: italic; margin-left: 0.25rem; }

/* Rendu markdown basique dans les messages */
.ai-message--assistant { white-space: pre-wrap; }
.ai-message__apply-btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  margin-top: 0.75rem;
  padding: 0.4rem 0.875rem;
  background: #2563eb; color: white;
  border: none; border-radius: 8px;
  font-size: 0.8125rem; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.ai-message__apply-btn:hover { background: #1d4ed8; }
.ai-message__apply-btn:disabled { background: #93c5fd; cursor: default; }
.ai-message__apply-btn svg { width: 13px; height: 13px; }

/* ─── DARK THEME PARITY for AI modal / context menu / drive ───
   These component blocks ship hardcoded light fallbacks; override the
   load-bearing colours so they read correctly in dark mode. */
:root[data-theme='dark'] .ai-bar__trigger { background: var(--surface-3); color: var(--text); }
:root[data-theme='dark'] .ai-bar__trigger:hover { background: var(--surface-hover); }
:root[data-theme='dark'] .ai-message--assistant { background: var(--surface-2); color: var(--text); }
:root[data-theme='dark'] .ai-new-chat-btn { background: var(--surface-2); color: var(--text-2); }
:root[data-theme='dark'] .ai-new-chat-btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }
:root[data-theme='dark'] .ai-pipeline-badge { background: rgba(52,211,153,0.15); color: #6ee7b7; border-color: rgba(52,211,153,0.30); }
:root[data-theme='dark'] .ai-welcome { background: var(--surface-2); color: var(--text-2); }
:root[data-theme='dark'] .ai-welcome strong { color: var(--text); }
:root[data-theme='dark'] .canvas-ctx-item--danger:hover { background: rgba(248,113,113,0.12); }
:root[data-theme='dark'] .canvas-ctx-item--ai { color: var(--purple); }
:root[data-theme='dark'] .canvas-ctx-item--ai:hover { background: rgba(167,139,250,0.12); }
:root[data-theme='dark'] .ticket-status.open       { background: rgba(30,64,175,0.25); color: #93c5fd; }

/* ═══════════════════════════════════════════════════════════
   CANVAS 3-PANEL LAYOUT — Columns | Canvas | Config
   ═══════════════════════════════════════════════════════════ */

/* Source / Destination topbar strip */
.canvas-connectors-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 110;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
body.workflow-page .canvas-connectors-bar {
  position: sticky;
  top: var(--topbar-height);
}
.canvas-connectors-bar::-webkit-scrollbar { display: none; }

.connector-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color var(--transition);
}
.connector-badge--ok {
  border-color: rgba(16,185,129,0.30);
  background: var(--ok-bg);
  color: var(--ok-text);
}
.connector-badge--dest { color: var(--text-3); }
.connector-badge svg { width: 13px; height: 13px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; flex-shrink: 0; }
.connector-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.connector-value { font-weight: 600; font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.connector-ok-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.connector-edit-btn { background: none; border: none; cursor: pointer; padding: 0 2px; color: currentColor; opacity: 0.6; display: flex; align-items: center; transition: opacity var(--transition); }
.connector-edit-btn:hover { opacity: 1; }
.connector-edit-btn svg { width: 11px; height: 11px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.connector-arrow { color: var(--text-3); flex-shrink: 0; }
.connector-arrow svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.connector-pipeline-info {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-3);
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  flex-shrink: 0;
}
.connector-pipeline-info svg { width: 13px; height: 13px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; }

/* Workflow board — flex row for 3 panels */
body.workflow-page #workflow-board.workflow {
  flex-direction: row;
  align-items: stretch;
  overflow: hidden;
  height: calc(100vh - var(--topbar-height) - 36px); /* subtract connectors-bar */
}
/* In 3-panel layout the canvas height is set by the parent, not viewport */
body.workflow-page #workflow-board.workflow .canvas {
  min-height: unset;
  height: 100%;
}

/* ─── LEFT COLUMNS PANEL ─── */
.canvas-columns-panel {
  width: 220px;
  min-width: 220px;
  max-width: 220px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 50;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition), max-width var(--transition);
}
.canvas-columns-panel.collapsed {
  width: 36px;
  min-width: 36px;
  max-width: 36px;
}
.canvas-columns-panel.collapsed .canvas-columns-search-wrap,
.canvas-columns-panel.collapsed .canvas-columns-list,
.canvas-columns-panel.collapsed .canvas-columns-panel-footer,
.canvas-columns-panel.collapsed .canvas-panel-title { opacity: 0; pointer-events: none; visibility: hidden; }
.canvas-columns-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.canvas-panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  transition: opacity var(--transition), visibility var(--transition);
}
.canvas-columns-search-wrap {
  position: relative;
  padding: 8px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  transition: opacity var(--transition), visibility var(--transition);
}
.canvas-columns-search-wrap svg {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 13px;
  height: 13px;
  stroke: var(--text-3);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  pointer-events: none;
}
#canvas-columns-search {
  width: 100%;
  padding: 5px 8px 5px 26px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
#canvas-columns-search:focus { border-color: var(--brand-primary); }
.canvas-columns-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: opacity var(--transition), visibility var(--transition);
}
.canvas-col-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: grab;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  font-size: 12px;
  user-select: none;
}
.canvas-col-item:hover { background: var(--accent-dim); border-color: var(--accent-glow); }
.canvas-col-item.dragging { opacity: 0.55; cursor: grabbing; }
.canvas-col-item--dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-primary); flex-shrink: 0; }
.canvas-col-item--name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; color: var(--text); }
.canvas-col-item--type {
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--text-3);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.canvas-col-item--type[data-coltype="INTEGER"],
.canvas-col-item--type[data-coltype="FLOAT"]    { background: rgba(37,99,235,0.08); color: var(--brand-primary); border-color: var(--accent-glow); }
.canvas-col-item--type[data-coltype="DATE"],
.canvas-col-item--type[data-coltype="DATETIME"] { background: rgba(124,58,237,0.08); color: var(--purple); border-color: rgba(124,58,237,0.20); }
.canvas-col-item--type[data-coltype="BOOLEAN"]  { background: rgba(16,185,129,0.08); color: var(--green); border-color: var(--green-glow); }
.canvas-columns-panel-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  transition: opacity var(--transition), visibility var(--transition);
}
.canvas-add-step-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px dashed var(--border-2);
  border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.canvas-add-step-btn:hover { background: var(--accent-dim); border-color: var(--brand-primary); color: var(--brand-primary); }
.canvas-add-step-btn svg { width: 13px; height: 13px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

/* ─── RIGHT CONFIG PANEL ─── */
.canvas-config-panel {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition), max-width var(--transition), opacity var(--transition);
}
.canvas-config-panel--hidden { width: 0; min-width: 0; max-width: 0; opacity: 0; pointer-events: none; }
.canvas-config-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.canvas-config-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.canvas-config-panel-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.canvas-config-save-btn {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: none;
  background: var(--brand-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.canvas-config-save-btn:hover { background: var(--brand-primary-dark); }
.canvas-config-delete-btn {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.canvas-config-delete-btn:hover { border-color: var(--danger); color: var(--danger); background: var(--err-bg); }
.canvas-config-field { display: flex; flex-direction: column; gap: 5px; }
.canvas-config-field label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.canvas-config-field input,
.canvas-config-field select,
.canvas-config-field textarea {
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
  font-family: var(--font-sans);
}
.canvas-config-field input:focus,
.canvas-config-field select:focus,
.canvas-config-field textarea:focus { border-color: var(--brand-primary); }
.canvas-config-field textarea { min-height: 80px; resize: vertical; font-family: var(--font-mono); font-size: 12px; }
.canvas-config-step-type { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--accent-dim); border-radius: 8px; border: 1px solid var(--accent-glow); font-size: 12px; color: var(--text-2); }
.canvas-config-step-type-icon { font-size: 16px; flex-shrink: 0; }
.canvas-config-step-type-name { font-weight: 700; color: var(--text); }
.canvas-config-step-type-col { color: var(--text-3); font-family: var(--font-mono); font-size: 11px; }

/* ─── BOTTOM PREVIEW PANEL ─── */
.canvas-preview-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.canvas-preview-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 36px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.canvas-preview-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  padding: 4px 4px 4px 0;
  transition: color var(--transition);
}
.canvas-preview-toggle:hover { color: var(--text); }
.canvas-preview-toggle svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; transition: transform var(--transition); }
.canvas-preview-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.canvas-preview-row-count { font-size: 11px; font-weight: 500; color: var(--text-3); padding: 1px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.canvas-preview-content { overflow: hidden; transition: max-height 300ms cubic-bezier(0.4,0,0.2,1); max-height: 0; }
.canvas-preview-content--collapsed { max-height: 0 !important; }
.canvas-preview-content--open { max-height: 280px; overflow-y: auto; }
.canvas-preview-table-wrap { padding: 10px 12px; overflow-x: auto; }
.canvas-preview-empty { font-size: 12px; color: var(--text-3); padding: 8px 0; text-align: center; }
.canvas-preview-table-wrap table { border-collapse: collapse; width: max-content; font-size: 11px; font-family: var(--font-mono); }
.canvas-preview-table-wrap th { padding: 4px 10px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 700; color: var(--text-2); text-align: left; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.canvas-preview-table-wrap td { padding: 3px 10px; border: 1px solid var(--border); color: var(--text); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.canvas-preview-table-wrap tr:hover td { background: var(--surface-2); }
.canvas-preview-loading { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 20px; font-size: 12px; color: var(--text-3); }
.canvas-preview-loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: preview-spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes preview-spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 900px) {
  .canvas-columns-panel { display: none; }
  .canvas-config-panel { width: 220px; min-width: 220px; max-width: 220px; }
}
@media (max-width: 640px) {
  .canvas-connectors-bar { padding: 5px 8px; }
  .connector-value { max-width: 80px; }
  .canvas-config-panel { position: fixed; right: 0; top: var(--topbar-height); height: calc(100vh - var(--topbar-height)); z-index: 300; box-shadow: var(--shadow-lg); }
  .canvas-preview-content--open { max-height: 180px; }
}

/* ─── Rules Palette ──────────────────────────────────────────────────────── */
.rule-chip {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: var(--surface, white);
  cursor: pointer;
  transition: all 0.15s;
}
.rule-chip:hover { border-color: var(--accent, #2563eb); background: var(--accent-dim, #eff6ff); }
.rule-chip__name { font-size: 0.8125rem; font-weight: 600; color: var(--text-1, #1e293b); }
.rule-chip__desc { font-size: 0.7rem; color: var(--text-3, #94a3b8); line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Settings page — long scroll section titles */
.settings-section-title {
  font-size: 1rem; font-weight: 700; color: var(--text-1, #1e293b);
  margin: 32px 0 16px; padding-bottom: 8px;
  border-bottom: 2px solid var(--border, #e2e8f0);
}
.settings-section-title:first-child { margin-top: 0; }

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────── */

/* ── 1280px — Large tablets / small laptops ── */
@media (max-width: 1280px) {
  .sidebar { max-width: 200px; }

  /* Cards: 2 columns instead of 3+ */
  .dashboard-grid,
  .stats-grid,
  .kpi-grid,
  .admin-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .ai-modal__panel { max-width: 96vw; }
}

/* ── 1024px — Tablets ── */
@media (max-width: 1024px) {
  /* Layout: single column, sidebar hidden by default */
  .app-layout {
    grid-template-columns: 1fr;
  }

  /* Sidebar: off-canvas drawer */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    width: 260px;
    max-width: 260px;
  }

  body.sidebar-expanded .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.25);
  }

  /* Hamburger visible, desktop toggle hidden */
  #mobile-hamburger { display: flex; }
  #sidebar-toggle   { display: none; }
  #sidebar-collapse { display: none; }

  /* Topbar: full width */
  .topbar { width: 100%; }
  .topbar-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
  }

  /* Main content padding */
  .main-content,
  .content-area {
    padding: 16px;
  }

  /* Tables: horizontal scroll */
  .table-wrapper,
  .admin-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Grids: 2 columns */
  .dashboard-grid,
  .stats-grid,
  .kpi-grid,
  .admin-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Sidebar overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
  }

  body.sidebar-expanded .sidebar-overlay { display: block; }
}

/* ── 768px — Mobile landscape / large phones ── */
@media (max-width: 768px) {
  .topbar-inner {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .breadcrumb { display: none; }

  /* Single-column grids */
  .dashboard-grid,
  .stats-grid,
  .kpi-grid,
  .admin-cards {
    grid-template-columns: 1fr;
  }

  /* AI modal: bottom sheet */
  .ai-modal {
    padding: 0;
    align-items: flex-end;
  }
  .ai-modal__panel {
    border-radius: 20px 20px 0 0;
    height: 80vh;
    max-width: 100%;
  }

  /* Canvas min-height */
  .canvas-area,
  .workflow-canvas {
    min-height: 300px;
  }

  /* Form layout: stack vertically */
  .form-row,
  .form-grid {
    flex-direction: column;
  }

  /* Hide non-essential table columns */
  .hide-mobile { display: none; }
}

/* ── 480px — Small phones ── */
@media (max-width: 480px) {
  .topbar-inner { gap: 6px; }

  /* Hide brand text, keep logo */
  .brand span,
  .brand > :not(.brand-logo) {
    display: none;
  }

  /* Prevent iOS input zoom */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Buttons: compact */
  .btn {
    padding: 8px 14px;
    font-size: 13px;
  }

  /* Modal inner margin */
  .modal .modal {
    margin: 8px;
    border-radius: 14px;
  }

  /* AI modal: taller */
  .ai-modal__panel { height: 90vh; }

  /* Responsive headings */
  h1 { font-size: clamp(1.2rem, 5vw, 1.8rem); }
}
