/* ============================================
 * CHURCH DESIGN SYSTEM
 * ============================================
 * The sacred writing space - completely isolated from app CSS.
 * 
 * ARCHITECTURE PRINCIPLES:
 * 1. All selectors scoped under .church root
 * 2. All variables prefixed with --c- (church)
 * 3. Theme switching via data-church-theme attribute
 * 4. No generic class names - all use church__ prefix
 * 5. Zero !important - specificity through nesting
 * 6. External CSS cannot penetrate this boundary
 *
 * USAGE:
 * <div class="church" data-church-theme="dark">
 *   <div class="church__panel church__panel--guide">...</div>
 *   <div class="church__editor">...</div>
 *   <div class="church__panel church__panel--preview">...</div>
 * </div>
 */

/* ============================================
   LAYER DECLARATION - Isolates from global CSS
   ============================================ */
@layer church-reset, church-tokens, church-components;

/* ============================================
   RESET LAYER - Neutralize inherited styles
   ============================================ 
   This layer prevents legacy CSS (editor-themes.css, 
   church-theme.css, WritingWorkspace.css, etc.) from 
   bleeding into the Church.
   ============================================ */
@layer church-reset {
  /* Universal reset within church scope */
  .church,
  .church *,
  .church *::before,
  .church *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  /* Form elements inherit church typography */
  .church button,
  .church input,
  .church select,
  .church textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
  }
  
  /* ----------------------------------------
     DEFENSIVE OVERRIDES
     Block legacy .writing-workspace styles from 
     affecting church__* elements
     ---------------------------------------- */
  
  /* Reset all legacy editor variables to prevent inheritance */
  .church [class*="church__"] {
    --editor-bg: unset;
    --editor-bg-subtle: unset;
    --editor-text: unset;
    --editor-text-dim: unset;
    --editor-text-faint: unset;
    --editor-selection: unset;
    --editor-cursor: unset;
    --editor-line-highlight: unset;
    --editor-border: unset;
    --editor-font-family: unset;
    --editor-font-size: unset;
    --editor-line-height: unset;
    --editor-letter-spacing: unset;
    --editor-max-width: unset;
    --editor-paragraph-spacing: unset;
  }
  
  /* Reset legacy panel classes that might leak in */
  .church .preview-panel,
  .church .guide-panel,
  .church .preview-section,
  .church .guide-section {
    all: unset;
    display: block;
  }
  
  /* Block legacy button styles */
  .church .modal-btn,
  .church .icon-btn,
  .church .sidebar-btn {
    all: unset;
    cursor: pointer;
  }
  
  /* Block legacy status/badge styles */
  .church .validation-status,
  .church .storage-status,
  .church .premise-confidence {
    all: unset;
    display: inline-flex;
  }
  
  /* Block legacy input styles */
  .church .chat-input,
  .church .inbox-textarea,
  .church .inbox-category-select {
    all: unset;
  }
  
  /* Block legacy message styles */
  .church .chat-message,
  .church .chat-bubble,
  .church .chat-empty {
    all: unset;
    display: block;
  }
  
  /* Block legacy framework/element list styles */
  .church .framework-item,
  .church .element-item,
  .church .health-item,
  .church .sidebar-item {
    all: unset;
    display: flex;
  }
  
  /* Block legacy tab styles */
  .church .preview-tab,
  .church .guide-tab {
    all: unset;
    cursor: pointer;
  }
  
  /* Block legacy header styles */
  .church .preview-header,
  .church .guide-header,
  .church .inbox-header {
    all: unset;
    display: flex;
  }
  
  /* ----------------------------------------
     ANCHOR SPECIFICITY
     Ensure church classes win over legacy selectors
     ---------------------------------------- */
  .church.writing-workspace [class*="church__"],
  .writing-workspace.church [class*="church__"] {
    /* Church classes always use church tokens */
    background: var(--c-bg-muted, initial);
    color: var(--c-text-primary, inherit);
    border-color: var(--c-border-default, currentColor);
  }
}

/* ============================================
   TOKEN LAYER - Design System Variables
   ============================================ */
@layer church-tokens {
  /* ----------------------------------------
     DARK THEME (Default)
     ---------------------------------------- */
  .church,
  .church[data-church-theme="dark"] {
    /* === PRIMITIVE TOKENS === */
    /* These are raw values - never use directly in components */
    --c-raw-white: #ffffff;
    --c-raw-black: #000000;
    
    /* Slate scale (dark mode base) */
    --c-raw-slate-50: #f8fafc;
    --c-raw-slate-100: #f1f5f9;
    --c-raw-slate-200: #e2e8f0;
    --c-raw-slate-300: #cbd5e1;
    --c-raw-slate-400: #94a3b8;
    --c-raw-slate-500: #64748b;
    --c-raw-slate-600: #475569;
    --c-raw-slate-700: #334155;
    --c-raw-slate-800: #1e293b;
    --c-raw-slate-900: #0f172a;
    --c-raw-slate-950: #020617;
    
    /* Blue accent */
    --c-raw-blue-400: #60a5fa;
    --c-raw-blue-500: #3b82f6;
    --c-raw-blue-600: #2563eb;
    
    /* Status colors */
    --c-raw-green-500: #22c55e;
    --c-raw-green-600: #16a34a;
    --c-raw-amber-500: #f59e0b;
    --c-raw-red-500: #ef4444;
    --c-raw-red-600: #dc2626;
    
    /* === SEMANTIC TOKENS === */
    /* Use these in components */
    
    /* Backgrounds */
    --c-bg-base: var(--c-raw-slate-800);
    --c-bg-subtle: var(--c-raw-slate-900);
    --c-bg-muted: var(--c-raw-slate-700);
    --c-bg-elevated: var(--c-raw-slate-700);
    --c-bg-surface: var(--c-raw-slate-800);
    --c-bg-overlay: rgba(0, 0, 0, 0.6);
    
    /* Text */
    --c-text-primary: var(--c-raw-slate-50);
    --c-text-secondary: var(--c-raw-slate-300);
    --c-text-muted: var(--c-raw-slate-400);
    --c-text-inverse: var(--c-raw-slate-900);
    
    /* Borders */
    --c-border-default: var(--c-raw-slate-600);
    --c-border-muted: var(--c-raw-slate-700);
    --c-border-strong: var(--c-raw-slate-500);
    --c-border-focus: var(--c-raw-blue-500);
    
    /* Interactive */
    --c-accent-primary: var(--c-raw-blue-500);
    --c-accent-primary-hover: var(--c-raw-blue-400);
    --c-accent-secondary: var(--c-raw-slate-600);
    
    /* Status */
    --c-status-success: var(--c-raw-green-500);
    --c-status-success-bg: rgba(34, 197, 94, 0.1);
    --c-status-success-border: rgba(34, 197, 94, 0.3);
    --c-status-warning: var(--c-raw-amber-500);
    --c-status-warning-bg: rgba(245, 158, 11, 0.1);
    --c-status-warning-border: rgba(245, 158, 11, 0.3);
    --c-status-error: var(--c-raw-red-500);
    --c-status-error-bg: rgba(239, 68, 68, 0.1);
    --c-status-error-border: rgba(239, 68, 68, 0.3);
    
    /* Shadows - Light source: top-left (11 o'clock)
       Each shadow has: offset-x, offset-y, blur, spread, color
       Layered shadows create depth perception */
    --c-shadow-sm: 
      0 1px 2px rgba(0, 0, 0, 0.12),
      0 1px 1px rgba(0, 0, 0, 0.08);
    --c-shadow-md: 
      0 2px 4px rgba(0, 0, 0, 0.12),
      0 4px 8px rgba(0, 0, 0, 0.12),
      0 1px 2px rgba(0, 0, 0, 0.08);
    --c-shadow-lg: 
      0 4px 8px rgba(0, 0, 0, 0.1),
      0 8px 16px rgba(0, 0, 0, 0.1),
      0 16px 32px rgba(0, 0, 0, 0.15);
    --c-shadow-xl:
      0 8px 16px rgba(0, 0, 0, 0.08),
      0 16px 32px rgba(0, 0, 0, 0.08),
      0 32px 64px rgba(0, 0, 0, 0.12);
    
    /* Inner shadow for inset elements (inputs, etc.) */
    --c-shadow-inset: inset 0 1px 2px rgba(0, 0, 0, 0.15);
    
    /* Glow for focus states - uses accent color */
    --c-glow-focus: 0 0 0 3px rgba(59, 130, 246, 0.25);
    
    /* Spacing - Based on Golden Ratio (φ = 1.618) 
       Base unit: 8px. Scale: 8 × φ^n */
    --c-space-xs: 4px;                    /* 8 ÷ 2 */
    --c-space-sm: 8px;                    /* base */
    --c-space-md: 13px;                   /* 8 × 1.618 ≈ 13 */
    --c-space-lg: 21px;                   /* 13 × 1.618 ≈ 21 */
    --c-space-xl: 34px;                   /* 21 × 1.618 ≈ 34 (Fibonacci) */
    --c-space-2xl: 55px;                  /* 34 × 1.618 ≈ 55 (Fibonacci) */
    
    /* Typography - Major Third scale (1.25) for harmonic progression
       Base: 14px. Each step: × 1.25 */
    --c-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 
                   "Helvetica Neue", Arial, sans-serif;
    --c-font-mono: "SF Mono", Monaco, "Cascadia Code", Menlo, monospace;
    --c-font-size-xs: 11px;               /* 14 ÷ 1.25 */
    --c-font-size-sm: 12px;               /* 14 ÷ 1.16 (minor step) */
    --c-font-size-base: 14px;             /* base */
    --c-font-size-lg: 17px;               /* 14 × 1.25 ≈ 17 (rounded for pixels) */
    --c-font-size-xl: 21px;               /* 17 × 1.25 ≈ 21 */
    --c-font-size-2xl: 26px;              /* 21 × 1.25 ≈ 26 */
    --c-line-height: 1.618;               /* Golden ratio for body text */
    --c-line-height-tight: 1.25;          /* For headings */
    --c-line-height-loose: 1.8;           /* For reading */
    
    /* Letter spacing - Optical adjustments */
    --c-tracking-tight: -0.02em;          /* Large text needs tighter tracking */
    --c-tracking-normal: 0;
    --c-tracking-wide: 0.04em;            /* Small caps, labels */
    
    /* Radii - Subtle curve, not circles. Based on 1.5× scale */
    --c-radius-sm: 4px;
    --c-radius-md: 6px;
    --c-radius-lg: 9px;                   /* 6 × 1.5 */
    --c-radius-xl: 13px;                  /* 9 × 1.5 ≈ 13 */
    --c-radius-2xl: 20px;                 /* For cards, modals */
    
    /* Transitions - Apple-style cubic-bezier curves
       These mimic natural motion with slight overshoot */
    --c-ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);      /* Decelerate */
    --c-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);         /* Symmetric */
    --c-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);      /* Slight bounce */
    --c-ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);           /* Material-style */
    
    --c-transition-fast: 0.1s var(--c-ease-out);
    --c-transition-base: 0.18s var(--c-ease-out);            /* 180ms is perceptual sweet spot */
    --c-transition-slow: 0.3s var(--c-ease-in-out);
    --c-transition-spring: 0.4s var(--c-ease-spring);
  }
  
  /* ----------------------------------------
     LIGHT THEME (Day Mode)
     ---------------------------------------- */
  .church[data-church-theme="light"] {
    /* Backgrounds */
    --c-bg-base: var(--c-raw-white);
    --c-bg-subtle: var(--c-raw-slate-50);
    --c-bg-muted: var(--c-raw-slate-100);
    --c-bg-elevated: var(--c-raw-white);
    --c-bg-surface: var(--c-raw-slate-50);
    --c-bg-overlay: rgba(0, 0, 0, 0.4);
    
    /* Text */
    --c-text-primary: var(--c-raw-slate-900);
    --c-text-secondary: var(--c-raw-slate-600);
    --c-text-muted: var(--c-raw-slate-400);
    --c-text-inverse: var(--c-raw-white);
    
    /* Borders */
    --c-border-default: var(--c-raw-slate-200);
    --c-border-muted: var(--c-raw-slate-100);
    --c-border-strong: var(--c-raw-slate-300);
    
    /* Shadows - lighter */
    --c-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --c-shadow-md: 0 4px 8px rgba(0, 0, 0, 0.08);
    --c-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  }
  
  /* ----------------------------------------
     PAPER THEME (Warm Writing Mode)
     ---------------------------------------- */
  .church[data-church-theme="paper"] {
    /* Warm cream palette */
    --c-raw-cream-50: #fdfdf9;
    --c-raw-cream-100: #f8f7f3;
    --c-raw-cream-200: #f0efe8;
    --c-raw-cream-300: #e6e4dc;
    --c-raw-cream-400: #d4d1c8;
    --c-raw-cream-500: #8a857d;
    --c-raw-cream-600: #5a5650;
    --c-raw-cream-700: #2d2a24;
    --c-raw-brown-500: #8b7355;
    --c-raw-brown-600: #75614a;
    
    /* Backgrounds */
    --c-bg-base: var(--c-raw-cream-50);
    --c-bg-subtle: var(--c-raw-cream-100);
    --c-bg-muted: var(--c-raw-cream-200);
    --c-bg-elevated: var(--c-raw-white);
    --c-bg-surface: var(--c-raw-cream-100);
    --c-bg-overlay: rgba(45, 42, 36, 0.4);
    
    /* Text */
    --c-text-primary: var(--c-raw-cream-700);
    --c-text-secondary: var(--c-raw-cream-600);
    --c-text-muted: var(--c-raw-cream-500);
    --c-text-inverse: var(--c-raw-cream-50);
    
    /* Borders */
    --c-border-default: var(--c-raw-cream-300);
    --c-border-muted: var(--c-raw-cream-200);
    --c-border-strong: var(--c-raw-cream-400);
    --c-border-focus: #c4a57b;
    
    /* Accent - warm brown */
    --c-accent-primary: var(--c-raw-brown-500);
    --c-accent-primary-hover: var(--c-raw-brown-600);
    
    /* Status - muted versions */
    --c-status-success: #6b8e4e;
    --c-status-warning: #d4a574;
    --c-status-error: #b85c50;
    
    /* Shadows - warm tint */
    --c-shadow-sm: 0 1px 2px rgba(45, 42, 36, 0.08);
    --c-shadow-md: 0 4px 8px rgba(45, 42, 36, 0.12);
    --c-shadow-lg: 0 8px 24px rgba(45, 42, 36, 0.16);
  }
}

/* ============================================
   COMPONENT LAYER - All UI Components
   ============================================ */
@layer church-components {
  /* ----------------------------------------
     BASE STYLES
     ---------------------------------------- */
  .church {
    /* Isolation - prevents CSS leakage in both directions */
    isolation: isolate;
    contain: layout style;

    /* Base styles */
    background: var(--c-bg-base);
    color: var(--c-text-primary);
    font-family: var(--c-font-sans);
    font-size: var(--c-font-size-base);
    line-height: var(--c-line-height);

    /* Text rendering - Premium typography */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1, "liga" 1;  /* Kerning and ligatures */

    /* Prevent text size adjustment on orientation change (iOS/Android) */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;

    /* Selection color - matches theme */
    --selection-bg: rgba(59, 130, 246, 0.25);
    --selection-color: inherit;

    /* Fill container */
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;

    /* Smooth color transitions when theme changes */
    transition: background-color 0.3s var(--c-ease-smooth),
                color 0.3s var(--c-ease-smooth);
  }

  /* Selection styling */
  .church ::selection {
    background: var(--selection-bg);
    color: var(--selection-color);
  }

  /* Focus-visible: Only show focus rings for keyboard navigation */
  .church :focus {
    outline: none;
  }

  .church :focus-visible {
    outline: none;
    box-shadow: var(--c-glow-focus);
  }

  /* Reduced motion preference */
  @media (prefers-reduced-motion: reduce) {
    .church,
    .church * {
      transition-duration: 0.01ms !important;
      animation-duration: 0.01ms !important;
    }
  }

  /* ----------------------------------------
     LAYOUT STRUCTURE
     ---------------------------------------- */
  .church__body {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
  }
  
  .church__main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
  }
  
  /* ----------------------------------------
     HEADER
     ---------------------------------------- */
  .church__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--c-space-md);
    background: var(--c-bg-subtle);
    border-bottom: 1px solid var(--c-border-default);
    gap: var(--c-space-md);
    flex-shrink: 0;
  }
  
  .church__header-group {
    display: flex;
    align-items: center;
    gap: var(--c-space-sm);
  }
  
  /* ----------------------------------------
     PANELS (Guide & Preview)
     ---------------------------------------- */
  .church__panel {
    display: flex;
    flex-direction: column;
    background: var(--c-bg-subtle);
    overflow: hidden;
    flex-shrink: 0;
  }
  
  .church__panel--guide {
    width: 240px;
    min-width: 240px;
    border-right: 1px solid var(--c-border-default);
  }
  
  .church__panel--preview {
    width: 280px;
    min-width: 280px;
    border-left: 1px solid var(--c-border-default);
  }
  
  .church__panel--collapsed {
    width: 40px;
    min-width: 40px;
    align-items: center;
    justify-content: flex-start;
    padding-top: var(--c-space-md);
    cursor: pointer;
    transition: all var(--c-transition-base);
  }
  
  .church__panel--collapsed:hover {
    background: var(--c-bg-muted);
    width: 48px;
  }
  
  /* Panel Header */
  .church__panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--c-space-sm) var(--c-space-md);
    border-bottom: 1px solid var(--c-border-default);
    flex-shrink: 0;
  }
  
  .church__panel-title {
    font-size: var(--c-font-size-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--c-text-secondary);
    margin: 0;
  }
  
  /* Panel Tabs */
  .church__panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--c-border-muted);
    flex-shrink: 0;
  }
  
  .church__panel-tab {
    flex: 1;
    padding: var(--c-space-xs) var(--c-space-sm);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--c-text-secondary);
    font-size: var(--c-font-size-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--c-transition-fast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .church__panel-tab:hover {
    background: var(--c-bg-muted);
  }
  
  .church__panel-tab--active {
    background: var(--c-bg-muted);
    color: var(--c-text-primary);
    border-bottom-color: var(--c-accent-primary);
  }
  
  /* Panel Content */
  .church__panel-content {
    flex: 1;
    padding: var(--c-space-sm) var(--c-space-md);
    overflow-y: auto;
  }
  
  /* Editor Container - Subtle text area boundary */
  .church__editor-container {
    position: relative;
    background: var(--c-bg-elevated);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-lg);
    box-shadow: var(--c-shadow-sm);
    transition: all var(--c-transition-base);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  .church__editor-container:hover {
    border-color: var(--c-border-strong);
    box-shadow: var(--c-shadow-md);
  }
  
  .church__editor-container:focus-within {
    border-color: var(--c-accent-primary);
    box-shadow: var(--c-glow-focus);
  }
  
  /* Editor textarea - inherits container styling */
  .church__editor {
    width: 100%;
    min-height: 400px;
    padding: var(--c-space-lg);
    background: transparent;
    border: none;
    border-radius: var(--c-radius-lg);
    color: var(--c-text-primary);
    font-family: var(--c-font-family-serif);
    font-size: var(--c-font-size-lg);
    line-height: var(--c-line-height-loose);
    resize: vertical;
    outline: none;
    flex: 1;
  }
  
  .church__editor::placeholder {
    color: var(--c-text-muted);
    font-style: italic;
  }
  
  /* Page indicator for multi-page content */
  .church__page-indicator {
    position: absolute;
    top: var(--c-space-xs);
    right: var(--c-space-xs);
    display: flex;
    align-items: center;
    gap: var(--c-space-xs);
    padding: 4px var(--c-space-xs);
    background: var(--c-bg-elevated);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-md);
    font-size: var(--c-font-size-xs);
    color: var(--c-text-secondary);
    opacity: 0.8;
    transition: opacity var(--c-transition-fast);
  }
  
  .church__page-indicator:hover {
    opacity: 1;
  }
  
  .church__page-selector {
    background: transparent;
    border: none;
    color: var(--c-accent-primary);
    font-weight: 600;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 2px;
  }
  
  .church__page-selector:hover {
    background: var(--c-bg-muted);
  }
  
  .church__editor::selection {
    background: rgba(59, 130, 246, 0.25);
  }
  
  /* Paper theme selection */
  .church[data-church-theme="paper"] .church__editor::selection {
    background: rgba(196, 165, 123, 0.25);
  }
  
  /* ----------------------------------------
     STATUS BAR
     ---------------------------------------- */
  .church__status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--c-space-xs) var(--c-space-md);
    background: var(--c-bg-subtle);
    border-top: 1px solid var(--c-border-default);
    font-size: var(--c-font-size-xs);
    color: var(--c-text-secondary);
    flex-shrink: 0;
  }
  
  .church__status-group {
    display: flex;
    align-items: center;
    gap: var(--c-space-md);
  }
  
  .church__status-item {
    display: flex;
    align-items: center;
    gap: var(--c-space-xs);
  }
  
  /* ----------------------------------------
     BUTTONS - Apple-inspired refinement
     - Glassmorphism effects
     - Subtle blur and transparency
     - Smooth state transitions
     - Dynamic status indicators
     ---------------------------------------- */
  .church__btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.08);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: var(--c-text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    
    /* Smooth, Apple-like transitions */
    transition: 
      all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94),
      transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
    
    /* GPU acceleration for smooth transforms */
    will-change: transform, background;
    
    /* Prevent double-tap zoom on mobile */
    touch-action: manipulation;
    
    /* Minimum touch target */
    min-height: 32px;
    min-width: 32px;
  }
  
  .church__btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  .church__btn:focus-visible {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--c-accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
  }
  
  .church__btn:active:not(:disabled) {
    transform: scale(0.96) translateY(0);
    background: rgba(255, 255, 255, 0.18);
    transition-duration: 0.1s;
  }
  
  .church__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.05);
  }
  
  /* Primary buttons - system blue style */
  .church__btn--primary {
    background: rgba(59, 130, 246, 0.9);
    color: white;
    border-color: rgba(59, 130, 246, 0.8);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  
  .church__btn--primary:hover:not(:disabled) {
    background: rgba(59, 130, 246, 1);
    border-color: rgba(59, 130, 246, 1);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
  }
  
  .church__btn--primary:active:not(:disabled) {
    background: rgba(37, 99, 235, 1);
  }
  
  /* Ghost buttons - minimal visibility */
  .church__btn--ghost {
    background: transparent;
    border-color: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  
  .church__btn--ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.06);
    transform: none;
  }
  
  /* Icon buttons - circular, refined */
  .church__btn--icon {
    padding: 6px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 8px;
    position: relative;
  }
  
  .church__btn--icon.church__btn--ghost {
    border-radius: 8px;
  }
  
  /* ----------------------------------------
     DYNAMIC STATUS STATES
     For buttons that change based on content/load
     ---------------------------------------- */
  
  /* Warning state - when content exceeds limits */
  .church__btn--warning {
    background: rgba(251, 191, 36, 0.15);
    border-color: rgba(251, 191, 36, 0.3);
    color: #fbbf24;
    animation: pulse-warning 2s infinite;
  }
  
  .church__btn--warning:hover:not(:disabled) {
    background: rgba(251, 191, 36, 0.25);
    border-color: rgba(251, 191, 36, 0.5);
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.2);
  }
  
  /* Error state - when critical issues exist */
  .church__btn--error {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
    animation: pulse-error 1.5s infinite;
  }
  
  .church__btn--error:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
  }
  
  /* Success state - when everything is good */
  .church__btn--success {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.3);
    color: #22c55e;
  }
  
  .church__btn--success:hover:not(:disabled) {
    background: rgba(34, 197, 94, 0.25);
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
  }
  
  /* Loading state - spinner animation */
  .church__btn--loading {
    position: relative;
    color: transparent;
    pointer-events: none;
  }
  
  .church__btn--loading::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
    top: 50%;
    left: 50%;
    margin-left: -7px;
    margin-top: -7px;
  }
  
  /* Badge indicator - for counts/notifications */
  .church__btn-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--c-accent-primary);
    color: white;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }
  
  /* ----------------------------------------
     ANIMATIONS
     ---------------------------------------- */
  @keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
  }
  
  @keyframes pulse-error {
    0%, 100% { 
      opacity: 1; 
      transform: scale(1);
    }
    50% { 
      opacity: 0.8; 
      transform: scale(1.05);
    }
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  /* ----------------------------------------
     INPUTS
     ---------------------------------------- */
  .church__input,
  .church__textarea,
  .church__select {
    appearance: none;
    width: 100%;
    padding: var(--c-space-sm) var(--c-space-md);
    background: var(--c-bg-base);
    color: var(--c-text-primary);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-md);
    font-size: var(--c-font-size-base);
    transition: all var(--c-transition-base);
  }
  
  .church__input:focus,
  .church__textarea:focus,
  .church__select:focus {
    border-color: var(--c-border-focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  }
  
  .church[data-church-theme="paper"] .church__input:focus,
  .church[data-church-theme="paper"] .church__textarea:focus,
  .church[data-church-theme="paper"] .church__select:focus {
    box-shadow: 0 0 0 3px rgba(196, 165, 123, 0.2);
  }
  
  .church__input::placeholder,
  .church__textarea::placeholder {
    color: var(--c-text-muted);
  }
  
  /* Compact select for toolbars */
  .church__select {
    appearance: none;
    padding: var(--c-space-xs) var(--c-space-sm);
    padding-right: calc(var(--c-space-sm) + 12px);
    background: var(--c-bg-muted);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--c-space-xs) center;
    color: var(--c-text-primary);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-md);
    font-size: var(--c-font-size-sm);
    cursor: pointer;
    transition: all var(--c-transition-base);
  }
  
  .church__select:hover:not(:disabled) {
    background-color: var(--c-bg-elevated);
    border-color: var(--c-border-strong);
  }
  
  .church__select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  
  /* Textarea */
  .church__textarea {
    appearance: none;
    padding: var(--c-space-sm);
    background: var(--c-bg-muted);
    color: var(--c-text-primary);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-md);
    font-size: var(--c-font-size-sm);
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    transition: all var(--c-transition-base);
  }
  
  .church__textarea:focus {
    border-color: var(--c-border-focus);
    background: var(--c-bg-base);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  }
  
  /* ----------------------------------------
     CARDS
     ---------------------------------------- */
  .church__card {
    background: var(--c-bg-muted);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-lg);
    padding: var(--c-space-md);
  }
  
  .church__card--elevated {
    background: var(--c-bg-elevated);
    box-shadow: var(--c-shadow-md);
  }
  
  .church__card--highlight {
    border-left: 3px solid var(--c-accent-primary);
  }
  
  /* ----------------------------------------
     CHAT COMPONENTS
     ---------------------------------------- */
  .church__chat {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  
  .church__chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--c-space-sm);
    padding: var(--c-space-sm) 0;
  }
  
  .church__chat-empty {
    padding: var(--c-space-md);
    background: var(--c-bg-muted);
    border-radius: var(--c-radius-xl);
    border-left: 3px solid var(--c-accent-primary);
  }
  
  .church__chat-empty p {
    margin: var(--c-space-xs) 0;
    font-size: var(--c-font-size-sm);
  }
  
  .church__chat-hint {
    font-size: var(--c-font-size-sm);
    color: var(--c-text-muted);
    font-style: italic;
  }
  
  .church__chat-message {
    display: flex;
    flex-direction: column;
    gap: var(--c-space-xs);
    max-width: 85%;
  }
  
  .church__chat-message--user {
    align-self: flex-end;
  }
  
  .church__chat-message--assistant {
    align-self: flex-start;
  }
  
  .church__chat-bubble {
    padding: var(--c-space-md);
    border-radius: var(--c-radius-xl);
    font-size: var(--c-font-size-base);
    line-height: var(--c-line-height);
  }
  
  .church__chat-message--user .church__chat-bubble {
    background: var(--c-bg-muted);
    color: var(--c-text-primary);
    border-bottom-right-radius: var(--c-radius-sm);
  }
  
  .church__chat-message--assistant .church__chat-bubble {
    background: var(--c-bg-subtle);
    border: 1px solid var(--c-border-muted);
    color: var(--c-text-primary);
    border-bottom-left-radius: var(--c-radius-sm);
  }
  
  .church__chat-time {
    font-size: var(--c-font-size-xs);
    color: var(--c-text-muted);
    padding: 0 var(--c-space-xs);
  }
  
  .church__chat-message--user .church__chat-time {
    text-align: right;
  }
  
  .church__chat-input-area {
    padding: var(--c-space-lg);
    border-top: 1px solid var(--c-border-default);
    background: var(--c-bg-subtle);
  }
  
  .church__chat-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--c-space-sm);
  }
  
  .church__chat-input {
    padding: var(--c-space-sm) var(--c-space-md);
    background: var(--c-bg-muted);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-xl);
    color: var(--c-text-primary);
    font-size: var(--c-font-size-base);
    resize: vertical;
    min-height: 72px;
    transition: all var(--c-transition-base);
  }
  
  .church__chat-input:focus {
    border-color: var(--c-border-focus);
    background: var(--c-bg-base);
  }
  
  .church__chat-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--c-space-sm);
  }
  
  /* ----------------------------------------
     STATS/METRICS
     ---------------------------------------- */
  .church__stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--c-space-sm);
  }
  
  .church__stat-card {
    background: var(--c-bg-muted);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-lg);
    padding: var(--c-space-md);
    text-align: center;
  }
  
  .church__stat-label {
    font-size: var(--c-font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--c-text-secondary);
    margin-bottom: var(--c-space-xs);
  }
  
  .church__stat-value {
    font-size: var(--c-font-size-xl);
    font-weight: 700;
    color: var(--c-text-primary);
  }
  
  /* ----------------------------------------
     HEALTH/CHECKLIST
     ---------------------------------------- */
  .church__checklist {
    display: flex;
    flex-direction: column;
    gap: var(--c-space-xs);
  }
  
  .church__checklist-item {
    display: flex;
    align-items: center;
    gap: var(--c-space-sm);
    padding: var(--c-space-xs) var(--c-space-sm);
    background: var(--c-bg-muted);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-md);
    font-size: var(--c-font-size-sm);
    transition: all var(--c-transition-base);
  }
  
  .church__checklist-item--complete {
    border-color: var(--c-status-success-border);
    background: var(--c-status-success-bg);
  }
  
  .church__checklist-item--incomplete {
    opacity: 0.6;
  }
  
  .church__checklist-icon {
    font-size: var(--c-font-size-base);
    flex-shrink: 0;
  }
  
  .church__checklist-item--complete .church__checklist-icon {
    color: var(--c-status-success);
  }
  
  .church__checklist-item--incomplete .church__checklist-icon {
    color: var(--c-text-secondary);
  }
  
  .church__checklist-label {
    font-weight: 500;
    color: var(--c-text-primary);
  }
  
  /* ----------------------------------------
     PROGRESS BAR
     ---------------------------------------- */
  .church__progress {
    background: var(--c-bg-muted);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-lg);
    padding: var(--c-space-md);
  }
  
  .church__progress-bar {
    width: 100%;
    height: 8px;
    background: var(--c-bg-base);
    border-radius: var(--c-radius-sm);
    overflow: hidden;
    margin-bottom: var(--c-space-sm);
  }
  
  .church__progress-fill {
    height: 100%;
    background: var(--c-accent-primary);
    border-radius: var(--c-radius-sm);
    transition: width var(--c-transition-slow);
  }
  
  .church__progress-label {
    font-size: var(--c-font-size-xs);
    font-weight: 600;
    color: var(--c-text-secondary);
    text-align: center;
  }
  
  /* ----------------------------------------
     TOGGLE/CHECKBOX
     ---------------------------------------- */
  .church__toggle {
    display: flex;
    align-items: center;
    gap: var(--c-space-xs);
    font-size: var(--c-font-size-sm);
    color: var(--c-text-secondary);
    cursor: pointer;
    padding: var(--c-space-xs) var(--c-space-sm);
    border-radius: var(--c-radius-md);
    transition: all var(--c-transition-base);
  }
  
  .church__toggle:hover {
    background: var(--c-bg-muted);
  }
  
  .church__toggle input[type="checkbox"] {
    margin: 0;
    accent-color: var(--c-accent-primary);
  }
  
  .church__toggle-label {
    font-weight: 500;
  }
  
  /* ----------------------------------------
     BADGES
     ---------------------------------------- */
  .church__badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--c-space-sm);
    background: var(--c-bg-muted);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-sm);
    font-size: var(--c-font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  
  .church__badge--success {
    background: var(--c-status-success-bg);
    border-color: var(--c-status-success-border);
    color: var(--c-status-success);
  }
  
  .church__badge--warning {
    background: var(--c-status-warning-bg);
    border-color: var(--c-status-warning-border);
    color: var(--c-status-warning);
  }
  
  .church__badge--error {
    background: var(--c-status-error-bg);
    border-color: var(--c-status-error-border);
    color: var(--c-status-error);
  }
  
  .church__badge--accent {
    border-color: rgba(59, 130, 246, 0.5);
    color: var(--c-accent-primary);
  }
  
  /* ----------------------------------------
     SCROLLBARS
     ---------------------------------------- */
  .church ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
  
  .church ::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .church ::-webkit-scrollbar-thumb {
    background: var(--c-bg-muted);
    border-radius: 3px;
  }
  
  .church ::-webkit-scrollbar-thumb:hover {
    background: var(--c-border-default);
  }
  
  /* Paper theme scrollbar */
  .church[data-church-theme="paper"] ::-webkit-scrollbar-thumb {
    background: var(--c-border-muted);
  }
  
  .church[data-church-theme="paper"] ::-webkit-scrollbar-thumb:hover {
    background: var(--c-accent-secondary);
  }
  
  /* ----------------------------------------
     MODALS
     ---------------------------------------- */
  .church .info-modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--c-bg-overlay);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--c-space-xl);
  }
  
  .church .info-modal {
    background: var(--c-bg-base);
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-xl);
    box-shadow: var(--c-shadow-lg);
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  .church .info-modal-header {
    padding: var(--c-space-md) var(--c-space-lg);
    border-bottom: 1px solid var(--c-border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
  }
  
  .church .info-modal-title {
    font-size: var(--c-font-size-lg);
    font-weight: 700;
    color: var(--c-text-primary);
  }
  
  .church .info-modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--c-border-default);
    border-radius: var(--c-radius-md);
    color: var(--c-text-primary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all var(--c-transition-base);
  }
  
  .church .info-modal-close:hover {
    background: var(--c-status-error-bg);
    border-color: var(--c-status-error-border);
    color: var(--c-status-error);
  }
  
  .church .info-modal-body {
    padding: var(--c-space-lg);
    overflow-y: auto;
    flex: 1;
  }
  
  .church .info-modal-body p {
    margin: 0 0 var(--c-space-md) 0;
    font-size: var(--c-font-size-sm);
    line-height: 1.5;
    color: var(--c-text-primary);
  }
  
  .church .info-modal-body h4 {
    margin: var(--c-space-lg) 0 var(--c-space-sm) 0;
    font-size: var(--c-font-size-base);
    font-weight: 700;
    color: var(--c-text-primary);
  }
  
  .church .info-modal-body ul {
    margin: var(--c-space-sm) 0 var(--c-space-md) 0;
    padding-left: 20px;
  }
  
  .church .info-modal-body li {
    margin: var(--c-space-xs) 0;
    font-size: var(--c-font-size-sm);
    line-height: 1.4;
    color: var(--c-text-secondary);
  }
  
  .church .info-modal-body li strong {
    color: var(--c-text-primary);
  }
  
  /* ----------------------------------------
     MARKDOWN PREVIEW
     ---------------------------------------- */
  .church__markdown-preview {
    padding: var(--c-space-lg);
    font-size: var(--c-font-size-sm);
    line-height: 1.6;
    color: var(--c-text-primary);
  }
  
  .church__markdown-preview h1 {
    font-size: var(--c-font-size-xl);
    font-weight: 700;
    margin: var(--c-space-lg) 0 var(--c-space-sm) 0;
    color: var(--c-text-primary);
    border-bottom: 2px solid var(--c-border-default);
    padding-bottom: var(--c-space-xs);
  }
  
  .church__markdown-preview h2 {
    font-size: var(--c-font-size-lg);
    font-weight: 700;
    margin: var(--c-space-md) 0 var(--c-space-xs) 0;
    color: var(--c-text-primary);
  }
  
  .church__markdown-preview h3 {
    font-size: var(--c-font-size-base);
    font-weight: 600;
    margin: var(--c-space-md) 0 var(--c-space-xs) 0;
    color: var(--c-text-primary);
  }
  
  .church__markdown-preview p {
    margin: var(--c-space-sm) 0;
    color: var(--c-text-secondary);
  }
  
  .church__markdown-preview ul,
  .church__markdown-preview ol {
    margin: var(--c-space-sm) 0;
    padding-left: 20px;
  }
  
  .church__markdown-preview li {
    margin: var(--c-space-xs) 0;
    color: var(--c-text-secondary);
  }
  
  .church__markdown-preview code {
    background: var(--c-bg-muted);
    padding: 2px var(--c-space-xs);
    border-radius: var(--c-radius-sm);
    font-size: var(--c-font-size-sm);
    font-family: var(--c-font-mono);
  }
  
  .church__markdown-preview blockquote {
    border-left: 3px solid var(--c-accent-primary);
    padding-left: var(--c-space-md);
    margin: var(--c-space-sm) 0;
    color: var(--c-text-secondary);
    font-style: italic;
  }
  
  /* ----------------------------------------
     RESPONSIVE
     ---------------------------------------- */
  @media (max-width: 768px) {
    .church__panel--guide,
    .church__panel--preview {
      position: absolute;
      z-index: 100;
      height: 100%;
    }
    
    .church__panel--guide {
      left: 0;
    }
    
    .church__panel--preview {
      right: 0;
    }
  }
}
