/* ============================================================================
   RUSTICA FORGE — DESIGN SYSTEM
   Single source of truth for all visual tokens, component styles, and layouts.
   Load in <head> AFTER theme-engine.js, BEFORE page-specific <style> blocks.
   ============================================================================ */

/* ========================================================================
   SECTION 0: SELF-HOSTED FONTS (eliminates Google Fonts CDN dependency)
   ======================================================================== */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/inter-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/inter-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/inter-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/inter-latin.woff2') format('woff2');
}

/* ========================================================================
   SECTION 1: DESIGN TOKENS (CSS Custom Properties)
   ======================================================================== */

/* Fill behind iOS safe areas (notch/home indicator) with brand color instead of white */
html {
  background-color: #f5f4f1;
}

:root {
  /* === Brand Colors (defaults — theme-engine.js overrides at runtime) === */
  --rf-primary: #8b1a3a;
  --rf-primary-light: #b0304f;
  --rf-primary-dark: #6a1230;
  --rf-primary-rgb: 139, 26, 58;
  --rf-primary-gradient: linear-gradient(135deg, #8b1a3a, #b0304f);
  --rf-bg-body: #f5f4f1;
  --rf-bg-card: #ffffff;
  --rf-bg-card-alpha: rgba(255, 255, 255, 0.98);
  --rf-bg-sidebar: linear-gradient(180deg, #3d1224 0%, #2e0d1b 60%, #220a14 100%);
  --rf-bg-sidebar-hover: rgba(255, 255, 255, 0.07);
  --rf-bg-sidebar-active: rgba(255, 255, 255, 0.12);
  --rf-bg-page: #f5f4f1;
  --rf-text-primary: #1a1a1a;
  --rf-text-secondary: #555555;
  --rf-text-tertiary: #999999;
  --rf-text-sidebar: rgba(255, 255, 255, 0.6);
  --rf-text-sidebar-active: #ffffff;
  --rf-text-sidebar-section: rgba(255, 255, 255, 0.25);
  --rf-border-light: rgba(0, 0, 0, 0.10);
  --rf-border-sidebar: rgba(255, 255, 255, 0.06);
  --rf-input-bg: #ffffff;
  --rf-shadow-card: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.08);
  --rf-shadow-card-hover: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.1), 0 12px 40px rgba(0, 0, 0, 0.12);
  --rf-shadow-elevated: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(0, 0, 0, 0.08), 0 20px 60px rgba(0, 0, 0, 0.14);
  --rf-is-dark: 0;

  /* === Glow Tokens === */
  --rf-glow-primary: 0 0 12px rgba(var(--rf-primary-rgb), 0.25);
  --rf-glow-primary-strong: 0 0 20px rgba(var(--rf-primary-rgb), 0.35);
  --rf-glow-success: 0 0 12px rgba(16, 185, 129, 0.25);
  --rf-glow-danger: 0 0 12px rgba(239, 68, 68, 0.25);
  --rf-glow-warning: 0 0 12px rgba(245, 158, 11, 0.25);
  --rf-glow-info: 0 0 12px rgba(59, 130, 246, 0.25);

  /* === Button Spring & Timing Tokens === */
  --rf-btn-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --rf-btn-spring-out: cubic-bezier(0.22, 1.4, 0.36, 1);
  --rf-btn-snap: cubic-bezier(0.4, 0, 1, 1);
  --rf-btn-shadow-rest: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.04);
  --rf-btn-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1), 0 8px 24px rgba(0, 0, 0, 0.08);
  --rf-btn-shadow-press: 0 1px 2px rgba(0, 0, 0, 0.1), 0 0px 1px rgba(0, 0, 0, 0.06);

  /* === Typography Scale === */
  --rf-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --rf-font-mono: 'SF Mono', Monaco, 'Courier New', monospace;
  --rf-font-size-xs: 11px;
  --rf-font-size-sm: 13px;
  --rf-font-size-base: 14px;
  --rf-font-size-md: 15px;
  --rf-font-size-lg: 16px;
  --rf-font-size-xl: 20px;
  --rf-font-size-2xl: 24px;
  --rf-font-size-3xl: 28px;
  --rf-font-size-4xl: 32px;

  /* === Spacing Scale === */
  --rf-space-xs: 4px;
  --rf-space-sm: 8px;
  --rf-space-md: 12px;
  --rf-space-lg: 16px;
  --rf-space-xl: 20px;
  --rf-space-2xl: 24px;
  --rf-space-3xl: 32px;
  --rf-space-4xl: 40px;

  /* === Border Radius Scale === */
  --rf-radius-sm: 10px;
  --rf-radius-md: 14px;
  --rf-radius-lg: 20px;
  --rf-radius-xl: 24px;
  --rf-radius-2xl: 28px;
  --rf-radius-card: 24px;
  --rf-radius-pill: 50px;

  /* === Semantic Colors === */
  --rf-success: #10b981;
  --rf-success-light: #22c55e;
  --rf-success-bg: rgba(16, 185, 129, 0.1);
  --rf-success-text: #059669;
  --rf-danger: #ef4444;
  --rf-danger-light: #f87171;
  --rf-danger-bg: rgba(239, 68, 68, 0.1);
  --rf-danger-text: #dc2626;
  --rf-warning: #f59e0b;
  --rf-warning-light: #fbbf24;
  --rf-warning-bg: rgba(245, 158, 11, 0.1);
  --rf-warning-text: #d97706;
  --rf-info: #3b82f6;
  --rf-info-light: #60a5fa;
  --rf-info-bg: rgba(59, 130, 246, 0.1);
  --rf-info-text: #2563eb;
  --rf-purple: #8b5cf6;
  --rf-purple-bg: rgba(139, 92, 246, 0.1);

  /* === Z-Index Scale === */
  --rf-z-base: 1;
  --rf-z-sidebar: 100;
  --rf-z-header: 150;
  --rf-z-dropdown: 200;
  --rf-z-sticky: 300;
  --rf-z-modal-backdrop: 900;
  --rf-z-modal: 1000;
  --rf-z-toast: 1100;
  --rf-z-tooltip: 1200;
  --rf-z-theme-gear: 10000;
  --rf-z-theme-panel: 10001;

  /* === Transitions === */
  --rf-transition-fast: 0.15s ease;
  --rf-transition-normal: 0.2s ease;
  --rf-transition-slow: 0.3s ease;
  --rf-transition-spring: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  --rf-transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* === Dock / Sidebar Dimensions === */
  --rf-sidebar-width: 70px;
  --rf-dock-icon-size: 40px;
  --rf-dock-gap: 3px;

  /* === Page Container Max Width (overrideable per page via style attr) === */
  --rf-page-max-width: 100%;
}

/* ========================================================================
   SECTION 2: GLOBAL RESET & BASE STYLES
   ======================================================================== */

.rf-reset *, .rf-reset *::before, .rf-reset *::after {
  box-sizing: border-box;
}

/* When applied by the shell, base body styles */
body.rf-shell-body {
  font-family: var(--rf-font-family);
  background: var(--rf-bg-body);
  background-color: #f5f4f1;
  height: 100vh;              /* fallback for older browsers */
  height: 100dvh;             /* dynamic viewport: extends behind home indicator in standalone PWA */
  color: var(--rf-text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* Subtle page fade-in */
@keyframes rf-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

body.rf-shell-body .rf-main-content {
  animation: rf-fade-in 0.25s ease-out forwards;
}

/* ========================================================================
   SECTION 3: LAYOUT SYSTEM
   ======================================================================== */

/* Navigation Sidebar */
.rf-nav-sidebar {
  width: var(--rf-sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--rf-bg-sidebar);
  border-right: none;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: var(--rf-z-sidebar);
  overflow: hidden;
  transition: transform var(--rf-transition-slow);
  box-sizing: border-box;
  box-shadow: 2px 0 20px rgba(74, 22, 40, 0.2), 4px 0 40px rgba(74, 22, 40, 0.1);
}

/* Scrollable nav area between header and footer */
.rf-sidebar-nav-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 4px 0;
}

.rf-sidebar-nav-scroll::-webkit-scrollbar {
  width: 4px;
}

.rf-sidebar-nav-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.rf-sidebar-nav-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 10px;
}
.rf-sidebar-nav-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Sidebar scrollbar - handled by .rf-sidebar-nav-scroll */

/* Main Content Area — single scrollable viewport-height container */
.rf-main-content,
.main-content.rf-main-content {
  flex: 1;
  margin-left: var(--rf-sidebar-width);
  padding: var(--rf-space-2xl);
  height: 100vh;              /* fallback */
  height: 100dvh;             /* dynamic viewport: fills behind home indicator in standalone PWA */
  min-height: 0 !important;
  max-height: 100vh;          /* fallback */
  max-height: 100dvh;         /* dynamic viewport */
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* Page Container (full-width layout wrapper for shell pages) */
.rf-page-container {
  max-width: var(--rf-page-max-width);
  margin: 0 auto;
  background: var(--rf-bg-card);
  border-radius: var(--rf-radius-card);
  padding: 28px;
  box-shadow: var(--rf-shadow-elevated);
  border: none;
}

/* Mobile sidebar toggle */
.rf-sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: calc(var(--rf-z-sidebar) + 1);
  width: 42px;
  height: 42px;
  border-radius: var(--rf-radius-sm);
  border: none;
  background: var(--rf-bg-card-alpha);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--rf-transition-normal);
  padding: 0;
}

.rf-sidebar-toggle:hover {
  background: var(--rf-bg-card);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Animated hamburger bars → X */
.rf-hamburger {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 16px;
  position: relative;
}
.rf-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--rf-text-primary);
  border-radius: 1px;
  transition: transform 0.3s ease, opacity 0.2s ease;
  position: absolute;
}
.rf-hamburger span:nth-child(1) { top: 0; }
.rf-hamburger span:nth-child(2) { top: 7px; }
.rf-hamburger span:nth-child(3) { top: 14px; }

/* Active state: bars → X */
.rf-toggle-active .rf-hamburger span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.rf-toggle-active .rf-hamburger span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.rf-toggle-active .rf-hamburger span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.rf-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: calc(var(--rf-z-sidebar) - 1);
  opacity: 0;
  transition: opacity var(--rf-transition-slow);
}

.rf-sidebar-overlay.rf-visible {
  opacity: 1;
}

/* Breadcrumb Bar */
.rf-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--rf-font-size-sm);
  color: var(--rf-text-tertiary);
  margin-bottom: var(--rf-space-xl);
  padding: 0 4px;
}

.rf-breadcrumbs a {
  color: var(--rf-text-tertiary);
  text-decoration: none;
  transition: color var(--rf-transition-fast);
}

.rf-breadcrumbs a:hover {
  color: var(--rf-primary);
}

.rf-breadcrumbs .rf-breadcrumb-sep {
  color: var(--rf-text-tertiary);
  opacity: 0.5;
  font-size: 10px;
}

.rf-breadcrumbs .rf-breadcrumb-current {
  color: var(--rf-text-primary);
  font-weight: 500;
}

/* Mobile Responsive */
@media (max-width: 1024px) {
  .rf-nav-sidebar {
    transform: translateX(-100%);
  }

  .rf-nav-sidebar.rf-sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  .rf-sidebar-overlay.rf-active {
    display: block;
  }

  .rf-sidebar-toggle {
    display: flex;
  }

  .rf-main-content,
  .main-content.rf-main-content {
    margin-left: 0 !important;
    padding: 16px;
    padding-top: 64px;
    width: 100%;
    max-width: 100vw;
  }
}

@media (max-width: 768px) {
  .rf-main-content,
  .main-content.rf-main-content {
    padding: 12px;
    padding-top: 60px;
  }

  .rf-page-container {
    padding: 20px;
    border-radius: var(--rf-radius-2xl);
  }
}

/* ========================================================================
   SECTION 4: DOCK NAVIGATION STYLES (macOS-inspired icon dock)
   ======================================================================== */

/* Dock Header — logo only, centered */
.rf-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0 8px;
  flex-shrink: 0;
}

.rf-sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.rf-sidebar-logo img {
  height: 32px;
  width: auto;
  transition: transform 0.2s ease;
}

.rf-sidebar-logo img:hover {
  transform: scale(1.1);
}

/* Hide logo text in dock mode */
.rf-sidebar-logo span {
  display: none;
}

/* Hide old collapse button */
.rf-sidebar-collapse-btn {
  display: none;
}

/* ── Dock Nav Scroll Container ── */
.rf-sidebar-nav-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--rf-dock-gap);
}

.rf-sidebar-nav-scroll::-webkit-scrollbar { width: 0; }

/* ── Dock Section (group of icons) ── */
.rf-sidebar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--rf-dock-gap);
  padding: 4px 0;
}

/* Hide section titles in dock mode */
.rf-sidebar-section-title {
  display: none;
}

.rf-sidebar-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--rf-dock-gap);
}

/* ── Dock Divider (between sections) ── */
.rf-dock-divider {
  width: 28px;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 4px 0;
  flex-shrink: 0;
}

/* ── Dock Item (nav link as icon) ── */
.rf-sidebar-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--rf-dock-icon-size);
  height: var(--rf-dock-icon-size);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.5);
  text-decoration: none;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              background 0.15s ease,
              color 0.15s ease;
  transform-origin: center center;
  font-size: 0; /* hide text nodes */
  overflow: visible;
}

.rf-sidebar-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.08);
}

.rf-sidebar-link.active {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(var(--rf-primary-rgb), 0.3);
}

/* Active dot indicator below icon — use ::before so ::after is free for tooltip */
.rf-sidebar-link.active::before {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 6px rgba(var(--rf-primary-rgb), 0.5);
}

/* ── Dock Icon ── */
.rf-sidebar-link-icon {
  font-size: 20px;
  width: auto;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

/* ── Dock Tooltip (JS-driven, appended to body with position: fixed) ── */
.rf-dock-tooltip {
  position: fixed;
  left: calc(var(--rf-sidebar-width) + 12px);
  background: rgba(20, 20, 30, 0.95);
  color: rgba(255, 255, 255, 0.95);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: calc(var(--rf-z-sidebar) + 10);
  transform: translateY(-50%);
  font-family: var(--rf-font-family);
}
.rf-dock-tooltip.rf-dock-tooltip-visible {
  opacity: 1;
}

/* ── Badge (overlaid on dock icon) ── */
.rf-sidebar-link-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--rf-danger);
  color: white;
  padding: 0 5px;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ── Hide subtab-specific elements (subtabs are flattened into dock items) ── */
.rf-sidebar-subtab-group { display: contents; }
.rf-sidebar-parent { display: none; }
.rf-sidebar-subtabs { display: contents; }
.rf-sidebar-sublink { display: flex; }
.rf-sidebar-chevron { display: none; }

/* ── Dock Footer ── */
.rf-sidebar-footer {
  flex-shrink: 0;
  padding: 8px 0 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rf-sidebar-user {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.rf-sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

/* Hide user info text in dock */
.rf-sidebar-user-info { display: none; }
.rf-sidebar-user-name { display: none; }
.rf-sidebar-user-role { display: none; }

/* Footer action buttons — icon only */
.rf-sidebar-footer .rf-sidebar-link {
  width: 34px;
  height: 34px;
  font-size: 0;
}

.rf-sidebar-footer .rf-sidebar-link .rf-sidebar-link-icon {
  font-size: 16px;
}

.rf-sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 0;
  color: rgba(255, 255, 255, 0.4);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--rf-transition-normal);
}

.rf-sidebar-logout .rf-sidebar-link-icon {
  font-size: 16px;
}

.rf-sidebar-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ff6b6b;
}

/* Footer tooltip support — handled by same JS dock tooltip system */

.rf-sidebar-logout,
.rf-sidebar-user {
  position: relative;
}

/* ── Dock Divider in footer ── */
.rf-sidebar-divider {
  width: 28px;
  height: 1px;
  background: rgba(255, 255, 255, 0.06);
  margin: 2px 0;
}

/* ========================================================================
   SECTION 5: BUTTON SYSTEM — Premium Tactile Design
   Every button: hover glow, spring lift, press-down feel, ripple-ready.
   ======================================================================== */

/* ── Ripple layer (injected by JS, styled here) ── */
.rf-btn-ripple {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transform: scale(0);
  animation: rf-btn-ripple-expand 0.55s var(--rf-btn-spring-out) forwards;
}

@keyframes rf-btn-ripple-expand {
  0% {
    transform: scale(0);
    opacity: 0.4;
  }
  40% {
    opacity: 0.2;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

/* ── Base Button ── */
.rf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--rf-radius-sm);
  font-family: var(--rf-font-family);
  font-size: var(--rf-font-size-sm);
  font-weight: 600;
  line-height: 1.4;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;

  /* Ripple containment */
  position: relative;
  overflow: hidden;
  isolation: isolate;

  /* Spring-based transition system — transform overshoots, shadow is smooth */
  transition:
    transform 0.4s var(--rf-btn-spring),
    box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    background 0.25s ease,
    border-color 0.25s ease,
    color 0.2s ease;

  /* Subtle resting shadow for depth */
  box-shadow: var(--rf-btn-shadow-rest);
}

/* Ensure button content sits above ripple */
.rf-btn > * {
  position: relative;
  z-index: 1;
}

/* ── Hover — spring lift + shadow expansion ── */
.rf-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--rf-btn-shadow-hover);
}

/* ── Active / Press — physical push-down feel ── */
.rf-btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.97);
  box-shadow: var(--rf-btn-shadow-press);
  /* Snap down fast, spring back slow (handled by base transition on release) */
  transition:
    transform 0.08s var(--rf-btn-snap),
    box-shadow 0.08s var(--rf-btn-snap);
}

/* ── Focus ring (accessibility) ── */
.rf-btn:focus-visible {
  outline: 2px solid var(--rf-primary);
  outline-offset: 2px;
}

/* ── Disabled ── */
.rf-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BUTTON VARIANTS — each gets a unique glow color on hover
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Primary Button ── */
.rf-btn-primary {
  background: var(--rf-primary-gradient);
  color: white;
  box-shadow: 0 2px 8px rgba(var(--rf-primary-rgb), 0.2),
              0 1px 2px rgba(0, 0, 0, 0.06);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.rf-btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    0 4px 16px rgba(var(--rf-primary-rgb), 0.3),
    0 8px 32px rgba(var(--rf-primary-rgb), 0.15),
    0 0 0 1px rgba(var(--rf-primary-rgb), 0.15),
    0 0 20px rgba(var(--rf-primary-rgb), 0.25);
}

.rf-btn-primary:active:not(:disabled) {
  box-shadow:
    0 1px 4px rgba(var(--rf-primary-rgb), 0.3),
    0 0 12px rgba(var(--rf-primary-rgb), 0.15);
}

/* ── Secondary Button ── */
.rf-btn-secondary {
  background: rgba(0, 0, 0, 0.06);
  color: var(--rf-text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.rf-btn-secondary:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.08),
    0 8px 24px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04);
}

.rf-btn-secondary:active:not(:disabled) {
  background: rgba(0, 0, 0, 0.12);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ── Outline Button ── */
.rf-btn-outline {
  background: transparent;
  color: var(--rf-primary);
  border: 1.5px solid var(--rf-primary);
  box-shadow: 0 1px 2px rgba(var(--rf-primary-rgb), 0.06);
}

.rf-btn-outline:hover:not(:disabled) {
  background: rgba(var(--rf-primary-rgb), 0.06);
  transform: translateY(-2px);
  box-shadow:
    0 4px 12px rgba(var(--rf-primary-rgb), 0.12),
    0 0 0 1px rgba(var(--rf-primary-rgb), 0.2),
    0 0 16px rgba(var(--rf-primary-rgb), 0.12);
  border-color: var(--rf-primary-light);
}

.rf-btn-outline:active:not(:disabled) {
  background: rgba(var(--rf-primary-rgb), 0.1);
  box-shadow: 0 1px 4px rgba(var(--rf-primary-rgb), 0.15);
}

/* ── Danger Button ── */
.rf-btn-danger {
  background: linear-gradient(135deg, var(--rf-danger), var(--rf-danger-light));
  color: white;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2),
              0 1px 2px rgba(0, 0, 0, 0.06);
}

.rf-btn-danger:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    0 4px 16px rgba(239, 68, 68, 0.3),
    0 8px 32px rgba(239, 68, 68, 0.15),
    0 0 0 1px rgba(239, 68, 68, 0.15),
    0 0 20px rgba(239, 68, 68, 0.2);
}

.rf-btn-danger:active:not(:disabled) {
  box-shadow:
    0 1px 4px rgba(239, 68, 68, 0.3),
    0 0 12px rgba(239, 68, 68, 0.15);
}

/* ── Success Button ── */
.rf-btn-success {
  background: linear-gradient(135deg, var(--rf-success), var(--rf-success-light));
  color: white;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2),
              0 1px 2px rgba(0, 0, 0, 0.06);
}

.rf-btn-success:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    0 4px 16px rgba(16, 185, 129, 0.3),
    0 8px 32px rgba(16, 185, 129, 0.15),
    0 0 0 1px rgba(16, 185, 129, 0.15),
    0 0 20px rgba(16, 185, 129, 0.2);
}

.rf-btn-success:active:not(:disabled) {
  box-shadow:
    0 1px 4px rgba(16, 185, 129, 0.3),
    0 0 12px rgba(16, 185, 129, 0.15);
}

/* ── Ghost Button ── */
.rf-btn-ghost {
  background: transparent;
  color: var(--rf-text-secondary);
  box-shadow: none;
}

.rf-btn-ghost:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.05);
  color: var(--rf-text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.rf-btn-ghost:active:not(:disabled) {
  background: rgba(0, 0, 0, 0.08);
  box-shadow: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIZE VARIANTS — inherit all animations
   ═══════════════════════════════════════════════════════════════════════════ */

.rf-btn-sm {
  padding: 6px 14px;
  font-size: var(--rf-font-size-xs);
  border-radius: var(--rf-radius-sm);
}

.rf-btn-lg {
  padding: 14px 28px;
  font-size: var(--rf-font-size-md);
  border-radius: var(--rf-radius-lg);
}

.rf-btn-xl {
  padding: 16px 32px;
  font-size: var(--rf-font-size-lg);
  border-radius: var(--rf-radius-lg);
}

/* ── Icon-Only Button ── */
.rf-btn-icon {
  padding: 10px;
  width: 40px;
  height: 40px;
}

.rf-btn-icon.rf-btn-sm {
  padding: 6px;
  width: 32px;
  height: 32px;
}

/* ========================================================================
   SECTION 6: INPUT SYSTEM
   ======================================================================== */

.rf-input,
.rf-select,
.rf-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid rgba(0, 0, 0, 0.10);
  border-radius: var(--rf-radius-sm);
  font-family: var(--rf-font-family);
  font-size: var(--rf-font-size-base);
  color: var(--rf-text-primary);
  background: var(--rf-input-bg);
  transition: all var(--rf-transition-smooth);
  outline: none;
}

.rf-input:focus,
.rf-select:focus,
.rf-textarea:focus {
  border-color: var(--rf-primary);
  box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.12), 0 0 0 6px rgba(var(--rf-primary-rgb), 0.04);
  outline: none;
}

.rf-input::placeholder,
.rf-textarea::placeholder {
  color: var(--rf-text-tertiary);
}

.rf-input:disabled,
.rf-select:disabled,
.rf-textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: rgba(0, 0, 0, 0.03);
}

.rf-select {
  appearance: none;
  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='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.rf-textarea {
  min-height: 100px;
  resize: vertical;
}

/* Input Sizes */
.rf-input-sm, .rf-select-sm {
  padding: 7px 10px;
  font-size: var(--rf-font-size-sm);
}

.rf-input-lg, .rf-select-lg {
  padding: 14px 18px;
  font-size: var(--rf-font-size-lg);
}

/* Form Group */
.rf-form-group {
  margin-bottom: var(--rf-space-lg);
}

.rf-form-label {
  display: block;
  font-size: var(--rf-font-size-sm);
  font-weight: 600;
  color: var(--rf-text-primary);
  margin-bottom: 6px;
}

.rf-form-hint {
  font-size: var(--rf-font-size-xs);
  color: var(--rf-text-tertiary);
  margin-top: 4px;
}

.rf-form-error {
  font-size: var(--rf-font-size-xs);
  color: var(--rf-danger-text);
  margin-top: 4px;
}

/* Search Input */
.rf-search {
  position: relative;
}

.rf-search .rf-input {
  padding-left: 38px;
}

.rf-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--rf-text-tertiary);
  font-size: 16px;
  pointer-events: none;
}

/* ========================================================================
   SECTION 7: CARD SYSTEM
   ======================================================================== */

.rf-card {
  background: var(--rf-bg-card);
  border-radius: var(--rf-radius-lg);
  border: 1px solid rgba(0, 0, 0, 0.07);
  box-shadow: var(--rf-shadow-card);
  overflow: hidden;
  transition: box-shadow var(--rf-transition-smooth), transform var(--rf-transition-smooth);
}

.rf-card:hover {
  box-shadow: var(--rf-shadow-card-hover);
}

.rf-card-solid {
  background: var(--rf-bg-card);
}

.rf-card-elevated {
  box-shadow: var(--rf-shadow-elevated);
}

.rf-card-interactive:hover {
  transform: translateY(-4px);
  box-shadow: var(--rf-shadow-card-hover), 0 0 16px rgba(var(--rf-primary-rgb), 0.06);
}

/* Card with brand accent bar */
.rf-card-accent {
  border-left: 3px solid var(--rf-primary);
}

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

.rf-card-title {
  font-size: var(--rf-font-size-lg);
  font-weight: 700;
  color: var(--rf-text-primary);
}

.rf-card-body {
  padding: 20px 24px;
}

.rf-card-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--rf-border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* KPI / Stat Card */
.rf-kpi-card {
  background: var(--rf-bg-card);
  border-radius: var(--rf-radius-lg);
  padding: 24px;
  border: 1px solid rgba(0, 0, 0, 0.07);
  box-shadow: var(--rf-shadow-card);
  transition: box-shadow 0.4s var(--rf-btn-spring), transform 0.4s var(--rf-btn-spring), border-color 0.3s ease;
  position: relative;
  overflow: hidden;
}

.rf-kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--rf-primary-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.rf-kpi-card:hover {
  box-shadow: var(--rf-shadow-card-hover);
  transform: translateY(-3px);
  border-color: rgba(var(--rf-primary-rgb), 0.18);
}

.rf-kpi-card:hover::before {
  opacity: 1;
}

.rf-kpi-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--rf-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.rf-kpi-value {
  font-size: var(--rf-font-size-4xl);
  font-weight: 800;
  color: var(--rf-text-primary);
  letter-spacing: -1px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.rf-kpi-sub {
  font-size: var(--rf-font-size-xs);
  color: var(--rf-text-secondary);
  margin-top: 6px;
}

/* ========================================================================
   SECTION 8: TAB SYSTEM
   ======================================================================== */

.rf-tabs {
  display: flex;
  gap: 2px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--rf-radius-md);
  padding: 3px;
  flex-wrap: wrap;
}

.rf-tab {
  padding: 8px 16px;
  border-radius: var(--rf-radius-sm);
  border: none;
  background: transparent;
  font-family: var(--rf-font-family);
  font-size: var(--rf-font-size-sm);
  font-weight: 600;
  color: var(--rf-text-secondary);
  cursor: pointer;
  transition: all var(--rf-transition-normal);
  white-space: nowrap;
}

.rf-tab:hover:not(.active) {
  background: rgba(0, 0, 0, 0.06);
  color: var(--rf-text-primary);
}

.rf-tab.active {
  background: white;
  color: var(--rf-text-primary);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
  font-weight: 700;
}

/* Pill Tabs (gradient active) */
.rf-tabs-pill .rf-tab.active {
  background: var(--rf-primary-gradient);
  color: white;
  box-shadow: 0 4px 12px rgba(var(--rf-primary-rgb), 0.3), var(--rf-glow-primary);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* Tab Sizes */
.rf-tabs-sm .rf-tab {
  padding: 6px 12px;
  font-size: var(--rf-font-size-xs);
}

.rf-tabs-lg .rf-tab {
  padding: 12px 24px;
  font-size: var(--rf-font-size-base);
}

/* ========================================================================
   SECTION 9: TABLE SYSTEM
   ======================================================================== */

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

.rf-table th {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 16px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  color: var(--rf-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-bottom: 2px solid var(--rf-border-light);
  position: sticky;
  top: 0;
  z-index: 1;
}

.rf-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  color: var(--rf-text-primary);
  vertical-align: middle;
}

.rf-table tbody tr {
  transition: background var(--rf-transition-fast);
}

.rf-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.028);
}

.rf-table tbody tr:hover {
  background: rgba(var(--rf-primary-rgb), 0.08);
}

.rf-table tbody tr:last-child td {
  border-bottom: none;
}

/* Compact Table */
.rf-table-compact th,
.rf-table-compact td {
  padding: 8px 12px;
}

/* Clickable Rows */
.rf-table-clickable tbody tr {
  cursor: pointer;
}

.rf-table-clickable tbody tr:hover {
  background: rgba(var(--rf-primary-rgb), 0.08);
  box-shadow: inset 3px 0 0 var(--rf-primary);
}

/* ========================================================================
   SECTION 10: BADGE / STATUS SYSTEM
   ======================================================================== */

.rf-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--rf-radius-pill);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.4;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}

.rf-badge-success {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid rgba(4, 120, 87, 0.18);
}

.rf-badge-danger {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid rgba(185, 28, 28, 0.18);
}

.rf-badge-warning {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid rgba(180, 83, 9, 0.18);
}

.rf-badge-info {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid rgba(29, 78, 216, 0.18);
}

.rf-badge-purple {
  background: #f5f3ff;
  color: #6d28d9;
  border: 1px solid rgba(109, 40, 217, 0.18);
}

.rf-badge-neutral {
  background: #f3f4f6;
  color: var(--rf-text-secondary);
  border: 1px solid rgba(0, 0, 0, 0.10);
}

.rf-badge-primary {
  background: rgba(var(--rf-primary-rgb), 0.08);
  color: var(--rf-primary);
  border: 1px solid rgba(var(--rf-primary-rgb), 0.18);
}

/* Badge with dot */
@keyframes rf-badge-dot-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px currentColor; }
  50% { opacity: 0.6; box-shadow: 0 0 10px currentColor; }
}

.rf-badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
  animation: rf-badge-dot-pulse 2s ease-in-out infinite;
}

/* Solid badge variant */
.rf-badge-solid.rf-badge-success {
  background: #059669;
  color: white;
  border: none;
}

.rf-badge-solid.rf-badge-danger {
  background: #dc2626;
  color: white;
  border: none;
}

.rf-badge-solid.rf-badge-warning {
  background: #d97706;
  color: white;
  border: none;
}

.rf-badge-solid.rf-badge-info {
  background: #2563eb;
  color: white;
  border: none;
}

/* ========================================================================
   SECTION 11: MODAL SYSTEM
   ======================================================================== */

.rf-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--rf-z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--rf-transition-normal);
}

.rf-modal-overlay.rf-active {
  opacity: 1;
  visibility: visible;
}

.rf-modal {
  background: var(--rf-bg-card);
  border-radius: var(--rf-radius-lg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.18), 0 32px 60px rgba(0, 0, 0, 0.25);
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  z-index: var(--rf-z-modal);
  transform: translateY(20px) scale(0.96);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.rf-modal-overlay.rf-active .rf-modal {
  transform: translateY(0) scale(1);
}

.rf-modal-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.rf-modal-title {
  font-size: var(--rf-font-size-xl);
  font-weight: 700;
  color: var(--rf-text-primary);
}

.rf-modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--rf-radius-sm);
  border: none;
  background: rgba(0, 0, 0, 0.06);
  color: var(--rf-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--rf-transition-fast);
  flex-shrink: 0;
}

.rf-modal-close:hover {
  background: rgba(0, 0, 0, 0.1);
  color: var(--rf-text-primary);
}

.rf-modal-body {
  padding: 20px 24px;
}

.rf-modal-footer {
  padding: 0 24px 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* Modal Sizes */
.rf-modal-sm { max-width: 400px; }
.rf-modal-lg { max-width: 720px; }
.rf-modal-xl { max-width: 960px; }

/* Slide Panel (right-to-left) */
.rf-slide-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: var(--rf-z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: all var(--rf-transition-normal);
}

.rf-slide-panel-overlay.rf-active {
  opacity: 1;
  visibility: visible;
}

.rf-slide-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 820px;
  max-width: 100%;
  background: var(--rf-bg-card);
  z-index: var(--rf-z-modal);
  transform: translateX(100%);
  transition: transform var(--rf-transition-slow);
  overflow-y: auto;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

.rf-slide-panel-overlay.rf-active .rf-slide-panel {
  transform: translateX(0);
}

/* ========================================================================
   SECTION 12: TOAST / NOTIFICATION SYSTEM
   ======================================================================== */

.rf-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--rf-z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  max-width: 400px;
}

.rf-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-radius: var(--rf-radius-md);
  background: var(--rf-bg-card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--rf-border-light);
  font-size: var(--rf-font-size-sm);
  color: var(--rf-text-primary);
  pointer-events: auto;
  animation: rf-toast-in 0.3s ease-out;
  max-width: 100%;
}

.rf-toast.rf-toast-exit {
  animation: rf-toast-out 0.2s ease-in forwards;
}

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

@keyframes rf-toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.95); }
}

.rf-toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.rf-toast-message {
  flex: 1;
  min-width: 0;
}

.rf-toast-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--rf-text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  position: relative;
  overflow: hidden;
  transition:
    transform 0.35s var(--rf-btn-spring),
    background 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}

.rf-toast-close:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--rf-text-primary);
  transform: scale(1.1);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.08);
}

.rf-toast-close:active {
  transform: scale(0.9);
  transition: transform 0.08s var(--rf-btn-snap);
}

.rf-toast-success { border-left: 3px solid var(--rf-success); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 0 10px rgba(16, 185, 129, 0.1); }
.rf-toast-error { border-left: 3px solid var(--rf-danger); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 0 10px rgba(239, 68, 68, 0.1); }
.rf-toast-warning { border-left: 3px solid var(--rf-warning); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 0 10px rgba(245, 158, 11, 0.1); }
.rf-toast-info { border-left: 3px solid var(--rf-info); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 0 10px rgba(59, 130, 246, 0.1); }

/* ========================================================================
   SECTION 13: LOADING STATES
   ======================================================================== */

/* Spinner */
.rf-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--rf-border-light);
  border-top-color: var(--rf-primary);
  border-radius: 50%;
  animation: rf-spin 0.7s linear infinite;
  filter: drop-shadow(0 0 4px rgba(var(--rf-primary-rgb), 0.3));
}

.rf-spinner-sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.rf-spinner-lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

@keyframes rf-spin {
  to { transform: rotate(360deg); }
}

/* Loading Overlay */
.rf-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
}

/* Skeleton */
.rf-skeleton {
  background: linear-gradient(90deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0.02) 50%, rgba(0,0,0,0.06) 75%);
  background-size: 400% 100%;
  animation: rf-shimmer 2s ease-in-out infinite;
  border-radius: var(--rf-radius-sm);
}

.rf-skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}

.rf-skeleton-heading {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
}

.rf-skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

@keyframes rf-shimmer {
  0% { background-position: 400% 0; }
  100% { background-position: -400% 0; }
}

/* Skeleton Variants */
.rf-skeleton-card {
  height: 120px;
  border-radius: var(--rf-radius-lg);
}

.rf-skeleton-row {
  height: 48px;
  border-radius: var(--rf-radius-sm);
}

.rf-skeleton-kpi {
  height: 88px;
  border-radius: var(--rf-radius-lg);
}

/* Empty State */
.rf-empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--rf-text-tertiary);
}

.rf-empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.rf-empty-state-title {
  font-size: var(--rf-font-size-lg);
  font-weight: 600;
  color: var(--rf-text-secondary);
  margin-bottom: 8px;
}

.rf-empty-state-text {
  font-size: var(--rf-font-size-sm);
  color: var(--rf-text-tertiary);
  max-width: 400px;
  margin: 0 auto;
}

/* ========================================================================
   SECTION 14: UTILITY CLASSES
   ======================================================================== */

/* Flex Utilities */
.rf-flex { display: flex; }
.rf-flex-col { flex-direction: column; }
.rf-flex-center { align-items: center; justify-content: center; }
.rf-flex-between { justify-content: space-between; }
.rf-flex-wrap { flex-wrap: wrap; }
.rf-gap-xs { gap: var(--rf-space-xs); }
.rf-gap-sm { gap: var(--rf-space-sm); }
.rf-gap-md { gap: var(--rf-space-md); }
.rf-gap-lg { gap: var(--rf-space-lg); }
.rf-gap-xl { gap: var(--rf-space-xl); }

/* Grid Utilities */
.rf-grid { display: grid; gap: var(--rf-space-lg); }
.rf-grid-2 { grid-template-columns: repeat(2, 1fr); }
.rf-grid-3 { grid-template-columns: repeat(3, 1fr); }
.rf-grid-4 { grid-template-columns: repeat(4, 1fr); }
.rf-grid-auto { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* Text Utilities */
.rf-text-primary { color: var(--rf-text-primary); }
.rf-text-secondary { color: var(--rf-text-secondary); }
.rf-text-tertiary { color: var(--rf-text-tertiary); }
.rf-text-danger { color: var(--rf-danger-text); }
.rf-text-success { color: var(--rf-success-text); }
.rf-text-xs { font-size: var(--rf-font-size-xs); }
.rf-text-sm { font-size: var(--rf-font-size-sm); }
.rf-text-base { font-size: var(--rf-font-size-base); }
.rf-text-lg { font-size: var(--rf-font-size-lg); }
.rf-text-xl { font-size: var(--rf-font-size-xl); }
.rf-text-bold { font-weight: 700; }
.rf-text-semibold { font-weight: 600; }
.rf-text-center { text-align: center; }
.rf-text-mono { font-family: var(--rf-font-mono); }
.rf-text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Spacing Utilities */
.rf-mb-sm { margin-bottom: var(--rf-space-sm); }
.rf-mb-md { margin-bottom: var(--rf-space-md); }
.rf-mb-lg { margin-bottom: var(--rf-space-lg); }
.rf-mb-xl { margin-bottom: var(--rf-space-xl); }
.rf-mb-2xl { margin-bottom: var(--rf-space-2xl); }
.rf-mt-auto { margin-top: auto; }
.rf-ml-auto { margin-left: auto; }

/* Visibility */
.rf-hidden { display: none !important; }
.rf-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ========================================================================
   SECTION 14b: GLOBAL SCROLLBAR STYLING (Light Mode)
   ======================================================================== */

.rf-main-content::-webkit-scrollbar {
  width: 8px;
}

.rf-main-content::-webkit-scrollbar-track {
  background: transparent;
}

.rf-main-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.rf-main-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Firefox scrollbar */
.rf-main-content {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* ========================================================================
   SECTION 15: DARK MODE OVERRIDES (when theme-engine sets data-rf-dark)
   ======================================================================== */

[data-rf-dark="true"] {
  --rf-bg-page: rgba(255, 255, 255, 0.03);
}

/* Dark mode: fill behind iOS safe areas with dark color */
[data-rf-dark="true"] html,
html[data-rf-dark="true"] {
  background-color: #111827;
}

[data-rf-dark="true"] .rf-card,
[data-rf-dark="true"] .rf-kpi-card {
  border-color: rgba(255, 255, 255, 0.10);
  box-shadow: var(--rf-shadow-card), 0 0 0 1px rgba(255, 255, 255, 0.06);
}

[data-rf-dark="true"] .rf-kpi-card:hover {
  border-color: rgba(var(--rf-primary-rgb), 0.25);
}

[data-rf-dark="true"] .rf-page-container {
  border-color: rgba(255, 255, 255, 0.08);
}

[data-rf-dark="true"] .rf-table th {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-rf-dark="true"] .rf-table td {
  border-color: rgba(255, 255, 255, 0.06);
}

[data-rf-dark="true"] .rf-table tbody tr:hover {
  background: rgba(var(--rf-primary-rgb), 0.10);
}

[data-rf-dark="true"] .rf-input,
[data-rf-dark="true"] .rf-select,
[data-rf-dark="true"] .rf-textarea {
  background: var(--rf-input-bg);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-rf-dark="true"] .rf-input:focus,
[data-rf-dark="true"] .rf-select:focus,
[data-rf-dark="true"] .rf-textarea:focus {
  border-color: var(--rf-primary);
  box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.2), 0 0 0 6px rgba(var(--rf-primary-rgb), 0.06);
}

[data-rf-dark="true"] .rf-btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--rf-text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

[data-rf-dark="true"] .rf-btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 16px rgba(255, 255, 255, 0.04);
}

[data-rf-dark="true"] .rf-btn-secondary:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Dark mode ghost buttons */
[data-rf-dark="true"] .rf-btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--rf-text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Dark mode outline buttons */
[data-rf-dark="true"] .rf-btn-outline:hover:not(:disabled) {
  box-shadow:
    0 4px 12px rgba(var(--rf-primary-rgb), 0.2),
    0 0 0 1px rgba(var(--rf-primary-rgb), 0.3),
    0 0 20px rgba(var(--rf-primary-rgb), 0.15);
}

[data-rf-dark="true"] .rf-tabs {
  background: rgba(255, 255, 255, 0.06);
}

[data-rf-dark="true"] .rf-tab.active {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 1px 3px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.15);
}

[data-rf-dark="true"] .rf-toast {
  background: var(--rf-bg-card);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-rf-dark="true"] .rf-modal {
  background: var(--rf-bg-card);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 12px 28px rgba(0, 0, 0, 0.35), 0 32px 60px rgba(0, 0, 0, 0.45);
}

[data-rf-dark="true"] .rf-confirm-dialog {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 12px 28px rgba(0, 0, 0, 0.35), 0 32px 60px rgba(0, 0, 0, 0.45);
}

[data-rf-dark="true"] .rf-loading-overlay {
  background: rgba(0, 0, 0, 0.5);
}

[data-rf-dark="true"] .rf-skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.02) 50%, rgba(255,255,255,0.06) 75%);
  background-size: 400% 100%;
}

/* Sidebar is already dark, just deepen it slightly in dark mode */
[data-rf-dark="true"] .rf-nav-sidebar {
  background: #141420;
  border-right-color: rgba(255, 255, 255, 0.05);
}

[data-rf-dark="true"] .rf-badge-neutral {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.06);
}

[data-rf-dark="true"] .rf-badge-success { background: rgba(4, 120, 87, 0.15); border-color: rgba(4, 120, 87, 0.25); }
[data-rf-dark="true"] .rf-badge-danger { background: rgba(185, 28, 28, 0.15); border-color: rgba(185, 28, 28, 0.25); }
[data-rf-dark="true"] .rf-badge-warning { background: rgba(180, 83, 9, 0.15); border-color: rgba(180, 83, 9, 0.25); }
[data-rf-dark="true"] .rf-badge-info { background: rgba(29, 78, 216, 0.15); border-color: rgba(29, 78, 216, 0.25); }
[data-rf-dark="true"] .rf-badge-purple { background: rgba(109, 40, 217, 0.15); border-color: rgba(109, 40, 217, 0.25); }

[data-rf-dark="true"] ::placeholder {
  color: var(--rf-text-tertiary);
}

[data-rf-dark="true"] ::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}

[data-rf-dark="true"] ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

[data-rf-dark="true"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ========================================================================
   SECTION 16: PAGE HEADER SYSTEM
   ======================================================================== */

.rf-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--rf-space-2xl);
  flex-wrap: wrap;
  gap: var(--rf-space-lg);
}

.rf-page-title {
  font-size: var(--rf-font-size-3xl);
  font-weight: 800;
  color: var(--rf-text-primary);
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.rf-page-subtitle {
  font-size: var(--rf-font-size-sm);
  color: var(--rf-text-secondary);
  margin-top: var(--rf-space-xs);
  font-weight: 400;
}

.rf-page-actions {
  display: flex;
  gap: var(--rf-space-md);
  align-items: center;
  flex-wrap: wrap;
}

/* Section Title */
.rf-section-title {
  font-size: var(--rf-font-size-lg);
  font-weight: 600;
  color: var(--rf-text-primary);
  margin-bottom: var(--rf-space-lg);
}

/* ========================================================================
   SECTION 17: CONFIRMATION DIALOG
   ======================================================================== */

.rf-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: calc(var(--rf-z-modal) + 10);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--rf-transition-normal);
}

.rf-confirm-overlay.rf-active {
  opacity: 1;
  visibility: visible;
}

.rf-confirm-dialog {
  background: var(--rf-bg-card);
  border-radius: var(--rf-radius-lg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.18), 0 32px 60px rgba(0, 0, 0, 0.25);
  max-width: 440px;
  width: 100%;
  padding: 28px;
  transform: translateY(20px) scale(0.96);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.rf-confirm-overlay.rf-active .rf-confirm-dialog {
  transform: translateY(0) scale(1);
}

.rf-confirm-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: var(--rf-space-lg);
}

.rf-confirm-icon-danger {
  background: var(--rf-danger-bg);
  color: var(--rf-danger);
}

.rf-confirm-icon-warning {
  background: var(--rf-warning-bg);
  color: var(--rf-warning);
}

.rf-confirm-icon-info {
  background: var(--rf-info-bg);
  color: var(--rf-info);
}

.rf-confirm-title {
  font-size: var(--rf-font-size-xl);
  font-weight: 700;
  color: var(--rf-text-primary);
  margin-bottom: var(--rf-space-sm);
}

.rf-confirm-message {
  font-size: var(--rf-font-size-base);
  color: var(--rf-text-secondary);
  line-height: 1.6;
  margin-bottom: var(--rf-space-2xl);
}

.rf-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--rf-space-md);
}

/* ========================================================================
   SECTION 18: FILTER / SEARCH BAR
   ======================================================================== */

.rf-filter-bar {
  display: flex;
  gap: var(--rf-space-sm);
  align-items: center;
  flex-wrap: wrap;
}

.rf-search-bar {
  display: flex;
  align-items: center;
  gap: var(--rf-space-sm);
  background: var(--rf-input-bg);
  border: 1.5px solid var(--rf-border-light);
  border-radius: var(--rf-radius-sm);
  padding: 8px 14px;
  min-width: 240px;
  transition: all var(--rf-transition-normal);
}

.rf-search-bar:focus-within {
  border-color: var(--rf-primary);
  box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.12), 0 0 0 6px rgba(var(--rf-primary-rgb), 0.04);
}

.rf-search-bar input {
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--rf-font-size-base);
  font-family: var(--rf-font-family);
  flex: 1;
  color: var(--rf-text-primary);
  min-width: 0;
}

.rf-search-bar input::placeholder {
  color: var(--rf-text-tertiary);
}

.rf-search-bar-icon {
  color: var(--rf-text-tertiary);
  font-size: 16px;
  flex-shrink: 0;
}

.rf-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--rf-radius-pill);
  font-size: var(--rf-font-size-sm);
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--rf-border-light);
  background: var(--rf-input-bg);
  color: var(--rf-text-secondary);
  transition: all var(--rf-transition-normal);
  white-space: nowrap;
}

.rf-filter-pill:hover {
  border-color: var(--rf-primary);
  color: var(--rf-primary);
}

.rf-filter-pill.active {
  background: rgba(var(--rf-primary-rgb), 0.1);
  border-color: var(--rf-primary);
  color: var(--rf-primary);
  font-weight: 600;
  box-shadow: 0 0 8px rgba(var(--rf-primary-rgb), 0.12);
}

/* ========================================================================
   SECTION 19: KPI ROW (auto-fit grid)
   ======================================================================== */

.rf-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--rf-space-lg);
  margin-bottom: var(--rf-space-2xl);
}

/* ========================================================================
   SECTION 20: EXTENDED UTILITY CLASSES
   ======================================================================== */

/* Alignment */
.rf-items-center { align-items: center; }
.rf-items-start { align-items: flex-start; }
.rf-items-end { align-items: flex-end; }
.rf-justify-center { justify-content: center; }
.rf-justify-between { justify-content: space-between; }
.rf-justify-end { justify-content: flex-end; }
.rf-flex-1 { flex: 1; min-width: 0; }
.rf-flex-shrink-0 { flex-shrink: 0; }
.rf-inline-flex { display: inline-flex; }

/* Extended Spacing */
.rf-p-sm { padding: var(--rf-space-sm); }
.rf-p-md { padding: var(--rf-space-md); }
.rf-p-lg { padding: var(--rf-space-lg); }
.rf-p-xl { padding: var(--rf-space-xl); }
.rf-p-2xl { padding: var(--rf-space-2xl); }
.rf-px-sm { padding-left: var(--rf-space-sm); padding-right: var(--rf-space-sm); }
.rf-px-md { padding-left: var(--rf-space-md); padding-right: var(--rf-space-md); }
.rf-px-lg { padding-left: var(--rf-space-lg); padding-right: var(--rf-space-lg); }
.rf-px-xl { padding-left: var(--rf-space-xl); padding-right: var(--rf-space-xl); }
.rf-py-sm { padding-top: var(--rf-space-sm); padding-bottom: var(--rf-space-sm); }
.rf-py-md { padding-top: var(--rf-space-md); padding-bottom: var(--rf-space-md); }
.rf-py-lg { padding-top: var(--rf-space-lg); padding-bottom: var(--rf-space-lg); }
.rf-mt-0 { margin-top: 0; }
.rf-mt-sm { margin-top: var(--rf-space-sm); }
.rf-mt-md { margin-top: var(--rf-space-md); }
.rf-mt-lg { margin-top: var(--rf-space-lg); }
.rf-mt-xl { margin-top: var(--rf-space-xl); }
.rf-mt-2xl { margin-top: var(--rf-space-2xl); }
.rf-mr-sm { margin-right: var(--rf-space-sm); }
.rf-mr-md { margin-right: var(--rf-space-md); }
.rf-mb-0 { margin-bottom: 0; }
.rf-mb-xs { margin-bottom: var(--rf-space-xs); }
.rf-gap-2xl { gap: var(--rf-space-2xl); }

/* Width & Overflow */
.rf-w-full { width: 100%; }
.rf-w-auto { width: auto; }
.rf-min-w-0 { min-width: 0; }
.rf-overflow-auto { overflow: auto; }
.rf-overflow-hidden { overflow: hidden; }
.rf-overflow-x-auto { overflow-x: auto; }

/* Position */
.rf-relative { position: relative; }
.rf-absolute { position: absolute; }
.rf-sticky { position: sticky; top: 0; z-index: var(--rf-z-sticky); }

/* Cursor */
.rf-cursor-pointer { cursor: pointer; }
.rf-select-none { user-select: none; }

/* Border */
.rf-border-b { border-bottom: 1px solid var(--rf-border-light); }
.rf-border-t { border-top: 1px solid var(--rf-border-light); }
.rf-rounded-md { border-radius: var(--rf-radius-md); }
.rf-rounded-lg { border-radius: var(--rf-radius-lg); }

/* ========================================================================
   SECTION 21: MOTION SYSTEM
   ======================================================================== */

/* Keyframe Animations */
@keyframes rf-slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes rf-slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes rf-slide-in-right {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes rf-scale-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* Animation Classes */
.rf-animate-in       { animation: rf-slide-up 0.25s ease-out both; }
.rf-animate-down     { animation: rf-slide-down 0.25s ease-out both; }
.rf-animate-right    { animation: rf-slide-in-right 0.25s ease-out both; }
.rf-animate-scale    { animation: rf-scale-in 0.2s ease-out both; }

/* Hover Lift Effect */
.rf-hover-lift {
  transition: transform var(--rf-transition-normal), box-shadow var(--rf-transition-normal);
}

.rf-hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* Focus Ring (accessibility) */
.rf-focus-ring:focus-visible {
  outline: 2px solid var(--rf-primary);
  outline-offset: 2px;
}

/* Staggered List Animation (spring-based) */
.rf-stagger > * { animation: rf-slide-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.rf-stagger > *:nth-child(1)  { animation-delay: 0.00s; }
.rf-stagger > *:nth-child(2)  { animation-delay: 0.04s; }
.rf-stagger > *:nth-child(3)  { animation-delay: 0.08s; }
.rf-stagger > *:nth-child(4)  { animation-delay: 0.12s; }
.rf-stagger > *:nth-child(5)  { animation-delay: 0.16s; }
.rf-stagger > *:nth-child(6)  { animation-delay: 0.20s; }
.rf-stagger > *:nth-child(7)  { animation-delay: 0.24s; }
.rf-stagger > *:nth-child(8)  { animation-delay: 0.28s; }
.rf-stagger > *:nth-child(9)  { animation-delay: 0.32s; }
.rf-stagger > *:nth-child(10) { animation-delay: 0.36s; }

/* KPI Row Stagger (spring cascade) */
.rf-kpi-row > * { animation: rf-slide-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.rf-kpi-row > *:nth-child(1) { animation-delay: 0.00s; }
.rf-kpi-row > *:nth-child(2) { animation-delay: 0.06s; }
.rf-kpi-row > *:nth-child(3) { animation-delay: 0.12s; }
.rf-kpi-row > *:nth-child(4) { animation-delay: 0.18s; }
.rf-kpi-row > *:nth-child(5) { animation-delay: 0.24s; }
.rf-kpi-row > *:nth-child(6) { animation-delay: 0.30s; }

/* Glow Pulse Animation */
@keyframes rf-glow-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(var(--rf-primary-rgb), 0.2); }
  50%      { box-shadow: 0 0 16px rgba(var(--rf-primary-rgb), 0.35); }
}

.rf-glow-pulse {
  animation: rf-glow-pulse 2s ease-in-out infinite;
}

/* Reduced Motion Preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================================================
   DARK MODE: New sections overrides
   ======================================================================== */

[data-rf-dark="true"] .rf-confirm-dialog {
  background: var(--rf-bg-card);
}

[data-rf-dark="true"] .rf-search-bar {
  background: var(--rf-input-bg);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-rf-dark="true"] .rf-search-bar input {
  color: var(--rf-text-primary);
}

[data-rf-dark="true"] .rf-filter-pill {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--rf-text-secondary);
}

[data-rf-dark="true"] .rf-filter-pill:hover,
[data-rf-dark="true"] .rf-filter-pill.active {
  background: rgba(var(--rf-primary-rgb), 0.15);
  border-color: var(--rf-primary);
  color: var(--rf-primary-light);
}

[data-rf-dark="true"] .rf-kpi-card {
  border-color: rgba(255, 255, 255, 0.06);
}

[data-rf-dark="true"] .rf-border-b,
[data-rf-dark="true"] .rf-border-t {
  border-color: rgba(255, 255, 255, 0.08);
}

/* ========================================================================
   SECTION 22: MOBILE RESPONSIVE SYSTEM
   ======================================================================== */

/* --- Global: Responsive Typography (clamp-based scaling) --- */
@media (max-width: 1024px) {
  :root {
    --rf-font-size-3xl: clamp(22px, 4vw, 28px);
    --rf-font-size-4xl: clamp(26px, 5vw, 32px);
  }
}

/* ========================================================================
   ACCESSIBILITY: Focus Management & Skip Navigation
   ======================================================================== */

/* --- Skip-to-content link (hidden until focused via Tab) --- */
.rf-skip-link {
  position: fixed;
  top: -100%;
  left: 16px;
  z-index: 100000;
  padding: 12px 24px;
  background: var(--rf-primary, #8b1a3a);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--rf-font-family, 'Inter', sans-serif);
  text-decoration: none;
  border-radius: 0 0 var(--rf-radius-md, 8px) var(--rf-radius-md, 8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: top 0.2s ease, opacity 0.2s ease;
}

.rf-skip-link:focus {
  top: 0;
  opacity: 1;
  outline: 3px solid var(--rf-primary-light, #c94b6d);
  outline-offset: 2px;
}

/* --- Global: Focus visible for accessibility (keyboard users) --- */
*:focus-visible {
  outline: 2px solid var(--rf-primary);
  outline-offset: 2px;
}

/* Enhanced focus rings for specific interactive elements */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
select:focus-visible,
[tabindex]:focus-visible:not([tabindex="-1"]) {
  outline: 2px solid var(--rf-primary);
  outline-offset: 2px;
  border-radius: var(--rf-radius-sm, 4px);
}

/* Sidebar nav links get a subtle inset focus ring */
.rf-sidebar-link:focus-visible {
  outline: 2px solid var(--rf-primary-light, #c94b6d);
  outline-offset: -2px;
  border-radius: var(--rf-radius-sm, 6px);
}

/* Disable focus outline for mouse/touch users */
*:focus:not(:focus-visible) {
  outline: none;
}

/* ========================================================================
   SECTION 23: FUTURISTIC VISUAL EFFECTS
   ======================================================================== */

/* --- 23.1 Gradient Mesh Body Background --- */
body.rf-shell-body::before,
body.rf-shell-body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
}

body.rf-shell-body::before {
  width: 600px;
  height: 600px;
  top: -10%;
  right: -5%;
  background: radial-gradient(circle, rgba(var(--rf-primary-rgb), 0.05) 0%, transparent 70%);
}

body.rf-shell-body::after {
  width: 500px;
  height: 500px;
  bottom: -10%;
  left: 20%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.03) 0%, transparent 70%);
}

[data-rf-dark="true"] body.rf-shell-body::before {
  background: radial-gradient(circle, rgba(var(--rf-primary-rgb), 0.15) 0%, transparent 70%);
}

[data-rf-dark="true"] body.rf-shell-body::after {
  background: radial-gradient(circle, rgba(59, 130, 246, 0.08) 0%, transparent 70%);
}

/* --- 23.2 Gradient Text on Page Titles --- */
.rf-page-title {
  background: linear-gradient(135deg, var(--rf-primary), var(--rf-primary-light));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-rf-dark="true"] .rf-page-title {
  background: linear-gradient(135deg, var(--rf-primary-light), #e06080, var(--rf-primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* --- 23.3 Enhanced Glassmorphism --- */
.rf-page-container {
  backdrop-filter: blur(12px) brightness(1.05) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) brightness(1.05) saturate(1.2);
}

.rf-table th {
  backdrop-filter: blur(12px) brightness(1.05) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) brightness(1.05) saturate(1.2);
}

.rf-modal {
  backdrop-filter: blur(16px) brightness(1.05) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) brightness(1.05) saturate(1.2);
}

/* --- 23.4 Animated Scan Line on Active Elements --- */
@keyframes rf-scan-line {
  0%   { left: -100%; }
  100% { left: 100%; }
}

.rf-sidebar-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: rf-scan-line 3s ease-in-out infinite;
}

.rf-tab.active {
  position: relative;
  overflow: hidden;
}

.rf-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -100%;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(var(--rf-primary-rgb), 0.5), transparent);
  animation: rf-scan-line 3s ease-in-out infinite;
}

[data-rf-dark="true"] .rf-sidebar-link.active::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.9), transparent);
}

[data-rf-dark="true"] .rf-tab.active::after {
  background: linear-gradient(90deg, transparent, rgba(var(--rf-primary-rgb), 0.8), transparent);
}

/* --- 23.5 Neon Focus Glow on Inputs --- */
.rf-input:focus,
.rf-select:focus,
.rf-textarea:focus {
  box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.15),
              0 0 12px rgba(var(--rf-primary-rgb), 0.1),
              0 0 24px rgba(var(--rf-primary-rgb), 0.05);
}

@keyframes rf-neon-input-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.25), 0 0 16px rgba(var(--rf-primary-rgb), 0.2), 0 0 32px rgba(var(--rf-primary-rgb), 0.1); }
  50%      { box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.35), 0 0 22px rgba(var(--rf-primary-rgb), 0.3), 0 0 40px rgba(var(--rf-primary-rgb), 0.15); }
}

[data-rf-dark="true"] .rf-input:focus,
[data-rf-dark="true"] .rf-select:focus,
[data-rf-dark="true"] .rf-textarea:focus {
  box-shadow: 0 0 0 3px rgba(var(--rf-primary-rgb), 0.25),
              0 0 16px rgba(var(--rf-primary-rgb), 0.2),
              0 0 32px rgba(var(--rf-primary-rgb), 0.1);
  animation: rf-neon-input-pulse 2s ease-in-out infinite;
}

/* --- 23.6 KPI Hover Glow Aura --- */
@keyframes rf-neon-pulse {
  0%, 100% { box-shadow: var(--rf-shadow-card-hover), 0 0 20px rgba(var(--rf-primary-rgb), 0.1); }
  50%      { box-shadow: var(--rf-shadow-card-hover), 0 0 30px rgba(var(--rf-primary-rgb), 0.2); }
}

.rf-kpi-card:hover {
  animation: rf-neon-pulse 2s ease-in-out infinite;
}

@keyframes rf-neon-pulse-dark {
  0%, 100% { box-shadow: var(--rf-shadow-card-hover), 0 0 25px rgba(var(--rf-primary-rgb), 0.2); }
  50%      { box-shadow: var(--rf-shadow-card-hover), 0 0 40px rgba(var(--rf-primary-rgb), 0.35); }
}

[data-rf-dark="true"] .rf-kpi-card:hover {
  animation: rf-neon-pulse-dark 2s ease-in-out infinite;
}

/* --- 23.7 Badge Bounce Animation --- */
@keyframes rf-badge-bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.3); }
  60%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.rf-badge-updated {
  animation: rf-badge-bounce 0.4s var(--rf-btn-spring) forwards;
}

/* ========================================================================
   SECTION 24: HOVER-EXPAND SIDEBAR
   ======================================================================== */

/* Text labels hidden by default (dock mode) */
.rf-sidebar-link-text,
.rf-sidebar-footer-text,
.rf-sidebar-user-name-text {
  display: none;
}

/* Sidebar transition for expand/collapse */
.rf-nav-sidebar {
  transition: width 0.3s var(--rf-btn-spring), transform var(--rf-transition-slow);
}

/* --- Expanded state --- */
.rf-sidebar-expanded {
  width: 200px !important;
  box-shadow: 4px 0 30px rgba(0, 0, 0, 0.3), 8px 0 60px rgba(0, 0, 0, 0.15);
}

/* Nav links: icon + text layout */
.rf-sidebar-expanded .rf-sidebar-link {
  width: 100%;
  justify-content: flex-start;
  padding: 0 12px;
  gap: 10px;
  font-size: var(--rf-font-size-sm);
  border-radius: 10px;
}

/* Text labels visible */
.rf-sidebar-expanded .rf-sidebar-link-text {
  display: inline;
  opacity: 1;
  color: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.2s ease 0.1s;
}

/* Section titles visible */
.rf-sidebar-expanded .rf-sidebar-section-title {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--rf-text-sidebar-section);
  padding: 8px 12px 4px;
}

/* Section + nav alignment */
.rf-sidebar-expanded .rf-sidebar-section {
  align-items: stretch;
  width: 100%;
}

.rf-sidebar-expanded .rf-sidebar-nav {
  align-items: stretch;
}

/* Dock dividers span full width */
.rf-sidebar-expanded .rf-dock-divider {
  width: 100%;
}

/* Nav scroll alignment */
.rf-sidebar-expanded .rf-sidebar-nav-scroll {
  align-items: stretch;
  padding: 4px 8px;
}

/* Active indicator: left accent bar instead of bottom dot */
.rf-sidebar-expanded .rf-sidebar-link.active::before {
  bottom: auto;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 0 3px 3px 0;
}

/* Disable magnification in expanded mode */
.rf-sidebar-expanded .rf-sidebar-link {
  transform: none !important;
}

/* Hide tooltips when expanded */
body.rf-sidebar-is-expanded .rf-dock-tooltip {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Footer adjustments */
.rf-sidebar-expanded .rf-sidebar-footer {
  align-items: stretch;
  padding: 8px 8px 12px;
}

.rf-sidebar-expanded .rf-sidebar-footer .rf-sidebar-link {
  width: 100%;
}

.rf-sidebar-expanded .rf-sidebar-user {
  justify-content: flex-start;
  gap: 10px;
  padding: 4px 12px;
}

.rf-sidebar-expanded .rf-sidebar-logout {
  width: 100%;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 12px;
  font-size: var(--rf-font-size-sm);
}

/* Footer text labels visible when expanded */
.rf-sidebar-expanded .rf-sidebar-footer-text {
  display: inline;
  color: inherit;
  font-size: 13px;
  font-weight: 500;
}

.rf-sidebar-expanded .rf-sidebar-user-name-text {
  display: inline;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  font-weight: 500;
}

/* Mobile: disable hover-expand entirely */
@media (max-width: 1024px) {
  .rf-sidebar-expanded {
    width: var(--rf-sidebar-width) !important;
  }
  .rf-sidebar-expanded .rf-sidebar-link-text,
  .rf-sidebar-expanded .rf-sidebar-section-title,
  .rf-sidebar-expanded .rf-sidebar-footer-text,
  .rf-sidebar-expanded .rf-sidebar-user-name-text {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rf-skip-link {
    transition: none;
  }
}

/* --- Tablet (≤768px) --- */
@media (max-width: 768px) {
  .rf-hide-mobile { display: none !important; }
  .rf-show-mobile { display: block !important; }
  .rf-full-mobile { width: 100% !important; max-width: 100% !important; }

  .rf-modal-lg,
  .rf-modal-xl {
    max-width: calc(100vw - 32px);
  }

  .rf-slide-panel {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* KPI cards: 2 columns on tablet */
  .rf-kpi-row {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--rf-space-md);
  }

  /* Utility grids collapse */
  .rf-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .rf-grid-4 { grid-template-columns: repeat(2, 1fr); }

  /* Card headers stack */
  .rf-card-header {
    flex-wrap: wrap;
    padding: 16px;
  }

  .rf-card-body {
    padding: 16px;
  }

  /* Page title smaller */
  .rf-page-title {
    font-size: clamp(20px, 4vw, 28px);
  }

  /* Filter bars wrap better */
  .rf-filter-bar {
    gap: var(--rf-space-sm);
  }

  .rf-search-bar {
    min-width: 0;
    flex: 1 1 200px;
  }

  /* Page header stacks on mobile */
  .rf-page-header {
    gap: var(--rf-space-md);
  }

  .rf-page-actions {
    width: 100%;
  }

  /* Tabs scroll horizontally on tablet */
  .rf-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .rf-tabs::-webkit-scrollbar {
    display: none;
  }

  /* Table responsive wrapper */
  .rf-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px;
  }

  .rf-table-wrap .rf-table {
    min-width: 600px;
  }

  /* Confirm dialog narrower */
  .rf-confirm-dialog {
    padding: 20px;
  }
}

/* --- Phone (≤480px) --- */
@media (max-width: 480px) {
  .rf-main-content {
    padding: 8px;
    padding-top: 56px;
  }

  .rf-page-container {
    padding: 14px;
    border-radius: 16px;
  }

  .rf-modal {
    max-width: calc(100vw - 16px);
    max-height: 90vh;
    margin: 8px;
    border-radius: var(--rf-radius-md);
  }

  .rf-modal-lg,
  .rf-modal-xl {
    max-width: calc(100vw - 16px);
  }

  .rf-modal-overlay {
    padding: 8px;
    align-items: flex-end;
  }

  .rf-modal-header {
    padding: 16px 16px 0;
  }

  .rf-modal-body {
    padding: 16px;
  }

  .rf-modal-footer {
    padding: 0 16px 16px;
    flex-wrap: wrap;
  }

  .rf-modal-footer .rf-btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .rf-modal-close {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  /* KPI cards: single column on phone */
  .rf-kpi-row {
    grid-template-columns: 1fr;
    gap: var(--rf-space-sm);
  }

  .rf-kpi-card {
    padding: 14px;
  }

  .rf-kpi-value {
    font-size: var(--rf-font-size-2xl);
  }

  /* Utility grids all single column */
  .rf-grid-2,
  .rf-grid-3,
  .rf-grid-4 {
    grid-template-columns: 1fr;
  }

  .rf-table th,
  .rf-table td {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* Wider table scroll hint */
  .rf-table-wrap {
    position: relative;
  }

  .rf-table-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
    pointer-events: none;
    z-index: 1;
  }

  [data-rf-dark="true"] .rf-table-wrap::after {
    background: linear-gradient(to left, rgba(0,0,0,0.4), transparent);
  }

  .rf-breadcrumbs {
    font-size: 11px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .rf-breadcrumbs::-webkit-scrollbar {
    display: none;
  }

  /* Buttons full-width on phone */
  .rf-btn-xl {
    width: 100%;
  }

  /* Card adjustments */
  .rf-card-header {
    padding: 14px;
    gap: 8px;
  }

  .rf-card-body {
    padding: 14px;
  }

  .rf-card-footer {
    padding: 12px 14px;
    flex-wrap: wrap;
  }

  /* Section title smaller */
  .rf-section-title {
    font-size: var(--rf-font-size-md);
  }

  /* Confirm dialog full-width on phone */
  .rf-confirm-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .rf-confirm-dialog {
    max-width: 100%;
    padding: 16px;
    border-radius: var(--rf-radius-md);
  }

  .rf-confirm-actions {
    flex-direction: column-reverse;
    gap: var(--rf-space-sm);
  }

  .rf-confirm-actions .rf-btn {
    width: 100%;
  }

  /* Toast positioning — bottom center on phone */
  .rf-toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }

  .rf-toast {
    font-size: 13px;
    padding: 12px 14px;
  }

  /* Page header stacked on phone */
  .rf-page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--rf-space-sm);
  }

  .rf-page-actions {
    width: 100%;
    justify-content: stretch;
  }

  .rf-page-actions .rf-btn {
    flex: 1;
  }

  /* Search bar full width */
  .rf-search-bar {
    width: 100%;
    min-width: 0;
  }

  /* Filter pills scroll */
  .rf-filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }

  .rf-filter-bar::-webkit-scrollbar {
    display: none;
  }

  /* Sidebar toggle larger touch target */
  .rf-sidebar-toggle {
    width: 48px;
    height: 48px;
    font-size: 22px;
  }
}

/* --- Small phone (≤360px) --- */
@media (max-width: 360px) {
  .rf-main-content {
    padding: 6px;
    padding-top: 52px;
  }

  .rf-page-container {
    padding: 10px;
    border-radius: 12px;
  }

  .rf-page-title {
    font-size: 18px;
  }

  .rf-btn {
    padding: 8px 14px;
    font-size: 12px;
  }

  .rf-btn-lg {
    padding: 10px 20px;
    font-size: 13px;
  }
}

/* --- Touch device overrides --- */
@media (pointer: coarse) {
  .rf-btn {
    min-height: 44px;
  }

  .rf-btn-sm {
    min-height: 40px;
  }

  .rf-input,
  .rf-select,
  .rf-textarea {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .rf-input-sm {
    min-height: 40px;
  }

  .rf-sidebar-link {
    min-height: 44px;
  }

  /* Better tab touch targets */
  .rf-tab {
    min-height: 44px;
    padding: 10px 16px;
  }

  /* Better filter pill touch targets */
  .rf-filter-pill {
    min-height: 36px;
    padding: 8px 14px;
  }

  /* Toast close button bigger */
  .rf-toast-close {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  /* Modal close button bigger */
  .rf-modal-close {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  /* Checkbox/radio click area */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
  }
}

/* --- Responsive utility classes --- */
.rf-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Table responsive wrapper */
.rf-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 769px) {
  .rf-show-mobile { display: none !important; }
}

@media (min-width: 481px) {
  .rf-show-phone { display: none !important; }
}

@media (max-width: 480px) {
  .rf-show-phone { display: block !important; }
  .rf-hide-phone { display: none !important; }
}

/* --- Safe area support for notch devices (iPhone X+, modern Android) --- */
/* Required: viewport-fit=cover in viewport meta (set by rustica-shell.js) */
@supports (padding-top: env(safe-area-inset-top)) {
  /* ── Body: extend background behind all safe areas ── */
  body.rf-shell-body {
    /* Use 100dvh + safe areas to fill behind notch and home indicator */
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* ── Sidebar: account for top notch + bottom home indicator ── */
  .rf-nav-sidebar {
    padding-top: calc(0px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* ── Hamburger toggle: push below the status bar / notch ── */
  @media (max-width: 1024px) {
    .rf-sidebar-toggle {
      top: calc(16px + env(safe-area-inset-top));
    }

    /* Main content: push below status bar + leave room at bottom for home indicator */
    .rf-main-content,
    .main-content.rf-main-content {
      padding-top: calc(64px + env(safe-area-inset-top));
      padding-left: max(16px, env(safe-area-inset-left));
      padding-right: max(16px, env(safe-area-inset-right));
      padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
  }

  @media (max-width: 768px) {
    .rf-main-content,
    .main-content.rf-main-content {
      padding-top: calc(60px + env(safe-area-inset-top));
      padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
  }

  /* ── Toast container: above home indicator ── */
  .rf-toast-container {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ── Modal overlay: above home indicator ── */
  .rf-modal-overlay {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ── PWA install banner: above home indicator ── */
  .rf-install-banner {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* --- Landscape phone --- */
@media (max-height: 500px) and (orientation: landscape) {
  .rf-modal {
    max-height: 95vh;
  }

  .rf-modal-overlay {
    align-items: center;
    padding: 8px;
  }

  .rf-nav-sidebar {
    padding: 12px 16px;
  }

  .rf-sidebar-logo {
    margin-bottom: 12px;
  }

  .rf-sidebar-section {
    margin-bottom: 8px;
  }

  .rf-sidebar-link {
    padding: 8px 14px;
  }
}

/* --- Offline indicator --- */
.rf-offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--rf-z-toast);
  background: var(--rf-warning);
  color: #000;
  text-align: center;
  padding: 6px 16px;
  font-size: var(--rf-font-size-sm);
  font-weight: 600;
  display: none;
  animation: rf-slide-down 0.3s ease-out;
}

.rf-offline-banner.rf-active {
  display: block;
}

.rf-offline-banner + .rf-main-content {
  padding-top: calc(var(--rf-space-2xl) + 36px);
}

/* ========================================================================
   SECTION 23: UNDERLINE TAB VARIANT
   ======================================================================== */

/* Border-bottom tab style (used by production departments, CRM, QC) */
.rf-tabs-underline {
  display: flex;
  gap: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.rf-tabs-underline .rf-tab {
  padding: 6px 12px;
  border-radius: 0;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--rf-text-secondary);
  font-size: var(--rf-font-size-xs);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--rf-transition-fast);
  white-space: nowrap;
  box-shadow: none;
}

.rf-tabs-underline .rf-tab:hover:not(.active) {
  color: var(--rf-text-primary);
  background: transparent;
}

.rf-tabs-underline .rf-tab.active {
  color: var(--rf-primary);
  border-bottom-color: var(--rf-primary);
  background: transparent;
  box-shadow: none;
}

[data-rf-dark="true"] .rf-tabs-underline .rf-tab.active {
  color: var(--rf-primary-light);
  border-bottom-color: var(--rf-primary-light);
}

/* ========================================================================
   SECTION 24: APP BAR (fullscreen module top bar)
   ======================================================================== */

/* Standard top bar for fullscreen app pages (departments, IT, HR, CS) */
.rf-app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--rf-bg-card);
  border-bottom: 1px solid var(--rf-border-light);
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}

.rf-app-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.rf-app-bar-title {
  font-size: var(--rf-font-size-lg);
  font-weight: 700;
  color: var(--rf-text-primary);
  white-space: nowrap;
}

.rf-app-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

[data-rf-dark="true"] .rf-app-bar {
  background: var(--rf-bg-card);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

@media (max-width: 768px) {
  .rf-app-bar {
    padding: 6px 10px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .rf-app-bar-title {
    font-size: var(--rf-font-size-base);
  }

  .rf-app-bar-left {
    gap: 8px;
    flex: 1;
    min-width: 0;
  }

  .rf-app-bar .rf-tabs-underline {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 1;
    min-width: 0;
  }

  .rf-app-bar .rf-tabs-underline::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 480px) {
  .rf-app-bar {
    padding: 6px 8px;
  }

  .rf-app-bar-title {
    font-size: var(--rf-font-size-sm);
  }
}

/* ========================================================================
   SECTION 25: WARNING BUTTON VARIANT
   ======================================================================== */

.rf-btn-warning {
  background: linear-gradient(135deg, var(--rf-warning), var(--rf-warning-light));
  color: #1a1a00;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2),
              0 1px 2px rgba(0, 0, 0, 0.06);
}

.rf-btn-warning:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    0 4px 16px rgba(245, 158, 11, 0.3),
    0 8px 32px rgba(245, 158, 11, 0.15),
    0 0 0 1px rgba(245, 158, 11, 0.15),
    0 0 20px rgba(245, 158, 11, 0.2);
}

.rf-btn-warning:active:not(:disabled) {
  box-shadow:
    0 1px 4px rgba(245, 158, 11, 0.3),
    0 0 12px rgba(245, 158, 11, 0.15);
}

/* ========================================================================
   SECTION 26: MODAL RESPONSIVE SAFETY
   ======================================================================== */

/* Ensure modals never overflow viewport on any device */
.rf-modal { max-width: min(560px, calc(100vw - 32px)); }
.rf-modal-sm { max-width: min(400px, calc(100vw - 32px)); }
.rf-modal-lg { max-width: min(720px, calc(100vw - 32px)); }
.rf-modal-xl { max-width: min(960px, calc(100vw - 32px)); }

/* ========================================================================
   SECTION 27: FULLSCREEN APP LAYOUT
   ======================================================================== */

/* For pages that fill the viewport (production depts, CS, etc.) */
.rf-fullscreen-app .rf-main-content,
.rf-fullscreen-app .main-content.rf-main-content,
.rf-fullscreen-app .main-content {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: var(--rf-sidebar-width, 70px);
  margin: 0 !important;
  padding: 0 !important;
  width: auto !important;
  height: 100vh !important;           /* fallback */
  height: 100svh !important;          /* modern mobile-safe viewport */
  max-height: 100vh !important;       /* fallback */
  max-height: 100svh !important;      /* modern mobile-safe viewport */
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.rf-fullscreen-app .rf-breadcrumbs {
  display: none !important;
}

@media (max-width: 1024px) {
  .rf-fullscreen-app .rf-main-content,
  .rf-fullscreen-app .main-content.rf-main-content,
  .rf-fullscreen-app .main-content {
    left: 0 !important;
    padding-top: 0 !important;
  }

  /* Sidebar-custom pages (messages, email) - minimal padding for toggle button */
  .rf-sidebar-custom-content {
    padding: 0 !important;
    padding-top: 56px !important;
  }
}

@media (max-width: 768px) {
  .rf-sidebar-custom-content {
    padding: 0 !important;
    padding-top: 52px !important;
  }
}

/* Dock sidebar adjustment for fullscreen apps */
.rf-fullscreen-app .rf-main-content,
.rf-fullscreen-app .main-content {
  left: var(--rf-sidebar-width);
}

/* ========================================================================
   SECTION 28: GLOBAL SEARCH (Cmd+K)
   ======================================================================== */

.rf-search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  padding-top: 12vh;
}

.rf-search-modal {
  background: var(--rf-bg-card);
  border-radius: var(--rf-radius-lg);
  width: 620px;
  max-width: 95vw;
  max-height: 65vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  border: 1px solid var(--rf-border-light);
  animation: rf-search-in 0.15s ease-out;
}

@keyframes rf-search-in {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.rf-search-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rf-border-light);
}

.rf-search-input-row input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  font-family: var(--rf-font-family);
  color: var(--rf-text-primary);
}

.rf-search-input-row input::placeholder {
  color: var(--rf-text-tertiary);
}

.rf-search-kbd {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--rf-text-tertiary);
  font-family: var(--rf-font-family);
  flex-shrink: 0;
}

[data-rf-dark="true"] .rf-search-kbd {
  background: rgba(255, 255, 255, 0.1);
}

.rf-search-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.rf-search-placeholder {
  text-align: center;
  padding: 40px 20px;
  color: var(--rf-text-tertiary);
  font-size: var(--rf-font-size-sm);
}

.rf-search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.1s;
}

.rf-search-item:hover,
.rf-search-item.rf-search-selected {
  background: rgba(var(--rf-primary-rgb), 0.06);
}

.rf-search-item-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.rf-search-item-text {
  flex: 1;
  min-width: 0;
}

.rf-search-item-name {
  font-weight: 600;
  font-size: var(--rf-font-size-sm);
  color: var(--rf-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rf-search-item-meta {
  font-size: var(--rf-font-size-xs);
  color: var(--rf-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rf-search-type-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--rf-radius-pill);
  color: var(--rf-text-secondary);
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.rf-search-footer {
  padding: 8px 20px;
  border-top: 1px solid var(--rf-border-light);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  color: var(--rf-text-tertiary);
}

.rf-search-footer kbd {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.06);
  margin-right: 3px;
  font-family: var(--rf-font-family);
}

[data-rf-dark="true"] .rf-search-footer kbd {
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 768px) {
  .rf-search-overlay {
    padding-top: 5vh;
  }

  .rf-search-modal {
    max-height: 80vh;
    border-radius: var(--rf-radius-lg) var(--rf-radius-lg) 0 0;
    margin-top: auto;
  }

  .rf-search-item {
    padding: 12px 16px;
  }
}

/* ========================================================================
   SECTION 29: PRINT STYLES
   ======================================================================== */

@media print {
  .rf-nav-sidebar,
  .rf-sidebar-toggle,
  .rf-sidebar-overlay,
  .rf-toast-container,
  .rf-breadcrumbs,
  .rf-skip-link {
    display: none !important;
  }

  .rf-main-content {
    margin-left: 0 !important;
    padding: 0 !important;
  }

  body.rf-shell-body {
    display: block;
    background: white !important;
  }

  .rf-install-banner {
    display: none !important;
  }
}

/* ========================================================================
   SECTION: PWA INSTALL BANNER
   ======================================================================== */
.rf-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: var(--rf-bg-primary, #ffffff);
  border-top: 1px solid var(--rf-border-light, #e5e7eb);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: rf-install-slide-up 0.4s ease-out;
}

@keyframes rf-install-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.rf-install-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.rf-install-banner-icon {
  font-size: 1.75rem;
  flex-shrink: 0;
}

.rf-install-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.rf-install-banner-text strong {
  font-size: var(--rf-font-size-sm, 0.875rem);
  font-weight: 700;
  color: var(--rf-text-primary, #1f2937);
}

.rf-install-banner-text span {
  font-size: var(--rf-font-size-xs, 0.75rem);
  color: var(--rf-text-secondary, #6b7280);
  line-height: 1.4;
}

.rf-install-banner-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--rf-text-tertiary, #9ca3af);
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
  line-height: 1;
}
.rf-install-banner-close:hover {
  color: var(--rf-text-primary, #1f2937);
}

/* Dark mode */
[data-rf-dark="true"] .rf-install-banner {
  background: var(--rf-bg-primary, #1f2937);
  border-top-color: var(--rf-border-light, #374151);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}
