/* =========================================================
   Work Director — Application Stylesheet
   ---------------------------------------------------------
   Layer 1: Design tokens (raw scales + semantic) — from
            design-system-import/tokens.css
   Layer 2: Component primitives — from
            design-system-import/components.css
   Layer 3: Application classes — project-specific selectors
            (sidebar shell, role cards, node cards, etc.)
            wired to the same semantic tokens.
   ========================================================= */

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

:root {
  /* ---------- FONTS ---------- */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* ---------- TYPE SCALE ---------- */
  --text-display-size: 40px;  --text-display-line: 44px;
  --text-h1-size: 28px;       --text-h1-line: 34px;
  --text-h2-size: 20px;       --text-h2-line: 28px;
  --text-h3-size: 16px;       --text-h3-line: 22px;
  --text-body-size: 14px;     --text-body-line: 22px;
  --text-small-size: 13px;    --text-small-line: 18px;
  --text-caption-size: 12px;  --text-caption-line: 16px;

  /* ---------- SPACING (4px base) ---------- */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* ---------- RADIUS ---------- */
  --radius-none: 0;
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --radius-xl: 8px;
  --radius-pill: 999px;

  /* ---------- MOTION ---------- */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-emphasized: cubic-bezier(0.3, 0, 0, 1.2);
  --dur-instant: 80ms;
  --dur-fast: 140ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;

  /* ---------- RAW: STONE (warm neutral) ---------- */
  --stone-50:  oklch(0.985 0.004 75);
  --stone-100: oklch(0.965 0.006 75);
  --stone-200: oklch(0.925 0.008 72);
  --stone-300: oklch(0.870 0.010 70);
  --stone-400: oklch(0.760 0.012 70);
  --stone-500: oklch(0.620 0.012 70);
  --stone-600: oklch(0.490 0.012 70);
  --stone-700: oklch(0.380 0.010 70);
  --stone-800: oklch(0.275 0.009 70);
  --stone-900: oklch(0.205 0.008 72);
  --stone-950: oklch(0.145 0.006 75);

  /* ---------- RAW: IRIS (primary accent) ---------- */
  --iris-50:  oklch(0.975 0.014 250);
  --iris-100: oklch(0.945 0.030 250);
  --iris-200: oklch(0.890 0.060 250);
  --iris-300: oklch(0.810 0.105 250);
  --iris-400: oklch(0.700 0.155 250);
  --iris-500: oklch(0.605 0.180 250);
  --iris-600: oklch(0.520 0.180 250);
  --iris-700: oklch(0.440 0.155 250);
  --iris-800: oklch(0.355 0.115 250);
  --iris-900: oklch(0.280 0.075 250);
  --iris-950: oklch(0.205 0.045 250);

  /* ---------- RAW: OCHRE (secondary accent) ---------- */
  --ochre-50:  oklch(0.980 0.018 70);
  --ochre-100: oklch(0.955 0.040 70);
  --ochre-200: oklch(0.910 0.080 70);
  --ochre-300: oklch(0.850 0.120 68);
  --ochre-400: oklch(0.775 0.150 65);
  --ochre-500: oklch(0.700 0.155 60);
  --ochre-600: oklch(0.620 0.150 55);
  --ochre-700: oklch(0.520 0.130 50);
  --ochre-800: oklch(0.420 0.105 48);
  --ochre-900: oklch(0.330 0.075 48);
  --ochre-950: oklch(0.240 0.050 50);

  /* ---------- RAW: STATUS ---------- */
  --success-50:  oklch(0.965 0.025 155);
  --success-200: oklch(0.880 0.080 155);
  --success-500: oklch(0.625 0.135 155);
  --success-700: oklch(0.475 0.120 155);

  --warning-50:  oklch(0.975 0.030 80);
  --warning-200: oklch(0.910 0.090 80);
  --warning-500: oklch(0.760 0.150 75);
  --warning-700: oklch(0.560 0.130 60);

  --danger-50:  oklch(0.965 0.025 25);
  --danger-200: oklch(0.880 0.075 25);
  --danger-500: oklch(0.620 0.180 25);
  --danger-700: oklch(0.470 0.155 25);

  --info-50:  oklch(0.965 0.025 230);
  --info-200: oklch(0.880 0.075 230);
  --info-500: oklch(0.620 0.150 230);
  --info-700: oklch(0.470 0.130 230);

  /* ---------- SEMANTIC: SURFACES ---------- */
  --bg-canvas: var(--stone-50);
  --bg-tinted: var(--stone-100);
  --surface-1: #ffffff;
  --surface-2: var(--stone-100);
  --surface-3: var(--stone-200);
  --surface-inverse: var(--stone-900);

  /* ---------- SEMANTIC: TEXT ---------- */
  --text-primary: var(--stone-950);
  --text-secondary: var(--stone-700);
  --text-muted: var(--stone-500);
  --text-disabled: var(--stone-400);
  --text-on-accent: #ffffff;
  --text-link: var(--iris-700);

  /* ---------- SEMANTIC: BORDERS ---------- */
  --border-subtle: var(--stone-100);
  --border-default: var(--stone-200);
  --border-strong: var(--stone-300);
  --border-input: var(--stone-300);
  --border-focus: var(--iris-500);

  /* ---------- SEMANTIC: ACCENTS ---------- */
  --accent-primary: var(--iris-600);
  --accent-primary-hover: var(--iris-700);
  --accent-primary-soft: var(--iris-100);
  --accent-primary-soft-text: var(--iris-700);
  --accent-secondary: var(--ochre-600);
  --accent-secondary-hover: var(--ochre-700);
  --accent-secondary-soft: var(--ochre-100);
  --accent-secondary-soft-text: var(--ochre-800);

  /* ---------- SEMANTIC: STATE / STATUS ---------- */
  --state-running: var(--info-500);
  --state-running-soft: var(--info-50);
  --state-running-text: var(--info-700);

  --state-completed: var(--success-500);
  --state-completed-soft: var(--success-50);
  --state-completed-text: var(--success-700);

  --state-failed: var(--danger-500);
  --state-failed-soft: var(--danger-50);
  --state-failed-text: var(--danger-700);

  --state-cancelled: var(--stone-500);
  --state-cancelled-soft: var(--stone-100);
  --state-cancelled-text: var(--stone-700);

  --state-pending: var(--warning-500);
  --state-pending-soft: var(--warning-50);
  --state-pending-text: var(--warning-700);

  /* ---------- SEMANTIC: NODE TYPES ---------- */
  --node-form: var(--iris-500);
  --node-form-soft: var(--iris-50);
  --node-approval: var(--ochre-600);
  --node-approval-soft: var(--ochre-50);
  --node-assignment: var(--success-500);
  --node-assignment-soft: var(--success-50);
  --node-emailer: var(--info-500);
  --node-emailer-soft: var(--info-50);
  --node-notification: oklch(0.55 0.15 305);
  --node-notification-soft: oklch(0.965 0.025 305);

  /* ---------- SHADOWS ---------- */
  --shadow-xs: 0 1px 1px rgba(20, 16, 10, 0.04);
  --shadow-sm: 0 1px 2px rgba(20, 16, 10, 0.05), 0 1px 1px rgba(20, 16, 10, 0.03);
  --shadow-md: 0 4px 8px rgba(20, 16, 10, 0.06), 0 1px 2px rgba(20, 16, 10, 0.04);
  --shadow-lg: 0 12px 20px rgba(20, 16, 10, 0.08), 0 2px 4px rgba(20, 16, 10, 0.04);
  --shadow-overlay: 0 24px 48px rgba(20, 16, 10, 0.18), 0 4px 8px rgba(20, 16, 10, 0.06);
  --shadow-focus: 0 0 0 3px color-mix(in oklch, var(--accent-primary) 25%, transparent);

  /* ---------- LAYOUT ---------- */
  --sidebar-width: 220px;
  --topbar-height: 56px;
}

[data-theme="dark"] {
  --bg-canvas: var(--stone-950);
  --bg-tinted: var(--stone-900);
  --surface-1: var(--stone-900);
  --surface-2: var(--stone-800);
  --surface-3: var(--stone-700);
  --surface-inverse: var(--stone-100);

  --text-primary: var(--stone-50);
  --text-secondary: var(--stone-300);
  --text-muted: var(--stone-500);
  --text-disabled: var(--stone-600);
  --text-on-accent: var(--stone-950);
  --text-link: var(--iris-300);

  --border-subtle: var(--stone-800);
  --border-default: var(--stone-700);
  --border-strong: var(--stone-600);
  --border-input: var(--stone-700);
  --border-focus: var(--iris-400);

  --accent-primary: var(--iris-400);
  --accent-primary-hover: var(--iris-300);
  --accent-primary-soft: oklch(0.30 0.08 250);
  --accent-primary-soft-text: var(--iris-200);
  --accent-secondary: var(--ochre-400);
  --accent-secondary-hover: var(--ochre-300);
  --accent-secondary-soft: oklch(0.30 0.07 55);
  --accent-secondary-soft-text: var(--ochre-200);

  --state-running-soft: oklch(0.30 0.06 230);
  --state-running-text: var(--info-200);
  --state-completed-soft: oklch(0.30 0.06 155);
  --state-completed-text: var(--success-200);
  --state-failed-soft: oklch(0.30 0.07 25);
  --state-failed-text: var(--danger-200);
  --state-cancelled-soft: var(--stone-800);
  --state-cancelled-text: var(--stone-300);
  --state-pending-soft: oklch(0.30 0.06 75);
  --state-pending-text: var(--warning-200);

  --shadow-xs: 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 20px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-overlay: 0 24px 48px rgba(0, 0, 0, 0.6), 0 4px 8px rgba(0, 0, 0, 0.3);
  --shadow-focus: 0 0 0 3px color-mix(in oklch, var(--accent-primary) 35%, transparent);
}

/* =========================================================
   RESET & BASE
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-body-size);
  line-height: var(--text-body-line);
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}
.mono { font-family: var(--font-mono); font-feature-settings: normal; font-size: 12.5px; }
.dim { color: var(--text-muted); }
code { font-family: var(--font-mono); font-size: 0.92em; }
a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

h1 { font-size: var(--text-h1-size); line-height: var(--text-h1-line); letter-spacing: -0.015em; font-weight: 600; margin-bottom: var(--space-4); }
h2 { font-size: var(--text-h2-size); line-height: var(--text-h2-line); letter-spacing: -0.01em; font-weight: 600; margin: var(--space-6) 0 var(--space-3); }
h3 { font-size: var(--text-h3-size); line-height: var(--text-h3-line); font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }

:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-md);
}

/* =========================================================
   APP SHELL — Sidebar / Topbar / Content
   ========================================================= */
.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg-canvas);
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-tinted);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: var(--space-3) 0;
  min-height: 100vh;
}

/* New design-system brand area (icon + company name) */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 14px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: 8px;
}
.brand-mark { width: 26px; height: 26px; flex: none; border-radius: 6px; }
.brand-mark.sm { width: 20px; height: 20px; border-radius: 4px; }

/* Legacy sidebar header (kept for any non-AuthLayout consumer) */
.sidebar-header {
  padding: var(--space-1) var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-2);
}
.sidebar-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.sidebar-foot {
  margin-top: auto;
  padding: 8px 12px;
  border-top: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
  min-width: 0;
}
.user-pill:hover { background: var(--surface-2); text-decoration: none; }
.user-pill-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent-secondary-soft);
  color: var(--accent-secondary-soft-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  flex: none;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* New design-system topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  flex-shrink: 0;
}
.topbar-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  min-width: 0;
  overflow: hidden;
}
.topbar-crumb .active {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sep { color: var(--text-disabled); flex: none; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 4px 8px;
  width: 280px;
}
.topbar-search input {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12.5px;
  color: var(--text-primary);
  flex: 1;
  outline: none;
  min-width: 0;
  padding: 0;
  width: auto;
}
.topbar-search input:focus { box-shadow: none; }
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search kbd {
  border: 1px solid var(--border-default);
  background: var(--surface-1);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-size: 10.5px;
  color: var(--text-muted);
  flex: none;
}

/* Legacy topbar (older layouts, if any remain) */
.top-bar {
  height: var(--topbar-height);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  gap: var(--space-4);
}
.top-bar-left { display: flex; align-items: center; gap: var(--space-2); }
.top-bar-right { display: flex; align-items: center; gap: var(--space-2); }
.company-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }

.content { padding: var(--space-6); flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; }

/* ---------- NAV ---------- */
.nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-1) var(--space-2);
  gap: 1px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-2);
  color: var(--text-secondary);
  font-size: 13px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  text-decoration: none;
}
.nav-section {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-2) var(--space-1);
  font-weight: 600;
}
.nav-disabled {
  color: var(--text-disabled);
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.6;
}
.nav-disabled:hover { background: transparent; color: var(--text-disabled); }

/* =========================================================
   AUTH PAGE SHELL
   ========================================================= */
.auth-page,
.external-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-canvas);
  padding: var(--space-6);
}
.auth-card {
  background: var(--surface-1);
  padding: var(--space-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
}
.auth-card h1 {
  margin: 0 0 var(--space-5);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.auth-link {
  margin-top: var(--space-4);
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-link a { color: var(--text-link); }

/* =========================================================
   FORMS
   ========================================================= */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}
.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
textarea,
select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  width: 100%;
  transition: border-color var(--dur-instant), box-shadow var(--dur-instant);
}
input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="tel"]:hover,
textarea:hover,
select:hover { border-color: var(--border-strong); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}
input:disabled, textarea:disabled, select:disabled {
  background: var(--surface-2);
  color: var(--text-disabled);
  cursor: not-allowed;
}
textarea { resize: vertical; min-height: 64px; font-family: inherit; }
select { cursor: pointer; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.form-row { display: flex; gap: var(--space-2); }
.form-row input, .form-row select { flex: 1; }

.inline-form {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  align-items: center;
}
.inline-form input { flex: 1; }
.inline-form select { flex: 1; min-width: 0; }

.form-error {
  background: var(--state-failed-soft);
  color: var(--state-failed-text);
  border: 1px solid color-mix(in oklch, var(--state-failed) 30%, transparent);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: 13px;
}
.form-success {
  background: var(--state-completed-soft);
  color: var(--state-completed-text);
  border: 1px solid color-mix(in oklch, var(--state-completed) 30%, transparent);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: 13px;
}
.form-info {
  background: var(--state-running-soft);
  color: var(--state-running-text);
  border: 1px solid color-mix(in oklch, var(--state-running) 30%, transparent);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: 13px;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  --btn-bg: var(--surface-1);
  --btn-fg: var(--text-primary);
  --btn-border: var(--border-input);
  --btn-bg-hover: var(--surface-2);
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  height: 32px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  border-radius: var(--radius-md);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-instant) var(--ease-standard),
              color var(--dur-instant) var(--ease-standard),
              border-color var(--dur-instant) var(--ease-standard);
}
.btn:hover { background: var(--btn-bg-hover); text-decoration: none; }
.btn:disabled, .btn[disabled] { cursor: not-allowed; opacity: 0.5; pointer-events: none; }

.btn-primary {
  --btn-bg: var(--accent-primary);
  --btn-fg: var(--text-on-accent);
  --btn-border: var(--accent-primary);
  --btn-bg-hover: var(--accent-primary-hover);
}
.btn-danger {
  --btn-bg: var(--surface-1);
  --btn-fg: var(--state-failed-text);
  --btn-border: color-mix(in oklch, var(--state-failed) 40%, var(--border-input));
  --btn-bg-hover: var(--state-failed-soft);
}
.btn-success {
  --btn-bg: var(--state-completed);
  --btn-fg: var(--text-on-accent);
  --btn-border: var(--state-completed);
  --btn-bg-hover: color-mix(in oklch, var(--state-completed) 80%, black);
}
.btn-outline {
  --btn-bg: transparent;
  --btn-fg: var(--text-primary);
  --btn-border: var(--border-strong);
  --btn-bg-hover: var(--surface-2);
}
.btn-link {
  --btn-bg: transparent;
  --btn-fg: var(--text-secondary);
  --btn-border: transparent;
  --btn-bg-hover: var(--surface-2);
  height: 28px;
  padding: 0 8px;
  font-weight: 500;
}
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  position: relative;
  transition: background var(--dur-instant), color var(--dur-instant);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-primary); }

.btn-block { width: 100%; }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; border-radius: var(--radius-sm); gap: 4px; }
.btn-xs { height: 22px; padding: 0 6px; font-size: 11px; border-radius: var(--radius-sm); }
.btn-group { display: flex; gap: var(--space-2); margin-top: var(--space-4); }

/* =========================================================
   BADGES & STATUS PILLS
   ========================================================= */
.badge, .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 18px;
}

.status-running { background: var(--state-running-soft); color: var(--state-running-text); }
.status-completed { background: var(--state-completed-soft); color: var(--state-completed-text); }
.status-failed { background: var(--state-failed-soft); color: var(--state-failed-text); }
.status-cancelled { background: var(--state-cancelled-soft); color: var(--state-cancelled-text); }
.status-pending { background: var(--state-pending-soft); color: var(--state-pending-text); }

/* =========================================================
   TABLES
   ========================================================= */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-default);
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.actions { display: flex; gap: 6px; align-items: center; }
.event-cell { max-width: 500px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
}
.card h3 {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  font-weight: 600;
}
.card-number {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 32px;
  color: var(--text-primary);
}
.card-link {
  font-size: 12px;
  margin-top: var(--space-2);
  display: inline-block;
  color: var(--text-link);
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

/* =========================================================
   PAGE HEADER
   ========================================================= */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  gap: var(--space-4);
}
.page-header h1 { margin: 0; }

.toolbar {
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.toolbar select { width: auto; min-width: 160px; }

.empty {
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  background: var(--surface-1);
  color: var(--text-muted);
  font-size: 14px;
}

/* =========================================================
   DASHBOARD — design-system layout
   ========================================================= */
.page-title-row { margin-bottom: var(--space-6); }
.page-h1 {
  font-size: 26px;
  line-height: 32px;
  letter-spacing: -0.02em;
  font-weight: 600;
  margin: 0 0 var(--space-1);
}
.page-sub {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.metric {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.metric-label {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
  font-weight: 600;
}
.metric-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 32px;
  color: var(--text-primary);
}
.metric-trend {
  font-size: 11px;
  margin-top: 2px;
  color: var(--text-muted);
}
.metric-trend.positive { color: var(--state-completed-text); }
.metric-trend a, a.metric-trend { color: var(--text-link); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-4);
}
.dashboard-grid .card { padding: 0; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-3);
}
.card-head h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  text-transform: none;
}
.card-body { padding: 16px 18px; flex: 1; }
.card-body.padless { padding: 0; }
.dashboard-grid .card .table { border: none; border-radius: 0; }

.link-mute { color: var(--text-muted); font-size: 12px; text-decoration: none; }
.link-mute:hover { color: var(--text-primary); text-decoration: none; }

.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.task {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "type actions"
    "title actions"
    "meta actions";
  gap: 2px var(--space-3);
  align-items: center;
}
.task-type {
  grid-area: type;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-primary-soft-text);
  font-weight: 600;
}
.task strong { grid-area: title; font-size: 14px; font-weight: 500; color: var(--text-primary); }
.task-meta { grid-area: meta; font-size: 11px; color: var(--text-muted); }
.task-actions { grid-area: actions; display: flex; gap: 6px; }

.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

@media (max-width: 1100px) {
  .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* =========================================================
   ROLES PAGE
   ========================================================= */
.role-card {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.role-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.role-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text-primary);
  text-transform: none;
}
.role-members p,
.role-capabilities p { font-size: 12px; color: var(--text-muted); margin-bottom: var(--space-1); }
.role-members ul { list-style: none; padding: 0; margin: 0; }
.role-members li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 0;
  font-size: 13px;
}
.role-capabilities {
  margin-top: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.capability-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  padding: 2px 0;
  cursor: pointer;
  user-select: none;
}
.capability-toggle input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; }

/* =========================================================
   PARTICIPANTS / INVITES
   ========================================================= */
.invite-link {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-mono);
  word-break: break-all;
  user-select: all;
}
.invite-link-box { margin-bottom: var(--space-4); }

/* =========================================================
   TABS (workflow editor, instance detail, etc.)
   ========================================================= */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0;
  border-bottom: 1px solid var(--border-default);
  margin-bottom: var(--space-5);
}
.tab {
  font-size: 13px;
  padding: 10px 12px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-weight: 500;
}
.tab:hover { color: var(--text-primary); text-decoration: none; }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent-primary); }
.tab.disabled { color: var(--text-disabled); cursor: not-allowed; pointer-events: none; }
.tab-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
}

/* =========================================================
   WORKFLOW EDITOR — editor-grid layout
   ========================================================= */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--space-4);
  align-items: start;
}
.editor-pane { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.editor-side { display: flex; flex-direction: column; gap: var(--space-3); }
.editor-card {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.editor-actions { justify-content: flex-end; margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); }

@media (max-width: 1100px) {
  .editor-grid { grid-template-columns: 1fr; }
}

.editor-toggle { margin-bottom: var(--space-4); }
.editor-toggle label {
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
}

.editor-section {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  background: var(--surface-1);
}
.editor-section legend {
  font-weight: 600;
  font-size: 13px;
  padding: 0 var(--space-2);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.node-card {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-left: 4px solid var(--node-form);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: border-color var(--dur-instant);
}
.node-card:hover { border-color: var(--border-strong); border-left-color: var(--node-form); }
.node-card.node-form { border-left-color: var(--node-form); }
.node-card.node-form:hover { border-left-color: var(--node-form); }
.node-card.node-approval { border-left-color: var(--node-approval); }
.node-card.node-approval:hover { border-left-color: var(--node-approval); }
.node-card.node-assignment { border-left-color: var(--node-assignment); }
.node-card.node-assignment:hover { border-left-color: var(--node-assignment); }
.node-card.node-emailer { border-left-color: var(--node-emailer); }
.node-card.node-emailer:hover { border-left-color: var(--node-emailer); }
.node-card.node-notification { border-left-color: var(--node-notification); }
.node-card.node-notification:hover { border-left-color: var(--node-notification); }
.node-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.node-index {
  background: var(--accent-primary);
  color: var(--text-on-accent);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  font-family: var(--font-mono);
}
.node-name {
  flex: 1;
  min-width: 140px;
}
.node-actions { display: flex; gap: 4px; }
.node-fields {
  padding-left: var(--space-3);
  border-left: 2px solid var(--border-subtle);
  margin: var(--space-2) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.node-permissions { margin-top: var(--space-2); font-size: 13px; }
.node-permissions summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 0;
  user-select: none;
}
.node-permissions summary:hover { color: var(--text-primary); }

.form-field-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-1);
  flex-wrap: wrap;
}
.form-field-row input[type="text"] { flex: 1; min-width: 80px; }
.form-field-row select { min-width: 100px; width: auto; }

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}
.checkbox-label input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; }

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: help;
  margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
  line-height: 1;
}
.help-tip:hover { color: var(--text-primary); border-color: var(--text-primary); }

.role-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-1) 0;
}
.role-select { min-width: 150px; width: auto; }
.target-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.target-fields select { width: 100%; }

/* =========================================================
   NOTIFICATION BELL
   ========================================================= */
.notification-bell { position: relative; }
.notification-bell .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--state-failed);
  color: var(--text-on-accent);
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  border-radius: 8px;
  padding: 0 4px;
  border: 1px solid var(--surface-1);
}
.notification-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  width: 320px;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: var(--shadow-overlay);
  z-index: 100;
}
.notification-dropdown ul { list-style: none; margin: 0; padding: 0; }
.notification-dropdown li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  gap: var(--space-2);
}
.notification-dropdown li:last-child { border-bottom: none; }
.notification-dropdown .empty {
  border: none;
  padding: var(--space-4);
  text-align: center;
  color: var(--text-muted);
}

/* =========================================================
   TOASTS
   ========================================================= */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 420px;
}
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  animation: toast-in 0.2s var(--ease-standard);
}
.toast-success { border-left-color: var(--state-completed); }
.toast-error { border-left-color: var(--state-failed); color: var(--state-failed-text); }
.toast-dismiss {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}
.toast-dismiss:hover { color: var(--text-primary); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   INSTANCE / TASK DETAIL VIEWS
   ========================================================= */
.instance-header {
  margin-bottom: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.instance-header p { font-size: 13px; color: var(--text-secondary); }
.instance-header strong { color: var(--text-primary); margin-right: var(--space-1); }

.approval-view, .assignment-view {
  max-width: 540px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.attempt-info {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: var(--space-3);
}

/* =========================================================
   COMPANY LIST (select-company)
   ========================================================= */
.company-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

/* =========================================================
   JSON EDITOR
   ========================================================= */
.json-editor {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  min-height: 360px;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 740px) {
  .sidebar { width: 180px; }
  .content { padding: var(--space-4); }
  .card-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
}
