```
---
## When to Use Scoped CSS
### ✅ Scoped CSS is OK For:
#### 1. **Component-Specific Layout (Not Reusable)**
```vue
```
**Why it's OK:** This layout is unique to this specific dual-chart component and won't be used elsewhere.
#### 2. **Third-Party Library Integration (Chart.js, etc.)**
```vue
```
**Why it's OK:** Chart.js has specific requirements that are component-specific and not reusable patterns.
#### 3. **Complex Component State Styling**
```vue
```
**Why it's OK:** This state machine is unique to this visualization component.
#### 4. **Print Styles (Component-Specific)**
```vue
```
**Why it's OK:** Print styles for specific components that have unique printing requirements.
---
## Anti-Patterns
### ❌ NEVER Do These Things
#### 1. **Using `:deep()` for PrimeVue**
```vue
```
**Why it's bad:**
- Creates specificity issues
- Overrides break easily
- Not maintainable
- Causes cascading problems
**✅ Correct approach:**
All PrimeVue styling goes in `src/assets/css/vendor/primevue-overrides.css`:
```css
/* vendor/primevue-overrides.css */
.p-inputtext {
border: 2px solid var(--color-primary);
padding: 1rem;
}
.p-datatable .p-datatable-thead {
background: var(--color-bg-secondary);
}
```
#### 2. **Hardcoding Colors/Sizes**
```vue
```
#### 3. **Duplicating Existing Patterns**
```vue
```
#### 4. **Using `!important` in Scoped Styles**
```vue
```
**Exception:** `!important` is allowed in:
- `vendor/primevue-overrides.css` (to override PrimeVue)
- Print styles (`@media print`)
- Third-party library overrides (documented reason required)
#### 5. **Creating Custom Form/Button Base Styles**
```vue
```
---
## Code Review Checklist
### Before Submitting PR
- [ ] **No duplicate patterns** - Checked `docs/CSS_PATTERNS.md` first
- [ ] **No `:deep()` in components** - PrimeVue styles in `vendor/primevue-overrides.css`
- [ ] **Design tokens used** - No hardcoded colors, sizes, or spacing
- [ ] **No `!important` in scoped styles** - Except documented exceptions
- [ ] **Scoped styles < 50 lines** - If more, consider extracting to global
- [ ] **No form/button/card base styles** - Use existing global patterns
- [ ] **Responsive tested** - Works on mobile (375px), tablet (768px), desktop (1920px)
- [ ] **Build successful** - `npm run build` passes
- [ ] **Playwright tests pass** - `npm run test:e2e` passes
- [ ] **CSS is necessary** - Not adding CSS just because "it looks different"
### Review Questions
**For Scoped CSS:**
1. Is this styling truly unique to this component?
2. Could this be used in 2+ places? → Make it global
3. Can this use existing patterns? → Use global CSS
4. Is this < 50 lines? → If not, extract to global
5. Does it have a documented reason? → Add comment
**For Global CSS:**
1. Is this pattern used in 2+ places?
2. Will this be reused in the future?
3. Does it fit existing pattern categories?
4. Is it generic enough for reuse?
---
## Examples
### ✅ Example #1: Good Use of Global CSS
```vue
Sales
$10,500
+12.5%
```
**Why it's good:**
- Zero duplicate CSS
- Uses established patterns
- Maintainable
- Consistent with other cards
---
### ✅ Example #2: Good Use of Scoped CSS
```vue
Treasury
Bank{{ bankBalance }}
Cash{{ cashBalance }}
```
**Why it's good:**
- Unique layout specific to this component
- Uses design tokens
- Chart.js integration requires specific CSS
- Responsive
- Well-commented
---
### ❌ Example #3: Bad - Duplicate Pattern
```vue
Clients Balance
$50,000
Clients Balance
$50,000
```
---
## Best Practices
### 1. **Check Pattern Library First**
Before writing ANY CSS, check:
1. [CSS Patterns Library](./CSS_PATTERNS.md)
2. `src/assets/css/` directories
3. Ask yourself: "Has this been done before?"
### 2. **Use Design Tokens**
```vue
```
### 3. **Keep Scoped CSS Minimal**
**Rule of thumb:** If scoped styles > 50 lines, extract to global pattern.
```vue
```
### 4. **Document Scoped CSS Rationale**
```vue
```
### 5. **Responsive Design**
Use global responsive patterns when possible:
```vue